thirdweb 5.105.23 → 5.105.24
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/react/core/hooks/usePaymentMethods.js +52 -174
- package/dist/cjs/react/core/hooks/usePaymentMethods.js.map +1 -1
- package/dist/cjs/react/core/machines/paymentMachine.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/version.js +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/machines/paymentMachine.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/version.js +1 -1
- package/dist/types/react/core/hooks/usePaymentMethods.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/web/ui/Bridge/payment-selection/TokenSelection.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/react/core/hooks/usePaymentMethods.ts +77 -230
- package/src/react/core/machines/paymentMachine.ts +2 -0
- package/src/react/web/ui/Bridge/payment-selection/TokenSelection.tsx +19 -66
- 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
|
}
|
|
@@ -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";
|
|
@@ -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>
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.105.
|
|
1
|
+
export const version = "5.105.24";
|
|
@@ -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"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import * as Buy from "../../../bridge/Buy.js";
|
|
4
|
-
import * as Transfer from "../../../bridge/Transfer.js";
|
|
5
|
-
import { checksumAddress } from "../../../utils/address.js";
|
|
6
|
-
export function useBridgeQuote({ originToken, destinationToken, destinationAmount, feePayer, client, enabled = true, }) {
|
|
7
|
-
return useQuery({
|
|
8
|
-
enabled: enabled && !!originToken && !!destinationToken && !!destinationAmount,
|
|
9
|
-
queryFn: async () => {
|
|
10
|
-
// if ssame token and chain, use transfer
|
|
11
|
-
if (checksumAddress(originToken.address) ===
|
|
12
|
-
checksumAddress(destinationToken.address) &&
|
|
13
|
-
originToken.chainId === destinationToken.chainId) {
|
|
14
|
-
const transfer = await Transfer.prepare({
|
|
15
|
-
amount: destinationAmount,
|
|
16
|
-
chainId: originToken.chainId,
|
|
17
|
-
client,
|
|
18
|
-
feePayer,
|
|
19
|
-
receiver: destinationToken.address,
|
|
20
|
-
sender: originToken.address,
|
|
21
|
-
tokenAddress: originToken.address,
|
|
22
|
-
});
|
|
23
|
-
return transfer;
|
|
24
|
-
}
|
|
25
|
-
const quote = await Buy.quote({
|
|
26
|
-
amount: destinationAmount,
|
|
27
|
-
client,
|
|
28
|
-
destinationChainId: destinationToken.chainId,
|
|
29
|
-
destinationTokenAddress: destinationToken.address,
|
|
30
|
-
originChainId: originToken.chainId,
|
|
31
|
-
originTokenAddress: originToken.address,
|
|
32
|
-
});
|
|
33
|
-
return quote;
|
|
34
|
-
},
|
|
35
|
-
queryKey: [
|
|
36
|
-
"bridge-quote",
|
|
37
|
-
originToken.chainId,
|
|
38
|
-
originToken.address,
|
|
39
|
-
destinationToken.chainId,
|
|
40
|
-
destinationToken.address,
|
|
41
|
-
destinationAmount.toString(),
|
|
42
|
-
feePayer,
|
|
43
|
-
],
|
|
44
|
-
refetchInterval: 60000, // 30 seconds
|
|
45
|
-
retry: 3, // 1 minute
|
|
46
|
-
staleTime: 30000,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
//# 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;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,KAAK,QAAQ,MAAM,6BAA6B,CAAC;AAGxD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAW5D,MAAM,UAAU,cAAc,CAAC,EAC7B,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,MAAM,EACN,OAAO,GAAG,IAAI,GACO;IACrB,OAAO,QAAQ,CAAC;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,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC;gBAClC,eAAe,CAAC,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"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as Buy from "../../../bridge/Buy.js";
|
|
2
|
-
import * as Transfer from "../../../bridge/Transfer.js";
|
|
3
|
-
import type { Token } from "../../../bridge/types/Token.js";
|
|
4
|
-
import type { ThirdwebClient } from "../../../client/client.js";
|
|
5
|
-
interface UseBridgeQuoteParams {
|
|
6
|
-
originToken: Token;
|
|
7
|
-
destinationToken: Token;
|
|
8
|
-
destinationAmount: bigint;
|
|
9
|
-
client: ThirdwebClient;
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
feePayer?: "sender" | "receiver";
|
|
12
|
-
}
|
|
13
|
-
export declare function useBridgeQuote({ originToken, destinationToken, destinationAmount, feePayer, client, enabled, }: UseBridgeQuoteParams): import("@tanstack/react-query").UseQueryResult<Buy.quote.Result | Transfer.prepare.Result, Error>;
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=useBridgeQuote.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBridgeQuote.d.ts","sourceRoot":"","sources":["../../../../../src/react/core/hooks/useBridgeQuote.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,wBAAwB,CAAC;AAC9C,OAAO,KAAK,QAAQ,MAAM,6BAA6B,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,UAAU,oBAAoB;IAC5B,WAAW,EAAE,KAAK,CAAC;IACnB,gBAAgB,EAAE,KAAK,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;CAClC;AAED,wBAAgB,cAAc,CAAC,EAC7B,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,MAAM,EACN,OAAc,GACf,EAAE,oBAAoB,qGA8CtB"}
|