thirdweb 5.99.3 → 5.100.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/bridge/Buy.js +17 -13
- package/dist/cjs/bridge/Buy.js.map +1 -1
- package/dist/cjs/bridge/Chains.js +2 -2
- package/dist/cjs/bridge/Chains.js.map +1 -1
- package/dist/cjs/bridge/Onramp.js +152 -0
- package/dist/cjs/bridge/Onramp.js.map +1 -0
- package/dist/cjs/bridge/OnrampStatus.js +78 -0
- package/dist/cjs/bridge/OnrampStatus.js.map +1 -0
- package/dist/cjs/bridge/Routes.js +2 -2
- package/dist/cjs/bridge/Routes.js.map +1 -1
- package/dist/cjs/bridge/Sell.js +18 -14
- package/dist/cjs/bridge/Sell.js.map +1 -1
- package/dist/cjs/bridge/Status.js +15 -2
- package/dist/cjs/bridge/Status.js.map +1 -1
- package/dist/cjs/bridge/Transfer.js +229 -0
- package/dist/cjs/bridge/Transfer.js.map +1 -0
- package/dist/cjs/bridge/index.js +3 -1
- package/dist/cjs/bridge/index.js.map +1 -1
- package/dist/cjs/bridge/types/BridgeAction.js +3 -0
- package/dist/cjs/bridge/types/BridgeAction.js.map +1 -0
- package/dist/cjs/bridge/types/Token.js +3 -0
- package/dist/cjs/bridge/types/Token.js.map +1 -0
- package/dist/cjs/extensions/ens/resolve-l2-name.js +0 -2
- package/dist/cjs/extensions/ens/resolve-l2-name.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/getQuote.js +159 -53
- package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/getStatus.js +160 -14
- package/dist/cjs/pay/buyWithCrypto/getStatus.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js +95 -37
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -1
- package/dist/cjs/pay/buyWithFiat/getQuote.js +129 -33
- package/dist/cjs/pay/buyWithFiat/getQuote.js.map +1 -1
- package/dist/cjs/pay/buyWithFiat/getStatus.js +71 -20
- package/dist/cjs/pay/buyWithFiat/getStatus.js.map +1 -1
- package/dist/cjs/pay/utils/commonTypes.js +1 -1
- package/dist/cjs/pay/utils/commonTypes.js.map +1 -1
- package/dist/cjs/pay/utils/definitions.js +1 -43
- package/dist/cjs/pay/utils/definitions.js.map +1 -1
- package/dist/cjs/react/core/hooks/pay/useBuyWithFiatStatus.js +1 -3
- package/dist/cjs/react/core/hooks/pay/useBuyWithFiatStatus.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +44 -38
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/core/utils/wallet.js +15 -0
- package/dist/cjs/react/core/utils/wallet.js.map +1 -1
- package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +1 -1
- package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js +1 -23
- package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/locale/en.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/locale/en.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +0 -177
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +2 -10
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +5 -8
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +0 -15
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.js +0 -60
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +3 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js +4 -4
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js +83 -34
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js.map +1 -1
- package/dist/cjs/react/web/ui/TransactionButton/DepositScreen.js +133 -0
- package/dist/cjs/react/web/ui/TransactionButton/DepositScreen.js.map +1 -0
- package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.js +4 -3
- package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/TransactionButton/TransactionModal.js +9 -1
- package/dist/cjs/react/web/ui/TransactionButton/TransactionModal.js.map +1 -1
- package/dist/cjs/utils/any-evm/zksync/constants.js +1 -0
- package/dist/cjs/utils/any-evm/zksync/constants.js.map +1 -1
- package/dist/cjs/utils/domains.js +3 -0
- package/dist/cjs/utils/domains.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/bridge/Buy.js +17 -13
- package/dist/esm/bridge/Buy.js.map +1 -1
- package/dist/esm/bridge/Chains.js +2 -2
- package/dist/esm/bridge/Chains.js.map +1 -1
- package/dist/esm/bridge/Onramp.js +147 -0
- package/dist/esm/bridge/Onramp.js.map +1 -0
- package/dist/esm/bridge/OnrampStatus.js +75 -0
- package/dist/esm/bridge/OnrampStatus.js.map +1 -0
- package/dist/esm/bridge/Routes.js +2 -2
- package/dist/esm/bridge/Routes.js.map +1 -1
- package/dist/esm/bridge/Sell.js +18 -14
- package/dist/esm/bridge/Sell.js.map +1 -1
- package/dist/esm/bridge/Status.js +15 -2
- package/dist/esm/bridge/Status.js.map +1 -1
- package/dist/esm/bridge/Transfer.js +226 -0
- package/dist/esm/bridge/Transfer.js.map +1 -0
- package/dist/esm/bridge/index.js +2 -0
- package/dist/esm/bridge/index.js.map +1 -1
- package/dist/esm/bridge/types/BridgeAction.js +2 -0
- package/dist/esm/bridge/types/BridgeAction.js.map +1 -0
- package/dist/esm/bridge/types/Token.js +2 -0
- package/dist/esm/bridge/types/Token.js.map +1 -0
- package/dist/esm/extensions/ens/resolve-l2-name.js +0 -2
- package/dist/esm/extensions/ens/resolve-l2-name.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/getQuote.js +159 -53
- package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/getStatus.js +160 -14
- package/dist/esm/pay/buyWithCrypto/getStatus.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/getTransfer.js +95 -37
- package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -1
- package/dist/esm/pay/buyWithFiat/getQuote.js +129 -33
- package/dist/esm/pay/buyWithFiat/getQuote.js.map +1 -1
- package/dist/esm/pay/buyWithFiat/getStatus.js +71 -20
- package/dist/esm/pay/buyWithFiat/getStatus.js.map +1 -1
- package/dist/esm/pay/utils/commonTypes.js +1 -1
- package/dist/esm/pay/utils/commonTypes.js.map +1 -1
- package/dist/esm/pay/utils/definitions.js +0 -35
- package/dist/esm/pay/utils/definitions.js.map +1 -1
- package/dist/esm/react/core/hooks/pay/useBuyWithFiatStatus.js +1 -3
- package/dist/esm/react/core/hooks/pay/useBuyWithFiatStatus.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +44 -38
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/core/utils/wallet.js +15 -0
- package/dist/esm/react/core/utils/wallet.js.map +1 -1
- package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +1 -1
- package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js +1 -23
- package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/locale/en.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/locale/en.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +4 -180
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js +2 -10
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +5 -8
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js +2 -16
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.js +0 -59
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +3 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js +84 -34
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js.map +1 -1
- package/dist/esm/react/web/ui/TransactionButton/DepositScreen.js +130 -0
- package/dist/esm/react/web/ui/TransactionButton/DepositScreen.js.map +1 -0
- package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.js +4 -3
- package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.js.map +1 -1
- package/dist/esm/react/web/ui/TransactionButton/TransactionModal.js +9 -1
- package/dist/esm/react/web/ui/TransactionButton/TransactionModal.js.map +1 -1
- package/dist/esm/utils/any-evm/zksync/constants.js +1 -0
- package/dist/esm/utils/any-evm/zksync/constants.js.map +1 -1
- package/dist/esm/utils/domains.js +3 -0
- package/dist/esm/utils/domains.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/bridge/Buy.d.ts +11 -9
- package/dist/types/bridge/Buy.d.ts.map +1 -1
- package/dist/types/bridge/Onramp.d.ts +123 -0
- package/dist/types/bridge/Onramp.d.ts.map +1 -0
- package/dist/types/bridge/OnrampStatus.d.ts +108 -0
- package/dist/types/bridge/OnrampStatus.d.ts.map +1 -0
- package/dist/types/bridge/Sell.d.ts +13 -11
- package/dist/types/bridge/Sell.d.ts.map +1 -1
- package/dist/types/bridge/Status.d.ts.map +1 -1
- package/dist/types/bridge/Transfer.d.ts +199 -0
- package/dist/types/bridge/Transfer.d.ts.map +1 -0
- package/dist/types/bridge/index.d.ts +7 -3
- package/dist/types/bridge/index.d.ts.map +1 -1
- package/dist/types/bridge/types/BridgeAction.d.ts +2 -0
- package/dist/types/bridge/types/BridgeAction.d.ts.map +1 -0
- package/dist/types/bridge/types/Quote.d.ts +3 -65
- package/dist/types/bridge/types/Quote.d.ts.map +1 -1
- package/dist/types/bridge/types/Route.d.ts +38 -17
- package/dist/types/bridge/types/Route.d.ts.map +1 -1
- package/dist/types/bridge/types/Status.d.ts +15 -0
- package/dist/types/bridge/types/Status.d.ts.map +1 -1
- package/dist/types/bridge/types/Token.d.ts +11 -0
- package/dist/types/bridge/types/Token.d.ts.map +1 -0
- package/dist/types/extensions/ens/resolve-l2-name.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/commonTypes.d.ts +0 -9
- package/dist/types/pay/buyWithCrypto/commonTypes.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -1
- package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
- package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -1
- package/dist/types/pay/buyWithFiat/getQuote.d.ts.map +1 -1
- package/dist/types/pay/buyWithFiat/getStatus.d.ts +1 -12
- package/dist/types/pay/buyWithFiat/getStatus.d.ts.map +1 -1
- package/dist/types/pay/utils/commonTypes.d.ts +1 -1
- package/dist/types/pay/utils/commonTypes.d.ts.map +1 -1
- package/dist/types/pay/utils/definitions.d.ts +0 -35
- package/dist/types/pay/utils/definitions.d.ts.map +1 -1
- package/dist/types/react/core/hooks/pay/useBuyWithFiatStatus.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +1 -0
- package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
- package/dist/types/react/core/utils/wallet.d.ts.map +1 -1
- package/dist/types/react/web/hooks/transaction/useSendTransaction.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/fiat/FiatSteps.d.ts +1 -30
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/types.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/types.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.d.ts +0 -5
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.d.ts +1 -3
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.d.ts +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.d.ts +8 -4
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.d.ts.map +1 -1
- package/dist/types/react/web/ui/TransactionButton/DepositScreen.d.ts +15 -0
- package/dist/types/react/web/ui/TransactionButton/DepositScreen.d.ts.map +1 -0
- package/dist/types/react/web/ui/TransactionButton/ExecutingScreen.d.ts.map +1 -1
- package/dist/types/react/web/ui/TransactionButton/TransactionModal.d.ts +1 -0
- package/dist/types/react/web/ui/TransactionButton/TransactionModal.d.ts.map +1 -1
- package/dist/types/utils/any-evm/zksync/constants.d.ts.map +1 -1
- package/dist/types/utils/domains.d.ts +6 -0
- package/dist/types/utils/domains.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/bridge/Buy.ts +19 -13
- package/src/bridge/Chains.ts +2 -2
- package/src/bridge/Onramp.test.ts +118 -0
- package/src/bridge/Onramp.ts +244 -0
- package/src/bridge/OnrampStatus.ts +133 -0
- package/src/bridge/Routes.ts +2 -2
- package/src/bridge/Sell.ts +20 -14
- package/src/bridge/Status.ts +15 -2
- package/src/bridge/Transfer.test.ts +76 -0
- package/src/bridge/Transfer.ts +270 -0
- package/src/bridge/index.ts +12 -3
- package/src/bridge/types/BridgeAction.ts +1 -0
- package/src/bridge/types/Quote.ts +3 -65
- package/src/bridge/types/Route.ts +42 -17
- package/src/bridge/types/Status.ts +15 -1
- package/src/bridge/types/Token.ts +11 -0
- package/src/extensions/ens/resolve-l2-name.ts +0 -2
- package/src/pay/buyWithCrypto/commonTypes.ts +0 -10
- package/src/pay/buyWithCrypto/getQuote.ts +210 -100
- package/src/pay/buyWithCrypto/getStatus.ts +213 -20
- package/src/pay/buyWithCrypto/getTransfer.ts +129 -61
- package/src/pay/buyWithFiat/getQuote.ts +184 -33
- package/src/pay/buyWithFiat/getStatus.ts +101 -42
- package/src/pay/convert/cryptoToFiat.test.ts +7 -5
- package/src/pay/convert/fiatToCrypto.test.ts +6 -4
- package/src/pay/utils/commonTypes.ts +1 -1
- package/src/pay/utils/definitions.ts +0 -48
- package/src/react/core/hooks/pay/useBuyWithFiatStatus.ts +0 -2
- package/src/react/core/hooks/transaction/useSendTransaction.ts +53 -52
- package/src/react/core/utils/wallet.ts +15 -0
- package/src/react/web/hooks/transaction/useSendTransaction.tsx +1 -0
- package/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx +5 -64
- package/src/react/web/ui/ConnectWallet/locale/en.ts +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +3 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx +3 -510
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/OnRampScreen.tsx +2 -12
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/types.ts +2 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts +19 -20
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/SwapDetailsScreen.tsx +1 -37
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.test.ts +1 -95
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/statusMeta.ts +0 -69
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.tsx +3 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.tsx +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.ts +1 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.ts +118 -63
- package/src/react/web/ui/TransactionButton/DepositScreen.tsx +295 -0
- package/src/react/web/ui/TransactionButton/ExecutingScreen.tsx +4 -5
- package/src/react/web/ui/TransactionButton/TransactionModal.tsx +20 -1
- package/src/utils/any-evm/zksync/constants.ts +1 -0
- package/src/utils/domain.test.ts +1 -0
- package/src/utils/domains.ts +8 -0
- package/src/version.ts +1 -1
- package/dist/cjs/bridge/constants.js +0 -5
- package/dist/cjs/bridge/constants.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js +0 -37
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js +0 -86
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js +0 -25
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +0 -54
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js +0 -52
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.js +0 -81
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.js +0 -17
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.js.map +0 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js +0 -138
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js.map +0 -1
- package/dist/esm/bridge/constants.js +0 -2
- package/dist/esm/bridge/constants.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js +0 -34
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js +0 -83
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js +0 -22
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +0 -51
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js +0 -48
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.js +0 -78
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.js +0 -14
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.js.map +0 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js +0 -135
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js.map +0 -1
- package/dist/types/bridge/constants.d.ts +0 -2
- package/dist/types/bridge/constants.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.d.ts +0 -26
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.d.ts +0 -16
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.d.ts +0 -23
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts +0 -10
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.d.ts +0 -9
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.d.ts +0 -14
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.d.ts +0 -14
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.d.ts.map +0 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.d.ts +0 -21
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.d.ts.map +0 -1
- package/src/bridge/constants.ts +0 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.tsx +0 -142
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwap.tsx +0 -170
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/PostOnRampSwapFlow.tsx +0 -63
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.tsx +0 -163
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.tsx +0 -127
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.tsx +0 -138
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/TxDetailsScreen.tsx +0 -45
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.ts +0 -191
@@ -1,17 +1,13 @@
|
|
1
|
-
import
|
1
|
+
import { Value } from "ox";
|
2
|
+
import * as ox__AbiFunction from "ox/AbiFunction";
|
3
|
+
import { Transfer } from "../../bridge/index.js";
|
2
4
|
import { getCachedChain } from "../../chains/utils.js";
|
3
5
|
import type { ThirdwebClient } from "../../client/client.js";
|
6
|
+
import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
|
7
|
+
import { getContract } from "../../contract/contract.js";
|
8
|
+
import { decimals } from "../../extensions/erc20/read/decimals.js";
|
4
9
|
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
|
5
|
-
import type {
|
6
|
-
import { getClientFetch } from "../../utils/fetch.js";
|
7
|
-
import { stringify } from "../../utils/json.js";
|
8
|
-
import { getPayBuyWithCryptoTransferEndpoint } from "../utils/definitions.js";
|
9
|
-
import type {
|
10
|
-
QuoteApprovalInfo,
|
11
|
-
QuotePaymentToken,
|
12
|
-
QuoteTokenInfo,
|
13
|
-
QuoteTransactionRequest,
|
14
|
-
} from "./commonTypes.js";
|
10
|
+
import type { QuoteApprovalInfo, QuotePaymentToken } from "./commonTypes.js";
|
15
11
|
|
16
12
|
/**
|
17
13
|
* The parameters for [`getBuyWithCryptoTransfer`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithCryptoTransfer) function
|
@@ -66,21 +62,6 @@ export type GetBuyWithCryptoTransferParams = {
|
|
66
62
|
feePayer?: "sender" | "receiver";
|
67
63
|
};
|
68
64
|
|
69
|
-
/**
|
70
|
-
* @buyCrypto
|
71
|
-
*/
|
72
|
-
type BuyWithCryptoTransferResponse = {
|
73
|
-
quoteId: string;
|
74
|
-
transactionRequest: QuoteTransactionRequest;
|
75
|
-
approval?: QuoteApprovalInfo;
|
76
|
-
fromAddress: string;
|
77
|
-
toAddress: string;
|
78
|
-
token: QuoteTokenInfo;
|
79
|
-
paymentToken: QuotePaymentToken;
|
80
|
-
processingFee: QuotePaymentToken;
|
81
|
-
estimatedGasCostUSDCents: number;
|
82
|
-
};
|
83
|
-
|
84
65
|
/**
|
85
66
|
* @buyCrypto
|
86
67
|
*/
|
@@ -126,50 +107,137 @@ export async function getBuyWithCryptoTransfer(
|
|
126
107
|
params: GetBuyWithCryptoTransferParams,
|
127
108
|
): Promise<BuyWithCryptoTransfer> {
|
128
109
|
try {
|
129
|
-
const
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
110
|
+
const tokenContract = getContract({
|
111
|
+
address: params.tokenAddress,
|
112
|
+
chain: getCachedChain(params.chainId),
|
113
|
+
client: params.client,
|
114
|
+
});
|
115
|
+
const tokenDecimals =
|
116
|
+
tokenContract.address.toLowerCase() === NATIVE_TOKEN_ADDRESS
|
117
|
+
? 18
|
118
|
+
: await decimals({
|
119
|
+
contract: tokenContract,
|
120
|
+
});
|
121
|
+
const amount = Value.from(params.amount, tokenDecimals);
|
122
|
+
const quote = await Transfer.prepare({
|
123
|
+
chainId: params.chainId,
|
124
|
+
tokenAddress: params.tokenAddress,
|
125
|
+
amount,
|
126
|
+
sender: params.fromAddress,
|
127
|
+
receiver: params.toAddress,
|
128
|
+
client: params.client,
|
129
|
+
feePayer: params.feePayer,
|
146
130
|
});
|
147
131
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
132
|
+
const firstStep = quote.steps[0];
|
133
|
+
if (!firstStep) {
|
134
|
+
throw new Error(
|
135
|
+
"This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.",
|
136
|
+
);
|
154
137
|
}
|
155
138
|
|
156
|
-
const
|
139
|
+
const approvalTxs = firstStep.transactions.filter(
|
140
|
+
(tx) => tx.action === "approval",
|
141
|
+
);
|
142
|
+
if (approvalTxs.length > 1) {
|
143
|
+
throw new Error(
|
144
|
+
"This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.",
|
145
|
+
);
|
146
|
+
}
|
147
|
+
const approvalTx = approvalTxs[0];
|
148
|
+
|
149
|
+
let approvalData: QuoteApprovalInfo | undefined;
|
150
|
+
if (approvalTx) {
|
151
|
+
const abiFunction = ox__AbiFunction.from([
|
152
|
+
"function approve(address spender, uint256 amount)",
|
153
|
+
]);
|
154
|
+
const [spender, amount] = ox__AbiFunction.decodeData(
|
155
|
+
abiFunction,
|
156
|
+
approvalTx.data,
|
157
|
+
);
|
158
|
+
approvalData = {
|
159
|
+
chainId: firstStep.originToken.chainId,
|
160
|
+
tokenAddress: firstStep.originToken.address,
|
161
|
+
spenderAddress: spender,
|
162
|
+
amountWei: amount.toString(),
|
163
|
+
};
|
164
|
+
}
|
165
|
+
|
166
|
+
const txs = firstStep.transactions.filter((tx) => tx.action !== "approval");
|
167
|
+
if (txs.length > 1) {
|
168
|
+
throw new Error(
|
169
|
+
"This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.",
|
170
|
+
);
|
171
|
+
}
|
172
|
+
const tx = txs[0];
|
173
|
+
if (!tx) {
|
174
|
+
throw new Error(
|
175
|
+
"This quote is incompatible with getBuyWithCryptoTransfer. Please use Bridge.Transfer.prepare instead.",
|
176
|
+
);
|
177
|
+
}
|
157
178
|
|
158
179
|
const transfer: BuyWithCryptoTransfer = {
|
159
180
|
transactionRequest: {
|
160
|
-
|
161
|
-
client: params.client,
|
162
|
-
data: data.transactionRequest.data as Hash,
|
163
|
-
to: data.transactionRequest.to as Address,
|
164
|
-
value: BigInt(data.transactionRequest.value),
|
181
|
+
...tx,
|
165
182
|
extraGas: 50000n, // extra gas buffer
|
166
183
|
},
|
167
|
-
approvalData
|
168
|
-
fromAddress:
|
169
|
-
toAddress:
|
170
|
-
paymentToken:
|
171
|
-
|
172
|
-
|
184
|
+
approvalData,
|
185
|
+
fromAddress: params.fromAddress,
|
186
|
+
toAddress: params.toAddress,
|
187
|
+
paymentToken: {
|
188
|
+
token: {
|
189
|
+
tokenAddress: firstStep.originToken.address,
|
190
|
+
chainId: firstStep.originToken.chainId,
|
191
|
+
decimals: firstStep.originToken.decimals,
|
192
|
+
symbol: firstStep.originToken.symbol,
|
193
|
+
name: firstStep.originToken.name,
|
194
|
+
priceUSDCents: firstStep.originToken.priceUsd * 100,
|
195
|
+
},
|
196
|
+
amountWei: quote.originAmount.toString(),
|
197
|
+
amount: Value.format(
|
198
|
+
quote.originAmount,
|
199
|
+
firstStep.originToken.decimals,
|
200
|
+
).toString(),
|
201
|
+
amountUSDCents:
|
202
|
+
Number(
|
203
|
+
Value.format(quote.originAmount, firstStep.originToken.decimals),
|
204
|
+
) *
|
205
|
+
firstStep.originToken.priceUsd *
|
206
|
+
100,
|
207
|
+
},
|
208
|
+
processingFee: {
|
209
|
+
token: {
|
210
|
+
tokenAddress: firstStep.originToken.address,
|
211
|
+
chainId: firstStep.originToken.chainId,
|
212
|
+
decimals: firstStep.originToken.decimals,
|
213
|
+
symbol: firstStep.originToken.symbol,
|
214
|
+
name: firstStep.originToken.name,
|
215
|
+
priceUSDCents: firstStep.originToken.priceUsd * 100,
|
216
|
+
},
|
217
|
+
amountWei:
|
218
|
+
params.feePayer === "sender"
|
219
|
+
? (quote.originAmount - quote.destinationAmount).toString()
|
220
|
+
: "0",
|
221
|
+
amount:
|
222
|
+
params.feePayer === "sender"
|
223
|
+
? Value.format(
|
224
|
+
quote.originAmount - quote.destinationAmount,
|
225
|
+
firstStep.originToken.decimals,
|
226
|
+
).toString()
|
227
|
+
: "0",
|
228
|
+
amountUSDCents:
|
229
|
+
params.feePayer === "sender"
|
230
|
+
? Number(
|
231
|
+
Value.format(
|
232
|
+
quote.originAmount - quote.destinationAmount,
|
233
|
+
firstStep.originToken.decimals,
|
234
|
+
),
|
235
|
+
) *
|
236
|
+
firstStep.originToken.priceUsd *
|
237
|
+
100
|
238
|
+
: 0,
|
239
|
+
},
|
240
|
+
estimatedGasCostUSDCents: 0,
|
173
241
|
client: params.client,
|
174
242
|
};
|
175
243
|
|
@@ -1,9 +1,12 @@
|
|
1
|
+
import { prepare as prepareOnramp } from "../../bridge/Onramp.js";
|
2
|
+
import { getCachedChain } from "../../chains/utils.js";
|
1
3
|
import type { ThirdwebClient } from "../../client/client.js";
|
4
|
+
import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
|
5
|
+
import { getContract } from "../../contract/contract.js";
|
6
|
+
import { decimals } from "../../extensions/erc20/read/decimals.js";
|
2
7
|
import type { CurrencyMeta } from "../../react/web/ui/ConnectWallet/screens/Buy/fiat/currencies.js";
|
3
|
-
import {
|
4
|
-
import { stringify } from "../../utils/json.js";
|
8
|
+
import { toTokens, toUnits } from "../../utils/units.js";
|
5
9
|
import type { FiatProvider, PayTokenInfo } from "../utils/commonTypes.js";
|
6
|
-
import { getPayBuyWithFiatQuoteEndpoint } from "../utils/definitions.js";
|
7
10
|
/**
|
8
11
|
* Parameters for [`getBuyWithFiatQuote`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatQuote) function
|
9
12
|
* @deprecated
|
@@ -274,41 +277,189 @@ export async function getBuyWithFiatQuote(
|
|
274
277
|
params: GetBuyWithFiatQuoteParams,
|
275
278
|
): Promise<BuyWithFiatQuote> {
|
276
279
|
try {
|
277
|
-
|
280
|
+
// map preferred provider (FiatProvider) → onramp string expected by Onramp.prepare
|
281
|
+
const mapProviderToOnramp = (
|
282
|
+
provider?: FiatProvider,
|
283
|
+
): "stripe" | "coinbase" | "transak" => {
|
284
|
+
switch (provider) {
|
285
|
+
case "STRIPE":
|
286
|
+
return "stripe";
|
287
|
+
case "TRANSAK":
|
288
|
+
return "transak";
|
289
|
+
default: // default to coinbase when undefined or any other value
|
290
|
+
return "coinbase";
|
291
|
+
}
|
292
|
+
};
|
278
293
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
294
|
+
// Choose provider or default to STRIPE
|
295
|
+
const onrampProvider = mapProviderToOnramp(params.preferredProvider);
|
296
|
+
|
297
|
+
const d =
|
298
|
+
params.toTokenAddress !== NATIVE_TOKEN_ADDRESS
|
299
|
+
? await decimals({
|
300
|
+
contract: getContract({
|
301
|
+
client: params.client,
|
302
|
+
address: params.toTokenAddress,
|
303
|
+
chain: getCachedChain(params.toChainId),
|
304
|
+
}),
|
305
|
+
})
|
306
|
+
: 18;
|
307
|
+
|
308
|
+
// Prepare amount in wei if provided
|
309
|
+
const amountWei = params.toAmount ? toUnits(params.toAmount, d) : undefined;
|
310
|
+
|
311
|
+
// Call new Onramp.prepare to get the quote & link
|
312
|
+
const prepared = await prepareOnramp({
|
313
|
+
client: params.client,
|
314
|
+
onramp: onrampProvider,
|
315
|
+
chainId: params.toChainId,
|
316
|
+
tokenAddress: params.toTokenAddress,
|
317
|
+
receiver: params.toAddress,
|
318
|
+
sender: params.fromAddress,
|
319
|
+
amount: amountWei,
|
320
|
+
purchaseData: params.purchaseData,
|
321
|
+
currency: params.fromCurrencySymbol,
|
322
|
+
maxSteps: 2,
|
323
|
+
onrampTokenAddress: NATIVE_TOKEN_ADDRESS, // force onramp to native token to avoid missing gas issues
|
300
324
|
});
|
301
325
|
|
302
|
-
//
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
326
|
+
// Determine tokens based on steps rules
|
327
|
+
const hasSteps = prepared.steps.length > 0;
|
328
|
+
const firstStep = hasSteps
|
329
|
+
? (prepared.steps[0] as (typeof prepared.steps)[number])
|
330
|
+
: undefined;
|
331
|
+
|
332
|
+
// Estimated duration in seconds – sum of all step durations
|
333
|
+
const estimatedDurationSeconds = Math.max(
|
334
|
+
120,
|
335
|
+
Math.ceil(
|
336
|
+
prepared.steps.reduce((acc, s) => acc + s.estimatedExecutionTimeMs, 0) /
|
337
|
+
1000,
|
338
|
+
),
|
339
|
+
);
|
340
|
+
|
341
|
+
const estimatedToAmountMinWeiBigInt = prepared.destinationAmount;
|
342
|
+
|
343
|
+
const maxSlippageBPS = params.maxSlippageBPS ?? 0;
|
344
|
+
const slippageWei =
|
345
|
+
(estimatedToAmountMinWeiBigInt * BigInt(maxSlippageBPS)) / 10000n;
|
346
|
+
const toAmountMinWeiBigInt = estimatedToAmountMinWeiBigInt - slippageWei;
|
347
|
+
|
348
|
+
const estimatedToAmountMin = toTokens(estimatedToAmountMinWeiBigInt, d);
|
349
|
+
const toAmountMin = toTokens(toAmountMinWeiBigInt, d);
|
350
|
+
|
351
|
+
// Helper to convert a Token → PayTokenInfo
|
352
|
+
const tokenToPayTokenInfo = (token: {
|
353
|
+
chainId: number;
|
354
|
+
address: string;
|
355
|
+
decimals: number;
|
356
|
+
symbol: string;
|
357
|
+
name: string;
|
358
|
+
priceUsd: number;
|
359
|
+
}): PayTokenInfo => ({
|
360
|
+
chainId: token.chainId,
|
361
|
+
tokenAddress: token.address,
|
362
|
+
decimals: token.decimals,
|
363
|
+
priceUSDCents: Math.round(token.priceUsd * 100),
|
364
|
+
name: token.name,
|
365
|
+
symbol: token.symbol,
|
366
|
+
});
|
367
|
+
|
368
|
+
// Determine the raw token objects using new simplified rules
|
369
|
+
// 1. toToken is always the destination token
|
370
|
+
const toTokenRaw = prepared.destinationToken;
|
371
|
+
|
372
|
+
// 2. onRampToken: if exactly one step -> originToken of that step, else toTokenRaw
|
373
|
+
const onRampTokenRaw =
|
374
|
+
prepared.steps.length > 0 && firstStep
|
375
|
+
? firstStep.originToken
|
376
|
+
: toTokenRaw;
|
377
|
+
|
378
|
+
// 3. routingToken: if exactly two steps -> originToken of second step, else undefined
|
379
|
+
const routingTokenRaw =
|
380
|
+
prepared.steps.length > 1
|
381
|
+
? (prepared.steps[1] as (typeof prepared.steps)[number]).originToken
|
382
|
+
: undefined;
|
383
|
+
|
384
|
+
// Amounts for onRampToken/raw
|
385
|
+
const onRampTokenAmountWei: bigint =
|
386
|
+
prepared.steps.length > 0 && firstStep
|
387
|
+
? firstStep.originAmount
|
388
|
+
: prepared.destinationAmount;
|
389
|
+
|
390
|
+
const onRampTokenAmount = toTokens(
|
391
|
+
onRampTokenAmountWei,
|
392
|
+
onRampTokenRaw.decimals,
|
393
|
+
);
|
394
|
+
|
395
|
+
// Build info objects
|
396
|
+
const onRampTokenObject = {
|
397
|
+
amount: onRampTokenAmount,
|
398
|
+
amountWei: onRampTokenAmountWei.toString(),
|
399
|
+
amountUSDCents: Math.round(
|
400
|
+
Number(onRampTokenAmount) * onRampTokenRaw.priceUsd * 100,
|
401
|
+
),
|
402
|
+
token: tokenToPayTokenInfo(onRampTokenRaw),
|
403
|
+
};
|
404
|
+
|
405
|
+
let routingTokenObject:
|
406
|
+
| {
|
407
|
+
amount: string;
|
408
|
+
amountWei: string;
|
409
|
+
amountUSDCents: number;
|
410
|
+
token: PayTokenInfo;
|
411
|
+
}
|
412
|
+
| undefined;
|
413
|
+
|
414
|
+
if (routingTokenRaw) {
|
415
|
+
const routingAmountWei = (
|
416
|
+
prepared.steps[1] as (typeof prepared.steps)[number]
|
417
|
+
).originAmount;
|
418
|
+
const routingAmount = toTokens(
|
419
|
+
routingAmountWei,
|
420
|
+
routingTokenRaw.decimals,
|
421
|
+
);
|
422
|
+
routingTokenObject = {
|
423
|
+
amount: routingAmount,
|
424
|
+
amountWei: routingAmountWei.toString(),
|
425
|
+
amountUSDCents: Math.round(
|
426
|
+
Number(routingAmount) * routingTokenRaw.priceUsd * 100,
|
427
|
+
),
|
428
|
+
token: tokenToPayTokenInfo(routingTokenRaw),
|
429
|
+
};
|
309
430
|
}
|
310
431
|
|
311
|
-
|
432
|
+
const buyWithFiatQuote: BuyWithFiatQuote = {
|
433
|
+
estimatedDurationSeconds,
|
434
|
+
estimatedToAmountMin: estimatedToAmountMin,
|
435
|
+
estimatedToAmountMinWei: estimatedToAmountMinWeiBigInt.toString(),
|
436
|
+
toAmountMinWei: toAmountMinWeiBigInt.toString(),
|
437
|
+
toAmountMin: toAmountMin,
|
438
|
+
fromCurrency: {
|
439
|
+
amount: prepared.currencyAmount.toString(),
|
440
|
+
amountUnits: Number(prepared.currencyAmount).toFixed(2),
|
441
|
+
decimals: 2,
|
442
|
+
currencySymbol: prepared.currency,
|
443
|
+
},
|
444
|
+
fromCurrencyWithFees: {
|
445
|
+
amount: prepared.currencyAmount.toString(),
|
446
|
+
amountUnits: Number(prepared.currencyAmount).toFixed(2),
|
447
|
+
decimals: 2,
|
448
|
+
currencySymbol: prepared.currency,
|
449
|
+
},
|
450
|
+
toToken: tokenToPayTokenInfo(toTokenRaw),
|
451
|
+
toAddress: params.toAddress,
|
452
|
+
fromAddress: params.fromAddress,
|
453
|
+
maxSlippageBPS: maxSlippageBPS,
|
454
|
+
intentId: prepared.id,
|
455
|
+
processingFees: [],
|
456
|
+
onRampToken: onRampTokenObject,
|
457
|
+
routingToken: routingTokenObject,
|
458
|
+
onRampLink: prepared.link,
|
459
|
+
provider: (params.preferredProvider ?? "COINBASE") as FiatProvider,
|
460
|
+
};
|
461
|
+
|
462
|
+
return buyWithFiatQuote;
|
312
463
|
} catch (error) {
|
313
464
|
console.error("Error getting buy with fiat quote", error);
|
314
465
|
throw error;
|
@@ -1,10 +1,9 @@
|
|
1
|
+
import { status as onrampStatus } from "../../bridge/OnrampStatus.js";
|
1
2
|
import type { ThirdwebClient } from "../../client/client.js";
|
2
|
-
import { getClientFetch } from "../../utils/fetch.js";
|
3
3
|
import type {
|
4
4
|
PayOnChainTransactionDetails,
|
5
5
|
PayTokenInfo,
|
6
6
|
} from "../utils/commonTypes.js";
|
7
|
-
import { getPayBuyWithFiatStatusEndpoint } from "../utils/definitions.js";
|
8
7
|
|
9
8
|
/**
|
10
9
|
* Parameters for the [`getBuyWithFiatStatus`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatStatus) function
|
@@ -25,11 +24,6 @@ export type GetBuyWithFiatStatusParams = {
|
|
25
24
|
intentId: string;
|
26
25
|
};
|
27
26
|
|
28
|
-
export type ValidBuyWithFiatStatus = Exclude<
|
29
|
-
BuyWithFiatStatus,
|
30
|
-
{ status: "NOT_FOUND" }
|
31
|
-
>;
|
32
|
-
|
33
27
|
/**
|
34
28
|
* The returned object from [`getBuyWithFiatStatus`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithFiatStatus) function
|
35
29
|
*
|
@@ -50,28 +44,13 @@ export type BuyWithFiatStatus =
|
|
50
44
|
* - `NONE` - No status
|
51
45
|
* - `PENDING_PAYMENT` - Payment is not done yet in the on-ramp provider
|
52
46
|
* - `PAYMENT_FAILED` - Payment failed in the on-ramp provider
|
53
|
-
* - `PENDING_ON_RAMP_TRANSFER` - Payment is done but the on-ramp provider is yet to transfer the tokens to the user's wallet
|
54
|
-
* - `ON_RAMP_TRANSFER_IN_PROGRESS` - On-ramp provider is transferring the tokens to the user's wallet
|
55
47
|
* - `ON_RAMP_TRANSFER_COMPLETED` - On-ramp provider has transferred the tokens to the user's wallet
|
56
|
-
* - `ON_RAMP_TRANSFER_FAILED` - On-ramp provider failed to transfer the tokens to the user's wallet
|
57
|
-
* - `CRYPTO_SWAP_REQUIRED` - On-ramp provider has sent the tokens to the user's wallet but a swap is required to convert it to the desired token
|
58
|
-
* - `CRYPTO_SWAP_IN_PROGRESS` - Swap is in progress
|
59
|
-
* - `CRYPTO_SWAP_COMPLETED` - Swap is completed and the user has received the desired token
|
60
|
-
* - `CRYPTO_SWAP_FALLBACK` - Swap failed and the user has received a fallback token which is not the desired token
|
61
48
|
*/
|
62
49
|
status:
|
63
50
|
| "NONE"
|
64
51
|
| "PENDING_PAYMENT"
|
65
52
|
| "PAYMENT_FAILED"
|
66
|
-
| "
|
67
|
-
| "ON_RAMP_TRANSFER_IN_PROGRESS"
|
68
|
-
| "ON_RAMP_TRANSFER_COMPLETED"
|
69
|
-
| "ON_RAMP_TRANSFER_FAILED"
|
70
|
-
| "CRYPTO_SWAP_REQUIRED"
|
71
|
-
| "CRYPTO_SWAP_COMPLETED"
|
72
|
-
| "CRYPTO_SWAP_FALLBACK"
|
73
|
-
| "CRYPTO_SWAP_IN_PROGRESS"
|
74
|
-
| "CRYPTO_SWAP_FAILED";
|
53
|
+
| "ON_RAMP_TRANSFER_COMPLETED";
|
75
54
|
/**
|
76
55
|
* The wallet address to which the desired tokens are sent to
|
77
56
|
*/
|
@@ -171,7 +150,6 @@ export type BuyWithFiatStatus =
|
|
171
150
|
* })
|
172
151
|
*
|
173
152
|
* // when the fiatStatus.status is "ON_RAMP_TRANSFER_COMPLETED" - the process is complete
|
174
|
-
* // when the fiatStatus.status is "CRYPTO_SWAP_REQUIRED" - start the swap process
|
175
153
|
* ```
|
176
154
|
* @deprecated
|
177
155
|
* @buyCrypto
|
@@ -179,26 +157,107 @@ export type BuyWithFiatStatus =
|
|
179
157
|
export async function getBuyWithFiatStatus(
|
180
158
|
params: GetBuyWithFiatStatusParams,
|
181
159
|
): Promise<BuyWithFiatStatus> {
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
160
|
+
const result = await onrampStatus({
|
161
|
+
id: params.intentId,
|
162
|
+
client: params.client,
|
163
|
+
});
|
186
164
|
|
187
|
-
|
188
|
-
|
165
|
+
return toBuyWithFiatStatus({ intentId: params.intentId, result });
|
166
|
+
}
|
189
167
|
|
190
|
-
|
168
|
+
////////////////////////////////////////////////////////////////////////////////
|
169
|
+
// Helpers
|
170
|
+
////////////////////////////////////////////////////////////////////////////////
|
191
171
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
172
|
+
function toBuyWithFiatStatus(args: {
|
173
|
+
intentId: string;
|
174
|
+
result: Awaited<ReturnType<typeof onrampStatus>>;
|
175
|
+
}): BuyWithFiatStatus {
|
176
|
+
const { intentId, result } = args;
|
177
|
+
|
178
|
+
// Map status constants from the Bridge.Onramp.status response to BuyWithFiatStatus equivalents.
|
179
|
+
const STATUS_MAP: Record<
|
180
|
+
typeof result.status,
|
181
|
+
"NONE" | "PENDING_PAYMENT" | "PAYMENT_FAILED" | "ON_RAMP_TRANSFER_COMPLETED"
|
182
|
+
> = {
|
183
|
+
CREATED: "PENDING_PAYMENT",
|
184
|
+
PENDING: "PENDING_PAYMENT",
|
185
|
+
FAILED: "PAYMENT_FAILED",
|
186
|
+
COMPLETED: "ON_RAMP_TRANSFER_COMPLETED",
|
187
|
+
} as const;
|
188
|
+
|
189
|
+
const mappedStatus = STATUS_MAP[result.status];
|
190
|
+
|
191
|
+
return buildPlaceholderStatus({
|
192
|
+
intentId,
|
193
|
+
status: mappedStatus,
|
194
|
+
purchaseData: result.purchaseData,
|
195
|
+
});
|
196
|
+
}
|
197
|
+
|
198
|
+
function buildPlaceholderStatus(args: {
|
199
|
+
intentId: string;
|
200
|
+
status:
|
201
|
+
| "NONE"
|
202
|
+
| "PENDING_PAYMENT"
|
203
|
+
| "PAYMENT_FAILED"
|
204
|
+
| "ON_RAMP_TRANSFER_COMPLETED";
|
205
|
+
purchaseData?: unknown;
|
206
|
+
}): BuyWithFiatStatus {
|
207
|
+
const { intentId, status, purchaseData } = args;
|
208
|
+
|
209
|
+
// Build a minimal—but type-complete—object that satisfies BuyWithFiatStatus.
|
210
|
+
const emptyToken: PayTokenInfo = {
|
211
|
+
chainId: 0,
|
212
|
+
tokenAddress: "",
|
213
|
+
decimals: 18,
|
214
|
+
priceUSDCents: 0,
|
215
|
+
name: "",
|
216
|
+
symbol: "",
|
217
|
+
};
|
218
|
+
|
219
|
+
type BuyWithFiatStatusWithData = Exclude<
|
220
|
+
BuyWithFiatStatus,
|
221
|
+
{ status: "NOT_FOUND" }
|
222
|
+
>;
|
223
|
+
|
224
|
+
const quote: BuyWithFiatStatusWithData["quote"] = {
|
225
|
+
estimatedOnRampAmount: "0",
|
226
|
+
estimatedOnRampAmountWei: "0",
|
227
|
+
|
228
|
+
estimatedToTokenAmount: "0",
|
229
|
+
estimatedToTokenAmountWei: "0",
|
230
|
+
|
231
|
+
fromCurrency: {
|
232
|
+
amount: "0",
|
233
|
+
amountUnits: "USD",
|
234
|
+
decimals: 2,
|
235
|
+
currencySymbol: "USD",
|
236
|
+
},
|
237
|
+
fromCurrencyWithFees: {
|
238
|
+
amount: "0",
|
239
|
+
amountUnits: "USD",
|
240
|
+
decimals: 2,
|
241
|
+
currencySymbol: "USD",
|
242
|
+
},
|
243
|
+
onRampToken: emptyToken,
|
244
|
+
toToken: emptyToken,
|
245
|
+
estimatedDurationSeconds: 0,
|
246
|
+
createdAt: new Date().toISOString(),
|
247
|
+
} as BuyWithFiatStatusWithData["quote"];
|
248
|
+
|
249
|
+
// The source/destination fields can only be filled accurately when extra context is returned
|
250
|
+
// by the API. Since Bridge.Onramp.status doesn't yet provide these details, we omit them for
|
251
|
+
// now (they are optional).
|
252
|
+
|
253
|
+
const base: Exclude<BuyWithFiatStatus, { status: "NOT_FOUND" }> = {
|
254
|
+
intentId,
|
255
|
+
status,
|
256
|
+
toAddress: "",
|
257
|
+
fromAddress: "",
|
258
|
+
quote,
|
259
|
+
purchaseData: purchaseData as object | undefined,
|
260
|
+
};
|
198
261
|
|
199
|
-
|
200
|
-
} catch (error) {
|
201
|
-
console.error("Fetch error:", error);
|
202
|
-
throw new Error(`Fetch failed: ${error}`);
|
203
|
-
}
|
262
|
+
return base;
|
204
263
|
}
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
2
2
|
import { TEST_CLIENT } from "~test/test-clients.js";
|
3
|
-
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
|
4
3
|
import { base } from "../../chains/chain-definitions/base.js";
|
5
4
|
import { ethereum } from "../../chains/chain-definitions/ethereum.js";
|
6
5
|
import { sepolia } from "../../chains/chain-definitions/sepolia.js";
|
7
|
-
import {
|
6
|
+
import {
|
7
|
+
NATIVE_TOKEN_ADDRESS,
|
8
|
+
ZERO_ADDRESS,
|
9
|
+
} from "../../constants/addresses.js";
|
8
10
|
import { convertCryptoToFiat } from "./cryptoToFiat.js";
|
9
11
|
|
10
12
|
describe.runIf(process.env.TW_SECRET_KEY)("Pay: crypto-to-fiat", () => {
|
@@ -49,7 +51,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("Pay: crypto-to-fiat", () => {
|
|
49
51
|
expect(data.result).toBe(0);
|
50
52
|
});
|
51
53
|
|
52
|
-
it("should throw error for testnet chain (because testnets are not supported", async () => {
|
54
|
+
it("should throw error for testnet chain (because testnets are not supported)", async () => {
|
53
55
|
await expect(
|
54
56
|
convertCryptoToFiat({
|
55
57
|
chain: sepolia,
|
@@ -81,13 +83,13 @@ describe.runIf(process.env.TW_SECRET_KEY)("Pay: crypto-to-fiat", () => {
|
|
81
83
|
await expect(
|
82
84
|
convertCryptoToFiat({
|
83
85
|
chain: base,
|
84
|
-
fromTokenAddress:
|
86
|
+
fromTokenAddress: ZERO_ADDRESS,
|
85
87
|
fromAmount: 1,
|
86
88
|
to: "USD",
|
87
89
|
client: TEST_CLIENT,
|
88
90
|
}),
|
89
91
|
).rejects.toThrowError(
|
90
|
-
`Error: ${
|
92
|
+
`Error: ${ZERO_ADDRESS} on chainId: ${base.id} is not a valid contract address.`,
|
91
93
|
);
|
92
94
|
});
|
93
95
|
it("should throw if response is not OK", async () => {
|