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,71 +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 type { Token } from "../../../bridge/types/Token.js";
|
|
6
|
-
import type { ThirdwebClient } from "../../../client/client.js";
|
|
7
|
-
import { checksumAddress } from "../../../utils/address.js";
|
|
8
|
-
|
|
9
|
-
interface UseBridgeQuoteParams {
|
|
10
|
-
originToken: Token;
|
|
11
|
-
destinationToken: Token;
|
|
12
|
-
destinationAmount: bigint;
|
|
13
|
-
client: ThirdwebClient;
|
|
14
|
-
enabled?: boolean;
|
|
15
|
-
feePayer?: "sender" | "receiver";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function useBridgeQuote({
|
|
19
|
-
originToken,
|
|
20
|
-
destinationToken,
|
|
21
|
-
destinationAmount,
|
|
22
|
-
feePayer,
|
|
23
|
-
client,
|
|
24
|
-
enabled = true,
|
|
25
|
-
}: UseBridgeQuoteParams) {
|
|
26
|
-
return useQuery({
|
|
27
|
-
enabled:
|
|
28
|
-
enabled && !!originToken && !!destinationToken && !!destinationAmount,
|
|
29
|
-
queryFn: async () => {
|
|
30
|
-
// if ssame token and chain, use transfer
|
|
31
|
-
if (
|
|
32
|
-
checksumAddress(originToken.address) ===
|
|
33
|
-
checksumAddress(destinationToken.address) &&
|
|
34
|
-
originToken.chainId === destinationToken.chainId
|
|
35
|
-
) {
|
|
36
|
-
const transfer = await Transfer.prepare({
|
|
37
|
-
amount: destinationAmount,
|
|
38
|
-
chainId: originToken.chainId,
|
|
39
|
-
client,
|
|
40
|
-
feePayer,
|
|
41
|
-
receiver: destinationToken.address,
|
|
42
|
-
sender: originToken.address,
|
|
43
|
-
tokenAddress: originToken.address,
|
|
44
|
-
});
|
|
45
|
-
return transfer;
|
|
46
|
-
}
|
|
47
|
-
const quote = await Buy.quote({
|
|
48
|
-
amount: destinationAmount,
|
|
49
|
-
client,
|
|
50
|
-
destinationChainId: destinationToken.chainId,
|
|
51
|
-
destinationTokenAddress: destinationToken.address,
|
|
52
|
-
originChainId: originToken.chainId,
|
|
53
|
-
originTokenAddress: originToken.address,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return quote;
|
|
57
|
-
},
|
|
58
|
-
queryKey: [
|
|
59
|
-
"bridge-quote",
|
|
60
|
-
originToken.chainId,
|
|
61
|
-
originToken.address,
|
|
62
|
-
destinationToken.chainId,
|
|
63
|
-
destinationToken.address,
|
|
64
|
-
destinationAmount.toString(),
|
|
65
|
-
feePayer,
|
|
66
|
-
],
|
|
67
|
-
refetchInterval: 60000, // 30 seconds
|
|
68
|
-
retry: 3, // 1 minute
|
|
69
|
-
staleTime: 30000,
|
|
70
|
-
});
|
|
71
|
-
}
|