@relayprotocol/relay-kit-ui 5.1.2 → 6.0.0
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/_cjs/src/components/common/BalanceDisplay.js +4 -3
- package/_cjs/src/components/common/BalanceDisplay.js.map +1 -1
- package/_cjs/src/components/common/MultiWalletDropdown.js +5 -4
- package/_cjs/src/components/common/MultiWalletDropdown.js.map +1 -1
- package/_cjs/src/components/common/PercentageButtons.js +9 -9
- package/_cjs/src/components/common/PercentageButtons.js.map +1 -1
- package/_cjs/src/components/common/SlippageToleranceConfig.js +30 -17
- package/_cjs/src/components/common/SlippageToleranceConfig.js.map +1 -1
- package/_cjs/src/components/common/TokenSelector/ChainFilter.js +21 -19
- package/_cjs/src/components/common/TokenSelector/ChainFilter.js.map +1 -1
- package/_cjs/src/components/common/TokenSelector/ChainFilterRow.js +117 -0
- package/_cjs/src/components/common/TokenSelector/ChainFilterRow.js.map +1 -0
- package/_cjs/src/components/common/TokenSelector/ChainFilterSidebar.js +2 -13
- package/_cjs/src/components/common/TokenSelector/ChainFilterSidebar.js.map +1 -1
- package/_cjs/src/components/common/TokenSelector/CompactChainFilter.js +180 -0
- package/_cjs/src/components/common/TokenSelector/CompactChainFilter.js.map +1 -0
- package/_cjs/src/components/common/TokenSelector/PaymentMethod.js +456 -0
- package/_cjs/src/components/common/TokenSelector/PaymentMethod.js.map +1 -0
- package/_cjs/src/components/common/TokenSelector/PaymentTokenList.js +83 -0
- package/_cjs/src/components/common/TokenSelector/PaymentTokenList.js.map +1 -0
- package/_cjs/src/components/common/TokenSelector/triggers/PaymentMethodTrigger.js +77 -0
- package/_cjs/src/components/common/TokenSelector/triggers/PaymentMethodTrigger.js.map +1 -0
- package/_cjs/src/components/primitives/ChainTokenIcon.js +3 -2
- package/_cjs/src/components/primitives/ChainTokenIcon.js.map +1 -1
- package/_cjs/src/components/primitives/SlippageButton.js +40 -0
- package/_cjs/src/components/primitives/SlippageButton.js.map +1 -0
- package/_cjs/src/components/primitives/Tabs.js +4 -2
- package/_cjs/src/components/primitives/Tabs.js.map +1 -1
- package/_cjs/src/components/widgets/SwapButton.js +35 -7
- package/_cjs/src/components/widgets/SwapButton.js.map +1 -1
- package/_cjs/src/components/widgets/TokenWidget/AmountModeToggle.js +31 -0
- package/_cjs/src/components/widgets/TokenWidget/AmountModeToggle.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/AmountSectionHeader.js +8 -0
- package/_cjs/src/components/widgets/TokenWidget/AmountSectionHeader.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/BuyTabContent.js +218 -0
- package/_cjs/src/components/widgets/TokenWidget/BuyTabContent.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/DestinationWalletSelector.js +20 -0
- package/_cjs/src/components/widgets/TokenWidget/DestinationWalletSelector.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/FeeBreakdownInfo.js +26 -0
- package/_cjs/src/components/widgets/TokenWidget/FeeBreakdownInfo.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/FeeBreakdownTooltip.js +40 -0
- package/_cjs/src/components/widgets/TokenWidget/FeeBreakdownTooltip.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/SectionContainer.js +22 -0
- package/_cjs/src/components/widgets/TokenWidget/SectionContainer.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/SellTabContent.js +280 -0
- package/_cjs/src/components/widgets/TokenWidget/SellTabContent.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/TransactionDetailsFooter.js +28 -0
- package/_cjs/src/components/widgets/TokenWidget/TransactionDetailsFooter.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/hooks/useWalletGuards.js +108 -0
- package/_cjs/src/components/widgets/TokenWidget/hooks/useWalletGuards.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/index.js +9 -0
- package/_cjs/src/components/widgets/TokenWidget/index.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js +770 -0
- package/_cjs/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js.map +1 -0
- package/_cjs/src/components/widgets/TokenWidget/widget/index.js +1005 -0
- package/_cjs/src/components/widgets/TokenWidget/widget/index.js.map +1 -0
- package/_cjs/src/hooks/index.js +3 -1
- package/_cjs/src/hooks/index.js.map +1 -1
- package/_cjs/src/hooks/useDuneBalances.js +2 -1
- package/_cjs/src/hooks/useDuneBalances.js.map +1 -1
- package/_cjs/src/hooks/useEOADetection.js +3 -0
- package/_cjs/src/hooks/useEOADetection.js.map +1 -1
- package/_cjs/src/hooks/useMultiWalletBalances.js +119 -0
- package/_cjs/src/hooks/useMultiWalletBalances.js.map +1 -0
- package/_cjs/src/index.js.map +1 -1
- package/_cjs/src/styles.css +251 -88
- package/_cjs/src/utils/numbers.js +39 -1
- package/_cjs/src/utils/numbers.js.map +1 -1
- package/_cjs/src/utils/tokenSelector.js +4 -1
- package/_cjs/src/utils/tokenSelector.js.map +1 -1
- package/_cjs/src/utils/tokens.js +20 -1
- package/_cjs/src/utils/tokens.js.map +1 -1
- package/_cjs/src/version.js +1 -1
- package/_cjs/tsconfig.build.tsbuildinfo +1 -1
- package/_esm/src/components/common/BalanceDisplay.js +4 -3
- package/_esm/src/components/common/BalanceDisplay.js.map +1 -1
- package/_esm/src/components/common/MultiWalletDropdown.js +5 -4
- package/_esm/src/components/common/MultiWalletDropdown.js.map +1 -1
- package/_esm/src/components/common/PercentageButtons.js +10 -10
- package/_esm/src/components/common/PercentageButtons.js.map +1 -1
- package/_esm/src/components/common/SlippageToleranceConfig.js +31 -23
- package/_esm/src/components/common/SlippageToleranceConfig.js.map +1 -1
- package/_esm/src/components/common/TokenSelector/ChainFilter.js +25 -23
- package/_esm/src/components/common/TokenSelector/ChainFilter.js.map +1 -1
- package/_esm/src/components/common/TokenSelector/ChainFilterRow.js +112 -0
- package/_esm/src/components/common/TokenSelector/ChainFilterRow.js.map +1 -0
- package/_esm/src/components/common/TokenSelector/ChainFilterSidebar.js +4 -15
- package/_esm/src/components/common/TokenSelector/ChainFilterSidebar.js.map +1 -1
- package/_esm/src/components/common/TokenSelector/CompactChainFilter.js +176 -0
- package/_esm/src/components/common/TokenSelector/CompactChainFilter.js.map +1 -0
- package/_esm/src/components/common/TokenSelector/PaymentMethod.js +461 -0
- package/_esm/src/components/common/TokenSelector/PaymentMethod.js.map +1 -0
- package/_esm/src/components/common/TokenSelector/PaymentTokenList.js +79 -0
- package/_esm/src/components/common/TokenSelector/PaymentTokenList.js.map +1 -0
- package/_esm/src/components/common/TokenSelector/triggers/PaymentMethodTrigger.js +72 -0
- package/_esm/src/components/common/TokenSelector/triggers/PaymentMethodTrigger.js.map +1 -0
- package/_esm/src/components/primitives/ChainTokenIcon.js +3 -2
- package/_esm/src/components/primitives/ChainTokenIcon.js.map +1 -1
- package/_esm/src/components/primitives/SlippageButton.js +36 -0
- package/_esm/src/components/primitives/SlippageButton.js.map +1 -0
- package/_esm/src/components/primitives/Tabs.js +4 -2
- package/_esm/src/components/primitives/Tabs.js.map +1 -1
- package/_esm/src/components/widgets/SwapButton.js +35 -7
- package/_esm/src/components/widgets/SwapButton.js.map +1 -1
- package/_esm/src/components/widgets/TokenWidget/AmountModeToggle.js +30 -0
- package/_esm/src/components/widgets/TokenWidget/AmountModeToggle.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/AmountSectionHeader.js +7 -0
- package/_esm/src/components/widgets/TokenWidget/AmountSectionHeader.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/BuyTabContent.js +215 -0
- package/_esm/src/components/widgets/TokenWidget/BuyTabContent.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/DestinationWalletSelector.js +16 -0
- package/_esm/src/components/widgets/TokenWidget/DestinationWalletSelector.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/FeeBreakdownInfo.js +21 -0
- package/_esm/src/components/widgets/TokenWidget/FeeBreakdownInfo.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/FeeBreakdownTooltip.js +39 -0
- package/_esm/src/components/widgets/TokenWidget/FeeBreakdownTooltip.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/SectionContainer.js +22 -0
- package/_esm/src/components/widgets/TokenWidget/SectionContainer.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/SellTabContent.js +283 -0
- package/_esm/src/components/widgets/TokenWidget/SellTabContent.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/TransactionDetailsFooter.js +27 -0
- package/_esm/src/components/widgets/TokenWidget/TransactionDetailsFooter.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/hooks/useWalletGuards.js +104 -0
- package/_esm/src/components/widgets/TokenWidget/hooks/useWalletGuards.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/index.js +2 -0
- package/_esm/src/components/widgets/TokenWidget/index.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js +795 -0
- package/_esm/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.js.map +1 -0
- package/_esm/src/components/widgets/TokenWidget/widget/index.js +1073 -0
- package/_esm/src/components/widgets/TokenWidget/widget/index.js.map +1 -0
- package/_esm/src/hooks/index.js +2 -1
- package/_esm/src/hooks/index.js.map +1 -1
- package/_esm/src/hooks/useDuneBalances.js +2 -1
- package/_esm/src/hooks/useDuneBalances.js.map +1 -1
- package/_esm/src/hooks/useEOADetection.js +3 -0
- package/_esm/src/hooks/useEOADetection.js.map +1 -1
- package/_esm/src/hooks/useMultiWalletBalances.js +122 -0
- package/_esm/src/hooks/useMultiWalletBalances.js.map +1 -0
- package/_esm/src/index.js.map +1 -1
- package/_esm/src/styles.css +251 -88
- package/_esm/src/utils/numbers.js +44 -1
- package/_esm/src/utils/numbers.js.map +1 -1
- package/_esm/src/utils/tokenSelector.js +4 -1
- package/_esm/src/utils/tokenSelector.js.map +1 -1
- package/_esm/src/utils/tokens.js +25 -0
- package/_esm/src/utils/tokens.js.map +1 -1
- package/_esm/src/version.js +1 -1
- package/_esm/tsconfig.build.tsbuildinfo +1 -1
- package/_types/src/components/common/BalanceDisplay.d.ts +2 -0
- package/_types/src/components/common/BalanceDisplay.d.ts.map +1 -1
- package/_types/src/components/common/MultiWalletDropdown.d.ts +2 -1
- package/_types/src/components/common/MultiWalletDropdown.d.ts.map +1 -1
- package/_types/src/components/common/PercentageButtons.d.ts +3 -1
- package/_types/src/components/common/PercentageButtons.d.ts.map +1 -1
- package/_types/src/components/common/SlippageToleranceConfig.d.ts +7 -0
- package/_types/src/components/common/SlippageToleranceConfig.d.ts.map +1 -1
- package/_types/src/components/common/TokenSelector/ChainFilter.d.ts.map +1 -1
- package/_types/src/components/common/TokenSelector/ChainFilterRow.d.ts +19 -0
- package/_types/src/components/common/TokenSelector/ChainFilterRow.d.ts.map +1 -0
- package/_types/src/components/common/TokenSelector/ChainFilterSidebar.d.ts.map +1 -1
- package/_types/src/components/common/TokenSelector/CompactChainFilter.d.ts +14 -0
- package/_types/src/components/common/TokenSelector/CompactChainFilter.d.ts.map +1 -0
- package/_types/src/components/common/TokenSelector/PaymentMethod.d.ts +24 -0
- package/_types/src/components/common/TokenSelector/PaymentMethod.d.ts.map +1 -0
- package/_types/src/components/common/TokenSelector/PaymentTokenList.d.ts +15 -0
- package/_types/src/components/common/TokenSelector/PaymentTokenList.d.ts.map +1 -0
- package/_types/src/components/common/TokenSelector/triggers/PaymentMethodTrigger.d.ts +13 -0
- package/_types/src/components/common/TokenSelector/triggers/PaymentMethodTrigger.d.ts.map +1 -0
- package/_types/src/components/primitives/ChainTokenIcon.d.ts +1 -0
- package/_types/src/components/primitives/ChainTokenIcon.d.ts.map +1 -1
- package/_types/src/components/primitives/SlippageButton.d.ts +8 -0
- package/_types/src/components/primitives/SlippageButton.d.ts.map +1 -0
- package/_types/src/components/primitives/Tabs.d.ts.map +1 -1
- package/_types/src/components/widgets/SwapButton.d.ts +5 -2
- package/_types/src/components/widgets/SwapButton.d.ts.map +1 -1
- package/_types/src/components/widgets/TokenWidget/AmountModeToggle.d.ts +12 -0
- package/_types/src/components/widgets/TokenWidget/AmountModeToggle.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/AmountSectionHeader.d.ts +11 -0
- package/_types/src/components/widgets/TokenWidget/AmountSectionHeader.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/BuyTabContent.d.ts +52 -0
- package/_types/src/components/widgets/TokenWidget/BuyTabContent.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/DestinationWalletSelector.d.ts +17 -0
- package/_types/src/components/widgets/TokenWidget/DestinationWalletSelector.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/FeeBreakdownInfo.d.ts +16 -0
- package/_types/src/components/widgets/TokenWidget/FeeBreakdownInfo.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/FeeBreakdownTooltip.d.ts +15 -0
- package/_types/src/components/widgets/TokenWidget/FeeBreakdownTooltip.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/SectionContainer.d.ts +8 -0
- package/_types/src/components/widgets/TokenWidget/SectionContainer.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/SellTabContent.d.ts +61 -0
- package/_types/src/components/widgets/TokenWidget/SellTabContent.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/TransactionDetailsFooter.d.ts +14 -0
- package/_types/src/components/widgets/TokenWidget/TransactionDetailsFooter.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/hooks/useWalletGuards.d.ts +28 -0
- package/_types/src/components/widgets/TokenWidget/hooks/useWalletGuards.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/index.d.ts +3 -0
- package/_types/src/components/widgets/TokenWidget/index.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.d.ts +125 -0
- package/_types/src/components/widgets/TokenWidget/widget/TokenWidgetRenderer.d.ts.map +1 -0
- package/_types/src/components/widgets/TokenWidget/widget/index.d.ts +57 -0
- package/_types/src/components/widgets/TokenWidget/widget/index.d.ts.map +1 -0
- package/_types/src/hooks/index.d.ts +2 -1
- package/_types/src/hooks/index.d.ts.map +1 -1
- package/_types/src/hooks/useDuneBalances.d.ts.map +1 -1
- package/_types/src/hooks/useEOADetection.d.ts.map +1 -1
- package/_types/src/hooks/useMultiWalletBalances.d.ts +26 -0
- package/_types/src/hooks/useMultiWalletBalances.d.ts.map +1 -0
- package/_types/src/index.d.ts +1 -0
- package/_types/src/index.d.ts.map +1 -1
- package/_types/src/utils/numbers.d.ts +8 -1
- package/_types/src/utils/numbers.d.ts.map +1 -1
- package/_types/src/utils/tokenSelector.d.ts +1 -1
- package/_types/src/utils/tokenSelector.d.ts.map +1 -1
- package/_types/src/utils/tokens.d.ts +17 -0
- package/_types/src/utils/tokens.d.ts.map +1 -1
- package/_types/src/version.d.ts +1 -1
- package/_types/tsconfig.build.tsbuildinfo +1 -1
- package/dist/panda.buildinfo.json +74 -33
- package/dist/styles.css +251 -88
- package/package.json +8 -3
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const index_js_1 = require("../../../../hooks/index.js");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const wagmi_1 = require("wagmi");
|
|
8
|
+
const experimental_1 = require("wagmi/experimental");
|
|
9
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
10
|
+
const quote_js_1 = require("../../../../utils/quote.js");
|
|
11
|
+
const relay_kit_hooks_1 = require("@relayprotocol/relay-kit-hooks");
|
|
12
|
+
const events_js_1 = require("../../../../constants/events.js");
|
|
13
|
+
const RelayKitProvider_js_1 = require("../../../../providers/RelayKitProvider.js");
|
|
14
|
+
const address_js_1 = require("../../../../utils/address.js");
|
|
15
|
+
const relay_sdk_1 = require("@relayprotocol/relay-sdk");
|
|
16
|
+
const errors_js_1 = require("../../../../utils/errors.js");
|
|
17
|
+
const useSwapButtonCta_js_1 = require("../../../../hooks/widget/useSwapButtonCta.js");
|
|
18
|
+
const hashing_js_1 = require("../../../../utils/hashing.js");
|
|
19
|
+
const time_js_1 = require("../../../../utils/time.js");
|
|
20
|
+
const tokenPriceQueryOptions = {
|
|
21
|
+
staleTime: 60 * 1000,
|
|
22
|
+
refetchInterval: 30 * 1000,
|
|
23
|
+
refetchOnWindowFocus: false
|
|
24
|
+
};
|
|
25
|
+
const TokenWidgetRenderer = ({ transactionModalOpen, setTransactionModalOpen, depositAddressModalOpen, fromToken: _fromToken, setFromToken: _setFromToken, toToken: _toToken, setToToken: _setToToken, defaultToAddress, defaultAmount, defaultTradeType, slippageTolerance, context, wallet, multiWalletSupportEnabled = false, linkedWallets, supportedWalletVMs, useSecureBaseUrl, children, onAnalyticEvent, onSwapError }) => {
|
|
26
|
+
const [fromToken, setFromToken] = (0, index_js_1.useFallbackState)(_setFromToken ? _fromToken : undefined, _setFromToken
|
|
27
|
+
? [
|
|
28
|
+
_fromToken,
|
|
29
|
+
_setFromToken
|
|
30
|
+
]
|
|
31
|
+
: undefined);
|
|
32
|
+
const [toToken, setToToken] = (0, index_js_1.useFallbackState)(_setToToken ? _toToken : undefined, _setToToken
|
|
33
|
+
? [_toToken, _setToToken]
|
|
34
|
+
: undefined);
|
|
35
|
+
const providerOptionsContext = (0, react_1.useContext)(RelayKitProvider_js_1.ProviderOptionsContext);
|
|
36
|
+
const connectorKeyOverrides = providerOptionsContext.vmConnectorKeyOverrides;
|
|
37
|
+
const relayClient = (0, index_js_1.useRelayClient)();
|
|
38
|
+
const { connector } = (0, wagmi_1.useAccount)();
|
|
39
|
+
const walletClient = (0, wagmi_1.useWalletClient)();
|
|
40
|
+
const [customToAddress, setCustomToAddress] = (0, react_1.useState)(defaultToAddress);
|
|
41
|
+
const [destinationAddressOverride, setDestinationAddressOverride] = (0, react_1.useState)(undefined);
|
|
42
|
+
const [originAddressOverride, setOriginAddressOverride] = (0, react_1.useState)(undefined);
|
|
43
|
+
const [allowUnsupportedOrigin, setAllowUnsupportedOrigin] = (0, react_1.useState)(false);
|
|
44
|
+
const [allowUnsupportedRecipient, setAllowUnsupportedRecipient] = (0, react_1.useState)(false);
|
|
45
|
+
const [useExternalLiquidity, setUseExternalLiquidity] = (0, react_1.useState)(false);
|
|
46
|
+
const defaultAddress = (0, index_js_1.useWalletAddress)(wallet, linkedWallets);
|
|
47
|
+
const [tradeType, setTradeType] = (0, react_1.useState)(defaultTradeType ?? 'EXACT_INPUT');
|
|
48
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
49
|
+
const [steps, setSteps] = (0, react_1.useState)(null);
|
|
50
|
+
const [quoteInProgress, setQuoteInProgress] = (0, react_1.useState)(null);
|
|
51
|
+
const [waitingForSteps, setWaitingForSteps] = (0, react_1.useState)(false);
|
|
52
|
+
const [details, setDetails] = (0, react_1.useState)(null);
|
|
53
|
+
const [abortController, setAbortController] = (0, react_1.useState)(null);
|
|
54
|
+
const { value: amountInputValue, debouncedValue: debouncedInputAmountValue, setValue: setAmountInputValue, debouncedControls: debouncedAmountInputControls } = (0, index_js_1.useDebounceState)(!defaultTradeType || defaultTradeType === 'EXACT_INPUT'
|
|
55
|
+
? (defaultAmount ?? '')
|
|
56
|
+
: '', 500);
|
|
57
|
+
const { value: amountOutputValue, debouncedValue: debouncedOutputAmountValue, setValue: setAmountOutputValue, debouncedControls: debouncedAmountOutputControls } = (0, index_js_1.useDebounceState)(defaultTradeType === 'EXPECTED_OUTPUT' ? (defaultAmount ?? '') : '', 500);
|
|
58
|
+
const [swapError, setSwapError] = (0, react_1.useState)(null);
|
|
59
|
+
const tokenPairIsCanonical = fromToken?.chainId !== undefined &&
|
|
60
|
+
toToken?.chainId !== undefined &&
|
|
61
|
+
fromToken.symbol === toToken.symbol;
|
|
62
|
+
const toChain = (0, react_1.useMemo)(() => relayClient?.chains?.find((chain) => chain.id === toToken?.chainId), [relayClient?.chains, toToken?.chainId]);
|
|
63
|
+
const fromChain = (0, react_1.useMemo)(() => relayClient?.chains?.find((chain) => chain.id === fromToken?.chainId), [relayClient?.chains, fromToken?.chainId]);
|
|
64
|
+
const fromChainWalletVMSupported = (0, react_1.useMemo)(() => !fromChain?.vmType ||
|
|
65
|
+
supportedWalletVMs.includes(fromChain?.vmType) ||
|
|
66
|
+
fromChain?.id === 1337, [fromChain?.vmType, fromChain?.id, supportedWalletVMs]);
|
|
67
|
+
const toChainWalletVMSupported = (0, react_1.useMemo)(() => !toChain?.vmType || supportedWalletVMs.includes(toChain?.vmType), [toChain?.vmType, supportedWalletVMs]);
|
|
68
|
+
const address = (0, react_1.useMemo)(() => {
|
|
69
|
+
if (!multiWalletSupportEnabled || !linkedWallets?.length) {
|
|
70
|
+
return defaultAddress;
|
|
71
|
+
}
|
|
72
|
+
if (originAddressOverride) {
|
|
73
|
+
return originAddressOverride;
|
|
74
|
+
}
|
|
75
|
+
const targetChain = fromChain || toChain;
|
|
76
|
+
if (!targetChain) {
|
|
77
|
+
return defaultAddress;
|
|
78
|
+
}
|
|
79
|
+
const compatibleWallet = linkedWallets.find((wallet) => {
|
|
80
|
+
if (wallet.vmType !== targetChain.vmType) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return (0, address_js_1.isValidAddress)(targetChain.vmType, wallet.address, targetChain.id, wallet.connector, connectorKeyOverrides);
|
|
84
|
+
});
|
|
85
|
+
return compatibleWallet?.address || defaultAddress;
|
|
86
|
+
}, [
|
|
87
|
+
multiWalletSupportEnabled,
|
|
88
|
+
originAddressOverride,
|
|
89
|
+
fromChain,
|
|
90
|
+
toChain,
|
|
91
|
+
linkedWallets,
|
|
92
|
+
defaultAddress,
|
|
93
|
+
connectorKeyOverrides
|
|
94
|
+
]);
|
|
95
|
+
const defaultRecipient = (0, react_1.useMemo)(() => {
|
|
96
|
+
const _linkedWallet = linkedWallets?.find((linkedWallet) => address ===
|
|
97
|
+
(linkedWallet.vmType === 'evm'
|
|
98
|
+
? linkedWallet.address.toLowerCase()
|
|
99
|
+
: linkedWallet.address));
|
|
100
|
+
const _isValidToAddress = (0, address_js_1.isValidAddress)(toChain?.vmType, customToAddress ?? '', toChain?.id, !customToAddress && _linkedWallet?.address === address
|
|
101
|
+
? _linkedWallet?.connector
|
|
102
|
+
: undefined, connectorKeyOverrides);
|
|
103
|
+
if (multiWalletSupportEnabled &&
|
|
104
|
+
toChain &&
|
|
105
|
+
linkedWallets &&
|
|
106
|
+
!_isValidToAddress) {
|
|
107
|
+
const supportedWallet = linkedWallets.find((wallet) => wallet.address !== address &&
|
|
108
|
+
(0, address_js_1.isValidAddress)(toChain.vmType, wallet.address, toChain.id, wallet.connector, connectorKeyOverrides));
|
|
109
|
+
return supportedWallet?.address;
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}, [
|
|
113
|
+
multiWalletSupportEnabled,
|
|
114
|
+
toChain,
|
|
115
|
+
customToAddress,
|
|
116
|
+
address,
|
|
117
|
+
linkedWallets,
|
|
118
|
+
setCustomToAddress,
|
|
119
|
+
connectorKeyOverrides
|
|
120
|
+
]);
|
|
121
|
+
const recipient = destinationAddressOverride ??
|
|
122
|
+
customToAddress ??
|
|
123
|
+
defaultRecipient ??
|
|
124
|
+
(!allowUnsupportedRecipient && address ? address : undefined);
|
|
125
|
+
const { value: fromBalance, queryKey: fromBalanceQueryKey, isLoading: isLoadingFromBalance, isError: fromBalanceErrorFetching, isDuneBalance: fromBalanceIsDune, hasPendingBalance: fromBalancePending } = (0, index_js_1.useCurrencyBalance)({
|
|
126
|
+
chain: fromChain,
|
|
127
|
+
address: address,
|
|
128
|
+
currency: fromToken?.address ? fromToken.address : undefined,
|
|
129
|
+
enabled: fromToken !== undefined,
|
|
130
|
+
refreshInterval: undefined,
|
|
131
|
+
wallet
|
|
132
|
+
});
|
|
133
|
+
const { value: toBalance, queryKey: toBalanceQueryKey, isLoading: isLoadingToBalance, isDuneBalance: toBalanceIsDune, hasPendingBalance: toBalancePending } = (0, index_js_1.useCurrencyBalance)({
|
|
134
|
+
chain: toChain,
|
|
135
|
+
address: recipient,
|
|
136
|
+
currency: toToken?.address ? toToken.address : undefined,
|
|
137
|
+
enabled: toToken !== undefined && recipient !== undefined && recipient !== '',
|
|
138
|
+
refreshInterval: undefined,
|
|
139
|
+
wallet
|
|
140
|
+
});
|
|
141
|
+
const invalidateBalanceQueries = (0, react_1.useCallback)(() => {
|
|
142
|
+
const invalidatePeriodically = (invalidateFn) => {
|
|
143
|
+
let maxRefreshes = 4;
|
|
144
|
+
let refreshCount = 0;
|
|
145
|
+
const timer = setInterval(() => {
|
|
146
|
+
if (maxRefreshes === refreshCount) {
|
|
147
|
+
clearInterval(timer);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
refreshCount++;
|
|
151
|
+
invalidateFn();
|
|
152
|
+
}, 3000);
|
|
153
|
+
};
|
|
154
|
+
queryClient.invalidateQueries({ queryKey: ['useDuneBalances'] });
|
|
155
|
+
if (fromBalanceIsDune) {
|
|
156
|
+
invalidatePeriodically(() => {
|
|
157
|
+
queryClient.invalidateQueries({ queryKey: fromBalanceQueryKey });
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
queryClient.invalidateQueries({ queryKey: fromBalanceQueryKey });
|
|
162
|
+
}
|
|
163
|
+
if (toBalanceIsDune) {
|
|
164
|
+
invalidatePeriodically(() => {
|
|
165
|
+
queryClient.invalidateQueries({ queryKey: toBalanceQueryKey });
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
queryClient.invalidateQueries({ queryKey: toBalanceQueryKey });
|
|
170
|
+
}
|
|
171
|
+
}, [
|
|
172
|
+
queryClient,
|
|
173
|
+
fromBalanceQueryKey,
|
|
174
|
+
toBalanceQueryKey,
|
|
175
|
+
toBalanceIsDune,
|
|
176
|
+
fromBalanceIsDune,
|
|
177
|
+
address
|
|
178
|
+
]);
|
|
179
|
+
const { data: capabilities } = (0, experimental_1.useCapabilities)({
|
|
180
|
+
query: {
|
|
181
|
+
enabled: connector &&
|
|
182
|
+
(connector.id === 'coinbaseWalletSDK' || connector.id === 'coinbase')
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const hasAuxiliaryFundsSupport = Boolean(fromToken?.chainId
|
|
186
|
+
? capabilities?.[fromToken?.chainId]?.auxiliaryFunds?.supported
|
|
187
|
+
: false);
|
|
188
|
+
const isSvmSwap = fromChain?.vmType === 'svm' || toChain?.vmType === 'svm';
|
|
189
|
+
const isBvmSwap = fromChain?.vmType === 'bvm' || toChain?.vmType === 'bvm';
|
|
190
|
+
const linkedWallet = linkedWallets?.find((linkedWallet) => address ===
|
|
191
|
+
(linkedWallet.vmType === 'evm'
|
|
192
|
+
? linkedWallet.address.toLowerCase()
|
|
193
|
+
: linkedWallet.address) || linkedWallet.address === address);
|
|
194
|
+
const isRecipientLinked = (recipient
|
|
195
|
+
? linkedWallets?.find((wallet) => wallet.address === recipient)
|
|
196
|
+
: undefined) !== undefined;
|
|
197
|
+
const isValidFromAddress = (0, react_1.useMemo)(() => (0, address_js_1.isValidAddress)(fromChain?.vmType, address ?? '', fromChain?.id, linkedWallet?.connector, connectorKeyOverrides), [
|
|
198
|
+
fromChain?.vmType,
|
|
199
|
+
address,
|
|
200
|
+
fromChain?.id,
|
|
201
|
+
linkedWallet?.connector,
|
|
202
|
+
connectorKeyOverrides
|
|
203
|
+
]);
|
|
204
|
+
const fromAddressWithFallback = (0, address_js_1.addressWithFallback)(fromChain?.vmType, address, fromChain?.id, linkedWallet?.connector, connectorKeyOverrides);
|
|
205
|
+
const isValidToAddress = (0, react_1.useMemo)(() => (0, address_js_1.isValidAddress)(toChain?.vmType, recipient ?? '', toChain?.id), [toChain?.vmType, recipient, toChain?.id]);
|
|
206
|
+
const toAddressWithFallback = (0, address_js_1.addressWithFallback)(toChain?.vmType, recipient, toChain?.id);
|
|
207
|
+
const externalLiquiditySupport = (0, relay_kit_hooks_1.useQuote)(relayClient ? relayClient : undefined, wallet, fromToken && toToken
|
|
208
|
+
? {
|
|
209
|
+
user: (0, relay_sdk_1.getDeadAddress)(fromChain?.vmType, fromChain?.id),
|
|
210
|
+
originChainId: fromToken.chainId,
|
|
211
|
+
destinationChainId: toToken.chainId,
|
|
212
|
+
originCurrency: fromToken.address,
|
|
213
|
+
destinationCurrency: toToken.address,
|
|
214
|
+
recipient: (0, relay_sdk_1.getDeadAddress)(toChain?.vmType, toChain?.id),
|
|
215
|
+
tradeType,
|
|
216
|
+
appFees: providerOptionsContext.appFees,
|
|
217
|
+
amount: '10000000000000000000000',
|
|
218
|
+
referrer: relayClient?.source ?? undefined,
|
|
219
|
+
useExternalLiquidity: true
|
|
220
|
+
}
|
|
221
|
+
: undefined, undefined, undefined, {
|
|
222
|
+
refetchOnWindowFocus: false,
|
|
223
|
+
enabled: fromToken !== undefined &&
|
|
224
|
+
toToken !== undefined &&
|
|
225
|
+
fromChain &&
|
|
226
|
+
toChain &&
|
|
227
|
+
(fromChain.id === toChain.baseChainId ||
|
|
228
|
+
toChain.id === fromChain.baseChainId)
|
|
229
|
+
});
|
|
230
|
+
const supportsExternalLiquidity = tokenPairIsCanonical &&
|
|
231
|
+
externalLiquiditySupport.status === 'success' &&
|
|
232
|
+
fromChainWalletVMSupported
|
|
233
|
+
? true
|
|
234
|
+
: false;
|
|
235
|
+
const { displayName: toDisplayName } = (0, index_js_1.useENSResolver)(recipient, {
|
|
236
|
+
enabled: toChain?.vmType === 'evm' && isValidToAddress
|
|
237
|
+
});
|
|
238
|
+
const [currentSlippageTolerance, setCurrentSlippageTolerance] = (0, react_1.useState)(slippageTolerance);
|
|
239
|
+
(0, react_1.useEffect)(() => {
|
|
240
|
+
setCurrentSlippageTolerance(slippageTolerance);
|
|
241
|
+
}, [slippageTolerance]);
|
|
242
|
+
const { data: fromTokenPriceData, isLoading: isLoadingFromTokenPrice } = (0, relay_kit_hooks_1.useTokenPrice)(relayClient?.baseApiUrl, {
|
|
243
|
+
address: fromToken?.address ?? '',
|
|
244
|
+
chainId: fromToken?.chainId ?? 0,
|
|
245
|
+
referrer: relayClient?.source
|
|
246
|
+
}, {
|
|
247
|
+
enabled: !!(fromToken?.address && fromToken.chainId),
|
|
248
|
+
...tokenPriceQueryOptions
|
|
249
|
+
});
|
|
250
|
+
const { data: toTokenPriceData, isLoading: isLoadingToTokenPrice } = (0, relay_kit_hooks_1.useTokenPrice)(relayClient?.baseApiUrl, {
|
|
251
|
+
address: toToken?.address ?? '',
|
|
252
|
+
chainId: toToken?.chainId ?? 0,
|
|
253
|
+
referrer: relayClient?.source
|
|
254
|
+
}, {
|
|
255
|
+
enabled: !!(toToken?.address && toToken.chainId),
|
|
256
|
+
...tokenPriceQueryOptions
|
|
257
|
+
});
|
|
258
|
+
const originChainSupportsProtocolv2 = fromChain?.protocol?.v2?.depository !== undefined &&
|
|
259
|
+
toChain?.protocol?.v2?.chainId !== undefined;
|
|
260
|
+
const quoteProtocol = fromChain?.id && originChainSupportsProtocolv2 ? 'preferV2' : undefined;
|
|
261
|
+
const isFromNative = fromToken?.address === fromChain?.currency?.address;
|
|
262
|
+
const explicitDeposit = (0, index_js_1.useEOADetection)(wallet, quoteProtocol, fromToken?.chainId, fromChain?.vmType, fromChain, address, fromBalance, isFromNative);
|
|
263
|
+
const shouldSetQuoteParameters = fromToken &&
|
|
264
|
+
toToken &&
|
|
265
|
+
(quoteProtocol !== 'preferV2' ||
|
|
266
|
+
fromChain?.vmType !== 'evm' ||
|
|
267
|
+
explicitDeposit !== undefined);
|
|
268
|
+
const quoteParameters = shouldSetQuoteParameters
|
|
269
|
+
? {
|
|
270
|
+
user: fromAddressWithFallback,
|
|
271
|
+
originChainId: fromToken.chainId,
|
|
272
|
+
destinationChainId: toToken.chainId,
|
|
273
|
+
originCurrency: fromToken.address,
|
|
274
|
+
destinationCurrency: toToken.address,
|
|
275
|
+
recipient: toAddressWithFallback,
|
|
276
|
+
tradeType,
|
|
277
|
+
appFees: providerOptionsContext.appFees,
|
|
278
|
+
amount: tradeType === 'EXACT_INPUT'
|
|
279
|
+
? (0, viem_1.parseUnits)(debouncedInputAmountValue, fromToken.decimals).toString()
|
|
280
|
+
: (0, viem_1.parseUnits)(debouncedOutputAmountValue, toToken.decimals).toString(),
|
|
281
|
+
referrer: relayClient?.source ?? undefined,
|
|
282
|
+
useExternalLiquidity,
|
|
283
|
+
useDepositAddress: !fromChainWalletVMSupported || fromToken?.chainId === 1337,
|
|
284
|
+
refundTo: fromToken?.chainId === 1337 ? address : undefined,
|
|
285
|
+
slippageTolerance: slippageTolerance,
|
|
286
|
+
...(linkedWallet?.vmType === 'bvm' && wallet?.metadata?.publicKey
|
|
287
|
+
? {
|
|
288
|
+
additionalData: {
|
|
289
|
+
userPublicKey: wallet?.metadata?.publicKey
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
: {}),
|
|
293
|
+
protocolVersion: quoteProtocol,
|
|
294
|
+
...(quoteProtocol === 'preferV2' &&
|
|
295
|
+
explicitDeposit !== undefined && {
|
|
296
|
+
explicitDeposit: explicitDeposit
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
: undefined;
|
|
300
|
+
const onQuoteRequested = (options, config) => {
|
|
301
|
+
const interval = (0, time_js_1.get15MinuteInterval)();
|
|
302
|
+
const quoteRequestId = (0, hashing_js_1.sha256)({ ...options, interval });
|
|
303
|
+
onAnalyticEvent?.(events_js_1.EventNames.QUOTE_REQUESTED, {
|
|
304
|
+
parameters: options,
|
|
305
|
+
wallet_connector: linkedWallet?.connector,
|
|
306
|
+
chain_id_in: options?.originChainId,
|
|
307
|
+
chain_id_out: options?.destinationChainId,
|
|
308
|
+
http_config: config,
|
|
309
|
+
quote_request_id: quoteRequestId
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
const onQuoteReceived = ({ details, steps }, options) => {
|
|
313
|
+
const interval = (0, time_js_1.get15MinuteInterval)();
|
|
314
|
+
const quoteRequestId = (0, hashing_js_1.sha256)({ ...options, interval });
|
|
315
|
+
onAnalyticEvent?.(events_js_1.EventNames.QUOTE_RECEIVED, {
|
|
316
|
+
parameters: options,
|
|
317
|
+
wallet_connector: linkedWallet?.connector,
|
|
318
|
+
amount_in: details?.currencyIn?.amountFormatted,
|
|
319
|
+
amount_in_raw: details?.currencyIn?.amount,
|
|
320
|
+
currency_in: details?.currencyIn?.currency?.symbol,
|
|
321
|
+
chain_id_in: details?.currencyIn?.currency?.chainId,
|
|
322
|
+
amount_out: details?.currencyOut?.amountFormatted,
|
|
323
|
+
amount_out_raw: details?.currencyOut?.amount,
|
|
324
|
+
currency_out: details?.currencyOut?.currency?.symbol,
|
|
325
|
+
chain_id_out: details?.currencyOut?.currency?.chainId,
|
|
326
|
+
slippage_tolerance_destination_percentage: details?.slippageTolerance?.destination?.percent,
|
|
327
|
+
slippage_tolerance_origin_percentage: details?.slippageTolerance?.origin?.percent,
|
|
328
|
+
steps,
|
|
329
|
+
quote_request_id: quoteRequestId,
|
|
330
|
+
quote_id: steps ? (0, quote_js_1.extractQuoteId)(steps) : undefined
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
const quoteFetchingEnabled = Boolean(relayClient &&
|
|
334
|
+
((tradeType === 'EXACT_INPUT' &&
|
|
335
|
+
debouncedInputAmountValue &&
|
|
336
|
+
debouncedInputAmountValue.length > 0 &&
|
|
337
|
+
Number(debouncedInputAmountValue) !== 0) ||
|
|
338
|
+
(tradeType === 'EXPECTED_OUTPUT' &&
|
|
339
|
+
debouncedOutputAmountValue &&
|
|
340
|
+
debouncedOutputAmountValue.length > 0 &&
|
|
341
|
+
Number(debouncedOutputAmountValue) !== 0)) &&
|
|
342
|
+
fromToken !== undefined &&
|
|
343
|
+
toToken !== undefined &&
|
|
344
|
+
!transactionModalOpen &&
|
|
345
|
+
!depositAddressModalOpen);
|
|
346
|
+
const quoteRefetchInterval = !transactionModalOpen &&
|
|
347
|
+
!depositAddressModalOpen &&
|
|
348
|
+
debouncedInputAmountValue === amountInputValue &&
|
|
349
|
+
debouncedOutputAmountValue === amountOutputValue
|
|
350
|
+
? 12000
|
|
351
|
+
: undefined;
|
|
352
|
+
const handleQuoteError = (e) => {
|
|
353
|
+
const errorMessage = (0, errors_js_1.errorToJSON)(e?.response?.data?.message ? new Error(e?.response?.data?.message) : e);
|
|
354
|
+
const interval = (0, time_js_1.get15MinuteInterval)();
|
|
355
|
+
const quoteRequestId = (0, hashing_js_1.sha256)({ ...quoteParameters, interval });
|
|
356
|
+
onAnalyticEvent?.(events_js_1.EventNames.QUOTE_ERROR, {
|
|
357
|
+
wallet_connector: linkedWallet?.connector,
|
|
358
|
+
error_message: errorMessage,
|
|
359
|
+
parameters: quoteParameters,
|
|
360
|
+
quote_request_id: quoteRequestId,
|
|
361
|
+
status_code: e.response.status ?? e.status ?? ''
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
const { data: quote, error: quoteError, isFetching: isFetchingQuote, executeQuote: executeSwap, queryKey: quoteQueryKey } = (0, relay_kit_hooks_1.useQuote)(relayClient ? relayClient : undefined, wallet, quoteParameters, onQuoteRequested, onQuoteReceived, {
|
|
365
|
+
refetchOnWindowFocus: false,
|
|
366
|
+
enabled: Boolean(quoteFetchingEnabled && quoteParameters !== undefined),
|
|
367
|
+
refetchInterval: quoteRefetchInterval
|
|
368
|
+
}, handleQuoteError, undefined, useSecureBaseUrl?.(quoteParameters)
|
|
369
|
+
? providerOptionsContext?.secureBaseUrl
|
|
370
|
+
: undefined);
|
|
371
|
+
const invalidateQuoteQuery = (0, react_1.useCallback)(() => {
|
|
372
|
+
queryClient.invalidateQueries({ queryKey: quoteQueryKey });
|
|
373
|
+
}, [queryClient, quoteQueryKey]);
|
|
374
|
+
const derivedError = quote ||
|
|
375
|
+
(isFetchingQuote &&
|
|
376
|
+
Boolean(quoteFetchingEnabled && quoteParameters !== undefined))
|
|
377
|
+
? null
|
|
378
|
+
: quoteError;
|
|
379
|
+
const error = derivedError;
|
|
380
|
+
(0, index_js_1.useDisconnected)(address, () => {
|
|
381
|
+
setCustomToAddress(undefined);
|
|
382
|
+
setOriginAddressOverride(undefined);
|
|
383
|
+
setDestinationAddressOverride(undefined);
|
|
384
|
+
});
|
|
385
|
+
(0, react_1.useEffect)(() => {
|
|
386
|
+
if (tradeType === 'EXACT_INPUT') {
|
|
387
|
+
const amountOut = quote?.details?.currencyOut?.amount ?? '';
|
|
388
|
+
setAmountOutputValue(amountOut !== ''
|
|
389
|
+
? (0, viem_1.formatUnits)(BigInt(amountOut), Number(quote?.details?.currencyOut?.currency?.decimals ?? 18))
|
|
390
|
+
: '');
|
|
391
|
+
}
|
|
392
|
+
else if (tradeType === 'EXPECTED_OUTPUT') {
|
|
393
|
+
const amountIn = quote?.details?.currencyIn?.amount ?? '';
|
|
394
|
+
setAmountInputValue(amountIn !== ''
|
|
395
|
+
? (0, viem_1.formatUnits)(BigInt(amountIn), Number(quote?.details?.currencyIn?.currency?.decimals ?? 18))
|
|
396
|
+
: '');
|
|
397
|
+
}
|
|
398
|
+
debouncedAmountInputControls.flush();
|
|
399
|
+
debouncedAmountOutputControls.flush();
|
|
400
|
+
}, [quote, tradeType]);
|
|
401
|
+
(0, react_1.useEffect)(() => {
|
|
402
|
+
if (useExternalLiquidity &&
|
|
403
|
+
!externalLiquiditySupport.isFetching &&
|
|
404
|
+
!supportsExternalLiquidity) {
|
|
405
|
+
setUseExternalLiquidity(false);
|
|
406
|
+
}
|
|
407
|
+
}, [
|
|
408
|
+
supportsExternalLiquidity,
|
|
409
|
+
useExternalLiquidity,
|
|
410
|
+
externalLiquiditySupport.isFetching
|
|
411
|
+
]);
|
|
412
|
+
const feeBreakdown = (0, react_1.useMemo)(() => {
|
|
413
|
+
const chains = relayClient?.chains;
|
|
414
|
+
const fromChain = chains?.find((chain) => chain.id === fromToken?.chainId);
|
|
415
|
+
const toChain = chains?.find((chain) => chain.id === toToken?.chainId);
|
|
416
|
+
return fromToken && toToken && fromChain && toChain && quote
|
|
417
|
+
? (0, quote_js_1.parseFees)(toChain, fromChain, quote)
|
|
418
|
+
: null;
|
|
419
|
+
}, [quote, fromToken, toToken, relayClient]);
|
|
420
|
+
const totalAmount = BigInt(quote?.details?.currencyIn?.amount ?? 0n);
|
|
421
|
+
const hasInsufficientBalance = Boolean(!fromBalanceErrorFetching &&
|
|
422
|
+
totalAmount &&
|
|
423
|
+
address &&
|
|
424
|
+
(fromBalance ?? 0n) < totalAmount &&
|
|
425
|
+
!hasAuxiliaryFundsSupport &&
|
|
426
|
+
fromChainWalletVMSupported);
|
|
427
|
+
const fetchQuoteErrorMessage = error
|
|
428
|
+
? error?.message
|
|
429
|
+
? error?.message
|
|
430
|
+
: 'Unknown Error'
|
|
431
|
+
: null;
|
|
432
|
+
const fetchQuoteDataErrorMessage = error
|
|
433
|
+
? error?.response?.data?.message
|
|
434
|
+
? error?.response?.data.message
|
|
435
|
+
: 'Unknown Error'
|
|
436
|
+
: null;
|
|
437
|
+
const isInsufficientLiquidityError = Boolean(fetchQuoteErrorMessage?.includes('No quotes available'));
|
|
438
|
+
const isCapacityExceededError = fetchQuoteDataErrorMessage?.includes('Amount is higher than the available liquidity') || fetchQuoteDataErrorMessage?.includes('Insufficient relayer liquidity');
|
|
439
|
+
const isCouldNotExecuteError = fetchQuoteDataErrorMessage?.includes('Could not execute');
|
|
440
|
+
const highRelayerServiceFee = (0, quote_js_1.isHighRelayerServiceFeeUsd)(quote);
|
|
441
|
+
const relayerFeeProportion = (0, quote_js_1.calculateRelayerFeeProportionUsd)(quote);
|
|
442
|
+
const timeEstimate = (0, quote_js_1.calculatePriceTimeEstimate)(quote?.details);
|
|
443
|
+
const canonicalTimeEstimate = (0, quote_js_1.calculatePriceTimeEstimate)(externalLiquiditySupport.data?.details);
|
|
444
|
+
const recipientWalletSupportsChain = (0, index_js_1.useIsWalletCompatible)(toChain?.id, recipient, linkedWallets, onAnalyticEvent);
|
|
445
|
+
const isSameCurrencySameRecipientSwap = fromToken?.address === toToken?.address &&
|
|
446
|
+
fromToken?.chainId === toToken?.chainId &&
|
|
447
|
+
address === recipient;
|
|
448
|
+
const ctaCopy = (0, useSwapButtonCta_js_1.useSwapButtonCta)({
|
|
449
|
+
fromToken,
|
|
450
|
+
toToken,
|
|
451
|
+
multiWalletSupportEnabled,
|
|
452
|
+
isValidFromAddress,
|
|
453
|
+
fromChainWalletVMSupported,
|
|
454
|
+
isValidToAddress,
|
|
455
|
+
toChainWalletVMSupported,
|
|
456
|
+
fromChain,
|
|
457
|
+
toChain,
|
|
458
|
+
isSameCurrencySameRecipientSwap,
|
|
459
|
+
debouncedInputAmountValue,
|
|
460
|
+
debouncedOutputAmountValue,
|
|
461
|
+
hasInsufficientBalance,
|
|
462
|
+
isInsufficientLiquidityError,
|
|
463
|
+
quote,
|
|
464
|
+
operation: quote?.details?.operation
|
|
465
|
+
});
|
|
466
|
+
(0, index_js_1.usePreviousValueChange)(isCapacityExceededError && supportsExternalLiquidity, !isFetchingQuote && !externalLiquiditySupport.isFetching, (capacityExceeded) => {
|
|
467
|
+
if (capacityExceeded) {
|
|
468
|
+
onAnalyticEvent?.(events_js_1.EventNames.CTA_MAX_CAPACITY_PROMPTED, {
|
|
469
|
+
inputAmount: debouncedInputAmountValue,
|
|
470
|
+
outputAmount: debouncedOutputAmountValue
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
const swap = (0, react_1.useCallback)(async () => {
|
|
475
|
+
let submittedEvents = [];
|
|
476
|
+
const swapErrorHandler = (error, currentSteps) => {
|
|
477
|
+
const errorMessage = (0, errors_js_1.errorToJSON)(error?.response?.data?.message
|
|
478
|
+
? new Error(error?.response?.data?.message)
|
|
479
|
+
: error);
|
|
480
|
+
if (error &&
|
|
481
|
+
((typeof error.message === 'string' &&
|
|
482
|
+
error.message.includes('rejected')) ||
|
|
483
|
+
(typeof error === 'string' && error.includes('rejected')) ||
|
|
484
|
+
(typeof error === 'string' && error.includes('Approval Denied')) ||
|
|
485
|
+
(typeof error === 'string' && error.includes('denied transaction')) ||
|
|
486
|
+
(typeof error.message === 'string' &&
|
|
487
|
+
error.message.includes('Approval Denied')) ||
|
|
488
|
+
(typeof error.message === 'string' &&
|
|
489
|
+
error.message.includes('Plugin Closed')) ||
|
|
490
|
+
(typeof error.message === 'string' &&
|
|
491
|
+
error.message.includes('denied transaction')) ||
|
|
492
|
+
(typeof error.message === 'string' &&
|
|
493
|
+
error.message.includes('Failed to initialize request') &&
|
|
494
|
+
fromChain?.id === 2741))) {
|
|
495
|
+
setTransactionModalOpen(false);
|
|
496
|
+
onAnalyticEvent?.(events_js_1.EventNames.USER_REJECTED_WALLET, {
|
|
497
|
+
error_message: errorMessage
|
|
498
|
+
});
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
const { step, stepItem } = (0, quote_js_1.getCurrentStep)(currentSteps);
|
|
502
|
+
const swapEventData = {
|
|
503
|
+
...(0, quote_js_1.getSwapEventData)(quote?.details, quote?.fees, currentSteps ?? null, linkedWallet?.connector, quoteParameters),
|
|
504
|
+
error_message: errorMessage
|
|
505
|
+
};
|
|
506
|
+
const isApproval = step?.id === 'approve';
|
|
507
|
+
const errorEvent = isApproval
|
|
508
|
+
? events_js_1.EventNames.APPROVAL_ERROR
|
|
509
|
+
: events_js_1.EventNames.DEPOSIT_ERROR;
|
|
510
|
+
const isTransactionConfirmationError = (error &&
|
|
511
|
+
typeof error.message === 'string' &&
|
|
512
|
+
error.message.includes('TransactionConfirmationError')) ||
|
|
513
|
+
(error.name && error.name.includes('TransactionConfirmationError'));
|
|
514
|
+
if (stepItem?.receipt &&
|
|
515
|
+
stepItem.check &&
|
|
516
|
+
!isTransactionConfirmationError &&
|
|
517
|
+
(typeof stepItem.receipt === 'object' && 'status' in stepItem.receipt
|
|
518
|
+
? stepItem.receipt.status !== 'reverted'
|
|
519
|
+
: true) &&
|
|
520
|
+
(!stepItem.checkStatus || stepItem.checkStatus !== 'unknown')) {
|
|
521
|
+
const successEvent = isApproval
|
|
522
|
+
? events_js_1.EventNames.APPROVAL_SUCCESS
|
|
523
|
+
: events_js_1.EventNames.DEPOSIT_SUCCESS;
|
|
524
|
+
if (!submittedEvents.includes(successEvent)) {
|
|
525
|
+
onAnalyticEvent?.(successEvent, swapEventData);
|
|
526
|
+
submittedEvents.push(successEvent);
|
|
527
|
+
setTimeout(() => {
|
|
528
|
+
onAnalyticEvent?.(events_js_1.EventNames.FILL_ERROR, swapEventData);
|
|
529
|
+
}, 20);
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
onAnalyticEvent?.(events_js_1.EventNames.FILL_ERROR, swapEventData);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else if (!stepItem?.receipt ||
|
|
536
|
+
(typeof stepItem.receipt === 'object' &&
|
|
537
|
+
'status' in stepItem.receipt &&
|
|
538
|
+
stepItem.receipt.status === 'reverted')) {
|
|
539
|
+
onAnalyticEvent?.(errorEvent, swapEventData);
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
onAnalyticEvent?.(events_js_1.EventNames.SWAP_ERROR, swapEventData);
|
|
543
|
+
}
|
|
544
|
+
setSwapError(errorMessage);
|
|
545
|
+
onSwapError?.(errorMessage, { ...quote, steps: currentSteps });
|
|
546
|
+
};
|
|
547
|
+
try {
|
|
548
|
+
const swapEventData = (0, quote_js_1.getSwapEventData)(quote?.details, quote?.fees, quote?.steps ? quote?.steps : null, linkedWallet?.connector, quoteParameters);
|
|
549
|
+
onAnalyticEvent?.(events_js_1.EventNames.SWAP_CTA_CLICKED, swapEventData);
|
|
550
|
+
setWaitingForSteps(true);
|
|
551
|
+
if (!executeSwap) {
|
|
552
|
+
throw 'Missing a quote';
|
|
553
|
+
}
|
|
554
|
+
if (!wallet && !walletClient.data) {
|
|
555
|
+
throw 'Missing a wallet';
|
|
556
|
+
}
|
|
557
|
+
setSteps(quote?.steps);
|
|
558
|
+
setQuoteInProgress(quote);
|
|
559
|
+
setTransactionModalOpen(true);
|
|
560
|
+
const _wallet = wallet ?? (0, relay_sdk_1.adaptViemWallet)(walletClient.data);
|
|
561
|
+
const activeWalletChainId = await _wallet?.getChainId();
|
|
562
|
+
const activeWalletChain = relayClient?.chains?.find((chain) => chain.id === activeWalletChainId);
|
|
563
|
+
let targetChainId = fromToken?.chainId;
|
|
564
|
+
if (fromToken?.chainId === 1337) {
|
|
565
|
+
targetChainId =
|
|
566
|
+
activeWalletChain?.vmType !== 'evm' ? 1 : activeWalletChainId;
|
|
567
|
+
}
|
|
568
|
+
if (fromToken && targetChainId && targetChainId !== activeWalletChainId) {
|
|
569
|
+
onAnalyticEvent?.(events_js_1.EventNames.SWAP_SWITCH_NETWORK, {
|
|
570
|
+
activeWalletChainId,
|
|
571
|
+
...swapEventData
|
|
572
|
+
});
|
|
573
|
+
await _wallet?.switchChain(targetChainId);
|
|
574
|
+
}
|
|
575
|
+
let _currentSteps = undefined;
|
|
576
|
+
const execPromise = executeSwap(({ steps: currentSteps }) => {
|
|
577
|
+
setSteps(currentSteps);
|
|
578
|
+
_currentSteps = currentSteps;
|
|
579
|
+
const { step, stepItem } = (0, quote_js_1.getCurrentStep)(currentSteps);
|
|
580
|
+
const swapEventData = (0, quote_js_1.getSwapEventData)(quote?.details, quote?.fees, currentSteps, linkedWallet?.connector, quoteParameters);
|
|
581
|
+
if (step && stepItem) {
|
|
582
|
+
const isApproval = step.id === 'approve' || step.id === 'approval';
|
|
583
|
+
let submittedEvent = isApproval
|
|
584
|
+
? events_js_1.EventNames.APPROVAL_SUBMITTED
|
|
585
|
+
: events_js_1.EventNames.DEPOSIT_SUBMITTED;
|
|
586
|
+
const successEvent = isApproval
|
|
587
|
+
? events_js_1.EventNames.APPROVAL_SUCCESS
|
|
588
|
+
: events_js_1.EventNames.DEPOSIT_SUCCESS;
|
|
589
|
+
const isBatchTransaction = Boolean(Array.isArray(step.items) &&
|
|
590
|
+
step.items.length > 1 &&
|
|
591
|
+
wallet?.handleBatchTransactionStep);
|
|
592
|
+
if (!isApproval && isBatchTransaction) {
|
|
593
|
+
submittedEvent = events_js_1.EventNames.BATCH_TX_SUBMITTED;
|
|
594
|
+
}
|
|
595
|
+
if (!submittedEvents.includes(submittedEvent) &&
|
|
596
|
+
!stepItem.receipt &&
|
|
597
|
+
stepItem?.txHashes &&
|
|
598
|
+
stepItem?.txHashes?.length > 0) {
|
|
599
|
+
submittedEvents.push(submittedEvent);
|
|
600
|
+
onAnalyticEvent?.(submittedEvent, swapEventData);
|
|
601
|
+
}
|
|
602
|
+
else if (!submittedEvents.includes(successEvent) &&
|
|
603
|
+
((stepItem.receipt &&
|
|
604
|
+
!(typeof stepItem.receipt === 'object' &&
|
|
605
|
+
'status' in stepItem.receipt &&
|
|
606
|
+
stepItem.receipt.status === 'reverted')) ||
|
|
607
|
+
stepItem.checkStatus === 'pending')) {
|
|
608
|
+
onAnalyticEvent?.(successEvent, swapEventData);
|
|
609
|
+
submittedEvents.push(successEvent);
|
|
610
|
+
}
|
|
611
|
+
if (stepItem.status === 'complete' &&
|
|
612
|
+
stepItem.check &&
|
|
613
|
+
!submittedEvents.includes(events_js_1.EventNames.FILL_SUCCESS)) {
|
|
614
|
+
if (!submittedEvents.includes(events_js_1.EventNames.DEPOSIT_SUCCESS) &&
|
|
615
|
+
!isBatchTransaction) {
|
|
616
|
+
onAnalyticEvent?.(events_js_1.EventNames.DEPOSIT_SUCCESS, swapEventData);
|
|
617
|
+
submittedEvents.push(events_js_1.EventNames.DEPOSIT_SUCCESS);
|
|
618
|
+
setTimeout(() => {
|
|
619
|
+
onAnalyticEvent?.(events_js_1.EventNames.FILL_SUCCESS, swapEventData);
|
|
620
|
+
}, 20);
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
onAnalyticEvent?.(events_js_1.EventNames.FILL_SUCCESS, swapEventData);
|
|
624
|
+
}
|
|
625
|
+
submittedEvents.push(events_js_1.EventNames.FILL_SUCCESS);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
else if (currentSteps?.every((step) => step.items?.every((item) => item.status === 'complete')) &&
|
|
629
|
+
!submittedEvents.includes(events_js_1.EventNames.FILL_SUCCESS)) {
|
|
630
|
+
if (!submittedEvents.includes(events_js_1.EventNames.DEPOSIT_SUCCESS) &&
|
|
631
|
+
!submittedEvents.includes(events_js_1.EventNames.BATCH_TX_SUBMITTED)) {
|
|
632
|
+
onAnalyticEvent?.(events_js_1.EventNames.DEPOSIT_SUCCESS, swapEventData);
|
|
633
|
+
submittedEvents.push(events_js_1.EventNames.DEPOSIT_SUCCESS);
|
|
634
|
+
setTimeout(() => {
|
|
635
|
+
onAnalyticEvent?.(events_js_1.EventNames.FILL_SUCCESS, swapEventData);
|
|
636
|
+
}, 20);
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
onAnalyticEvent?.(events_js_1.EventNames.FILL_SUCCESS, swapEventData);
|
|
640
|
+
}
|
|
641
|
+
submittedEvents.push(events_js_1.EventNames.FILL_SUCCESS);
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
if (execPromise &&
|
|
645
|
+
typeof execPromise === 'object' &&
|
|
646
|
+
'abortController' in execPromise) {
|
|
647
|
+
setAbortController(execPromise.abortController);
|
|
648
|
+
}
|
|
649
|
+
execPromise
|
|
650
|
+
?.catch((error) => {
|
|
651
|
+
swapErrorHandler(error, _currentSteps);
|
|
652
|
+
})
|
|
653
|
+
.finally(() => {
|
|
654
|
+
setWaitingForSteps(false);
|
|
655
|
+
setAbortController(null);
|
|
656
|
+
invalidateBalanceQueries();
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
swapErrorHandler(error);
|
|
661
|
+
setWaitingForSteps(false);
|
|
662
|
+
}
|
|
663
|
+
}, [
|
|
664
|
+
relayClient,
|
|
665
|
+
address,
|
|
666
|
+
connector,
|
|
667
|
+
wallet,
|
|
668
|
+
walletClient,
|
|
669
|
+
fromToken,
|
|
670
|
+
toToken,
|
|
671
|
+
customToAddress,
|
|
672
|
+
recipient,
|
|
673
|
+
debouncedInputAmountValue,
|
|
674
|
+
debouncedOutputAmountValue,
|
|
675
|
+
tradeType,
|
|
676
|
+
useExternalLiquidity,
|
|
677
|
+
waitingForSteps,
|
|
678
|
+
executeSwap,
|
|
679
|
+
setSteps,
|
|
680
|
+
setQuoteInProgress,
|
|
681
|
+
invalidateBalanceQueries,
|
|
682
|
+
linkedWallet,
|
|
683
|
+
abortController
|
|
684
|
+
]);
|
|
685
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children({
|
|
686
|
+
quote,
|
|
687
|
+
steps,
|
|
688
|
+
setSteps,
|
|
689
|
+
swap,
|
|
690
|
+
transactionModalOpen,
|
|
691
|
+
feeBreakdown,
|
|
692
|
+
fromToken,
|
|
693
|
+
setFromToken,
|
|
694
|
+
toToken,
|
|
695
|
+
setToToken,
|
|
696
|
+
swapError,
|
|
697
|
+
error,
|
|
698
|
+
toDisplayName,
|
|
699
|
+
address,
|
|
700
|
+
originAddressOverride,
|
|
701
|
+
setOriginAddressOverride,
|
|
702
|
+
recipient,
|
|
703
|
+
destinationAddressOverride,
|
|
704
|
+
customToAddress,
|
|
705
|
+
setCustomToAddress,
|
|
706
|
+
setDestinationAddressOverride,
|
|
707
|
+
tradeType,
|
|
708
|
+
setTradeType,
|
|
709
|
+
details,
|
|
710
|
+
isSameCurrencySameRecipientSwap,
|
|
711
|
+
allowUnsupportedOrigin,
|
|
712
|
+
setAllowUnsupportedOrigin,
|
|
713
|
+
allowUnsupportedRecipient,
|
|
714
|
+
setAllowUnsupportedRecipient,
|
|
715
|
+
debouncedInputAmountValue,
|
|
716
|
+
debouncedAmountInputControls,
|
|
717
|
+
setAmountInputValue,
|
|
718
|
+
amountInputValue,
|
|
719
|
+
amountOutputValue,
|
|
720
|
+
debouncedOutputAmountValue,
|
|
721
|
+
debouncedAmountOutputControls,
|
|
722
|
+
setAmountOutputValue,
|
|
723
|
+
toBalance,
|
|
724
|
+
toBalancePending,
|
|
725
|
+
isLoadingToBalance,
|
|
726
|
+
isFetchingQuote,
|
|
727
|
+
isLoadingFromBalance,
|
|
728
|
+
fromBalance,
|
|
729
|
+
fromBalancePending,
|
|
730
|
+
highRelayerServiceFee,
|
|
731
|
+
relayerFeeProportion,
|
|
732
|
+
hasInsufficientBalance,
|
|
733
|
+
isInsufficientLiquidityError,
|
|
734
|
+
isCapacityExceededError,
|
|
735
|
+
isCouldNotExecuteError,
|
|
736
|
+
ctaCopy,
|
|
737
|
+
isFromNative,
|
|
738
|
+
useExternalLiquidity,
|
|
739
|
+
slippageTolerance: currentSlippageTolerance,
|
|
740
|
+
supportsExternalLiquidity,
|
|
741
|
+
timeEstimate,
|
|
742
|
+
canonicalTimeEstimate,
|
|
743
|
+
fetchingExternalLiquiditySupport: externalLiquiditySupport.isFetching,
|
|
744
|
+
isSvmSwap,
|
|
745
|
+
isBvmSwap,
|
|
746
|
+
isValidFromAddress,
|
|
747
|
+
isValidToAddress,
|
|
748
|
+
supportedWalletVMs,
|
|
749
|
+
fromChainWalletVMSupported,
|
|
750
|
+
toChainWalletVMSupported,
|
|
751
|
+
isRecipientLinked,
|
|
752
|
+
recipientWalletSupportsChain,
|
|
753
|
+
invalidateBalanceQueries,
|
|
754
|
+
invalidateQuoteQuery,
|
|
755
|
+
setUseExternalLiquidity,
|
|
756
|
+
setDetails,
|
|
757
|
+
setSwapError,
|
|
758
|
+
quoteInProgress,
|
|
759
|
+
setQuoteInProgress,
|
|
760
|
+
linkedWallet,
|
|
761
|
+
quoteParameters,
|
|
762
|
+
abortController,
|
|
763
|
+
fromTokenPriceData,
|
|
764
|
+
toTokenPriceData,
|
|
765
|
+
isLoadingFromTokenPrice,
|
|
766
|
+
isLoadingToTokenPrice
|
|
767
|
+
}) }));
|
|
768
|
+
};
|
|
769
|
+
exports.default = TokenWidgetRenderer;
|
|
770
|
+
//# sourceMappingURL=TokenWidgetRenderer.js.map
|