thirdweb 5.99.2 → 5.100.0-nightly-713ebe0a2d6d8a409e41ce0f0317fc34b1f221bb-20250520000414

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.
Files changed (201) hide show
  1. package/dist/cjs/bridge/Buy.js +16 -12
  2. package/dist/cjs/bridge/Buy.js.map +1 -1
  3. package/dist/cjs/bridge/Chains.js +2 -2
  4. package/dist/cjs/bridge/Chains.js.map +1 -1
  5. package/dist/cjs/bridge/Routes.js +2 -2
  6. package/dist/cjs/bridge/Routes.js.map +1 -1
  7. package/dist/cjs/bridge/Sell.js +17 -13
  8. package/dist/cjs/bridge/Sell.js.map +1 -1
  9. package/dist/cjs/bridge/Status.js +15 -2
  10. package/dist/cjs/bridge/Status.js.map +1 -1
  11. package/dist/cjs/bridge/Transfer.js +229 -0
  12. package/dist/cjs/bridge/Transfer.js.map +1 -0
  13. package/dist/cjs/bridge/index.js +2 -1
  14. package/dist/cjs/bridge/index.js.map +1 -1
  15. package/dist/cjs/bridge/types/Token.js +3 -0
  16. package/dist/cjs/bridge/types/Token.js.map +1 -0
  17. package/dist/cjs/exports/wallets.js +3 -1
  18. package/dist/cjs/exports/wallets.js.map +1 -1
  19. package/dist/cjs/pay/buyWithCrypto/getQuote.js +159 -53
  20. package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
  21. package/dist/cjs/pay/buyWithCrypto/getStatus.js +160 -14
  22. package/dist/cjs/pay/buyWithCrypto/getStatus.js.map +1 -1
  23. package/dist/cjs/pay/buyWithCrypto/getTransfer.js +95 -37
  24. package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -1
  25. package/dist/cjs/pay/utils/definitions.js +1 -31
  26. package/dist/cjs/pay/utils/definitions.js.map +1 -1
  27. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +23 -21
  28. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  29. package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js +2 -15
  30. package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
  31. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  33. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js +0 -135
  34. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js.map +1 -1
  35. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +3 -1
  36. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
  37. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +1 -1
  38. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
  39. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js +4 -4
  40. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js.map +1 -1
  41. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js +83 -34
  42. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js.map +1 -1
  43. package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.js +2 -2
  44. package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.js.map +1 -1
  45. package/dist/cjs/utils/any-evm/zksync/constants.js +1 -0
  46. package/dist/cjs/utils/any-evm/zksync/constants.js.map +1 -1
  47. package/dist/cjs/utils/domains.js +3 -0
  48. package/dist/cjs/utils/domains.js.map +1 -1
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/cjs/version.js.map +1 -1
  51. package/dist/cjs/wallets/injected/mipdStore.js +12 -0
  52. package/dist/cjs/wallets/injected/mipdStore.js.map +1 -1
  53. package/dist/esm/bridge/Buy.js +16 -12
  54. package/dist/esm/bridge/Buy.js.map +1 -1
  55. package/dist/esm/bridge/Chains.js +2 -2
  56. package/dist/esm/bridge/Chains.js.map +1 -1
  57. package/dist/esm/bridge/Routes.js +2 -2
  58. package/dist/esm/bridge/Routes.js.map +1 -1
  59. package/dist/esm/bridge/Sell.js +17 -13
  60. package/dist/esm/bridge/Sell.js.map +1 -1
  61. package/dist/esm/bridge/Status.js +15 -2
  62. package/dist/esm/bridge/Status.js.map +1 -1
  63. package/dist/esm/bridge/Transfer.js +226 -0
  64. package/dist/esm/bridge/Transfer.js.map +1 -0
  65. package/dist/esm/bridge/index.js +1 -0
  66. package/dist/esm/bridge/index.js.map +1 -1
  67. package/dist/esm/bridge/types/Token.js +2 -0
  68. package/dist/esm/bridge/types/Token.js.map +1 -0
  69. package/dist/esm/exports/wallets.js +1 -0
  70. package/dist/esm/exports/wallets.js.map +1 -1
  71. package/dist/esm/pay/buyWithCrypto/getQuote.js +159 -53
  72. package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
  73. package/dist/esm/pay/buyWithCrypto/getStatus.js +160 -14
  74. package/dist/esm/pay/buyWithCrypto/getStatus.js.map +1 -1
  75. package/dist/esm/pay/buyWithCrypto/getTransfer.js +95 -37
  76. package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -1
  77. package/dist/esm/pay/utils/definitions.js +0 -25
  78. package/dist/esm/pay/utils/definitions.js.map +1 -1
  79. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +23 -21
  80. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  81. package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js +2 -15
  82. package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js.map +1 -1
  83. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +1 -1
  84. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  85. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js +1 -134
  86. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.js.map +1 -1
  87. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +3 -1
  88. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
  89. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js +1 -1
  90. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.js.map +1 -1
  91. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js +1 -1
  92. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.js.map +1 -1
  93. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js +84 -34
  94. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js.map +1 -1
  95. package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.js +2 -2
  96. package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.js.map +1 -1
  97. package/dist/esm/utils/any-evm/zksync/constants.js +1 -0
  98. package/dist/esm/utils/any-evm/zksync/constants.js.map +1 -1
  99. package/dist/esm/utils/domains.js +3 -0
  100. package/dist/esm/utils/domains.js.map +1 -1
  101. package/dist/esm/version.js +1 -1
  102. package/dist/esm/version.js.map +1 -1
  103. package/dist/esm/wallets/injected/mipdStore.js +11 -0
  104. package/dist/esm/wallets/injected/mipdStore.js.map +1 -1
  105. package/dist/types/bridge/Buy.d.ts +10 -8
  106. package/dist/types/bridge/Buy.d.ts.map +1 -1
  107. package/dist/types/bridge/Sell.d.ts +12 -10
  108. package/dist/types/bridge/Sell.d.ts.map +1 -1
  109. package/dist/types/bridge/Status.d.ts.map +1 -1
  110. package/dist/types/bridge/Transfer.d.ts +199 -0
  111. package/dist/types/bridge/Transfer.d.ts.map +1 -0
  112. package/dist/types/bridge/index.d.ts +1 -0
  113. package/dist/types/bridge/index.d.ts.map +1 -1
  114. package/dist/types/bridge/types/Route.d.ts +3 -17
  115. package/dist/types/bridge/types/Route.d.ts.map +1 -1
  116. package/dist/types/bridge/types/Status.d.ts +15 -0
  117. package/dist/types/bridge/types/Status.d.ts.map +1 -1
  118. package/dist/types/bridge/types/Token.d.ts +10 -0
  119. package/dist/types/bridge/types/Token.d.ts.map +1 -0
  120. package/dist/types/exports/wallets.d.ts +1 -0
  121. package/dist/types/exports/wallets.d.ts.map +1 -1
  122. package/dist/types/pay/buyWithCrypto/commonTypes.d.ts +0 -9
  123. package/dist/types/pay/buyWithCrypto/commonTypes.d.ts.map +1 -1
  124. package/dist/types/pay/buyWithCrypto/getQuote.d.ts.map +1 -1
  125. package/dist/types/pay/buyWithCrypto/getStatus.d.ts +1 -1
  126. package/dist/types/pay/buyWithCrypto/getStatus.d.ts.map +1 -1
  127. package/dist/types/pay/buyWithCrypto/getTransfer.d.ts.map +1 -1
  128. package/dist/types/pay/utils/definitions.d.ts +0 -25
  129. package/dist/types/pay/utils/definitions.d.ts.map +1 -1
  130. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  131. package/dist/types/react/web/ui/ConnectWallet/TransactionsScreen.d.ts.map +1 -1
  132. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.d.ts +2 -13
  133. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.d.ts.map +1 -1
  134. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.d.ts.map +1 -1
  135. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.d.ts +0 -1
  136. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.d.ts.map +1 -1
  137. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.d.ts +8 -4
  138. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.d.ts.map +1 -1
  139. package/dist/types/react/web/ui/MediaRenderer/MediaRenderer.d.ts +1 -1
  140. package/dist/types/react/web/ui/TransactionButton/ExecutingScreen.d.ts.map +1 -1
  141. package/dist/types/utils/any-evm/zksync/constants.d.ts.map +1 -1
  142. package/dist/types/utils/domains.d.ts +6 -0
  143. package/dist/types/utils/domains.d.ts.map +1 -1
  144. package/dist/types/version.d.ts +1 -1
  145. package/dist/types/version.d.ts.map +1 -1
  146. package/dist/types/wallets/injected/mipdStore.d.ts +7 -0
  147. package/dist/types/wallets/injected/mipdStore.d.ts.map +1 -1
  148. package/package.json +1 -1
  149. package/src/bridge/Buy.ts +18 -12
  150. package/src/bridge/Chains.ts +2 -2
  151. package/src/bridge/Routes.ts +2 -2
  152. package/src/bridge/Sell.ts +19 -13
  153. package/src/bridge/Status.ts +15 -2
  154. package/src/bridge/Transfer.test.ts +76 -0
  155. package/src/bridge/Transfer.ts +270 -0
  156. package/src/bridge/index.ts +1 -0
  157. package/src/bridge/types/Route.ts +3 -17
  158. package/src/bridge/types/Status.ts +15 -1
  159. package/src/bridge/types/Token.ts +10 -0
  160. package/src/exports/wallets.ts +1 -0
  161. package/src/extensions/prebuilts/deploy-modular-core.test.ts +2 -1
  162. package/src/pay/buyWithCrypto/commonTypes.ts +0 -10
  163. package/src/pay/buyWithCrypto/getQuote.ts +210 -100
  164. package/src/pay/buyWithCrypto/getStatus.ts +213 -20
  165. package/src/pay/buyWithCrypto/getTransfer.ts +129 -61
  166. package/src/pay/utils/definitions.ts +0 -34
  167. package/src/react/core/hooks/transaction/useSendTransaction.ts +27 -33
  168. package/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx +29 -35
  169. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +3 -1
  170. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.ts +2 -181
  171. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.tsx +3 -1
  172. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.tsx +1 -1
  173. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/pendingSwapTx.ts +1 -3
  174. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.ts +118 -63
  175. package/src/react/web/ui/TransactionButton/ExecutingScreen.tsx +0 -2
  176. package/src/utils/any-evm/zksync/constants.ts +1 -0
  177. package/src/utils/domain.test.ts +1 -0
  178. package/src/utils/domains.ts +8 -0
  179. package/src/version.ts +1 -1
  180. package/src/wallets/injected/mipdStore.ts +14 -0
  181. package/dist/cjs/bridge/constants.js +0 -5
  182. package/dist/cjs/bridge/constants.js.map +0 -1
  183. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +0 -54
  184. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +0 -1
  185. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js +0 -52
  186. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js.map +0 -1
  187. package/dist/esm/bridge/constants.js +0 -2
  188. package/dist/esm/bridge/constants.js.map +0 -1
  189. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js +0 -51
  190. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.js.map +0 -1
  191. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js +0 -48
  192. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.js.map +0 -1
  193. package/dist/types/bridge/constants.d.ts +0 -2
  194. package/dist/types/bridge/constants.d.ts.map +0 -1
  195. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts +0 -10
  196. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.d.ts.map +0 -1
  197. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.d.ts +0 -9
  198. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.d.ts.map +0 -1
  199. package/src/bridge/constants.ts +0 -1
  200. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.tsx +0 -163
  201. package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistoryButton.tsx +0 -127
@@ -1,17 +1,13 @@
1
- import type { Hash } from "viem";
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 { Address } from "../../utils/address.js";
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 clientFetch = getClientFetch(params.client);
130
-
131
- const response = await clientFetch(getPayBuyWithCryptoTransferEndpoint(), {
132
- method: "POST",
133
- headers: {
134
- Accept: "application/json",
135
- "Content-Type": "application/json",
136
- },
137
- body: stringify({
138
- fromAddress: params.fromAddress,
139
- toAddress: params.toAddress,
140
- chainId: params.chainId,
141
- tokenAddress: params.tokenAddress,
142
- amount: params.amount,
143
- purchaseData: params.purchaseData,
144
- feePayer: params.feePayer,
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
- if (!response.ok) {
149
- const errorObj = await response.json();
150
- if (errorObj && "error" in errorObj) {
151
- throw errorObj;
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 data: BuyWithCryptoTransferResponse = (await response.json()).result;
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
- chain: getCachedChain(data.transactionRequest.chainId),
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: data.approval,
168
- fromAddress: data.fromAddress,
169
- toAddress: data.toAddress,
170
- paymentToken: data.paymentToken,
171
- processingFee: data.processingFee,
172
- estimatedGasCostUSDCents: data.estimatedGasCostUSDCents,
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
 
@@ -7,26 +7,6 @@ const getPayBaseUrl = () => {
7
7
  : `https://${payDomain}`;
8
8
  };
9
9
 
10
- /**
11
- * Endpoint to get the status of a "Buy with Crypto" quote.
12
- * @internal
13
- */
14
- export const getPayBuyWithCryptoStatusUrl = () =>
15
- `${getPayBaseUrl()}/buy-with-crypto/status/v1`;
16
- /**
17
- * Endpoint to get "Buy with Crypto" quote.
18
- * @internal
19
- */
20
- export const getPayBuyWithCryptoQuoteEndpoint = () =>
21
- `${getPayBaseUrl()}/buy-with-crypto/quote/v1`;
22
-
23
- /**
24
- * Endpoint to get "Buy with Crypto" transfer.
25
- * @internal
26
- */
27
- export const getPayBuyWithCryptoTransferEndpoint = () =>
28
- `${getPayBaseUrl()}/buy-with-crypto/transfer/v1`;
29
-
30
10
  /**
31
11
  * Endpoint to get a "Buy with Fiat" quote.
32
12
  * @internal
@@ -55,20 +35,6 @@ export const getPayBuyWithFiatHistoryEndpoint = () =>
55
35
  export const getPayBuyWithCryptoHistoryEndpoint = () =>
56
36
  `${getPayBaseUrl()}/buy-with-crypto/history/v1`;
57
37
 
58
- /**
59
- * Endpoint to get a list of supported destination chains and tokens for thirdweb pay.
60
- * @internal
61
- */
62
- export const getPaySupportedDestinations = () =>
63
- `${getPayBaseUrl()}/destination-tokens/v1`;
64
-
65
- /**
66
- * Endpoint to get a list of supported source chains + tokens for thirdweb pay.
67
- * @internal
68
- */
69
- export const getPaySupportedSources = () =>
70
- `${getPayBaseUrl()}/buy-with-crypto/source-tokens/v1`;
71
-
72
38
  /**
73
39
  * Endpoint to get buy history for a given wallet address.
74
40
  * This includes both "Buy with Crypto" and "Buy with Fiat" transactions.
@@ -1,5 +1,6 @@
1
1
  import { type UseMutationResult, useMutation } from "@tanstack/react-query";
2
2
  import { trackPayEvent } from "../../../../analytics/track/pay.js";
3
+ import * as Bridge from "../../../../bridge/index.js";
3
4
  import type { Chain } from "../../../../chains/types.js";
4
5
  import type { BuyWithCryptoStatus } from "../../../../pay/buyWithCrypto/getStatus.js";
5
6
  import type { BuyWithFiatStatus } from "../../../../pay/buyWithFiat/getStatus.js";
@@ -14,7 +15,6 @@ import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised
14
15
  import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
15
16
  import { getTokenBalance } from "../../../../wallets/utils/getTokenBalance.js";
16
17
  import { getWalletBalance } from "../../../../wallets/utils/getWalletBalance.js";
17
- import { fetchBuySupportedDestinations } from "../../../web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.js";
18
18
  import type { LocaleId } from "../../../web/ui/types.js";
19
19
  import type { Theme } from "../../design-system/index.js";
20
20
  import type { SupportedTokens } from "../../utils/defaultTokens.js";
@@ -179,22 +179,26 @@ export function useSendTransactionCore(args: {
179
179
 
180
180
  (async () => {
181
181
  try {
182
- const [_nativeValue, _erc20Value, supportedDestinations] =
183
- await Promise.all([
184
- resolvePromisedValue(tx.value),
185
- resolvePromisedValue(tx.erc20Value),
186
- fetchBuySupportedDestinations(tx.client).catch((err) => {
187
- trackPayEvent({
188
- client: tx.client,
189
- walletAddress: account.address,
190
- walletType: wallet?.id,
191
- toChainId: tx.chain.id,
192
- event: "pay_transaction_modal_pay_api_error",
193
- error: err?.message,
194
- });
195
- return null;
196
- }),
197
- ]);
182
+ const [_nativeValue, _erc20Value] = await Promise.all([
183
+ resolvePromisedValue(tx.value),
184
+ resolvePromisedValue(tx.erc20Value),
185
+ ]);
186
+
187
+ const supportedDestinations = await Bridge.routes({
188
+ client: tx.client,
189
+ destinationChainId: tx.chain.id,
190
+ destinationTokenAddress: _erc20Value?.tokenAddress,
191
+ }).catch((err) => {
192
+ trackPayEvent({
193
+ client: tx.client,
194
+ walletAddress: account.address,
195
+ walletType: wallet?.id,
196
+ toChainId: tx.chain.id,
197
+ event: "pay_transaction_modal_pay_api_error",
198
+ error: err?.message,
199
+ });
200
+ return null;
201
+ });
198
202
 
199
203
  if (!supportedDestinations) {
200
204
  // could not fetch supported destinations, just send the tx
@@ -202,21 +206,7 @@ export function useSendTransactionCore(args: {
202
206
  return;
203
207
  }
204
208
 
205
- if (
206
- !supportedDestinations
207
- .map((x) => x.chain.id)
208
- .includes(tx.chain.id) ||
209
- (_erc20Value &&
210
- !supportedDestinations.some(
211
- (x) =>
212
- x.chain.id === tx.chain.id &&
213
- x.tokens.find(
214
- (t) =>
215
- t.address.toLowerCase() ===
216
- _erc20Value.tokenAddress.toLowerCase(),
217
- ),
218
- ))
219
- ) {
209
+ if (supportedDestinations.length === 0) {
220
210
  trackPayEvent({
221
211
  client: tx.client,
222
212
  walletAddress: account.address,
@@ -224,7 +214,11 @@ export function useSendTransactionCore(args: {
224
214
  toChainId: tx.chain.id,
225
215
  toToken: _erc20Value?.tokenAddress || undefined,
226
216
  event: "pay_transaction_modal_chain_token_not_supported",
227
- error: `chain ${tx.chain.id} ${_erc20Value ? `/ token ${_erc20Value?.tokenAddress}` : ""} not supported`,
217
+ error: JSON.stringify({
218
+ chain: tx.chain.id,
219
+ token: _erc20Value?.tokenAddress,
220
+ message: "chain/token not supported",
221
+ }),
228
222
  });
229
223
  // chain/token not supported, just send the tx
230
224
  sendTx();
@@ -11,13 +11,9 @@ import { useActiveWallet } from "../../../core/hooks/wallets/useActiveWallet.js"
11
11
  import { useActiveWalletChain } from "../../../core/hooks/wallets/useActiveWalletChain.js";
12
12
  import { LoadingScreen } from "../../wallets/shared/LoadingScreen.js";
13
13
  import { Spacer } from "../components/Spacer.js";
14
- import Tabs from "../components/Tabs.js";
15
14
  import { Container, Line, ModalHeader } from "../components/basic.js";
16
15
  import { ButtonLink } from "../components/buttons.js";
17
- import { CoinsIcon } from "./icons/CoinsIcon.js";
18
- import { FundsIcon } from "./icons/FundsIcon.js";
19
16
  import type { ConnectLocale } from "./locale/types.js";
20
- import { PayTxHistoryList } from "./screens/Buy/pay-transactions/BuyTxHistory.js";
21
17
  import { TxDetailsScreen } from "./screens/Buy/pay-transactions/TxDetailsScreen.js";
22
18
  import type { TxStatusInfo } from "./screens/Buy/pay-transactions/useBuyTransactionsToShow.js";
23
19
  import type { PayerInfo } from "./screens/Buy/types.js";
@@ -37,7 +33,7 @@ export function TransactionsScreen(props: {
37
33
  locale: ConnectLocale;
38
34
  client: ThirdwebClient;
39
35
  }) {
40
- const [activeTab, setActiveTab] = useState("Transactions");
36
+ // const [activeTab, setActiveTab] = useState("Transactions");
41
37
  // For now, you can only select pay transactions (purcahses)
42
38
  const [selectedTx, setSelectedTx] = useState<TxStatusInfo | null>(null);
43
39
 
@@ -84,42 +80,40 @@ export function TransactionsScreen(props: {
84
80
  }}
85
81
  >
86
82
  <Spacer y="md" />
87
- <Tabs
88
- options={[
89
- {
83
+ {/* <Tabs */}
84
+ {/* options={[ */}
85
+ {/* {
90
86
  label: (
91
87
  <span className="flex gap-2">
92
88
  <CoinsIcon size={iconSize.sm} /> Transactions
93
89
  </span>
94
90
  ),
95
91
  value: "Transactions",
96
- },
97
- {
98
- label: (
99
- <span className="flex gap-2">
100
- <FundsIcon size={iconSize.sm} /> Purchases
101
- </span>
102
- ),
103
- value: "Purchases",
104
- },
105
- ]}
106
- selected={activeTab}
107
- onSelect={setActiveTab}
108
- >
109
- {activeTab === "Purchases" && (
110
- <PayTxHistoryList
111
- client={props.client}
112
- onSelectTx={setSelectedTx}
113
- />
114
- )}
115
- {activeTab === "Transactions" && (
116
- <WalletTransactionHistory
117
- locale={props.locale}
118
- client={props.client}
119
- address={payer.account.address}
120
- />
121
- )}
122
- </Tabs>
92
+ // },
93
+ // TODO (UB): add back in once we have a way to show purchases with new service
94
+ // {
95
+ // label: (
96
+ // <span className="flex gap-2">
97
+ // <FundsIcon size={iconSize.sm} /> Purchases
98
+ // </span>
99
+ // ),
100
+ // value: "Purchases",
101
+ // },
102
+ // ]}
103
+ // selected={activeTab}
104
+ // onSelect={setActiveTab}
105
+ {/* > */}
106
+ {/* {activeTab === "Purchases" && ( */}
107
+ {/* <PayTxHistoryList client={props.client} onSelectTx={setSelectedTx} /> */}
108
+ {/* )} */}
109
+ {/* {activeTab === "Transactions" && ( */}
110
+ <WalletTransactionHistory
111
+ locale={props.locale}
112
+ client={props.client}
113
+ address={payer.account.address}
114
+ />
115
+ {/* })} */}
116
+ {/* </Tabs> */}
123
117
  </Container>
124
118
  <Line />
125
119
  <Container p="lg">
@@ -436,7 +436,9 @@ function BuyScreenContent(props: BuyScreenContentProps) {
436
436
  tokenList={(
437
437
  (toChain?.id ? destinationSupportedTokens[toChain.id] : undefined) ||
438
438
  []
439
- ).filter((x) => x.address !== NATIVE_TOKEN_ADDRESS)}
439
+ ).filter(
440
+ (x) => x.address.toLowerCase() !== NATIVE_TOKEN_ADDRESS.toLowerCase(),
441
+ )}
440
442
  onTokenSelect={(tokenInfo) => {
441
443
  setToToken(tokenInfo);
442
444
  goBack();
@@ -1,17 +1,5 @@
1
- import { type UseQueryOptions, useQueries } from "@tanstack/react-query";
2
- import { useState, useSyncExternalStore } from "react";
3
- import type { ThirdwebClient } from "../../../../../../../client/client.js";
4
- import {
5
- type ValidBuyWithCryptoStatus,
6
- getBuyWithCryptoStatus,
7
- } from "../../../../../../../pay/buyWithCrypto/getStatus.js";
8
- import {
9
- type ValidBuyWithFiatStatus,
10
- getBuyWithFiatStatus,
11
- } from "../../../../../../../pay/buyWithFiat/getStatus.js";
12
- import { useBuyHistory } from "../../../../../../core/hooks/pay/useBuyHistory.js";
13
- import { useActiveAccount } from "../../../../../../core/hooks/wallets/useActiveAccount.js";
14
- import { pendingTransactions } from "../swap/pendingSwapTx.js";
1
+ import type { ValidBuyWithCryptoStatus } from "../../../../../../../pay/buyWithCrypto/getStatus.js";
2
+ import type { ValidBuyWithFiatStatus } from "../../../../../../../pay/buyWithFiat/getStatus.js";
15
3
 
16
4
  export type TxStatusInfo =
17
5
  | {
@@ -22,170 +10,3 @@ export type TxStatusInfo =
22
10
  type: "fiat";
23
11
  status: ValidBuyWithFiatStatus;
24
12
  };
25
-
26
- export function useBuyTransactionsToShow(client: ThirdwebClient) {
27
- const account = useActiveAccount();
28
- const [pageIndex, setPageIndex] = useState(0);
29
- const txStatusList: TxStatusInfo[] = [];
30
- const PAGE_SIZE = 10;
31
-
32
- const buyHistory = useBuyHistory(
33
- {
34
- walletAddress: account?.address || "",
35
- start: pageIndex * PAGE_SIZE,
36
- count: PAGE_SIZE,
37
- client,
38
- },
39
- {
40
- refetchInterval: 10 * 1000, // 10 seconds
41
- },
42
- );
43
-
44
- const pendingTxStoreValue = useSyncExternalStore(
45
- pendingTransactions.subscribe,
46
- pendingTransactions.getValue,
47
- );
48
-
49
- const pendingStatusQueries = useQueries<
50
- UseQueryOptions<TxStatusInfo | null>[]
51
- >({
52
- queries: pendingTxStoreValue.map((tx) => {
53
- return {
54
- queryKey: ["pending-tx-status", tx],
55
- queryFn: async () => {
56
- if (tx.type === "swap") {
57
- const swapStatus = await getBuyWithCryptoStatus({
58
- client: client,
59
- transactionHash: tx.txHash,
60
- chainId: tx.chainId,
61
- });
62
-
63
- if (
64
- swapStatus.status === "NOT_FOUND" ||
65
- swapStatus.status === "NONE"
66
- ) {
67
- return null;
68
- }
69
-
70
- return {
71
- type: "swap",
72
- status: swapStatus,
73
- };
74
- }
75
-
76
- const fiatStatus = await getBuyWithFiatStatus({
77
- client: client,
78
- intentId: tx.intentId,
79
- });
80
-
81
- if (
82
- fiatStatus.status === "NOT_FOUND" ||
83
- fiatStatus.status === "NONE"
84
- ) {
85
- return null;
86
- }
87
-
88
- return {
89
- type: "fiat",
90
- status: fiatStatus,
91
- };
92
- },
93
- refetchInterval: 10 * 1000, // 10 seconds
94
- };
95
- }),
96
- });
97
-
98
- if (pendingStatusQueries.length > 0 && pageIndex === 0) {
99
- for (const query of pendingStatusQueries) {
100
- if (query.data) {
101
- const txStatusInfo = query.data;
102
-
103
- // if already present in endpoint - don't add it
104
- if (buyHistory.data) {
105
- if (txStatusInfo.type === "swap") {
106
- const isPresent = buyHistory.data.page.find((tx) => {
107
- if (
108
- "buyWithCryptoStatus" in tx &&
109
- tx.buyWithCryptoStatus.status !== "NOT_FOUND"
110
- ) {
111
- return (
112
- tx.buyWithCryptoStatus.source?.transactionHash ===
113
- txStatusInfo.status.source?.transactionHash
114
- );
115
- }
116
- return false;
117
- });
118
-
119
- if (!isPresent) {
120
- txStatusList.push(txStatusInfo);
121
- }
122
- }
123
-
124
- if (txStatusInfo.type === "fiat") {
125
- const isPresent = buyHistory.data.page.find((tx) => {
126
- if (
127
- "buyWithFiatStatus" in tx &&
128
- tx.buyWithFiatStatus.status !== "NOT_FOUND"
129
- ) {
130
- return (
131
- tx.buyWithFiatStatus.intentId === txStatusInfo.status.intentId
132
- );
133
- }
134
- return false;
135
- });
136
-
137
- if (!isPresent) {
138
- txStatusList.push(txStatusInfo);
139
- }
140
- }
141
- } else {
142
- // if no buy history available for this walllet - add without duplicate check
143
- txStatusList.push(txStatusInfo);
144
- }
145
- }
146
- }
147
- }
148
-
149
- if (buyHistory.data) {
150
- for (const tx of buyHistory.data.page) {
151
- if ("buyWithCryptoStatus" in tx) {
152
- if (
153
- tx.buyWithCryptoStatus.status !== "NOT_FOUND" &&
154
- tx.buyWithCryptoStatus.status !== "NONE"
155
- ) {
156
- txStatusList.push({
157
- type: "swap",
158
- status: tx.buyWithCryptoStatus,
159
- });
160
- }
161
- } else {
162
- if (
163
- tx.buyWithFiatStatus.status !== "NOT_FOUND" &&
164
- tx.buyWithFiatStatus.status !== "NONE"
165
- ) {
166
- txStatusList.push({
167
- type: "fiat",
168
- status: tx.buyWithFiatStatus,
169
- });
170
- }
171
- }
172
- }
173
- }
174
-
175
- const hidePagination =
176
- !buyHistory.data ||
177
- (buyHistory.data && !buyHistory.data.hasNextPage && pageIndex === 0);
178
-
179
- return {
180
- pageIndex,
181
- setPageIndex,
182
- txInfosToShow: txStatusList,
183
- hidePagination,
184
- isLoading: buyHistory.isLoading,
185
- pagination: buyHistory.data
186
- ? {
187
- hasNextPage: buyHistory.data.hasNextPage,
188
- }
189
- : undefined,
190
- };
191
- }
@@ -43,7 +43,9 @@ export function WalletRow(props: {
43
43
  client,
44
44
  address,
45
45
  });
46
- const addressOrENS = ensNameQuery.data || shortenAddress(address);
46
+ const addressOrENS = address
47
+ ? ensNameQuery.data || shortenAddress(address)
48
+ : "";
47
49
  return (
48
50
  <Container flex="row" style={{ justifyContent: "space-between" }}>
49
51
  <Container flex="row" center="y" gap="sm" color="secondaryText">
@@ -214,7 +214,7 @@ async function fetchBalancesForWallet({
214
214
  chain.id === toChain.id
215
215
  ? !(
216
216
  mode === "fund_wallet" && account.address === accountAddress
217
- )
217
+ ) && balance.value > 0n
218
218
  : balance.value > 0n;
219
219
 
220
220
  if (include) {