thirdweb 5.105.23 → 5.105.25
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/extensions/erc1155/read/getOwnedNFTs.js +1 -1
- package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
- package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js +1 -1
- package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
- package/dist/cjs/insight/get-nfts.js +2 -2
- package/dist/cjs/insight/get-nfts.js.map +1 -1
- package/dist/cjs/insight/get-tokens.js +3 -2
- package/dist/cjs/insight/get-tokens.js.map +1 -1
- package/dist/cjs/react/core/hooks/usePaymentMethods.js +52 -174
- package/dist/cjs/react/core/hooks/usePaymentMethods.js.map +1 -1
- package/dist/cjs/react/core/hooks/useTransactionDetails.js +2 -3
- package/dist/cjs/react/core/hooks/useTransactionDetails.js.map +1 -1
- package/dist/cjs/react/core/machines/paymentMachine.js.map +1 -1
- package/dist/cjs/react/core/providers/invalidateWalletBalance.js +6 -2
- package/dist/cjs/react/core/providers/invalidateWalletBalance.js.map +1 -1
- package/dist/cjs/react/web/ui/Bridge/payment-selection/TokenSelection.js +3 -17
- package/dist/cjs/react/web/ui/Bridge/payment-selection/TokenSelection.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js +8 -6
- package/dist/cjs/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
- package/dist/cjs/utils/abi/encodeAbiParameters.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js +1 -1
- package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
- package/dist/esm/extensions/erc721/read/getOwnedNFTs.js +1 -1
- package/dist/esm/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
- package/dist/esm/insight/get-nfts.js +2 -2
- package/dist/esm/insight/get-nfts.js.map +1 -1
- package/dist/esm/insight/get-tokens.js +3 -2
- package/dist/esm/insight/get-tokens.js.map +1 -1
- package/dist/esm/react/core/hooks/usePaymentMethods.js +53 -175
- package/dist/esm/react/core/hooks/usePaymentMethods.js.map +1 -1
- package/dist/esm/react/core/hooks/useTransactionDetails.js +2 -3
- package/dist/esm/react/core/hooks/useTransactionDetails.js.map +1 -1
- package/dist/esm/react/core/machines/paymentMachine.js.map +1 -1
- package/dist/esm/react/core/providers/invalidateWalletBalance.js +6 -2
- package/dist/esm/react/core/providers/invalidateWalletBalance.js.map +1 -1
- package/dist/esm/react/web/ui/Bridge/payment-selection/TokenSelection.js +3 -17
- package/dist/esm/react/web/ui/Bridge/payment-selection/TokenSelection.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js +8 -6
- package/dist/esm/react/web/ui/ConnectWallet/screens/ViewNFTs.js.map +1 -1
- package/dist/esm/utils/abi/encodeAbiParameters.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/insight/get-nfts.d.ts +1 -1
- package/dist/types/insight/get-nfts.d.ts.map +1 -1
- package/dist/types/insight/get-tokens.d.ts +1 -1
- package/dist/types/insight/get-tokens.d.ts.map +1 -1
- package/dist/types/react/core/hooks/usePaymentMethods.d.ts.map +1 -1
- package/dist/types/react/core/hooks/useTransactionDetails.d.ts.map +1 -1
- package/dist/types/react/core/machines/paymentMachine.d.ts +2 -0
- package/dist/types/react/core/machines/paymentMachine.d.ts.map +1 -1
- package/dist/types/react/core/providers/invalidateWalletBalance.d.ts.map +1 -1
- package/dist/types/react/web/ui/Bridge/payment-selection/TokenSelection.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/ViewNFTs.d.ts.map +1 -1
- package/dist/types/utils/abi/encodeAbiParameters.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/extensions/erc1155/read/getOwnedNFTs.ts +1 -1
- package/src/extensions/erc721/read/getOwnedNFTs.ts +1 -1
- package/src/insight/get-nfts.ts +4 -3
- package/src/insight/get-tokens.ts +4 -3
- package/src/react/core/hooks/usePaymentMethods.ts +77 -230
- package/src/react/core/hooks/useTransactionDetails.ts +2 -3
- package/src/react/core/machines/paymentMachine.ts +2 -0
- package/src/react/core/providers/invalidateWalletBalance.ts +6 -2
- package/src/react/web/ui/Bridge/payment-selection/TokenSelection.tsx +19 -66
- package/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx +10 -8
- package/src/utils/abi/encodeAbiParameters.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/cjs/react/core/hooks/useBridgeQuote.js +0 -52
- package/dist/cjs/react/core/hooks/useBridgeQuote.js.map +0 -1
- package/dist/esm/react/core/hooks/useBridgeQuote.js +0 -49
- package/dist/esm/react/core/hooks/useBridgeQuote.js.map +0 -1
- package/dist/types/react/core/hooks/useBridgeQuote.d.ts +0 -15
- package/dist/types/react/core/hooks/useBridgeQuote.d.ts.map +0 -1
- package/src/react/core/hooks/useBridgeQuote.ts +0 -71
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { Quote } from "../../../bridge/index.js";
|
|
3
|
+
import { ApiError } from "../../../bridge/types/Errors.js";
|
|
4
4
|
import type { Token } from "../../../bridge/types/Token.js";
|
|
5
|
-
import {
|
|
6
|
-
getCachedChain,
|
|
7
|
-
getInsightEnabledChainIds,
|
|
8
|
-
} from "../../../chains/utils.js";
|
|
9
5
|
import type { ThirdwebClient } from "../../../client/client.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
6
|
+
import { getThirdwebBaseUrl } from "../../../utils/domains.js";
|
|
7
|
+
import { getClientFetch } from "../../../utils/fetch.js";
|
|
8
|
+
import { toTokens, toUnits } from "../../../utils/units.js";
|
|
12
9
|
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
|
|
13
|
-
import {
|
|
14
|
-
type GetWalletBalanceResult,
|
|
15
|
-
getWalletBalance,
|
|
16
|
-
} from "../../../wallets/utils/getWalletBalance.js";
|
|
17
10
|
import type { PaymentMethod } from "../machines/paymentMachine.js";
|
|
18
11
|
import { useActiveWallet } from "./wallets/useActiveWallet.js";
|
|
19
12
|
|
|
20
|
-
type OwnedTokenWithQuote = {
|
|
21
|
-
originToken: Token;
|
|
22
|
-
balance: bigint;
|
|
23
|
-
originAmount: bigint;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
13
|
/**
|
|
27
14
|
* Hook that returns available payment methods for BridgeEmbed
|
|
28
15
|
* Fetches real routes data based on the destination token
|
|
@@ -57,225 +44,85 @@ export function usePaymentMethods(options: {
|
|
|
57
44
|
const localWallet = useActiveWallet(); // TODO (bridge): get all connected wallets
|
|
58
45
|
const wallet = payerWallet || localWallet;
|
|
59
46
|
|
|
60
|
-
const
|
|
47
|
+
const query = useQuery({
|
|
61
48
|
enabled: !!wallet,
|
|
62
49
|
queryFn: async (): Promise<PaymentMethod[]> => {
|
|
63
|
-
|
|
50
|
+
const account = wallet?.getAccount();
|
|
51
|
+
if (!wallet || !account) {
|
|
64
52
|
throw new Error("No wallet connected");
|
|
65
53
|
}
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
chains({ client }),
|
|
70
|
-
getInsightEnabledChainIds(),
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
// 2. Check insight availability for all chains
|
|
74
|
-
const insightEnabledChains = allChains.filter((c) =>
|
|
75
|
-
insightEnabledChainIds.includes(c.chainId),
|
|
55
|
+
const url = new URL(
|
|
56
|
+
`${getThirdwebBaseUrl("bridge")}/v1/buy/quote/${account.address}`,
|
|
76
57
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
balance: bigint;
|
|
81
|
-
originToken: Token;
|
|
82
|
-
}> = [];
|
|
83
|
-
let page = 0;
|
|
84
|
-
const limit = 500;
|
|
85
|
-
|
|
86
|
-
while (true) {
|
|
87
|
-
let batch: GetWalletBalanceResult[];
|
|
88
|
-
try {
|
|
89
|
-
batch = await getOwnedTokens({
|
|
90
|
-
chains: insightEnabledChains.map((c) => getCachedChain(c.chainId)),
|
|
91
|
-
client,
|
|
92
|
-
ownerAddress: wallet.getAccount()?.address || "",
|
|
93
|
-
queryOptions: {
|
|
94
|
-
limit,
|
|
95
|
-
metadata: "false",
|
|
96
|
-
page,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
} catch (error) {
|
|
100
|
-
// If the batch fails, fall back to getting native balance for each chain
|
|
101
|
-
console.warn(`Failed to get owned tokens for batch ${page}:`, error);
|
|
102
|
-
|
|
103
|
-
const chainsInBatch = insightEnabledChains.map((c) =>
|
|
104
|
-
getCachedChain(c.chainId),
|
|
105
|
-
);
|
|
106
|
-
const nativeBalances = await Promise.allSettled(
|
|
107
|
-
chainsInBatch.map(async (chain) => {
|
|
108
|
-
const balance = await getWalletBalance({
|
|
109
|
-
address: wallet.getAccount()?.address || "",
|
|
110
|
-
chain,
|
|
111
|
-
client,
|
|
112
|
-
});
|
|
113
|
-
return balance;
|
|
114
|
-
}),
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
// Transform successful native balances into the same format as getOwnedTokens results
|
|
118
|
-
batch = nativeBalances
|
|
119
|
-
.filter((result) => result.status === "fulfilled")
|
|
120
|
-
.map((result) => result.value)
|
|
121
|
-
.filter((balance) => balance.value > 0n);
|
|
122
|
-
|
|
123
|
-
// Convert to our format
|
|
124
|
-
const tokensWithBalance = batch.map((b) => ({
|
|
125
|
-
balance: b.value,
|
|
126
|
-
originToken: {
|
|
127
|
-
address: b.tokenAddress,
|
|
128
|
-
chainId: b.chainId,
|
|
129
|
-
decimals: b.decimals,
|
|
130
|
-
iconUri: "",
|
|
131
|
-
name: b.name,
|
|
132
|
-
prices: {
|
|
133
|
-
USD: 0,
|
|
134
|
-
},
|
|
135
|
-
symbol: b.symbol,
|
|
136
|
-
} as Token,
|
|
137
|
-
}));
|
|
138
|
-
|
|
139
|
-
allOwnedTokens = [...allOwnedTokens, ...tokensWithBalance];
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (batch.length === 0) {
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Convert to our format and filter out zero balances
|
|
148
|
-
const tokensWithBalance = batch
|
|
149
|
-
.filter((b) => b.value > 0n)
|
|
150
|
-
.map((b) => ({
|
|
151
|
-
balance: b.value,
|
|
152
|
-
originToken: {
|
|
153
|
-
address: b.tokenAddress,
|
|
154
|
-
chainId: b.chainId,
|
|
155
|
-
decimals: b.decimals,
|
|
156
|
-
iconUri: "",
|
|
157
|
-
name: b.name,
|
|
158
|
-
prices: {
|
|
159
|
-
USD: 0,
|
|
160
|
-
},
|
|
161
|
-
symbol: b.symbol,
|
|
162
|
-
} as Token,
|
|
163
|
-
}));
|
|
164
|
-
|
|
165
|
-
allOwnedTokens = [...allOwnedTokens, ...tokensWithBalance];
|
|
166
|
-
page += 1;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// 4. For each chain where we have owned tokens, fetch possible routes
|
|
170
|
-
const chainsWithOwnedTokens = Array.from(
|
|
171
|
-
new Set(allOwnedTokens.map((t) => t.originToken.chainId)),
|
|
58
|
+
url.searchParams.set(
|
|
59
|
+
"destinationChainId",
|
|
60
|
+
destinationToken.chainId.toString(),
|
|
172
61
|
);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (includeDestinationToken) {
|
|
178
|
-
const tokenKey = `${
|
|
179
|
-
destinationToken.chainId
|
|
180
|
-
}-${destinationToken.address.toLowerCase()}`;
|
|
181
|
-
allValidOriginTokens.set(tokenKey, destinationToken);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Fetch routes for each chain with owned tokens
|
|
185
|
-
await Promise.all(
|
|
186
|
-
chainsWithOwnedTokens.map(async (chainId) => {
|
|
187
|
-
try {
|
|
188
|
-
// TODO (bridge): this is quite inefficient, need to fix the popularity sorting to really capture all users tokens
|
|
189
|
-
const routesForChain = await routes({
|
|
190
|
-
client,
|
|
191
|
-
destinationChainId: destinationToken.chainId,
|
|
192
|
-
destinationTokenAddress: destinationToken.address,
|
|
193
|
-
includePrices: true,
|
|
194
|
-
limit: 100,
|
|
195
|
-
maxSteps: 3,
|
|
196
|
-
originChainId: chainId,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
// Add all origin tokens from this chain's routes
|
|
200
|
-
for (const route of routesForChain) {
|
|
201
|
-
// Skip if the origin token is the same as the destination token, will be added later only if includeDestinationToken is true
|
|
202
|
-
if (
|
|
203
|
-
route.originToken.chainId === destinationToken.chainId &&
|
|
204
|
-
route.originToken.address.toLowerCase() ===
|
|
205
|
-
destinationToken.address.toLowerCase()
|
|
206
|
-
) {
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
const tokenKey = `${
|
|
210
|
-
route.originToken.chainId
|
|
211
|
-
}-${route.originToken.address.toLowerCase()}`;
|
|
212
|
-
allValidOriginTokens.set(tokenKey, route.originToken);
|
|
213
|
-
}
|
|
214
|
-
} catch (error) {
|
|
215
|
-
// Log error but don't fail the entire operation
|
|
216
|
-
console.warn(`Failed to fetch routes for chain ${chainId}:`, error);
|
|
217
|
-
}
|
|
218
|
-
}),
|
|
62
|
+
url.searchParams.set("destinationTokenAddress", destinationToken.address);
|
|
63
|
+
url.searchParams.set(
|
|
64
|
+
"amount",
|
|
65
|
+
toUnits(destinationAmount, destinationToken.decimals).toString(),
|
|
219
66
|
);
|
|
220
67
|
|
|
221
|
-
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
validOwnedTokens.push({
|
|
232
|
-
balance: ownedToken.balance,
|
|
233
|
-
originAmount: 0n,
|
|
234
|
-
originToken: validOriginToken, // Use the token with pricing info from routes
|
|
235
|
-
});
|
|
236
|
-
}
|
|
68
|
+
const clientFetch = getClientFetch(client);
|
|
69
|
+
const response = await clientFetch(url.toString());
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const errorJson = await response.json();
|
|
72
|
+
throw new ApiError({
|
|
73
|
+
code: errorJson.code || "UNKNOWN_ERROR",
|
|
74
|
+
correlationId: errorJson.correlationId || undefined,
|
|
75
|
+
message: errorJson.message || response.statusText,
|
|
76
|
+
statusCode: response.status,
|
|
77
|
+
});
|
|
237
78
|
}
|
|
238
79
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
80
|
+
const {
|
|
81
|
+
data: allValidOriginTokens,
|
|
82
|
+
}: { data: { quote: Quote; balance: string; token: Token }[] } =
|
|
83
|
+
await response.json();
|
|
84
|
+
|
|
85
|
+
// Sort by enough balance to pay THEN gross balance
|
|
86
|
+
const validTokenQuotes = allValidOriginTokens.map((s) => ({
|
|
87
|
+
balance: BigInt(s.balance),
|
|
88
|
+
originToken: s.token,
|
|
89
|
+
payerWallet: wallet,
|
|
90
|
+
type: "wallet" as const,
|
|
91
|
+
quote: s.quote,
|
|
92
|
+
}));
|
|
93
|
+
const insufficientBalanceQuotes = validTokenQuotes
|
|
94
|
+
.filter((s) => s.balance < s.quote.originAmount)
|
|
95
|
+
.sort((a, b) => {
|
|
96
|
+
return (
|
|
97
|
+
Number.parseFloat(
|
|
98
|
+
toTokens(a.quote.originAmount, a.originToken.decimals),
|
|
99
|
+
) *
|
|
100
|
+
(a.originToken.prices.USD || 1) -
|
|
101
|
+
Number.parseFloat(
|
|
102
|
+
toTokens(b.quote.originAmount, b.originToken.decimals),
|
|
103
|
+
) *
|
|
104
|
+
(b.originToken.prices.USD || 1)
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
const sufficientBalanceQuotes = validTokenQuotes
|
|
108
|
+
.filter((s) => s.balance >= s.quote.originAmount)
|
|
109
|
+
.sort((a, b) => {
|
|
110
|
+
return (
|
|
111
|
+
Number.parseFloat(
|
|
112
|
+
toTokens(b.quote.originAmount, b.originToken.decimals),
|
|
113
|
+
) *
|
|
114
|
+
(b.originToken.prices.USD || 1) -
|
|
115
|
+
Number.parseFloat(
|
|
116
|
+
toTokens(a.quote.originAmount, a.originToken.decimals),
|
|
117
|
+
) *
|
|
118
|
+
(a.originToken.prices.USD || 1)
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
// Move all sufficient balance quotes to the top
|
|
122
|
+
return [...sufficientBalanceQuotes, ...insufficientBalanceQuotes];
|
|
276
123
|
},
|
|
277
124
|
queryKey: [
|
|
278
|
-
"
|
|
125
|
+
"payment-methods",
|
|
279
126
|
destinationToken.chainId,
|
|
280
127
|
destinationToken.address,
|
|
281
128
|
destinationAmount,
|
|
@@ -287,11 +134,11 @@ export function usePaymentMethods(options: {
|
|
|
287
134
|
});
|
|
288
135
|
|
|
289
136
|
return {
|
|
290
|
-
data:
|
|
291
|
-
error:
|
|
292
|
-
isError:
|
|
293
|
-
isLoading:
|
|
294
|
-
isSuccess:
|
|
295
|
-
refetch:
|
|
137
|
+
data: query.data || [],
|
|
138
|
+
error: query.error,
|
|
139
|
+
isError: query.isError,
|
|
140
|
+
isLoading: query.isLoading,
|
|
141
|
+
isSuccess: query.isSuccess,
|
|
142
|
+
refetch: query.refetch,
|
|
296
143
|
};
|
|
297
144
|
}
|
|
@@ -13,6 +13,7 @@ import type { SupportedFiatCurrency } from "../../../pay/convert/type.js";
|
|
|
13
13
|
import { encode } from "../../../transaction/actions/encode.js";
|
|
14
14
|
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
|
|
15
15
|
import { getTransactionGasCost } from "../../../transaction/utils.js";
|
|
16
|
+
import { stringify } from "../../../utils/json.js";
|
|
16
17
|
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
|
|
17
18
|
import { toTokens } from "../../../utils/units.js";
|
|
18
19
|
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
|
|
@@ -180,9 +181,7 @@ export function useTransactionDetails({
|
|
|
180
181
|
},
|
|
181
182
|
queryKey: [
|
|
182
183
|
"transaction-details",
|
|
183
|
-
transaction
|
|
184
|
-
transaction.chain.id,
|
|
185
|
-
transaction.erc20Value?.toString(),
|
|
184
|
+
stringify(transaction),
|
|
186
185
|
hasSponsoredTransactions,
|
|
187
186
|
],
|
|
188
187
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useCallback, useState } from "react";
|
|
2
|
+
import type { Quote } from "../../../bridge/index.js";
|
|
2
3
|
import type { Token } from "../../../bridge/types/Token.js";
|
|
3
4
|
import type { Address } from "../../../utils/address.js";
|
|
4
5
|
import type { AsyncStorage } from "../../../utils/storage/AsyncStorage.js";
|
|
@@ -24,6 +25,7 @@ export type PaymentMethod =
|
|
|
24
25
|
payerWallet: Wallet;
|
|
25
26
|
originToken: Token;
|
|
26
27
|
balance: bigint;
|
|
28
|
+
quote: Quote;
|
|
27
29
|
}
|
|
28
30
|
| {
|
|
29
31
|
type: "fiat";
|
|
@@ -5,8 +5,6 @@ export function invalidateWalletBalance(
|
|
|
5
5
|
chainId?: number,
|
|
6
6
|
) {
|
|
7
7
|
queryClient.invalidateQueries({
|
|
8
|
-
// invalidate any walletBalance queries for this chainId
|
|
9
|
-
// TODO: add wallet address in here if we can get it somehow
|
|
10
8
|
queryKey: chainId ? ["walletBalance", chainId] : ["walletBalance"],
|
|
11
9
|
});
|
|
12
10
|
queryClient.invalidateQueries({
|
|
@@ -14,4 +12,10 @@ export function invalidateWalletBalance(
|
|
|
14
12
|
? ["internal_account_balance", chainId]
|
|
15
13
|
: ["internal_account_balance"],
|
|
16
14
|
});
|
|
15
|
+
queryClient.invalidateQueries({
|
|
16
|
+
queryKey: chainId ? ["nfts", chainId] : ["nfts"],
|
|
17
|
+
});
|
|
18
|
+
queryClient.invalidateQueries({
|
|
19
|
+
queryKey: chainId ? ["tokens", chainId] : ["tokens"],
|
|
20
|
+
});
|
|
17
21
|
}
|
|
@@ -3,7 +3,6 @@ import type { Token } from "../../../../../bridge/types/Token.js";
|
|
|
3
3
|
import type { ThirdwebClient } from "../../../../../client/client.js";
|
|
4
4
|
import { useCustomTheme } from "../../../../core/design-system/CustomThemeProvider.js";
|
|
5
5
|
import { radius, spacing } from "../../../../core/design-system/index.js";
|
|
6
|
-
import { useBridgeQuote } from "../../../../core/hooks/useBridgeQuote.js";
|
|
7
6
|
import type { PaymentMethod } from "../../../../core/machines/paymentMachine.js";
|
|
8
7
|
import { formatTokenAmount } from "../../ConnectWallet/screens/formatTokenBalance.js";
|
|
9
8
|
import { Container } from "../../components/basic.js";
|
|
@@ -36,29 +35,12 @@ interface PaymentMethodTokenRowProps {
|
|
|
36
35
|
|
|
37
36
|
function PaymentMethodTokenRow({
|
|
38
37
|
paymentMethod,
|
|
39
|
-
destinationToken,
|
|
40
|
-
destinationAmount,
|
|
41
38
|
client,
|
|
42
39
|
onPaymentMethodSelected,
|
|
43
|
-
feePayer,
|
|
44
40
|
}: PaymentMethodTokenRowProps) {
|
|
45
41
|
const theme = useCustomTheme();
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
data: quote,
|
|
50
|
-
isLoading: quoteLoading,
|
|
51
|
-
error: quoteError,
|
|
52
|
-
} = useBridgeQuote({
|
|
53
|
-
client,
|
|
54
|
-
destinationAmount,
|
|
55
|
-
destinationToken,
|
|
56
|
-
feePayer,
|
|
57
|
-
originToken: paymentMethod.originToken,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Use the fetched originAmount if available, otherwise fall back to the one from paymentMethod
|
|
61
|
-
const displayOriginAmount = quote?.originAmount;
|
|
43
|
+
const displayOriginAmount = paymentMethod.quote.originAmount;
|
|
62
44
|
const hasEnoughBalance = displayOriginAmount
|
|
63
45
|
? paymentMethod.balance >= displayOriginAmount
|
|
64
46
|
: false;
|
|
@@ -97,57 +79,28 @@ function PaymentMethodTokenRow({
|
|
|
97
79
|
gap="3xs"
|
|
98
80
|
style={{ alignItems: "flex-end", flex: 1 }}
|
|
99
81
|
>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
<Text
|
|
83
|
+
color="primaryText"
|
|
84
|
+
size="sm"
|
|
85
|
+
style={{ fontWeight: 600, textWrap: "nowrap" }}
|
|
86
|
+
>
|
|
87
|
+
{formatTokenAmount(
|
|
88
|
+
displayOriginAmount,
|
|
89
|
+
paymentMethod.originToken.decimals,
|
|
90
|
+
)}{" "}
|
|
91
|
+
{paymentMethod.originToken.symbol}
|
|
92
|
+
</Text>
|
|
93
|
+
<Container flex="row" gap="3xs">
|
|
94
|
+
<Text color="secondaryText" size="xs">
|
|
95
|
+
Balance:{" "}
|
|
113
96
|
</Text>
|
|
114
|
-
|
|
115
|
-
<Text
|
|
116
|
-
color="primaryText"
|
|
117
|
-
size="sm"
|
|
118
|
-
style={{ fontWeight: 600, textWrap: "nowrap" }}
|
|
119
|
-
>
|
|
97
|
+
<Text color={hasEnoughBalance ? "success" : "danger"} size="xs">
|
|
120
98
|
{formatTokenAmount(
|
|
121
|
-
|
|
99
|
+
paymentMethod.balance,
|
|
122
100
|
paymentMethod.originToken.decimals,
|
|
123
|
-
)}
|
|
124
|
-
{paymentMethod.originToken.symbol}
|
|
101
|
+
)}
|
|
125
102
|
</Text>
|
|
126
|
-
|
|
127
|
-
"--.--"
|
|
128
|
-
)}
|
|
129
|
-
{!quoteLoading && (
|
|
130
|
-
<Container flex="row" gap="3xs">
|
|
131
|
-
<Text color="secondaryText" size="xs">
|
|
132
|
-
Balance:{" "}
|
|
133
|
-
</Text>
|
|
134
|
-
<Text
|
|
135
|
-
color={
|
|
136
|
-
!quoteLoading
|
|
137
|
-
? hasEnoughBalance
|
|
138
|
-
? "success"
|
|
139
|
-
: "danger"
|
|
140
|
-
: "secondaryText"
|
|
141
|
-
}
|
|
142
|
-
size="xs"
|
|
143
|
-
>
|
|
144
|
-
{formatTokenAmount(
|
|
145
|
-
paymentMethod.balance,
|
|
146
|
-
paymentMethod.originToken.decimals,
|
|
147
|
-
)}
|
|
148
|
-
</Text>
|
|
149
|
-
</Container>
|
|
150
|
-
)}
|
|
103
|
+
</Container>
|
|
151
104
|
</Container>
|
|
152
105
|
</Container>
|
|
153
106
|
</Button>
|
|
@@ -127,6 +127,9 @@ export function ViewNFTsContent(props: {
|
|
|
127
127
|
chains: [activeChain],
|
|
128
128
|
client: props.client,
|
|
129
129
|
ownerAddress: activeAccount.address,
|
|
130
|
+
contractAddresses: props.supportedNFTs?.[activeChain.id]?.map((nft) =>
|
|
131
|
+
nft.toLowerCase(),
|
|
132
|
+
),
|
|
130
133
|
});
|
|
131
134
|
|
|
132
135
|
return result
|
|
@@ -139,20 +142,19 @@ export function ViewNFTsContent(props: {
|
|
|
139
142
|
};
|
|
140
143
|
});
|
|
141
144
|
},
|
|
142
|
-
queryKey: [
|
|
145
|
+
queryKey: [
|
|
146
|
+
"nfts",
|
|
147
|
+
activeChain?.id,
|
|
148
|
+
activeAccount?.address,
|
|
149
|
+
props.supportedNFTs,
|
|
150
|
+
],
|
|
143
151
|
});
|
|
144
152
|
|
|
145
153
|
if (!activeChain?.id || !activeAccount?.address) {
|
|
146
154
|
return null;
|
|
147
155
|
}
|
|
148
156
|
|
|
149
|
-
const filteredNFTs =
|
|
150
|
-
? nftQuery.data?.filter((nft) =>
|
|
151
|
-
props.supportedNFTs?.[activeChain.id]
|
|
152
|
-
?.map((supportedNFTAddress) => supportedNFTAddress.toLowerCase())
|
|
153
|
-
.includes(nft.address.toLowerCase()),
|
|
154
|
-
)
|
|
155
|
-
: nftQuery.data;
|
|
157
|
+
const filteredNFTs = nftQuery.data;
|
|
156
158
|
|
|
157
159
|
return (
|
|
158
160
|
<>
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
* @throws {Error} - If the number of parameters and values do not match.
|
|
24
24
|
* @example
|
|
25
25
|
* ```ts
|
|
26
|
-
* import { encodeAbiParameters } from "
|
|
26
|
+
* import { encodeAbiParameters } from "thirdweb/utils";
|
|
27
27
|
*
|
|
28
28
|
* const params = [
|
|
29
29
|
* { name: "param1", type: "uint256" },
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.105.
|
|
1
|
+
export const version = "5.105.25";
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.useBridgeQuote = useBridgeQuote;
|
|
5
|
-
const react_query_1 = require("@tanstack/react-query");
|
|
6
|
-
const Buy = require("../../../bridge/Buy.js");
|
|
7
|
-
const Transfer = require("../../../bridge/Transfer.js");
|
|
8
|
-
const address_js_1 = require("../../../utils/address.js");
|
|
9
|
-
function useBridgeQuote({ originToken, destinationToken, destinationAmount, feePayer, client, enabled = true, }) {
|
|
10
|
-
return (0, react_query_1.useQuery)({
|
|
11
|
-
enabled: enabled && !!originToken && !!destinationToken && !!destinationAmount,
|
|
12
|
-
queryFn: async () => {
|
|
13
|
-
// if ssame token and chain, use transfer
|
|
14
|
-
if ((0, address_js_1.checksumAddress)(originToken.address) ===
|
|
15
|
-
(0, address_js_1.checksumAddress)(destinationToken.address) &&
|
|
16
|
-
originToken.chainId === destinationToken.chainId) {
|
|
17
|
-
const transfer = await Transfer.prepare({
|
|
18
|
-
amount: destinationAmount,
|
|
19
|
-
chainId: originToken.chainId,
|
|
20
|
-
client,
|
|
21
|
-
feePayer,
|
|
22
|
-
receiver: destinationToken.address,
|
|
23
|
-
sender: originToken.address,
|
|
24
|
-
tokenAddress: originToken.address,
|
|
25
|
-
});
|
|
26
|
-
return transfer;
|
|
27
|
-
}
|
|
28
|
-
const quote = await Buy.quote({
|
|
29
|
-
amount: destinationAmount,
|
|
30
|
-
client,
|
|
31
|
-
destinationChainId: destinationToken.chainId,
|
|
32
|
-
destinationTokenAddress: destinationToken.address,
|
|
33
|
-
originChainId: originToken.chainId,
|
|
34
|
-
originTokenAddress: originToken.address,
|
|
35
|
-
});
|
|
36
|
-
return quote;
|
|
37
|
-
},
|
|
38
|
-
queryKey: [
|
|
39
|
-
"bridge-quote",
|
|
40
|
-
originToken.chainId,
|
|
41
|
-
originToken.address,
|
|
42
|
-
destinationToken.chainId,
|
|
43
|
-
destinationToken.address,
|
|
44
|
-
destinationAmount.toString(),
|
|
45
|
-
feePayer,
|
|
46
|
-
],
|
|
47
|
-
refetchInterval: 60000, // 30 seconds
|
|
48
|
-
retry: 3, // 1 minute
|
|
49
|
-
staleTime: 30000,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=useBridgeQuote.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBridgeQuote.js","sourceRoot":"","sources":["../../../../../src/react/core/hooks/useBridgeQuote.ts"],"names":[],"mappings":";AAAA,YAAY,CAAC;;AAiBb,wCAqDC;AArED,uDAAiD;AACjD,8CAA8C;AAC9C,wDAAwD;AAGxD,0DAA4D;AAW5D,SAAgB,cAAc,CAAC,EAC7B,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,MAAM,EACN,OAAO,GAAG,IAAI,GACO;IACrB,OAAO,IAAA,sBAAQ,EAAC;QACd,OAAO,EACL,OAAO,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,gBAAgB,IAAI,CAAC,CAAC,iBAAiB;QACvE,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,yCAAyC;YACzC,IACE,IAAA,4BAAe,EAAC,WAAW,CAAC,OAAO,CAAC;gBAClC,IAAA,4BAAe,EAAC,gBAAgB,CAAC,OAAO,CAAC;gBAC3C,WAAW,CAAC,OAAO,KAAK,gBAAgB,CAAC,OAAO,EAChD,CAAC;gBACD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC;oBACtC,MAAM,EAAE,iBAAiB;oBACzB,OAAO,EAAE,WAAW,CAAC,OAAO;oBAC5B,MAAM;oBACN,QAAQ;oBACR,QAAQ,EAAE,gBAAgB,CAAC,OAAO;oBAClC,MAAM,EAAE,WAAW,CAAC,OAAO;oBAC3B,YAAY,EAAE,WAAW,CAAC,OAAO;iBAClC,CAAC,CAAC;gBACH,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC;gBAC5B,MAAM,EAAE,iBAAiB;gBACzB,MAAM;gBACN,kBAAkB,EAAE,gBAAgB,CAAC,OAAO;gBAC5C,uBAAuB,EAAE,gBAAgB,CAAC,OAAO;gBACjD,aAAa,EAAE,WAAW,CAAC,OAAO;gBAClC,kBAAkB,EAAE,WAAW,CAAC,OAAO;aACxC,CAAC,CAAC;YAEH,OAAO,KAAK,CAAC;QACf,CAAC;QACD,QAAQ,EAAE;YACR,cAAc;YACd,WAAW,CAAC,OAAO;YACnB,WAAW,CAAC,OAAO;YACnB,gBAAgB,CAAC,OAAO;YACxB,gBAAgB,CAAC,OAAO;YACxB,iBAAiB,CAAC,QAAQ,EAAE;YAC5B,QAAQ;SACT;QACD,eAAe,EAAE,KAAK,EAAE,aAAa;QACrC,KAAK,EAAE,CAAC,EAAE,WAAW;QACrB,SAAS,EAAE,KAAK;KACjB,CAAC,CAAC;AACL,CAAC"}
|