From 133cc349377eb9187083ccc22d83caa66b2834bc Mon Sep 17 00:00:00 2001 From: Kien Ngo Date: Fri, 19 Jul 2024 10:57:34 -0400 Subject: [PATCH] Load extensions dynamically (#518) * Update * Update page.tsx * Update tsconfig.json * Update page.tsx * Update page.tsx --- .../v5/extensions/built-in/page.mdx | 18 ---- .../v5/extensions/built-in/page.tsx | 93 +++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 94 insertions(+), 19 deletions(-) delete mode 100644 src/app/typescript/v5/extensions/built-in/page.mdx create mode 100644 src/app/typescript/v5/extensions/built-in/page.tsx diff --git a/src/app/typescript/v5/extensions/built-in/page.mdx b/src/app/typescript/v5/extensions/built-in/page.mdx deleted file mode 100644 index a9b9386b..00000000 --- a/src/app/typescript/v5/extensions/built-in/page.mdx +++ /dev/null @@ -1,18 +0,0 @@ -# Built-in extensions for common standards - -The SDK comes packed with a set of built-in extensions for common standards. These extensions are designed to make it easy to interact with popular contracts and protocols. They are available as part of the SDK and can be used in your application without any additional setup. - -| Standard | Import Path | Description | -| ---------- | ---------------------------------------------------------------------------------- | -------------------------------------- | -| Common | [`thirdweb/extensions/common`](/references/typescript/v5/functions#common) | Common contract extensions | -| ERC20 | [`thirdweb/extensions/erc20`](/references/typescript/v5/functions#erc20) | ERC20 token standard extensions | -| ERC721 | [`thirdweb/extensions/erc721`](/references/typescript/v5/functions#erc721) | ERC721 token standard extensions | -| ERC1155 | [`thirdweb/extensions/erc1155`](/references/typescript/v5/functions#erc1155) | ERC1155 token standard extensions | -| ERC4337 | [`thirdweb/extensions/erc4337`](/references/typescript/v5/functions#erc4337) | ERC4337 account abstraction extensions | -| ERC4626 | [`thirdweb/extensions/erc4626`](/references/typescript/v5/functions#erc4626) | ERC4626 Tokenized Vaults extensions | -| ENS | [`thirdweb/extensions/ens`](/references/typescript/v5/functions#ens) | ENS extensions | -| Uniswap | [`thirdweb/extensions/uniswap`](/references/typescript/v5/functions#uniswap) | Uniswap extensions | -| Farcaster | [`thirdweb/extensions/farcaster`](/references/typescript/v5/functions#farcaster) | Farcaster protocol extensions | -| Multicall3 | [`thirdweb/extensions/multicall3`](/references/typescript/v5/functions#multicall3) | Multicall3 extensions | - -More extensions are being added regularly. Anyone can [create an extension](/typescript/v5/extensions/create) and contribute it back to the repository. You can also [generate extensions](/typescript/v5/extensions/generate) for any deployed contract. diff --git a/src/app/typescript/v5/extensions/built-in/page.tsx b/src/app/typescript/v5/extensions/built-in/page.tsx new file mode 100644 index 00000000..952b6ef5 --- /dev/null +++ b/src/app/typescript/v5/extensions/built-in/page.tsx @@ -0,0 +1,93 @@ +import { withCache } from "../../../../../lib/withCache"; +import { fetchJSON } from "@/lib/fetchJSON"; +import { TBody, Table, Td, Th, Tr } from "@/components/Document/Table"; +import Link from "next/link"; + +export default async function ExtensionPage() { + const URL = + "https://raw.githubusercontent.com/thirdweb-dev/js/main/packages/thirdweb/typedoc/documentation.json.gz"; + const doc = await withCache(() => fetchJSON(URL), { + cacheKey: URL, + // cache for 24hrs - we don't really add new extensions everyday - plus this json file is large + cacheTime: 24 * 60 * 60 * 1000, + }); + const toExclude = [""]; + const extensions = [ + ...new Set( + doc.children + .filter((item: { name: string; }) => item.name.startsWith("extensions/")) + .map((item: { name: string; }) => item.name.split("/")[1]), + ), + ].filter((name) => !toExclude.includes(name as string)) as string[]; + + const overrides: Record = { + common: { + name: "Common", + description: "Common contract extensions", + }, + erc20: { description: "ERC20 token standard extensions" }, + erc721: { description: "ERC721 token standard extensions" }, + erc1155: { description: "ERC1155 token standard extensions" }, + erc4337: { description: "ERC4337 account abstraction extensions" }, + erc4626: { description: "ERC4626 Tokenized Vaults extensions" }, + farcaster: { description: "Farcaster protocol extensions" }, + lens: { description: "Lens protocol extensions" }, + }; + return ( + <> +

+ Built-in extensions for common standards{" "} +

+
+ The SDK comes packed with a set of built-in extensions for common + standards. These extensions are designed to make it easy to interact + with popular contracts and protocols. They are available as part of the + SDK and can be used in your application without any additional setup. +
+ + + + + + + + + {extensions.map((item) => { + return ( + + + + + + ); + })} + +
StandardImport PathDescription
{overrides[item]?.name ?? item.toUpperCase()} + + thirdweb/extensions/{item} + + + {overrides[item]?.description ?? + `${item.toUpperCase()} extensions`} +
+ More extensions are being added regularly. Anyone can{" "} + + create an extension + {" "} + and contribute it back to the repository. You can also{" "} + + generate extensions + {" "} + for any deployed contract. + + ); +} diff --git a/tsconfig.json b/tsconfig.json index 98247dd3..bfc1a9f5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2020", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true,