thirdweb 5.105.22 → 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/react/web/wallets/shared/WalletConnectConnection.js +7 -33
- package/dist/cjs/react/web/wallets/shared/WalletConnectConnection.js.map +1 -1
- package/dist/cjs/utils/web/isMobile.js +0 -2
- package/dist/cjs/utils/web/isMobile.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/create-wallet.js +21 -4
- package/dist/cjs/wallets/create-wallet.js.map +1 -1
- package/dist/cjs/wallets/wallet-connect/controller.js +27 -25
- package/dist/cjs/wallets/wallet-connect/controller.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/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/react/web/wallets/shared/WalletConnectConnection.js +8 -34
- package/dist/esm/react/web/wallets/shared/WalletConnectConnection.js.map +1 -1
- package/dist/esm/utils/web/isMobile.js +2 -2
- package/dist/esm/utils/web/isMobile.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/create-wallet.js +21 -4
- package/dist/esm/wallets/create-wallet.js.map +1 -1
- package/dist/esm/wallets/wallet-connect/controller.js +27 -25
- package/dist/esm/wallets/wallet-connect/controller.js.map +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/react/web/wallets/shared/WalletConnectConnection.d.ts.map +1 -1
- package/dist/types/utils/web/isMobile.d.ts +0 -8
- package/dist/types/utils/web/isMobile.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/create-wallet.d.ts.map +1 -1
- package/dist/types/wallets/wallet-connect/controller.d.ts.map +1 -1
- package/package.json +1 -1
- 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/react/web/wallets/shared/WalletConnectConnection.tsx +11 -46
- package/src/utils/web/isMobile.ts +2 -2
- package/src/version.ts +1 -1
- package/src/wallets/create-wallet.ts +53 -31
- package/src/wallets/wallet-connect/controller.ts +28 -25
- 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
|
@@ -2,8 +2,10 @@ import { trackConnect } from "../analytics/track/connect.js";
|
|
|
2
2
|
import type { Chain } from "../chains/types.js";
|
|
3
3
|
import { getCachedChainIfExists } from "../chains/utils.js";
|
|
4
4
|
import { webLocalStorage } from "../utils/storage/webStorage.js";
|
|
5
|
+
import { formatWalletConnectUrl } from "../utils/url.js";
|
|
5
6
|
import { isMobile } from "../utils/web/isMobile.js";
|
|
6
7
|
import { openWindow } from "../utils/web/openWindow.js";
|
|
8
|
+
import { getWalletInfo } from "./__generated__/getWalletInfo.js";
|
|
7
9
|
import type {
|
|
8
10
|
InjectedSupportedWalletIds,
|
|
9
11
|
WCSupportedWalletIds,
|
|
@@ -313,43 +315,63 @@ export function createWallet<const ID extends WalletId>(
|
|
|
313
315
|
...wcOptions,
|
|
314
316
|
walletConnect: {
|
|
315
317
|
...wcOptions.walletConnect,
|
|
316
|
-
onDisplayUri:
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
318
|
+
onDisplayUri:
|
|
319
|
+
wcOptions.walletConnect?.onDisplayUri ||
|
|
320
|
+
(async (uri) => {
|
|
321
|
+
// Check if we're in a browser environment
|
|
322
|
+
if (
|
|
323
|
+
typeof window !== "undefined" &&
|
|
324
|
+
typeof document !== "undefined"
|
|
325
|
+
) {
|
|
326
|
+
// on mobile, open the wallet app via deeplink
|
|
327
|
+
if (isMobile()) {
|
|
328
|
+
const walletInfo = await getWalletInfo(id);
|
|
329
|
+
|
|
330
|
+
const mobileAppLink =
|
|
331
|
+
walletInfo.mobile.native ||
|
|
332
|
+
walletInfo.mobile.universal;
|
|
333
|
+
if (mobileAppLink) {
|
|
334
|
+
openWindow(
|
|
335
|
+
formatWalletConnectUrl(mobileAppLink, uri)
|
|
336
|
+
.redirect,
|
|
326
337
|
);
|
|
338
|
+
} else {
|
|
339
|
+
// on android, wc:// links show the app picker
|
|
340
|
+
openWindow(uri);
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
327
344
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
345
|
+
try {
|
|
346
|
+
// on desktop, create a QR overlay
|
|
347
|
+
const { createQROverlay } = await import(
|
|
348
|
+
"./wallet-connect/qr-overlay.js"
|
|
349
|
+
);
|
|
332
350
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
wcOptions.walletConnect?.qrModalOptions
|
|
337
|
-
?.themeMode ?? "dark",
|
|
338
|
-
qrSize: 280,
|
|
339
|
-
showCloseButton: true,
|
|
340
|
-
onCancel: () => {
|
|
341
|
-
wcOptions.walletConnect?.onCancel?.();
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
} catch (error) {
|
|
345
|
-
console.error(
|
|
346
|
-
"Failed to create QR overlay:",
|
|
347
|
-
error,
|
|
348
|
-
);
|
|
351
|
+
// Clean up any existing overlay
|
|
352
|
+
if (qrOverlay) {
|
|
353
|
+
qrOverlay.destroy();
|
|
349
354
|
}
|
|
355
|
+
|
|
356
|
+
// Create new QR overlay
|
|
357
|
+
qrOverlay = createQROverlay(uri, {
|
|
358
|
+
theme:
|
|
359
|
+
wcOptions.walletConnect?.qrModalOptions
|
|
360
|
+
?.themeMode ?? "dark",
|
|
361
|
+
qrSize: 280,
|
|
362
|
+
showCloseButton: true,
|
|
363
|
+
onCancel: () => {
|
|
364
|
+
wcOptions.walletConnect?.onCancel?.();
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
} catch (error) {
|
|
368
|
+
console.error(
|
|
369
|
+
"Failed to create QR overlay:",
|
|
370
|
+
error,
|
|
371
|
+
);
|
|
350
372
|
}
|
|
351
373
|
}
|
|
352
|
-
|
|
374
|
+
}),
|
|
353
375
|
},
|
|
354
376
|
},
|
|
355
377
|
emitter,
|
|
@@ -123,30 +123,28 @@ export async function connectWC(
|
|
|
123
123
|
optionalChains: optionalChains,
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
rpcMap,
|
|
146
|
-
},
|
|
126
|
+
// For UniversalProvider, we need to connect with namespaces
|
|
127
|
+
await provider.connect({
|
|
128
|
+
...(wcOptions?.pairingTopic
|
|
129
|
+
? { pairingTopic: wcOptions?.pairingTopic }
|
|
130
|
+
: {}),
|
|
131
|
+
namespaces: {
|
|
132
|
+
[NAMESPACE]: {
|
|
133
|
+
chains: chainsToRequest,
|
|
134
|
+
events: ["chainChanged", "accountsChanged"],
|
|
135
|
+
methods: [
|
|
136
|
+
"eth_sendTransaction",
|
|
137
|
+
"eth_signTransaction",
|
|
138
|
+
"eth_sign",
|
|
139
|
+
"personal_sign",
|
|
140
|
+
"eth_signTypedData",
|
|
141
|
+
"wallet_switchEthereumChain",
|
|
142
|
+
"wallet_addEthereumChain",
|
|
143
|
+
],
|
|
144
|
+
rpcMap,
|
|
147
145
|
},
|
|
148
|
-
}
|
|
149
|
-
}
|
|
146
|
+
},
|
|
147
|
+
});
|
|
150
148
|
|
|
151
149
|
setRequestedChainsIds(
|
|
152
150
|
chainsToRequest.map((x) => Number(x.split(":")[1])),
|
|
@@ -223,9 +221,14 @@ export async function autoConnectWC(
|
|
|
223
221
|
sessionHandler,
|
|
224
222
|
);
|
|
225
223
|
|
|
224
|
+
if (!provider.session) {
|
|
225
|
+
await provider.disconnect();
|
|
226
|
+
throw new Error("No wallet connect session found on provider.");
|
|
227
|
+
}
|
|
228
|
+
|
|
226
229
|
// For UniversalProvider, get accounts from enable() method
|
|
227
|
-
const
|
|
228
|
-
const address =
|
|
230
|
+
const namespaceAccounts = provider.session?.namespaces?.[NAMESPACE]?.accounts;
|
|
231
|
+
const address = namespaceAccounts?.[0]?.split(":")[2];
|
|
229
232
|
|
|
230
233
|
if (!address) {
|
|
231
234
|
throw new Error("No accounts found on provider.");
|
|
@@ -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"}
|
|
@@ -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
|
-
}
|