thirdweb 5.54.0 → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exports/extensions/common.js +3 -1
- package/dist/cjs/exports/extensions/common.js.map +1 -1
- package/dist/cjs/exports/extensions/ens.js +3 -1
- package/dist/cjs/exports/extensions/ens.js.map +1 -1
- package/dist/cjs/pay/buyWithFiat/getQuote.js +1 -0
- package/dist/cjs/pay/buyWithFiat/getQuote.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/core/utils/walletIcon.js +5 -1
- package/dist/cjs/react/core/utils/walletIcon.js.map +1 -1
- package/dist/cjs/react/native/ui/components/WalletImage.js +2 -0
- package/dist/cjs/react/native/ui/components/WalletImage.js.map +1 -1
- package/dist/cjs/react/native/ui/connect/InAppWalletUI.js +1 -0
- package/dist/cjs/react/native/ui/connect/InAppWalletUI.js.map +1 -1
- package/dist/cjs/react/native/ui/icons/svgs.js +5 -1
- package/dist/cjs/react/native/ui/icons/svgs.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +2 -2
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +3 -2
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.js +3 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js +3 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/WalletSwitcherConnectionScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/PayEmbed.js +1 -1
- package/dist/cjs/react/web/ui/PayEmbed.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -0
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/oauthSignIn.js +1 -0
- package/dist/cjs/react/web/wallets/shared/oauthSignIn.js.map +1 -1
- package/dist/cjs/utils/ens/avatar.js +25 -59
- package/dist/cjs/utils/ens/avatar.js.map +1 -1
- package/dist/cjs/utils/nft/parseNft.js +76 -0
- package/dist/cjs/utils/nft/parseNft.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/types.js +1 -0
- package/dist/cjs/wallets/in-app/core/authentication/types.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/native-connector.js +2 -0
- package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/ecosystem.js +2 -0
- package/dist/cjs/wallets/in-app/web/ecosystem.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +1 -0
- package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +2 -0
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/cjs/wallets/types.js +1 -0
- package/dist/cjs/wallets/types.js.map +1 -1
- package/dist/esm/exports/extensions/common.js +1 -0
- package/dist/esm/exports/extensions/common.js.map +1 -1
- package/dist/esm/exports/extensions/ens.js +1 -0
- package/dist/esm/exports/extensions/ens.js.map +1 -1
- package/dist/esm/pay/buyWithFiat/getQuote.js +1 -0
- package/dist/esm/pay/buyWithFiat/getQuote.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/core/utils/walletIcon.js +4 -0
- package/dist/esm/react/core/utils/walletIcon.js.map +1 -1
- package/dist/esm/react/native/ui/components/WalletImage.js +3 -1
- package/dist/esm/react/native/ui/components/WalletImage.js.map +1 -1
- package/dist/esm/react/native/ui/connect/InAppWalletUI.js +2 -1
- package/dist/esm/react/native/ui/connect/InAppWalletUI.js.map +1 -1
- package/dist/esm/react/native/ui/icons/svgs.js +4 -0
- package/dist/esm/react/native/ui/icons/svgs.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +2 -2
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +3 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.js +3 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js +3 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/WalletSwitcherConnectionScreen.js.map +1 -1
- package/dist/esm/react/web/ui/PayEmbed.js +1 -1
- package/dist/esm/react/web/ui/PayEmbed.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +1 -0
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/oauthSignIn.js +1 -0
- package/dist/esm/react/web/wallets/shared/oauthSignIn.js.map +1 -1
- package/dist/esm/utils/ens/avatar.js +24 -58
- package/dist/esm/utils/ens/avatar.js.map +1 -1
- package/dist/esm/utils/nft/parseNft.js +75 -0
- package/dist/esm/utils/nft/parseNft.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/authentication/types.js +1 -0
- package/dist/esm/wallets/in-app/core/authentication/types.js.map +1 -1
- package/dist/esm/wallets/in-app/native/native-connector.js +2 -0
- package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/esm/wallets/in-app/web/ecosystem.js +2 -0
- package/dist/esm/wallets/in-app/web/ecosystem.js.map +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +1 -0
- package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +2 -0
- package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/esm/wallets/types.js +1 -0
- package/dist/esm/wallets/types.js.map +1 -1
- package/dist/types/exports/extensions/common.d.ts +1 -0
- package/dist/types/exports/extensions/common.d.ts.map +1 -1
- package/dist/types/exports/extensions/ens.d.ts +1 -0
- package/dist/types/exports/extensions/ens.d.ts.map +1 -1
- package/dist/types/pay/buyWithFiat/getQuote.d.ts +7 -0
- package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
- package/dist/types/pay/utils/commonTypes.d.ts +1 -0
- package/dist/types/pay/utils/commonTypes.d.ts.map +1 -1
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +7 -0
- package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +2 -0
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/core/utils/storage.d.ts +1 -1
- package/dist/types/react/core/utils/storage.d.ts.map +1 -1
- package/dist/types/react/core/utils/walletIcon.d.ts +3 -1
- package/dist/types/react/core/utils/walletIcon.d.ts.map +1 -1
- package/dist/types/react/native/ui/components/WalletImage.d.ts.map +1 -1
- package/dist/types/react/native/ui/connect/InAppWalletUI.d.ts.map +1 -1
- package/dist/types/react/native/ui/icons/svgs.d.ts +1 -0
- package/dist/types/react/native/ui/icons/svgs.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/WalletSwitcherConnectionScreen.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/WalletSwitcherConnectionScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/PayEmbed.d.ts +6 -1
- package/dist/types/react/web/ui/PayEmbed.d.ts.map +1 -1
- package/dist/types/react/web/wallets/shared/ConnectWalletSocialOptions.d.ts.map +1 -1
- package/dist/types/react/web/wallets/shared/oauthSignIn.d.ts.map +1 -1
- package/dist/types/utils/ens/avatar.d.ts +25 -4
- package/dist/types/utils/ens/avatar.d.ts.map +1 -1
- package/dist/types/utils/nft/parseNft.d.ts +26 -0
- package/dist/types/utils/nft/parseNft.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/authentication/types.d.ts +1 -0
- package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
- package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/ecosystem.d.ts +2 -0
- package/dist/types/wallets/in-app/web/ecosystem.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +1 -0
- package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
- package/dist/types/wallets/types.d.ts +2 -2
- package/dist/types/wallets/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/exports/extensions/common.ts +1 -0
- package/src/exports/extensions/ens.ts +5 -0
- package/src/pay/buyWithFiat/getQuote.ts +9 -0
- package/src/pay/utils/commonTypes.ts +2 -0
- package/src/react/core/hooks/connection/ConnectButtonProps.ts +8 -0
- package/src/react/core/hooks/transaction/useSendTransaction.ts +2 -0
- package/src/react/core/utils/walletIcon.ts +6 -0
- package/src/react/native/ui/components/WalletImage.tsx +3 -0
- package/src/react/native/ui/connect/InAppWalletUI.tsx +2 -0
- package/src/react/native/ui/icons/svgs.ts +5 -0
- package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +1 -0
- package/src/react/web/ui/ConnectWallet/Details.tsx +4 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +6 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/WalletSwitcherDrawerContent.tsx +21 -17
- package/src/react/web/ui/ConnectWallet/screens/Details/WalletManagerScreen.tsx +17 -15
- package/src/react/web/ui/ConnectWallet/screens/WalletSwitcherConnectionScreen.tsx +2 -0
- package/src/react/web/ui/PayEmbed.tsx +8 -1
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +1 -0
- package/src/react/web/wallets/shared/oauthSignIn.ts +1 -0
- package/src/utils/bytecode/resolveImplementation.test.ts +1 -1
- package/src/utils/ens/avatar.ts +27 -71
- package/src/utils/nft/parseNft.ts +89 -0
- package/src/version.ts +1 -1
- package/src/wallets/in-app/core/authentication/types.ts +1 -0
- package/src/wallets/in-app/native/native-connector.ts +2 -0
- package/src/wallets/in-app/web/ecosystem.ts +2 -0
- package/src/wallets/in-app/web/in-app.ts +1 -0
- package/src/wallets/in-app/web/lib/web-connector.ts +2 -0
- package/src/wallets/types.ts +1 -0
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { ThirdwebClient } from "../../client/client.js";
|
2
2
|
import { getClientFetch } from "../../utils/fetch.js";
|
3
|
+
import type { FiatProvider } from "../utils/commonTypes.js";
|
3
4
|
import { getPayBuyWithFiatQuoteEndpoint } from "../utils/definitions.js";
|
4
5
|
|
5
6
|
/**
|
@@ -82,6 +83,13 @@ export type GetBuyWithFiatQuoteParams = {
|
|
82
83
|
* If erc20, will onramp native token + erc20
|
83
84
|
*/
|
84
85
|
toGasAmountWei?: string;
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Optional parameter to specify the preferred onramp provider.
|
89
|
+
*
|
90
|
+
* By default, we choose a recommended provider based on the location of the user, KYC status, and currency.
|
91
|
+
*/
|
92
|
+
preferredProvider?: FiatProvider;
|
85
93
|
};
|
86
94
|
|
87
95
|
/**
|
@@ -303,6 +311,7 @@ export async function getBuyWithFiatQuote(
|
|
303
311
|
purchaseData: params.purchaseData,
|
304
312
|
fromAddress: params.fromAddress,
|
305
313
|
toGasAmountWei: params.toGasAmountWei,
|
314
|
+
preferredProvider: params.preferredProvider,
|
306
315
|
}),
|
307
316
|
});
|
308
317
|
|
@@ -2,11 +2,13 @@ import type { Chain } from "../../../../chains/types.js";
|
|
2
2
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
3
3
|
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
|
4
4
|
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
|
5
|
+
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
|
5
6
|
import type { PreparedTransaction } from "../../../../transaction/prepare-transaction.js";
|
6
7
|
import type { Prettify } from "../../../../utils/type-utils.js";
|
7
8
|
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
|
8
9
|
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
|
9
10
|
import type { AppMetadata } from "../../../../wallets/types.js";
|
11
|
+
import type { WalletId } from "../../../../wallets/wallet-types.js";
|
10
12
|
import type { NetworkSelectorProps } from "../../../web/ui/ConnectWallet/NetworkSelector.js";
|
11
13
|
import type { WelcomeScreen } from "../../../web/ui/ConnectWallet/screens/types.js";
|
12
14
|
import type { LocaleId } from "../../../web/ui/types.js";
|
@@ -86,6 +88,7 @@ export type PayUIOptions = Prettify<
|
|
86
88
|
prefillSource?: {
|
87
89
|
currency?: "USD" | "CAD" | "GBP" | "EUR" | "JPY";
|
88
90
|
};
|
91
|
+
preferredProvider?: FiatProvider;
|
89
92
|
}
|
90
93
|
| false;
|
91
94
|
|
@@ -310,6 +313,11 @@ export type ConnectButton_detailsModalOptions = {
|
|
310
313
|
* By default the "Buy Funds" button is shown.
|
311
314
|
*/
|
312
315
|
hideBuyFunds?: boolean;
|
316
|
+
|
317
|
+
/**
|
318
|
+
* All wallet IDs included in this array will be hidden from wallet selection when connected.
|
319
|
+
*/
|
320
|
+
hiddenWallets?: WalletId[];
|
313
321
|
};
|
314
322
|
|
315
323
|
/**
|
@@ -3,6 +3,7 @@ import type { Chain } from "../../../../chains/types.js";
|
|
3
3
|
import { getGasPrice } from "../../../../gas/get-gas-price.js";
|
4
4
|
import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
|
5
5
|
import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
|
6
|
+
import type { FiatProvider } from "../../../../pay/utils/commonTypes.js";
|
6
7
|
import { estimateGasCost } from "../../../../transaction/actions/estimate-gas-cost.js";
|
7
8
|
import type { GaslessOptions } from "../../../../transaction/actions/gasless/types.js";
|
8
9
|
import { sendTransaction } from "../../../../transaction/actions/send-transaction.js";
|
@@ -58,6 +59,7 @@ export type SendTransactionPayModalConfig =
|
|
58
59
|
currency?: "USD" | "CAD" | "GBP" | "EUR" | "JPY";
|
59
60
|
};
|
60
61
|
testMode?: boolean;
|
62
|
+
preferredProvider?: FiatProvider;
|
61
63
|
};
|
62
64
|
purchaseData?: object;
|
63
65
|
/**
|
@@ -28,6 +28,9 @@ export const telegramIconUri =
|
|
28
28
|
export const microsoftIconUri =
|
29
29
|
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciICB2aWV3Qm94PSIwIDAgNDggNDgiIHdpZHRoPSI0OHB4IiBoZWlnaHQ9IjQ4cHgiPjxwYXRoIGZpbGw9IiNmZjU3MjIiIGQ9Ik02IDZIMjJWMjJINnoiIHRyYW5zZm9ybT0icm90YXRlKC0xODAgMTQgMTQpIi8+PHBhdGggZmlsbD0iIzRjYWY1MCIgZD0iTTI2IDZINDJWMjJIMjZ6IiB0cmFuc2Zvcm09InJvdGF0ZSgtMTgwIDM0IDE0KSIvPjxwYXRoIGZpbGw9IiNmZmMxMDciIGQ9Ik0yNiAyNkg0MlY0MkgyNnoiIHRyYW5zZm9ybT0icm90YXRlKC0xODAgMzQgMzQpIi8+PHBhdGggZmlsbD0iIzAzYTlmNCIgZD0iTTYgMjZIMjJWNDJINnoiIHRyYW5zZm9ybT0icm90YXRlKC0xODAgMTQgMzQpIi8+PC9zdmc+";
|
30
30
|
|
31
|
+
export const xIcon =
|
32
|
+
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIwIiBoZWlnaHQ9IjMyMCIgdmlld0JveD0iMCAwIDMyMCAzMjAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIzMjAiIGhlaWdodD0iMzIwIiByeD0iMjQiIGZpbGw9ImJsYWNrIi8+CjxwYXRoIGQ9Ik0xNzcuMzE1IDE0NS4zMzVMMjQ1LjA2OCA2N0gyMjkuMDEzTDE3MC4xODIgMTM1LjAxN0wxMjMuMTk1IDY3SDY5TDE0MC4wNTUgMTY5Ljg1NEw2OSAyNTJIODUuMDU2M0wxNDcuMTgzIDE4MC4xNzJMMTk2LjgwNSAyNTJIMjUxTDE3Ny4zMTEgMTQ1LjMzNUgxNzcuMzE1Wk0xNTUuMzIzIDE3MC43NkwxNDguMTI0IDE2MC41MThMOTAuODQxNyA3OS4wMjJIMTE1LjUwM0wxNjEuNzMxIDE0NC43OTJMMTY4LjkzIDE1NS4wMzRMMjI5LjAyIDI0MC41MjVIMjA0LjM1OUwxNTUuMzIzIDE3MC43NjRWMTcwLjc2WiIgZmlsbD0id2hpdGUiLz4KPC9zdmc+Cg==";
|
33
|
+
|
31
34
|
export const emailIcon =
|
32
35
|
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEzLjMzMzUgMi42NjY1SDIuNjY2ODNDMS45MzA0NSAyLjY2NjUgMS4zMzM1IDMuMjYzNDYgMS4zMzM1IDMuOTk5ODRWMTEuOTk5OEMxLjMzMzUgMTIuNzM2MiAxLjkzMDQ1IDEzLjMzMzIgMi42NjY4MyAxMy4zMzMySDEzLjMzMzVDMTQuMDY5OSAxMy4zMzMyIDE0LjY2NjggMTIuNzM2MiAxNC42NjY4IDExLjk5OThWMy45OTk4NEMxNC42NjY4IDMuMjYzNDYgMTQuMDY5OSAyLjY2NjUgMTMuMzMzNSAyLjY2NjVaIiBzdHJva2U9IiMzMzg1RkYiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPgo8cGF0aCBkPSJNMTQuNjY2OCA0LjY2NjVMOC42ODY4MyA4LjQ2NjVDOC40ODEwMSA4LjU5NTQ1IDguMjQzMDQgOC42NjM4NCA4LjAwMDE2IDguNjYzODRDNy43NTcyOCA4LjY2Mzg0IDcuNTE5MzEgOC41OTU0NSA3LjMxMzUgOC40NjY1TDEuMzMzNSA0LjY2NjUiIHN0cm9rZT0iIzMzODVGRiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+Cjwvc3ZnPgo=";
|
33
36
|
|
@@ -49,6 +52,7 @@ export const socialIcons = {
|
|
49
52
|
facebook: facebookIconUri,
|
50
53
|
discord: discordIconUri,
|
51
54
|
line: lineIconUri,
|
55
|
+
x: xIcon,
|
52
56
|
farcaster: farcasterIconUri,
|
53
57
|
telegram: telegramIconUri,
|
54
58
|
};
|
@@ -72,6 +76,8 @@ export function getWalletIcon(provider: string) {
|
|
72
76
|
return discordIconUri;
|
73
77
|
case "line":
|
74
78
|
return lineIconUri;
|
79
|
+
case "x":
|
80
|
+
return xIcon;
|
75
81
|
case "farcaster":
|
76
82
|
return farcasterIconUri;
|
77
83
|
case "telegram":
|
@@ -17,6 +17,7 @@ import {
|
|
17
17
|
PHONE_ICON,
|
18
18
|
TELEGRAM_ICON,
|
19
19
|
WALLET_ICON,
|
20
|
+
X_ICON,
|
20
21
|
} from "../icons/svgs.js";
|
21
22
|
import { RNImage } from "./RNImage.js";
|
22
23
|
|
@@ -84,6 +85,8 @@ export function getAuthProviderImage(authProvider: string | null): string {
|
|
84
85
|
return DISCORD_ICON;
|
85
86
|
case "line":
|
86
87
|
return LINE_ICON;
|
88
|
+
case "x":
|
89
|
+
return X_ICON;
|
87
90
|
case "farcaster":
|
88
91
|
return FARCASTER_ICON;
|
89
92
|
case "telegram":
|
@@ -36,6 +36,7 @@ import {
|
|
36
36
|
GOOGLE_ICON,
|
37
37
|
LINE_ICON,
|
38
38
|
TELEGRAM_ICON,
|
39
|
+
X_ICON,
|
39
40
|
} from "../icons/svgs.js";
|
40
41
|
import type { ModalState } from "./ConnectModal.js";
|
41
42
|
import { LoadingView } from "./LoadingView.js";
|
@@ -55,6 +56,7 @@ const socialIcons = {
|
|
55
56
|
apple: APPLE_ICON,
|
56
57
|
discord: DISCORD_ICON,
|
57
58
|
line: LINE_ICON,
|
59
|
+
x: X_ICON,
|
58
60
|
farcaster: FARCASTER_ICON,
|
59
61
|
telegram: TELEGRAM_ICON,
|
60
62
|
};
|
@@ -93,6 +93,11 @@ export const RIGHT_ARROW = `<svg width="20" height="20" viewBox="0 0 20 20" fill
|
|
93
93
|
</svg>
|
94
94
|
`;
|
95
95
|
|
96
|
+
export const X_ICON = `<svg width="320" height="320" viewBox="0 0 320 320" fill="none" xmlns="http://www.w3.org/2000/svg">
|
97
|
+
<rect width="320" height="320" rx="24" fill="black"/>
|
98
|
+
<path d="M177.315 145.335L245.068 67H229.013L170.182 135.017L123.195 67H69L140.055 169.854L69 252H85.0563L147.183 180.172L196.805 252H251L177.311 145.335H177.315ZM155.323 170.76L148.124 160.518L90.8417 79.022H115.503L161.731 144.792L168.93 155.034L229.02 240.525H204.359L155.323 170.764V170.76Z" fill="white"/>
|
99
|
+
</svg>`;
|
100
|
+
|
96
101
|
export const WALLET_ICON = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
97
102
|
<path d="M12.6667 4.66667V2.66667C12.6667 2.48986 12.5964 2.32029 12.4714 2.19526C12.3464 2.07024 12.1768 2 12 2H3.33333C2.97971 2 2.64057 2.14048 2.39052 2.39052C2.14048 2.64057 2 2.97971 2 3.33333C2 3.68696 2.14048 4.02609 2.39052 4.27614C2.64057 4.52619 2.97971 4.66667 3.33333 4.66667H13.3333C13.5101 4.66667 13.6797 4.7369 13.8047 4.86193C13.9298 4.98695 14 5.15652 14 5.33333V8M14 8H12C11.6464 8 11.3072 8.14048 11.0572 8.39052C10.8071 8.64057 10.6667 8.97971 10.6667 9.33333C10.6667 9.68696 10.8071 10.0261 11.0572 10.2761C11.3072 10.5262 11.6464 10.6667 12 10.6667H14C14.1768 10.6667 14.3464 10.5964 14.4714 10.4714C14.5964 10.3464 14.6667 10.1768 14.6667 10V8.66667C14.6667 8.48986 14.5964 8.32029 14.4714 8.19526C14.3464 8.07024 14.1768 8 14 8Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
98
103
|
<path d="M2 3.3335V12.6668C2 13.0205 2.14048 13.3596 2.39052 13.6096C2.64057 13.8597 2.97971 14.0002 3.33333 14.0002H13.3333C13.5101 14.0002 13.6797 13.9299 13.8047 13.8049C13.9298 13.6799 14 13.5103 14 13.3335V10.6668" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
@@ -19,6 +19,7 @@ import { formatNumber } from "../../../../utils/formatNumber.js";
|
|
19
19
|
import type { Account, Wallet } from "../../../../wallets/interfaces/wallet.js";
|
20
20
|
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
|
21
21
|
import type { AppMetadata } from "../../../../wallets/types.js";
|
22
|
+
import type { WalletId } from "../../../../wallets/wallet-types.js";
|
22
23
|
import {
|
23
24
|
CustomThemeProvider,
|
24
25
|
parseTheme,
|
@@ -744,6 +745,7 @@ function DetailsModal(props: {
|
|
744
745
|
chain={props.connectOptions?.chain}
|
745
746
|
chains={props.connectOptions?.chains}
|
746
747
|
client={client}
|
748
|
+
hiddenWallets={props.connectOptions?.hiddenWallets}
|
747
749
|
connectLocale={locale}
|
748
750
|
recommendedWallets={props.connectOptions?.recommendedWallets}
|
749
751
|
showAllWallets={!!props.connectOptions?.showAllWallets}
|
@@ -924,6 +926,7 @@ function DetailsModal(props: {
|
|
924
926
|
mode: "fund_wallet",
|
925
927
|
}
|
926
928
|
}
|
929
|
+
hiddenWallets={props.detailsModal?.hiddenWallets}
|
927
930
|
theme={typeof props.theme === "string" ? props.theme : props.theme.type}
|
928
931
|
onDone={closeModal}
|
929
932
|
connectOptions={undefined}
|
@@ -1156,6 +1159,7 @@ export type DetailsModalConnectOptions = {
|
|
1156
1159
|
chain?: Chain;
|
1157
1160
|
chains?: Chain[];
|
1158
1161
|
recommendedWallets?: Wallet[];
|
1162
|
+
hiddenWallets?: WalletId[];
|
1159
1163
|
showAllWallets?: boolean;
|
1160
1164
|
};
|
1161
1165
|
|
@@ -10,6 +10,7 @@ import type { BuyWithFiatStatus } from "../../../../../../pay/buyWithFiat/getSta
|
|
10
10
|
import { isSwapRequiredPostOnramp } from "../../../../../../pay/buyWithFiat/isSwapRequiredPostOnramp.js";
|
11
11
|
import { formatNumber } from "../../../../../../utils/formatNumber.js";
|
12
12
|
import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
|
13
|
+
import type { WalletId } from "../../../../../../wallets/wallet-types.js";
|
13
14
|
import {
|
14
15
|
type Theme,
|
15
16
|
iconSize,
|
@@ -91,6 +92,7 @@ export type BuyScreenProps = {
|
|
91
92
|
theme: "light" | "dark" | Theme;
|
92
93
|
onDone: () => void;
|
93
94
|
connectOptions: PayEmbedConnectOptions | undefined;
|
95
|
+
hiddenWallets?: WalletId[];
|
94
96
|
isEmbed: boolean;
|
95
97
|
};
|
96
98
|
|
@@ -128,6 +130,7 @@ type BuyScreenContentProps = {
|
|
128
130
|
theme: "light" | "dark" | Theme;
|
129
131
|
payOptions: PayUIOptions;
|
130
132
|
onDone: () => void;
|
133
|
+
hiddenWallets?: WalletId[];
|
131
134
|
connectOptions: PayEmbedConnectOptions | undefined;
|
132
135
|
isEmbed: boolean;
|
133
136
|
};
|
@@ -265,6 +268,7 @@ function BuyScreenContent(props: BuyScreenContentProps) {
|
|
265
268
|
});
|
266
269
|
}
|
267
270
|
}}
|
271
|
+
hiddenWallets={props.hiddenWallets}
|
268
272
|
recommendedWallets={props.connectOptions?.recommendedWallets}
|
269
273
|
showAllWallets={
|
270
274
|
props.connectOptions?.showAllWallets === undefined
|
@@ -541,6 +545,7 @@ function BuyScreenContent(props: BuyScreenContentProps) {
|
|
541
545
|
{screen.id === "select-wallet" && (
|
542
546
|
<WalletSwitcherDrawerContent
|
543
547
|
client={client}
|
548
|
+
hiddenWallets={props.hiddenWallets}
|
544
549
|
onSelect={(w) => {
|
545
550
|
const chain = w.getChain();
|
546
551
|
const account = w.getAccount();
|
@@ -1352,6 +1357,7 @@ function FiatScreenContent(props: {
|
|
1352
1357
|
isTestMode: buyWithFiatOptions?.testMode,
|
1353
1358
|
purchaseData: props.payOptions.purchaseData,
|
1354
1359
|
fromAddress: payer.account.address,
|
1360
|
+
preferredProvider: buyWithFiatOptions?.preferredProvider,
|
1355
1361
|
}
|
1356
1362
|
: undefined,
|
1357
1363
|
);
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { PlusIcon } from "@radix-ui/react-icons";
|
2
2
|
import type { ThirdwebClient } from "../../../../../../../client/client.js";
|
3
3
|
import type { Wallet } from "../../../../../../../wallets/interfaces/wallet.js";
|
4
|
+
import type { WalletId } from "../../../../../../../wallets/wallet-types.js";
|
4
5
|
import { useCustomTheme } from "../../../../../../core/design-system/CustomThemeProvider.js";
|
5
6
|
import {
|
6
7
|
iconSize,
|
@@ -22,6 +23,7 @@ export function WalletSwitcherDrawerContent(props: {
|
|
22
23
|
onBack: () => void;
|
23
24
|
onConnect: () => void;
|
24
25
|
selectedAddress: string;
|
26
|
+
hiddenWallets?: WalletId[];
|
25
27
|
}) {
|
26
28
|
const theme = useCustomTheme();
|
27
29
|
const connectedWallets = useConnectedWallets();
|
@@ -34,23 +36,25 @@ export function WalletSwitcherDrawerContent(props: {
|
|
34
36
|
return (
|
35
37
|
<Container>
|
36
38
|
<Container flex="column" gap="xs">
|
37
|
-
{connectedWallets
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
{connectedWallets
|
40
|
+
.filter((w) => !props.hiddenWallets?.includes(w.id))
|
41
|
+
.map((w) => {
|
42
|
+
const address = w.getAccount()?.address;
|
43
|
+
return (
|
44
|
+
<WalletSelectorButton
|
45
|
+
key={w.id}
|
46
|
+
walletId={w.id}
|
47
|
+
client={props.client}
|
48
|
+
address={address || ""}
|
49
|
+
onClick={() => {
|
50
|
+
props.onSelect(w);
|
51
|
+
props.onBack();
|
52
|
+
}}
|
53
|
+
disableChevron
|
54
|
+
checked={false}
|
55
|
+
/>
|
56
|
+
);
|
57
|
+
})}
|
54
58
|
{!hideConnectButton && (
|
55
59
|
<Button
|
56
60
|
variant="secondary"
|
@@ -80,21 +80,23 @@ export function WalletManagerScreen(
|
|
80
80
|
}}
|
81
81
|
>
|
82
82
|
<Container flex="column" gap="xs">
|
83
|
-
{connectedWallets
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
83
|
+
{connectedWallets
|
84
|
+
.filter((w) => !props.hiddenWallets?.includes(w.id))
|
85
|
+
.map((w) => {
|
86
|
+
return (
|
87
|
+
<WalletManangerButton
|
88
|
+
key={w.id}
|
89
|
+
client={props.client}
|
90
|
+
// address={address || ""}
|
91
|
+
onClick={() => {
|
92
|
+
setActive(w);
|
93
|
+
props.onBack();
|
94
|
+
}}
|
95
|
+
chain={props.activeChain}
|
96
|
+
wallet={w}
|
97
|
+
/>
|
98
|
+
);
|
99
|
+
})}
|
98
100
|
</Container>
|
99
101
|
</Container>
|
100
102
|
|
@@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../../../../../client/client.js";
|
|
3
3
|
import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
|
4
4
|
import type { SmartWalletOptions } from "../../../../../wallets/smart/types.js";
|
5
5
|
import type { AppMetadata } from "../../../../../wallets/types.js";
|
6
|
+
import type { WalletId } from "../../../../../wallets/wallet-types.js";
|
6
7
|
import { useConnectedWallets } from "../../../../core/hooks/wallets/useConnectedWallets.js";
|
7
8
|
import { getDefaultWallets } from "../../../wallets/defaultWallets.js";
|
8
9
|
import { ConnectModalContent } from "../Modal/ConnectModalContent.js";
|
@@ -21,6 +22,7 @@ export type WalletSwitcherConnectionScreenProps = {
|
|
21
22
|
onSelect: (wallet: Wallet) => void;
|
22
23
|
recommendedWallets: Wallet[] | undefined;
|
23
24
|
showAllWallets: boolean;
|
25
|
+
hiddenWallets?: WalletId[];
|
24
26
|
walletConnect:
|
25
27
|
| {
|
26
28
|
projectId?: string;
|
@@ -6,6 +6,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
|
|
6
6
|
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
|
7
7
|
import type { SmartWalletOptions } from "../../../wallets/smart/types.js";
|
8
8
|
import type { AppMetadata } from "../../../wallets/types.js";
|
9
|
+
import type { WalletId } from "../../../wallets/wallet-types.js";
|
9
10
|
import { CustomThemeProvider } from "../../core/design-system/CustomThemeProvider.js";
|
10
11
|
import type { Theme } from "../../core/design-system/index.js";
|
11
12
|
import type { SiweAuthOptions } from "../../core/hooks/auth/useSiweAuth.js";
|
@@ -119,12 +120,17 @@ export type PayEmbedProps = {
|
|
119
120
|
theme?: "light" | "dark" | Theme;
|
120
121
|
|
121
122
|
/**
|
122
|
-
* Customize the options for "Connect" Button
|
123
|
+
* Customize the options for "Connect" Button showing in the PayEmbed UI when the user is not connected to a wallet.
|
123
124
|
*
|
124
125
|
* Refer to the [`PayEmbedConnectOptions`](https://portal.thirdweb.com/references/typescript/v5/PayEmbedConnectOptions) type for more details.
|
125
126
|
*/
|
126
127
|
connectOptions?: PayEmbedConnectOptions;
|
127
128
|
|
129
|
+
/**
|
130
|
+
* All wallet IDs included in this array will be hidden from wallet selection when connected.
|
131
|
+
*/
|
132
|
+
hiddenWallets?: WalletId[];
|
133
|
+
|
128
134
|
style?: React.CSSProperties;
|
129
135
|
|
130
136
|
className?: string;
|
@@ -201,6 +207,7 @@ export function PayEmbed(props: PayEmbedProps) {
|
|
201
207
|
theme={theme}
|
202
208
|
client={props.client}
|
203
209
|
connectLocale={localeQuery.data}
|
210
|
+
hiddenWallets={props.hiddenWallets}
|
204
211
|
payOptions={
|
205
212
|
props.payOptions || {
|
206
213
|
mode: "fund_wallet",
|
package/src/utils/ens/avatar.ts
CHANGED
@@ -1,20 +1,40 @@
|
|
1
|
-
import { getCachedChain } from "../../chains/utils.js";
|
2
1
|
import type { ThirdwebClient } from "../../client/client.js";
|
3
|
-
import { getContract } from "../../contract/contract.js";
|
4
|
-
import { isAddress } from "../address.js";
|
5
2
|
import { getClientFetch } from "../fetch.js";
|
6
3
|
import { resolveScheme } from "../ipfs.js";
|
4
|
+
import { parseNftUri } from "../nft/parseNft.js";
|
7
5
|
|
8
|
-
type
|
6
|
+
export type ParseAvatarOptions = {
|
9
7
|
client: ThirdwebClient;
|
10
8
|
uri: string;
|
11
9
|
};
|
12
10
|
|
13
11
|
/**
|
14
|
-
*
|
12
|
+
* Parses an ENS or similar avatar record. Supports NFT URIs, IPFS scheme, and HTTPS URIs.
|
13
|
+
* @param options - The options for parsing an ENS avatar record.
|
14
|
+
* @param options.client - The Thirdweb client.
|
15
|
+
* @param options.uri - The URI to parse.
|
16
|
+
* @returns A promise that resolves to the avatar URL, or null if the URI could not be parsed.
|
17
|
+
* @example
|
18
|
+
* ```ts
|
19
|
+
* import { parseAvatarRecord } from "thirdweb/utils/ens";
|
20
|
+
* const avatarUrl = await parseAvatarRecord({
|
21
|
+
* client,
|
22
|
+
* uri: "ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/",
|
23
|
+
* });
|
24
|
+
*
|
25
|
+
* console.log(avatarUrl); // "https://ipfs.io/ipfs/bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/"
|
26
|
+
*
|
27
|
+
* const avatarUrl2 = await parseAvatarRecord({
|
28
|
+
* client,
|
29
|
+
* uri: "eip155:1/erc1155:0xb32979486938aa9694bfc898f35dbed459f44424/10063",
|
30
|
+
* });
|
31
|
+
*
|
32
|
+
* console.log(avatarUrl2); // "https://opensea.io/assets/0xb32979486938aa9694bfc898f35dbed459f44424/10063"
|
33
|
+
* ```
|
34
|
+
* @extension ENS
|
15
35
|
*/
|
16
36
|
export async function parseAvatarRecord(
|
17
|
-
options:
|
37
|
+
options: ParseAvatarOptions,
|
18
38
|
): Promise<string | null> {
|
19
39
|
let uri: string | null = options.uri;
|
20
40
|
if (/eip155:/i.test(options.uri)) {
|
@@ -36,71 +56,7 @@ export async function parseAvatarRecord(
|
|
36
56
|
return null;
|
37
57
|
}
|
38
58
|
|
39
|
-
|
40
|
-
* @internal
|
41
|
-
*/
|
42
|
-
async function parseNftUri(options: AvatarOptions): Promise<string | null> {
|
43
|
-
let uri = options.uri;
|
44
|
-
// parse valid nft spec (CAIP-22/CAIP-29)
|
45
|
-
// @see: https://github.com/ChainAgnostic/CAIPs/tree/master/CAIPs
|
46
|
-
if (uri.startsWith("did:nft:")) {
|
47
|
-
// convert DID to CAIP
|
48
|
-
uri = uri.replace("did:nft:", "").replace(/_/g, "/");
|
49
|
-
}
|
50
|
-
|
51
|
-
const [reference = "", asset_namespace = "", tokenID = ""] = uri.split("/");
|
52
|
-
const [eip_namespace, chainID] = reference.split(":");
|
53
|
-
const [erc_namespace, contractAddress] = asset_namespace.split(":");
|
54
|
-
|
55
|
-
if (!eip_namespace || eip_namespace.toLowerCase() !== "eip155") {
|
56
|
-
throw new Error(
|
57
|
-
`Invalid EIP namespace, expected EIP155, got: "${eip_namespace}"`,
|
58
|
-
);
|
59
|
-
}
|
60
|
-
if (!chainID) {
|
61
|
-
throw new Error("Chain ID not found");
|
62
|
-
}
|
63
|
-
if (!contractAddress || !isAddress(contractAddress)) {
|
64
|
-
throw new Error("Contract address not found");
|
65
|
-
}
|
66
|
-
if (!tokenID) {
|
67
|
-
throw new Error("Token ID not found");
|
68
|
-
}
|
69
|
-
const chain = getCachedChain(Number(chainID));
|
70
|
-
const contract = getContract({
|
71
|
-
client: options.client,
|
72
|
-
chain,
|
73
|
-
address: contractAddress,
|
74
|
-
});
|
75
|
-
switch (erc_namespace) {
|
76
|
-
case "erc721": {
|
77
|
-
const { getNFT } = await import("../../extensions/erc721/read/getNFT.js");
|
78
|
-
const nft = await getNFT({
|
79
|
-
contract,
|
80
|
-
tokenId: BigInt(tokenID),
|
81
|
-
});
|
82
|
-
return nft.metadata.image ?? null;
|
83
|
-
}
|
84
|
-
case "erc1155": {
|
85
|
-
const { getNFT } = await import(
|
86
|
-
"../../extensions/erc1155/read/getNFT.js"
|
87
|
-
);
|
88
|
-
const nft = await getNFT({
|
89
|
-
contract,
|
90
|
-
tokenId: BigInt(tokenID),
|
91
|
-
});
|
92
|
-
return nft.metadata.image ?? null;
|
93
|
-
}
|
94
|
-
|
95
|
-
default: {
|
96
|
-
throw new Error(
|
97
|
-
`Invalid ERC namespace, expected ERC721 or ERC1155, got: "${erc_namespace}"`,
|
98
|
-
);
|
99
|
-
}
|
100
|
-
}
|
101
|
-
}
|
102
|
-
|
103
|
-
async function isImageUri(options: AvatarOptions): Promise<boolean> {
|
59
|
+
async function isImageUri(options: ParseAvatarOptions): Promise<boolean> {
|
104
60
|
try {
|
105
61
|
const res = await getClientFetch(options.client)(options.uri, {
|
106
62
|
method: "HEAD",
|
@@ -1,4 +1,8 @@
|
|
1
|
+
import { getCachedChain } from "../../chains/utils.js";
|
2
|
+
import type { ThirdwebClient } from "../../client/client.js";
|
3
|
+
import { getContract } from "../../contract/contract.js";
|
1
4
|
import type { FileOrBufferOrString } from "../../storage/upload/types.js";
|
5
|
+
import { isAddress } from "../address.js";
|
2
6
|
import type { Prettify } from "../type-utils.js";
|
3
7
|
|
4
8
|
/**
|
@@ -95,3 +99,88 @@ export function parseNFT(base: NFTMetadata, options: ParseNFTOptions): NFT {
|
|
95
99
|
throw new Error("Invalid NFT type");
|
96
100
|
}
|
97
101
|
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Parses an NFT URI.
|
105
|
+
* @param options - The options for parsing an NFT URI.
|
106
|
+
* @param options.client - The Thirdweb client.
|
107
|
+
* @param options.uri - The NFT URI to parse.
|
108
|
+
* @returns A promise that resolves to the NFT URI, or null if the URI could not be parsed.
|
109
|
+
*
|
110
|
+
* @example
|
111
|
+
* ```ts
|
112
|
+
* import { parseNftUri } from "thirdweb/utils/ens";
|
113
|
+
* const nftUri = await parseNftUri({
|
114
|
+
* client,
|
115
|
+
* uri: "eip155:1/erc1155:0xb32979486938aa9694bfc898f35dbed459f44424/10063",
|
116
|
+
* });
|
117
|
+
*
|
118
|
+
* console.log(nftUri); // ipfs://bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/
|
119
|
+
* ```
|
120
|
+
*
|
121
|
+
* @extension ENS
|
122
|
+
*
|
123
|
+
*/
|
124
|
+
export async function parseNftUri(options: {
|
125
|
+
client: ThirdwebClient;
|
126
|
+
uri: string;
|
127
|
+
}): Promise<string | null> {
|
128
|
+
let uri = options.uri;
|
129
|
+
// parse valid nft spec (CAIP-22/CAIP-29)
|
130
|
+
// @see: https://github.com/ChainAgnostic/CAIPs/tree/master/CAIPs
|
131
|
+
if (uri.startsWith("did:nft:")) {
|
132
|
+
// convert DID to CAIP
|
133
|
+
uri = uri.replace("did:nft:", "").replace(/_/g, "/");
|
134
|
+
}
|
135
|
+
|
136
|
+
const [reference = "", asset_namespace = "", tokenID = ""] = uri.split("/");
|
137
|
+
const [eip_namespace, chainID] = reference.split(":");
|
138
|
+
const [erc_namespace, contractAddress] = asset_namespace.split(":");
|
139
|
+
|
140
|
+
if (!eip_namespace || eip_namespace.toLowerCase() !== "eip155") {
|
141
|
+
throw new Error(
|
142
|
+
`Invalid EIP namespace, expected EIP155, got: "${eip_namespace}"`,
|
143
|
+
);
|
144
|
+
}
|
145
|
+
if (!chainID) {
|
146
|
+
throw new Error("Chain ID not found");
|
147
|
+
}
|
148
|
+
if (!contractAddress || !isAddress(contractAddress)) {
|
149
|
+
throw new Error("Contract address not found");
|
150
|
+
}
|
151
|
+
if (!tokenID) {
|
152
|
+
throw new Error("Token ID not found");
|
153
|
+
}
|
154
|
+
const chain = getCachedChain(Number(chainID));
|
155
|
+
const contract = getContract({
|
156
|
+
client: options.client,
|
157
|
+
chain,
|
158
|
+
address: contractAddress,
|
159
|
+
});
|
160
|
+
switch (erc_namespace) {
|
161
|
+
case "erc721": {
|
162
|
+
const { getNFT } = await import("../../extensions/erc721/read/getNFT.js");
|
163
|
+
const nft = await getNFT({
|
164
|
+
contract,
|
165
|
+
tokenId: BigInt(tokenID),
|
166
|
+
});
|
167
|
+
return nft.metadata.image ?? null;
|
168
|
+
}
|
169
|
+
case "erc1155": {
|
170
|
+
const { getNFT } = await import(
|
171
|
+
"../../extensions/erc1155/read/getNFT.js"
|
172
|
+
);
|
173
|
+
const nft = await getNFT({
|
174
|
+
contract,
|
175
|
+
tokenId: BigInt(tokenID),
|
176
|
+
});
|
177
|
+
return nft.metadata.image ?? null;
|
178
|
+
}
|
179
|
+
|
180
|
+
default: {
|
181
|
+
throw new Error(
|
182
|
+
`Invalid ERC namespace, expected ERC721 or ERC1155, got: "${erc_namespace}"`,
|
183
|
+
);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|