thirdweb 5.40.1-nightly-b128530355f0dc47d897bd2ef7c3823752ea9b6c-20240727000321 → 5.42.0-nightly-e27ebef85bb61342c3de53f85e134cf4a29f787c-20240730000342
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/client/client.js +19 -1
- package/dist/cjs/client/client.js.map +1 -1
- package/dist/cjs/exports/extensions/common.js +3 -1
- package/dist/cjs/exports/extensions/common.js.map +1 -1
- package/dist/cjs/exports/extensions/erc1155.js +2 -1
- package/dist/cjs/exports/extensions/erc1155.js.map +1 -1
- package/dist/cjs/exports/extensions/erc20.js +3 -1
- package/dist/cjs/exports/extensions/erc20.js.map +1 -1
- package/dist/cjs/exports/react.js +7 -2
- package/dist/cjs/exports/react.js.map +1 -1
- package/dist/cjs/exports/utils.js +3 -1
- package/dist/cjs/exports/utils.js.map +1 -1
- package/dist/cjs/extensions/erc20/write/getApprovalForTransaction.js +38 -0
- package/dist/cjs/extensions/erc20/write/getApprovalForTransaction.js.map +1 -1
- package/dist/cjs/react/core/hooks/others/useChainQuery.js +19 -3
- package/dist/cjs/react/core/hooks/others/useChainQuery.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/transaction-button-utils.js.map +1 -1
- package/dist/cjs/react/core/utils/socialIcons.js +3 -1
- package/dist/cjs/react/core/utils/socialIcons.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 +3 -1
- package/dist/cjs/react/native/ui/connect/InAppWalletUI.js.map +1 -1
- package/dist/cjs/react/native/ui/icons/svgs.js +7 -1
- package/dist/cjs/react/native/ui/icons/svgs.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +5 -5
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js +12 -1
- package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +4 -3
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewAssets.js +37 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewAssets.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js +21 -18
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js +12 -9
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.js +3 -2
- package/dist/cjs/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.js.map +1 -1
- package/dist/cjs/react/web/ui/components/Tabs.js +5 -3
- package/dist/cjs/react/web/ui/components/Tabs.js.map +1 -1
- package/dist/cjs/react/web/ui/components/WalletImage.js +3 -0
- package/dist/cjs/react/web/ui/components/WalletImage.js.map +1 -1
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +127 -0
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -0
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +70 -3
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.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 +2 -1
- package/dist/cjs/react/web/wallets/shared/oauthSignIn.js.map +1 -1
- package/dist/cjs/storage/download.js +44 -4
- package/dist/cjs/storage/download.js.map +1 -1
- package/dist/cjs/transaction/actions/send-and-confirm-transaction.js +1 -1
- package/dist/cjs/utils/contract/parse-abi-params.js +87 -0
- package/dist/cjs/utils/contract/parse-abi-params.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js +11 -5
- package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/type.js +1 -0
- package/dist/cjs/wallets/in-app/core/authentication/type.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +2 -3
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js +5 -1
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/native-connector.js +1 -0
- package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/auth/oauth.js +7 -17
- package/dist/cjs/wallets/in-app/web/lib/auth/oauth.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +1 -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/client/client.js +19 -1
- package/dist/esm/client/client.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/erc1155.js +1 -1
- package/dist/esm/exports/extensions/erc1155.js.map +1 -1
- package/dist/esm/exports/extensions/erc20.js +1 -0
- package/dist/esm/exports/extensions/erc20.js.map +1 -1
- package/dist/esm/exports/react.js +3 -0
- package/dist/esm/exports/react.js.map +1 -1
- package/dist/esm/exports/utils.js +1 -0
- package/dist/esm/exports/utils.js.map +1 -1
- package/dist/esm/extensions/erc20/write/getApprovalForTransaction.js +38 -0
- package/dist/esm/extensions/erc20/write/getApprovalForTransaction.js.map +1 -1
- package/dist/esm/react/core/hooks/others/useChainQuery.js +19 -3
- package/dist/esm/react/core/hooks/others/useChainQuery.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/transaction-button-utils.js.map +1 -1
- package/dist/esm/react/core/utils/socialIcons.js +2 -0
- package/dist/esm/react/core/utils/socialIcons.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 +4 -2
- package/dist/esm/react/native/ui/connect/InAppWalletUI.js.map +1 -1
- package/dist/esm/react/native/ui/icons/svgs.js +6 -0
- package/dist/esm/react/native/ui/icons/svgs.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +5 -5
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js +12 -1
- package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js +2 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +2 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +4 -3
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewAssets.js +34 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewAssets.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js +21 -19
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js +12 -10
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewTokens.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.js +3 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.js.map +1 -1
- package/dist/esm/react/web/ui/components/Tabs.js +5 -3
- package/dist/esm/react/web/ui/components/Tabs.js.map +1 -1
- package/dist/esm/react/web/ui/components/WalletImage.js +4 -1
- package/dist/esm/react/web/ui/components/WalletImage.js.map +1 -1
- package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +124 -0
- package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -0
- package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +69 -3
- package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.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 +2 -1
- package/dist/esm/react/web/wallets/shared/oauthSignIn.js.map +1 -1
- package/dist/esm/storage/download.js +44 -4
- package/dist/esm/storage/download.js.map +1 -1
- package/dist/esm/transaction/actions/send-and-confirm-transaction.js +1 -1
- package/dist/esm/utils/contract/parse-abi-params.js +84 -0
- package/dist/esm/utils/contract/parse-abi-params.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js +11 -5
- package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/type.js +1 -0
- package/dist/esm/wallets/in-app/core/authentication/type.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +2 -3
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/wallets/in-app/native/auth/native-auth.js +5 -1
- package/dist/esm/wallets/in-app/native/auth/native-auth.js.map +1 -1
- package/dist/esm/wallets/in-app/native/native-connector.js +1 -0
- package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/auth/oauth.js +6 -15
- package/dist/esm/wallets/in-app/web/lib/auth/oauth.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +1 -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/client/client.d.ts +19 -1
- package/dist/types/client/client.d.ts.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/erc1155.d.ts +1 -1
- package/dist/types/exports/extensions/erc1155.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc20.d.ts +1 -0
- package/dist/types/exports/extensions/erc20.d.ts.map +1 -1
- package/dist/types/exports/react.d.ts +2 -0
- package/dist/types/exports/react.d.ts.map +1 -1
- package/dist/types/exports/utils.d.ts +2 -0
- package/dist/types/exports/utils.d.ts.map +1 -1
- package/dist/types/extensions/erc20/write/getApprovalForTransaction.d.ts +44 -0
- package/dist/types/extensions/erc20/write/getApprovalForTransaction.d.ts.map +1 -1
- package/dist/types/react/core/hooks/others/useChainQuery.d.ts +21 -4
- package/dist/types/react/core/hooks/others/useChainQuery.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/transaction-button-utils.d.ts +1 -0
- package/dist/types/react/core/hooks/transaction/transaction-button-utils.d.ts.map +1 -1
- package/dist/types/react/core/utils/socialIcons.d.ts +2 -0
- package/dist/types/react/core/utils/socialIcons.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/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.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/TransactionsScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/{ViewFunds.d.ts → ViewAssets.d.ts} +4 -2
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewAssets.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts +6 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts +5 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewTokens.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/types.d.ts +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/types.d.ts.map +1 -1
- package/dist/types/react/web/ui/PayEmbed.d.ts +1 -1
- package/dist/types/react/web/ui/components/Tabs.d.ts +5 -1
- package/dist/types/react/web/ui/components/Tabs.d.ts.map +1 -1
- package/dist/types/react/web/ui/components/WalletImage.d.ts.map +1 -1
- package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts +63 -0
- package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts.map +1 -0
- package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.d.ts +21 -0
- package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.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/storage/download.d.ts +43 -3
- package/dist/types/storage/download.d.ts.map +1 -1
- package/dist/types/transaction/actions/send-and-confirm-transaction.d.ts +1 -1
- package/dist/types/utils/contract/parse-abi-params.d.ts +29 -0
- package/dist/types/utils/contract/parse-abi-params.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts +6 -1
- package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/type.d.ts +2 -1
- package/dist/types/wallets/in-app/core/authentication/type.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/native/auth/native-auth.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/lib/auth/oauth.d.ts +0 -1
- package/dist/types/wallets/in-app/web/lib/auth/oauth.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 +1 -1
- package/dist/types/wallets/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client/client.ts +19 -1
- package/src/exports/extensions/common.ts +5 -0
- package/src/exports/extensions/erc1155.ts +1 -0
- package/src/exports/extensions/erc20.ts +5 -0
- package/src/exports/react.ts +7 -0
- package/src/exports/utils.ts +3 -0
- package/src/extensions/erc20/write/getApprovalForTransaction.ts +44 -0
- package/src/react/core/hooks/others/useChainQuery.ts +24 -4
- package/src/react/core/hooks/transaction/transaction-button-utils.ts +1 -0
- package/src/react/core/utils/socialIcons.ts +3 -0
- package/src/react/native/ui/components/WalletImage.tsx +3 -0
- package/src/react/native/ui/connect/InAppWalletUI.tsx +8 -3
- package/src/react/native/ui/icons/svgs.ts +7 -0
- package/src/react/web/ui/ConnectWallet/Details.tsx +5 -4
- package/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx +20 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.tsx +2 -2
- package/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx +2 -2
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.tsx +25 -22
- package/src/react/web/ui/ConnectWallet/screens/ViewAssets.tsx +104 -0
- package/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx +63 -52
- package/src/react/web/ui/ConnectWallet/screens/ViewTokens.tsx +38 -29
- package/src/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.tsx +8 -2
- package/src/react/web/ui/ConnectWallet/screens/types.ts +1 -1
- package/src/react/web/ui/PayEmbed.tsx +1 -1
- package/src/react/web/ui/components/Tabs.tsx +11 -6
- package/src/react/web/ui/components/WalletImage.tsx +4 -0
- package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/BuyDirectListingButton.test.tsx +27 -0
- package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.tsx +200 -0
- package/src/react/web/ui/prebuilt/thirdweb/ClaimButton/index.tsx +78 -5
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +1 -0
- package/src/react/web/wallets/shared/oauthSignIn.ts +2 -1
- package/src/storage/download.ts +47 -4
- package/src/transaction/actions/send-and-confirm-transaction.ts +1 -1
- package/src/utils/contract/parse-abi-params.test.ts +160 -0
- package/src/utils/contract/parse-abi-params.ts +90 -0
- package/src/version.ts +1 -1
- package/src/wallets/in-app/core/authentication/getLoginPath.ts +22 -9
- package/src/wallets/in-app/core/authentication/type.ts +1 -0
- package/src/wallets/in-app/core/wallet/index.ts +2 -3
- package/src/wallets/in-app/native/auth/native-auth.ts +5 -1
- package/src/wallets/in-app/native/native-connector.ts +1 -0
- package/src/wallets/in-app/web/lib/auth/oauth.ts +6 -24
- package/src/wallets/in-app/web/lib/web-connector.ts +1 -0
- package/src/wallets/types.ts +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewFunds.js +0 -31
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewFunds.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewFunds.js +0 -28
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewFunds.js.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewFunds.d.ts.map +0 -1
- package/src/react/web/ui/ConnectWallet/screens/ViewFunds.tsx +0 -76
@@ -0,0 +1,200 @@
|
|
1
|
+
"use client";
|
2
|
+
|
3
|
+
import { useCallback } from "react";
|
4
|
+
import type { Chain } from "../../../../../../chains/types.js";
|
5
|
+
import type { ThirdwebClient } from "../../../../../../client/client.js";
|
6
|
+
import { getContract } from "../../../../../../contract/contract.js";
|
7
|
+
import { getListing } from "../../../../../../extensions/marketplace/direct-listings/read/getListing.js";
|
8
|
+
import type { BaseTransactionOptions } from "../../../../../../transaction/types.js";
|
9
|
+
import { useReadContract } from "../../../../../core/hooks/contract/useReadContract.js";
|
10
|
+
import type { TransactionButtonProps } from "../../../../../core/hooks/transaction/transaction-button-utils.js";
|
11
|
+
import { useSendAndConfirmTransaction } from "../../../../../core/hooks/transaction/useSendAndConfirmTransaction.js";
|
12
|
+
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
|
13
|
+
import { TransactionButton } from "../../../TransactionButton/index.js";
|
14
|
+
|
15
|
+
export type BuyDirectListingButtonProps = Omit<
|
16
|
+
TransactionButtonProps,
|
17
|
+
"transaction"
|
18
|
+
> & {
|
19
|
+
/**
|
20
|
+
* The contract address of the Marketplace v3 contract.
|
21
|
+
*/
|
22
|
+
contractAddress: string;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* The chain which the Drop contract is deployed on
|
26
|
+
*/
|
27
|
+
chain: Chain;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* thirdweb Client
|
31
|
+
*/
|
32
|
+
client: ThirdwebClient;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* ID of the marketplace's DirectListing
|
36
|
+
*/
|
37
|
+
listingId: bigint;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Qty to buy (optional)
|
41
|
+
*
|
42
|
+
* - For ERC721 listing: the `quantity` is always hard-coded to 1n - passing this props doesn't do anything
|
43
|
+
*
|
44
|
+
* - For ERC1155 listing: the `quantity` defaults to the quantity of the listing if not specified.
|
45
|
+
*
|
46
|
+
* The component will also throw an error if you pass a `quantity` and it's greater than the listing's quantity
|
47
|
+
*/
|
48
|
+
quantity?: bigint;
|
49
|
+
};
|
50
|
+
|
51
|
+
/**
|
52
|
+
* This button is used with thirdweb Marketplace v3 contract, for buying NFT(s) from a listing.
|
53
|
+
*
|
54
|
+
* Under the hood, it prepares a transaction using the [`buyFromListing` extension](https://portal.thirdweb.com/references/typescript/v5/marketplace/buyFromListing)
|
55
|
+
* and then pass it to a <TransactionButton />
|
56
|
+
*
|
57
|
+
* Since it uses the TransactionButton, it can take in any props that can be passed
|
58
|
+
* to the [`TransactionButton`](https://portal.thirdweb.com/references/typescript/v5/TransactionButton)
|
59
|
+
*
|
60
|
+
*
|
61
|
+
* @param props
|
62
|
+
* @returns <TransactionButton />
|
63
|
+
*
|
64
|
+
* @example
|
65
|
+
* ```tsx
|
66
|
+
* import { BuyDirectListingButton } from "thirdweb/react";
|
67
|
+
*
|
68
|
+
* <BuyDirectListingButton
|
69
|
+
* contractAddress="0x..." // contract address of the marketplace v3
|
70
|
+
* chain={...} // the chain which the marketplace contract is deployed on
|
71
|
+
* client={...} // thirdweb client
|
72
|
+
* listingId={100n} // the listingId or the item you want to buy
|
73
|
+
* quantity={1n} // optional - see the docs to learn more
|
74
|
+
* >
|
75
|
+
* Buy NFT
|
76
|
+
* </BuyDirectListingButton>
|
77
|
+
* ```
|
78
|
+
*
|
79
|
+
* @component
|
80
|
+
*/
|
81
|
+
export function BuyDirectListingButton(props: BuyDirectListingButtonProps) {
|
82
|
+
const {
|
83
|
+
contractAddress,
|
84
|
+
listingId,
|
85
|
+
children,
|
86
|
+
chain,
|
87
|
+
client,
|
88
|
+
quantity,
|
89
|
+
payModal,
|
90
|
+
} = props;
|
91
|
+
const defaultPayModalMetadata = payModal ? payModal.metadata : undefined;
|
92
|
+
const account = useActiveAccount();
|
93
|
+
const contract = getContract({
|
94
|
+
address: contractAddress,
|
95
|
+
client,
|
96
|
+
chain,
|
97
|
+
});
|
98
|
+
|
99
|
+
const { data: payMetadata } = useReadContract(getPayMetadata, {
|
100
|
+
contract,
|
101
|
+
listingId,
|
102
|
+
queryOptions: {
|
103
|
+
enabled: !defaultPayModalMetadata,
|
104
|
+
},
|
105
|
+
});
|
106
|
+
|
107
|
+
const { mutateAsync } = useSendAndConfirmTransaction();
|
108
|
+
|
109
|
+
const prepareBuyTransaction = useCallback(async () => {
|
110
|
+
if (!account) {
|
111
|
+
throw new Error("No account detected");
|
112
|
+
}
|
113
|
+
const [listing, { getApprovalForTransaction }, { buyFromListing }] =
|
114
|
+
await Promise.all([
|
115
|
+
getListing({
|
116
|
+
contract,
|
117
|
+
listingId,
|
118
|
+
}),
|
119
|
+
import(
|
120
|
+
"../../../../../../extensions/erc20/write/getApprovalForTransaction.js"
|
121
|
+
),
|
122
|
+
import(
|
123
|
+
"../../../../../../extensions/marketplace/direct-listings/write/buyFromListing.js"
|
124
|
+
),
|
125
|
+
]);
|
126
|
+
if (!listing) {
|
127
|
+
throw new Error(`Could not retrieve listing with ID: ${listingId}`);
|
128
|
+
}
|
129
|
+
|
130
|
+
let _quantity = 1n;
|
131
|
+
// For ERC721 the quantity should always be 1n. We throw an error if user passes a different props
|
132
|
+
if (listing.asset.type === "ERC721") {
|
133
|
+
if (typeof quantity === "bigint" && (quantity !== 1n || quantity < 0n)) {
|
134
|
+
throw new Error(
|
135
|
+
"Invalid quantity. This is an ERC721 listing & quantity is always `1n`",
|
136
|
+
);
|
137
|
+
}
|
138
|
+
} else if (listing.asset.type === "ERC1155") {
|
139
|
+
if (typeof quantity === "bigint") {
|
140
|
+
if (quantity > listing.quantity) {
|
141
|
+
throw new Error(
|
142
|
+
`quantity exceeds available amount. Available: ${listing.quantity.toString()}`,
|
143
|
+
);
|
144
|
+
}
|
145
|
+
if (quantity < 0n) {
|
146
|
+
throw new Error("Invalid quantity. Should be at least 1n");
|
147
|
+
}
|
148
|
+
_quantity = quantity;
|
149
|
+
}
|
150
|
+
_quantity = listing.quantity;
|
151
|
+
}
|
152
|
+
|
153
|
+
const buyTx = buyFromListing({
|
154
|
+
contract,
|
155
|
+
listingId,
|
156
|
+
quantity: _quantity,
|
157
|
+
recipient: account?.address || "",
|
158
|
+
});
|
159
|
+
|
160
|
+
const approveTx = await getApprovalForTransaction({
|
161
|
+
transaction: buyTx,
|
162
|
+
account,
|
163
|
+
});
|
164
|
+
|
165
|
+
if (approveTx) {
|
166
|
+
await mutateAsync(approveTx);
|
167
|
+
}
|
168
|
+
|
169
|
+
return buyTx;
|
170
|
+
}, [account, contract, quantity, listingId, mutateAsync]);
|
171
|
+
|
172
|
+
return (
|
173
|
+
<TransactionButton
|
174
|
+
payModal={{
|
175
|
+
metadata: defaultPayModalMetadata || payMetadata,
|
176
|
+
...payModal,
|
177
|
+
}}
|
178
|
+
transaction={() => prepareBuyTransaction()}
|
179
|
+
{...props}
|
180
|
+
>
|
181
|
+
{children}
|
182
|
+
</TransactionButton>
|
183
|
+
);
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* @internal
|
188
|
+
*/
|
189
|
+
async function getPayMetadata(
|
190
|
+
options: BaseTransactionOptions<{ listingId: bigint }>,
|
191
|
+
): Promise<{ name?: string; image?: string }> {
|
192
|
+
const listing = await getListing(options);
|
193
|
+
if (!listing) {
|
194
|
+
return { name: undefined, image: undefined };
|
195
|
+
}
|
196
|
+
return {
|
197
|
+
name: listing.asset?.metadata?.name,
|
198
|
+
image: listing.asset?.metadata?.image,
|
199
|
+
};
|
200
|
+
}
|
@@ -4,8 +4,13 @@ import {
|
|
4
4
|
type ThirdwebContract,
|
5
5
|
getContract,
|
6
6
|
} from "../../../../../../contract/contract.js";
|
7
|
+
import { getContractMetadata } from "../../../../../../extensions/common/read/getContractMetadata.js";
|
8
|
+
import { getNFT } from "../../../../../../extensions/erc1155/read/getNFT.js";
|
7
9
|
import type { PreparedTransaction } from "../../../../../../transaction/prepare-transaction.js";
|
10
|
+
import type { BaseTransactionOptions } from "../../../../../../transaction/types.js";
|
8
11
|
import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
|
12
|
+
import { useReadContract } from "../../../../../core/hooks/contract/useReadContract.js";
|
13
|
+
import { useSendAndConfirmTransaction } from "../../../../../core/hooks/transaction/useSendAndConfirmTransaction.js";
|
9
14
|
import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
|
10
15
|
import { TransactionButton } from "../../../TransactionButton/index.js";
|
11
16
|
import type {
|
@@ -28,6 +33,7 @@ import type {
|
|
28
33
|
* @param props
|
29
34
|
* @returns A wrapper for TransactionButton
|
30
35
|
*
|
36
|
+
* @component
|
31
37
|
* @example
|
32
38
|
*
|
33
39
|
* ```tsx
|
@@ -77,22 +83,66 @@ import type {
|
|
77
83
|
* Claim now
|
78
84
|
* </ClaimButton>
|
79
85
|
*
|
86
|
+
* // Attach custom Pay metadata
|
87
|
+
* <ClaimButton
|
88
|
+
* payModal={{
|
89
|
+
* metadata: {
|
90
|
+
* name: "Van Gogh Starry Night",
|
91
|
+
* image: "https://unsplash.com/starry-night.png"
|
92
|
+
* }
|
93
|
+
* }}
|
94
|
+
* >...</ClaimButton>
|
95
|
+
*
|
80
96
|
* ```
|
81
97
|
*/
|
82
98
|
export function ClaimButton(props: ClaimButtonProps) {
|
83
|
-
const { children, contractAddress, client, chain, claimParams } =
|
99
|
+
const { children, contractAddress, client, chain, claimParams, payModal } =
|
100
|
+
props;
|
101
|
+
const defaultPayModalMetadata = payModal ? payModal.metadata : undefined;
|
84
102
|
const contract = getContract({
|
85
103
|
address: contractAddress,
|
86
104
|
client,
|
87
105
|
chain,
|
88
106
|
});
|
107
|
+
|
108
|
+
const { data: payMetadata } = useReadContract(getPayMetadata, {
|
109
|
+
contract,
|
110
|
+
tokenId: claimParams.type === "ERC1155" ? claimParams.tokenId : undefined,
|
111
|
+
queryOptions: {
|
112
|
+
enabled: !defaultPayModalMetadata,
|
113
|
+
},
|
114
|
+
});
|
89
115
|
const account = useActiveAccount();
|
90
|
-
|
116
|
+
const { mutateAsync } = useSendAndConfirmTransaction();
|
91
117
|
return (
|
92
118
|
<TransactionButton
|
93
|
-
|
94
|
-
|
95
|
-
|
119
|
+
payModal={{
|
120
|
+
metadata: defaultPayModalMetadata || payMetadata,
|
121
|
+
...payModal,
|
122
|
+
}}
|
123
|
+
transaction={async () => {
|
124
|
+
if (!account) {
|
125
|
+
throw new Error("No account detected");
|
126
|
+
}
|
127
|
+
const [claimTx, { getApprovalForTransaction }] = await Promise.all([
|
128
|
+
getClaimTransaction({
|
129
|
+
contract,
|
130
|
+
account,
|
131
|
+
claimParams,
|
132
|
+
}),
|
133
|
+
import(
|
134
|
+
"../../../../../../extensions/erc20/write/getApprovalForTransaction.js"
|
135
|
+
),
|
136
|
+
]);
|
137
|
+
const approveTx = await getApprovalForTransaction({
|
138
|
+
transaction: claimTx,
|
139
|
+
account,
|
140
|
+
});
|
141
|
+
if (approveTx) {
|
142
|
+
await mutateAsync(approveTx);
|
143
|
+
}
|
144
|
+
return claimTx;
|
145
|
+
}}
|
96
146
|
{...props}
|
97
147
|
>
|
98
148
|
{children}
|
@@ -100,6 +150,29 @@ export function ClaimButton(props: ClaimButtonProps) {
|
|
100
150
|
);
|
101
151
|
}
|
102
152
|
|
153
|
+
/**
|
154
|
+
* @internal
|
155
|
+
*/
|
156
|
+
export async function getPayMetadata(
|
157
|
+
options: BaseTransactionOptions<{ tokenId?: bigint }>,
|
158
|
+
): Promise<{ name?: string; image?: string }> {
|
159
|
+
const { contract, tokenId } = options;
|
160
|
+
const [contractMetadata, nft] = await Promise.all([
|
161
|
+
getContractMetadata(options),
|
162
|
+
tokenId ? getNFT({ contract, tokenId }) : undefined,
|
163
|
+
]);
|
164
|
+
if (tokenId) {
|
165
|
+
return {
|
166
|
+
image: nft?.metadata?.image,
|
167
|
+
name: nft?.metadata?.name,
|
168
|
+
};
|
169
|
+
}
|
170
|
+
return {
|
171
|
+
image: contractMetadata?.image,
|
172
|
+
name: contractMetadata?.name,
|
173
|
+
};
|
174
|
+
}
|
175
|
+
|
103
176
|
/**
|
104
177
|
* @internal Export for test
|
105
178
|
*/
|
@@ -33,8 +33,9 @@ function getOauthLoginPath(
|
|
33
33
|
case "apple":
|
34
34
|
case "facebook":
|
35
35
|
case "google":
|
36
|
+
case "farcaster":
|
36
37
|
case "discord":
|
37
|
-
return getSocialAuthLoginPath(authOption, client, ecosystem);
|
38
|
+
return getSocialAuthLoginPath({ authOption, client, ecosystem });
|
38
39
|
default:
|
39
40
|
return "";
|
40
41
|
}
|
package/src/storage/download.ts
CHANGED
@@ -9,18 +9,58 @@ export type DownloadOptions = Prettify<
|
|
9
9
|
>;
|
10
10
|
|
11
11
|
/**
|
12
|
-
* Downloads a file from the specified URI.
|
12
|
+
* @description Downloads a file from the specified IPFS, Arweave, or HTTP URI.
|
13
|
+
*
|
14
|
+
* `download` will parse the provided URI based on its scheme (ipfs://, ar://, https://) and convert it to a URL to fetch the file from thirdweb's storage service.
|
15
|
+
*
|
13
16
|
* @param options - The download options.
|
14
|
-
* @
|
15
|
-
* @
|
17
|
+
* @param options.client - The Thirdweb client. See [createThirdwebClient](https://portal.thirdweb.com/references/typescript/v5/createThirdwebClient).
|
18
|
+
* @param options.uri - The URI of the file to download. Can be IPFS, Arweave, or HTTP.
|
19
|
+
* @param [options.requestTimeoutMs] - The maximum time in milliseconds to wait for the request to complete. Defaults to 60 seconds (60,000 milliseconds).
|
20
|
+
*
|
21
|
+
* @returns Asynchronously returns the network response from fetching the file.
|
22
|
+
* @throws An error if the URI scheme is invalid or if the request fails.
|
23
|
+
*
|
16
24
|
* @example
|
25
|
+
* Download a file from IPFS:
|
17
26
|
* ```ts
|
18
27
|
* import { download } from "thirdweb/storage";
|
28
|
+
* import { createThirdwebClient } from "@thirdweb-dev/sdk";
|
29
|
+
*
|
30
|
+
* const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID" });
|
31
|
+
*
|
19
32
|
* const file = await download({
|
20
33
|
* client,
|
21
34
|
* uri: "ipfs://Qm...",
|
22
35
|
* });
|
23
36
|
* ```
|
37
|
+
*
|
38
|
+
* Download a file from Arweave:
|
39
|
+
* ```ts
|
40
|
+
* import { download } from "thirdweb/storage";
|
41
|
+
* import { createThirdwebClient } from "@thirdweb-dev/sdk";
|
42
|
+
*
|
43
|
+
* const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID" });
|
44
|
+
*
|
45
|
+
* const file = await download({
|
46
|
+
* client,
|
47
|
+
* uri: "ar://{arweave-transaction-id}",
|
48
|
+
* });
|
49
|
+
* ```
|
50
|
+
*
|
51
|
+
* Download a file from HTTP:
|
52
|
+
* ```ts
|
53
|
+
* import { download } from "thirdweb/storage";
|
54
|
+
* import { createThirdwebClient } from "@thirdweb-dev/sdk";
|
55
|
+
*
|
56
|
+
* const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID" });
|
57
|
+
*
|
58
|
+
* const file = await download({
|
59
|
+
* client,
|
60
|
+
* uri: "https://example.com/file.txt",
|
61
|
+
* });
|
62
|
+
* ```
|
63
|
+
*
|
24
64
|
* @storage
|
25
65
|
*/
|
26
66
|
export async function download(options: DownloadOptions) {
|
@@ -31,11 +71,14 @@ export async function download(options: DownloadOptions) {
|
|
31
71
|
} else {
|
32
72
|
url = resolveScheme(options);
|
33
73
|
}
|
74
|
+
|
34
75
|
const res = await getClientFetch(options.client)(url, {
|
35
76
|
keepalive: options.client.config?.storage?.fetch?.keepalive,
|
36
77
|
headers: options.client.config?.storage?.fetch?.headers,
|
37
|
-
requestTimeoutMs:
|
78
|
+
requestTimeoutMs:
|
79
|
+
options.client.config?.storage?.fetch?.requestTimeoutMs ?? 60000,
|
38
80
|
});
|
81
|
+
|
39
82
|
if (!res.ok) {
|
40
83
|
res.body?.cancel();
|
41
84
|
throw new Error(`Failed to download file: ${res.statusText}`);
|
@@ -0,0 +1,160 @@
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
2
|
+
import { toHex } from "../encoding/hex.js";
|
3
|
+
import { parseAbiParams } from "./parse-abi-params.js";
|
4
|
+
|
5
|
+
describe("parseAbiParams", () => {
|
6
|
+
describe("parseAbiParams", () => {
|
7
|
+
it("should convert address and uint256 correctly", () => {
|
8
|
+
const types = ["address", "uint256"];
|
9
|
+
const values = ["0x1234567890abcdef1234567890abcdef12345678", "1200000"];
|
10
|
+
const expected = [
|
11
|
+
"0x1234567890abcdef1234567890abcdef12345678",
|
12
|
+
BigInt(1200000),
|
13
|
+
];
|
14
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
15
|
+
});
|
16
|
+
|
17
|
+
it("should convert address and bool correctly", () => {
|
18
|
+
const types = ["address", "bool"];
|
19
|
+
const values = ["0x1234567890abcdef1234567890abcdef12345678", "true"];
|
20
|
+
const expected = ["0x1234567890abcdef1234567890abcdef12345678", true];
|
21
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
22
|
+
});
|
23
|
+
|
24
|
+
it("should convert bytes32 correctly", () => {
|
25
|
+
const types = ["bytes32"];
|
26
|
+
const values = [
|
27
|
+
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
28
|
+
];
|
29
|
+
const expected = [
|
30
|
+
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
31
|
+
];
|
32
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
33
|
+
});
|
34
|
+
|
35
|
+
it("should throw an error for invalid hex in bytes32", () => {
|
36
|
+
const types = ["bytes32"];
|
37
|
+
const values = ["invalidHex"];
|
38
|
+
expect(() => parseAbiParams(types, values)).toThrowError(
|
39
|
+
"invalidHex is not a valid hex string",
|
40
|
+
);
|
41
|
+
});
|
42
|
+
|
43
|
+
it("should convert uint256 correctly", () => {
|
44
|
+
const types = ["uint256"];
|
45
|
+
const values = ["1200000"];
|
46
|
+
const expected = [BigInt(1200000)];
|
47
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
48
|
+
});
|
49
|
+
|
50
|
+
it("should throw an error for invalid address", () => {
|
51
|
+
const types = ["address"];
|
52
|
+
const values = ["invalidAddress"];
|
53
|
+
expect(() => parseAbiParams(types, values)).toThrowError(
|
54
|
+
"invalidAddress is not a valid address",
|
55
|
+
);
|
56
|
+
});
|
57
|
+
|
58
|
+
it("should throw an error for mismatched number of types and values", () => {
|
59
|
+
const types = ["address", "uint256"];
|
60
|
+
const values = ["0x1234567890abcdef1234567890abcdef12345678"];
|
61
|
+
expect(() => parseAbiParams(types, values)).toThrowError(
|
62
|
+
"Passed the wrong number of constructor arguments: 1, expected 2",
|
63
|
+
);
|
64
|
+
});
|
65
|
+
|
66
|
+
it("should convert tuple correctly", () => {
|
67
|
+
const types = ["tuple"];
|
68
|
+
const values = [
|
69
|
+
'["0x1234567890abcdef1234567890abcdef12345678", "1200000"]',
|
70
|
+
];
|
71
|
+
const expected = [
|
72
|
+
["0x1234567890abcdef1234567890abcdef12345678", "1200000"],
|
73
|
+
];
|
74
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
75
|
+
});
|
76
|
+
|
77
|
+
it("should convert array of addresses correctly", () => {
|
78
|
+
const types = ["address[]"];
|
79
|
+
const values = [
|
80
|
+
'["0x1234567890abcdef1234567890abcdef12345678", "0xabcdef1234567890abcdef1234567890abcdef12"]',
|
81
|
+
];
|
82
|
+
const expected = [
|
83
|
+
[
|
84
|
+
"0x1234567890abcdef1234567890abcdef12345678",
|
85
|
+
"0xabcdef1234567890abcdef1234567890abcdef12",
|
86
|
+
],
|
87
|
+
];
|
88
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
89
|
+
});
|
90
|
+
|
91
|
+
it('should convert boolean correctly for "true"', () => {
|
92
|
+
const types = ["bool"];
|
93
|
+
const values = ["true"];
|
94
|
+
const expected = [true];
|
95
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
96
|
+
});
|
97
|
+
|
98
|
+
it('should convert boolean correctly for "false"', () => {
|
99
|
+
const types = ["bool"];
|
100
|
+
const values = ["false"];
|
101
|
+
const expected = [false];
|
102
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
103
|
+
});
|
104
|
+
|
105
|
+
it("should convert boolean correctly for boolean true", () => {
|
106
|
+
const types = ["bool"];
|
107
|
+
const values = [true];
|
108
|
+
const expected = [true];
|
109
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
110
|
+
});
|
111
|
+
|
112
|
+
it("should convert boolean correctly for boolean false", () => {
|
113
|
+
const types = ["bool"];
|
114
|
+
const values = [false];
|
115
|
+
const expected = [false];
|
116
|
+
expect(parseAbiParams(types, values)).toEqual(expected);
|
117
|
+
});
|
118
|
+
|
119
|
+
it("should throw an error for invalid boolean value", () => {
|
120
|
+
const types = ["bool"];
|
121
|
+
const values = ["notBoolean"];
|
122
|
+
expect(() => parseAbiParams(types, values)).toThrowError(
|
123
|
+
"Invalid boolean value. Expecting either 'true' or 'false'",
|
124
|
+
);
|
125
|
+
});
|
126
|
+
|
127
|
+
it("should just return the value if already json-parsed", () => {
|
128
|
+
const types = ["tuple"];
|
129
|
+
const values = [{ cat: "orange" }];
|
130
|
+
expect(parseAbiParams(types, values)).toEqual(values);
|
131
|
+
});
|
132
|
+
|
133
|
+
it("should throw error if not a hex string", () => {
|
134
|
+
const values = ["orange cat"];
|
135
|
+
expect(() => parseAbiParams(["bytes64"], values)).toThrowError(
|
136
|
+
"orange cat is not a valid hex string",
|
137
|
+
);
|
138
|
+
|
139
|
+
expect(() => parseAbiParams(["bytes32"], values)).toThrowError(
|
140
|
+
"orange cat is not a valid hex string",
|
141
|
+
);
|
142
|
+
});
|
143
|
+
|
144
|
+
it("should throw error if cannot convert to BigInt", () => {
|
145
|
+
expect(() => parseAbiParams(["uint256"], [true])).toThrowError(
|
146
|
+
"Cannot convert type boolean to BigInt",
|
147
|
+
);
|
148
|
+
|
149
|
+
expect(() => parseAbiParams(["uint256"], ["cat"])).toThrowError(
|
150
|
+
"Cannot convert cat to a BigInt",
|
151
|
+
);
|
152
|
+
});
|
153
|
+
|
154
|
+
it("should return value unaltered if already a hex", () => {
|
155
|
+
const value = toHex("cat");
|
156
|
+
const result = parseAbiParams(["bytes64"], [value]);
|
157
|
+
expect(result).toStrictEqual([value]);
|
158
|
+
});
|
159
|
+
});
|
160
|
+
});
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { isAddress } from "../address.js";
|
2
|
+
import { isHex, padHex } from "../encoding/hex.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Converts an array of parameter values to their respective types based on the provided type array.
|
6
|
+
*
|
7
|
+
* This utility function is particularly useful for ensuring that parameter values are correctly formatted
|
8
|
+
* according to the expected types before they are used in further processing or passed to a Solidity smart contract.
|
9
|
+
*
|
10
|
+
* @param {string[]} constructorParamTypes - An array of type strings indicating the expected types of the values,
|
11
|
+
* following Solidity type conventions (e.g., "address", "uint256", "bool").
|
12
|
+
* @param {unknown[]} constructorParamValues - An array of values to be converted according to the types.
|
13
|
+
* @returns - An array of values converted to their respective types.
|
14
|
+
*
|
15
|
+
* @example
|
16
|
+
* ```ts
|
17
|
+
* import { parseAbiParams } from "thirdweb/utils";
|
18
|
+
*
|
19
|
+
* const example1 = parseAbiParams(
|
20
|
+
* ["address", "uint256"],
|
21
|
+
* ["0x.....", "1200000"]
|
22
|
+
* ); // result: ["0x......", 1200000n]
|
23
|
+
*
|
24
|
+
* const example2 = parseAbiParams(
|
25
|
+
* ["address", "bool"],
|
26
|
+
* ["0x.....", "true"]
|
27
|
+
* ); // result: ["0x......", true]
|
28
|
+
* ```
|
29
|
+
* @utils
|
30
|
+
*/
|
31
|
+
export function parseAbiParams(
|
32
|
+
constructorParamTypes: string[],
|
33
|
+
constructorParamValues: unknown[],
|
34
|
+
): Array<string | bigint | boolean> {
|
35
|
+
// Make sure they have the same length
|
36
|
+
if (constructorParamTypes.length !== constructorParamValues.length) {
|
37
|
+
throw new Error(
|
38
|
+
`Passed the wrong number of constructor arguments: ${constructorParamValues.length}, expected ${constructorParamTypes.length}`,
|
39
|
+
);
|
40
|
+
}
|
41
|
+
return constructorParamTypes.map((type, index) => {
|
42
|
+
const value = constructorParamValues[index];
|
43
|
+
if (type === "tuple" || type.endsWith("[]")) {
|
44
|
+
if (typeof value === "string") {
|
45
|
+
return JSON.parse(value);
|
46
|
+
}
|
47
|
+
return value;
|
48
|
+
}
|
49
|
+
if (type === "bytes32") {
|
50
|
+
if (!isHex(value)) {
|
51
|
+
throw new Error(`${value} is not a valid hex string`);
|
52
|
+
}
|
53
|
+
return padHex(value);
|
54
|
+
}
|
55
|
+
if (type.startsWith("bytes")) {
|
56
|
+
if (!isHex(value)) {
|
57
|
+
throw new Error(`${value} is not a valid hex string`);
|
58
|
+
}
|
59
|
+
return value;
|
60
|
+
}
|
61
|
+
if (type === "address") {
|
62
|
+
if (typeof value !== "string" || !isAddress(value)) {
|
63
|
+
throw new Error(`${value} is not a valid address`);
|
64
|
+
}
|
65
|
+
return value;
|
66
|
+
}
|
67
|
+
if (type.startsWith("uint") || type.startsWith("int")) {
|
68
|
+
if (typeof value !== "string" && typeof value !== "number") {
|
69
|
+
throw new Error(`Cannot convert type ${typeof value} to BigInt`);
|
70
|
+
}
|
71
|
+
try {
|
72
|
+
const val = BigInt(value);
|
73
|
+
return val;
|
74
|
+
} catch (err) {
|
75
|
+
throw new Error((err as Error).message);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
if (type.startsWith("bool")) {
|
79
|
+
if (value === "false" || value === false) {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
if (value === "true" || value === true) {
|
83
|
+
return true;
|
84
|
+
}
|
85
|
+
throw new Error(
|
86
|
+
"Invalid boolean value. Expecting either 'true' or 'false'",
|
87
|
+
);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
}
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.
|
1
|
+
export const version = "5.42.0-nightly-e27ebef85bb61342c3de53f85e134cf4a29f787c-20240730000342";
|