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.
- package/dist/cjs/bridge/Buy.js +16 -12
- 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/Routes.js +2 -2
- package/dist/cjs/bridge/Routes.js.map +1 -1
- package/dist/cjs/bridge/Sell.js +17 -13
- 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 +2 -1
- package/dist/cjs/bridge/index.js.map +1 -1
- package/dist/cjs/bridge/types/Token.js +3 -0
- package/dist/cjs/bridge/types/Token.js.map +1 -0
- package/dist/cjs/exports/wallets.js +3 -1
- package/dist/cjs/exports/wallets.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/utils/definitions.js +1 -31
- package/dist/cjs/pay/utils/definitions.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js +23 -21
- package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.js +2 -15
- package/dist/cjs/react/web/ui/ConnectWallet/TransactionsScreen.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/pay-transactions/useBuyTransactionsToShow.js +0 -135
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.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/ExecutingScreen.js +2 -2
- package/dist/cjs/react/web/ui/TransactionButton/ExecutingScreen.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/cjs/wallets/injected/mipdStore.js +12 -0
- package/dist/cjs/wallets/injected/mipdStore.js.map +1 -1
- package/dist/esm/bridge/Buy.js +16 -12
- 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/Routes.js +2 -2
- package/dist/esm/bridge/Routes.js.map +1 -1
- package/dist/esm/bridge/Sell.js +17 -13
- 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 +1 -0
- package/dist/esm/bridge/index.js.map +1 -1
- package/dist/esm/bridge/types/Token.js +2 -0
- package/dist/esm/bridge/types/Token.js.map +1 -0
- package/dist/esm/exports/wallets.js +1 -0
- package/dist/esm/exports/wallets.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/utils/definitions.js +0 -25
- package/dist/esm/pay/utils/definitions.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js +23 -21
- package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.js +2 -15
- package/dist/esm/react/web/ui/ConnectWallet/TransactionsScreen.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/pay-transactions/useBuyTransactionsToShow.js +1 -134
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.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/ExecutingScreen.js +2 -2
- package/dist/esm/react/web/ui/TransactionButton/ExecutingScreen.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/esm/wallets/injected/mipdStore.js +11 -0
- package/dist/esm/wallets/injected/mipdStore.js.map +1 -1
- package/dist/types/bridge/Buy.d.ts +10 -8
- package/dist/types/bridge/Buy.d.ts.map +1 -1
- package/dist/types/bridge/Sell.d.ts +12 -10
- 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 +1 -0
- package/dist/types/bridge/index.d.ts.map +1 -1
- package/dist/types/bridge/types/Route.d.ts +3 -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 +10 -0
- package/dist/types/bridge/types/Token.d.ts.map +1 -0
- package/dist/types/exports/wallets.d.ts +1 -0
- package/dist/types/exports/wallets.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/utils/definitions.d.ts +0 -25
- package/dist/types/pay/utils/definitions.d.ts.map +1 -1
- package/dist/types/react/core/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/pay-transactions/useBuyTransactionsToShow.d.ts +2 -13
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.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/MediaRenderer/MediaRenderer.d.ts +1 -1
- package/dist/types/react/web/ui/TransactionButton/ExecutingScreen.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/dist/types/wallets/injected/mipdStore.d.ts +7 -0
- package/dist/types/wallets/injected/mipdStore.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/bridge/Buy.ts +18 -12
- package/src/bridge/Chains.ts +2 -2
- package/src/bridge/Routes.ts +2 -2
- package/src/bridge/Sell.ts +19 -13
- 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 +1 -0
- package/src/bridge/types/Route.ts +3 -17
- package/src/bridge/types/Status.ts +15 -1
- package/src/bridge/types/Token.ts +10 -0
- package/src/exports/wallets.ts +1 -0
- package/src/extensions/prebuilts/deploy-modular-core.test.ts +2 -1
- 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/utils/definitions.ts +0 -34
- package/src/react/core/hooks/transaction/useSendTransaction.ts +27 -33
- package/src/react/web/ui/ConnectWallet/TransactionsScreen.tsx +29 -35
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +3 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.ts +2 -181
- 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/ExecutingScreen.tsx +0 -2
- 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/src/wallets/injected/mipdStore.ts +14 -0
- 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/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/esm/bridge/constants.js +0 -2
- package/dist/esm/bridge/constants.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/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/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/src/bridge/constants.ts +0 -1
- 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
@@ -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
|
|
@@ -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
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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:
|
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
|
-
|
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
{
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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(
|
439
|
+
).filter(
|
440
|
+
(x) => x.address.toLowerCase() !== NATIVE_TOKEN_ADDRESS.toLowerCase(),
|
441
|
+
)}
|
440
442
|
onTokenSelect={(tokenInfo) => {
|
441
443
|
setToToken(tokenInfo);
|
442
444
|
goBack();
|
package/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/useBuyTransactionsToShow.ts
CHANGED
@@ -1,17 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import {
|
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 =
|
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">
|