@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,1005 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const index_js_1 = require("../../../primitives/index.js");
|
|
6
|
+
const Tabs_js_1 = require("../../../primitives/Tabs.js");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const index_js_2 = require("../../../../hooks/index.js");
|
|
9
|
+
const viem_1 = require("viem");
|
|
10
|
+
const wagmi_1 = require("wagmi");
|
|
11
|
+
const relay_sdk_1 = require("@relayprotocol/relay-sdk");
|
|
12
|
+
const events_js_1 = require("../../../../constants/events.js");
|
|
13
|
+
const WidgetContainer_js_1 = tslib_1.__importDefault(require("../../WidgetContainer.js"));
|
|
14
|
+
const RelayKitProvider_js_1 = require("../../../../providers/RelayKitProvider.js");
|
|
15
|
+
const tokens_js_1 = require("../../../../utils/tokens.js");
|
|
16
|
+
const UnverifiedTokenModal_js_1 = require("../../../common/UnverifiedTokenModal.js");
|
|
17
|
+
const localStorage_js_1 = require("../../../../utils/localStorage.js");
|
|
18
|
+
const quote_js_1 = require("../../../../utils/quote.js");
|
|
19
|
+
const nativeMaxAmount_js_1 = require("../../../../utils/nativeMaxAmount.js");
|
|
20
|
+
const TokenWidgetRenderer_js_1 = tslib_1.__importDefault(require("./TokenWidgetRenderer.js"));
|
|
21
|
+
const BuyTabContent_js_1 = tslib_1.__importDefault(require("../BuyTabContent.js"));
|
|
22
|
+
const SellTabContent_js_1 = tslib_1.__importDefault(require("../SellTabContent.js"));
|
|
23
|
+
const relay_kit_hooks_1 = require("@relayprotocol/relay-kit-hooks");
|
|
24
|
+
const useWalletGuards_js_1 = require("../hooks/useWalletGuards.js");
|
|
25
|
+
const TokenWidget = ({ fromToken, setFromToken, toToken, setToToken, defaultFromTokenAddress, defaultFromTokenChainId, defaultToTokenAddress, defaultToTokenChainId, defaultToAddress, defaultAmount, defaultTradeType, slippageTolerance, onOpenSlippageConfig, lockToToken = false, lockFromToken = false, lockChainId, singleChainMode = false, wallet, multiWalletSupportEnabled = false, linkedWallets, supportedWalletVMs, disableInputAutoFocus = false, popularChainIds, disablePasteWalletAddressOption, useSecureBaseUrl, onSetPrimaryWallet, onLinkNewWallet, onFromTokenChange, onToTokenChange, onConnectWallet, onAnalyticEvent: _onAnalyticEvent, onSwapSuccess, onSwapValidating, onSwapError }) => {
|
|
26
|
+
const onAnalyticEvent = (0, react_1.useCallback)((eventName, data) => {
|
|
27
|
+
try {
|
|
28
|
+
_onAnalyticEvent?.(eventName, data);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error('Error in onAnalyticEvent', eventName, data, e);
|
|
32
|
+
}
|
|
33
|
+
}, [_onAnalyticEvent]);
|
|
34
|
+
const relayClient = (0, index_js_2.useRelayClient)();
|
|
35
|
+
const providerOptionsContext = (0, react_1.useContext)(RelayKitProvider_js_1.ProviderOptionsContext);
|
|
36
|
+
const connectorKeyOverrides = providerOptionsContext.vmConnectorKeyOverrides;
|
|
37
|
+
const [transactionModalOpen, setTransactionModalOpen] = (0, react_1.useState)(false);
|
|
38
|
+
const [depositAddressModalOpen, setDepositAddressModalOpen] = (0, react_1.useState)(false);
|
|
39
|
+
const [addressModalOpen, setAddressModalOpen] = (0, react_1.useState)(false);
|
|
40
|
+
const [pendingSuccessFlush, setPendingSuccessFlush] = (0, react_1.useState)(false);
|
|
41
|
+
const [unverifiedTokens, setUnverifiedTokens] = (0, react_1.useState)([]);
|
|
42
|
+
const [isUsdInputMode, setIsUsdInputMode] = (0, react_1.useState)(false);
|
|
43
|
+
const [usdInputValue, setUsdInputValue] = (0, react_1.useState)('');
|
|
44
|
+
const [usdOutputValue, setUsdOutputValue] = (0, react_1.useState)('');
|
|
45
|
+
const [tokenInputCache, setTokenInputCache] = (0, react_1.useState)('');
|
|
46
|
+
const [activeTab, setActiveTab] = (0, react_1.useState)('buy');
|
|
47
|
+
const tabTokenStateRef = (0, react_1.useRef)({ buy: {}, sell: {} });
|
|
48
|
+
const tabRecipientRef = (0, react_1.useRef)({ buy: {}, sell: {} });
|
|
49
|
+
const setTradeTypeRef = (0, react_1.useRef)(null);
|
|
50
|
+
const tradeTypeRef = (0, react_1.useRef)(defaultTradeType ?? 'EXPECTED_OUTPUT');
|
|
51
|
+
const [resolvedFromToken, setResolvedFromToken] = (0, react_1.useState)(fromToken);
|
|
52
|
+
const [resolvedToToken, setResolvedToToken] = (0, react_1.useState)(toToken);
|
|
53
|
+
const hasLockedToken = lockFromToken || lockToToken;
|
|
54
|
+
const isSingleChainLocked = singleChainMode && lockChainId !== undefined;
|
|
55
|
+
const [localSlippageTolerance, setLocalSlippageTolerance] = (0, react_1.useState)(slippageTolerance);
|
|
56
|
+
const { data: fromTokenList } = (0, relay_kit_hooks_1.useTokenList)(relayClient?.baseApiUrl, defaultFromTokenAddress && defaultFromTokenChainId && !fromToken
|
|
57
|
+
? {
|
|
58
|
+
chainIds: [defaultFromTokenChainId],
|
|
59
|
+
address: defaultFromTokenAddress,
|
|
60
|
+
limit: 1
|
|
61
|
+
}
|
|
62
|
+
: undefined, {
|
|
63
|
+
enabled: !!(defaultFromTokenAddress &&
|
|
64
|
+
defaultFromTokenChainId &&
|
|
65
|
+
!fromToken &&
|
|
66
|
+
relayClient)
|
|
67
|
+
});
|
|
68
|
+
const { data: toTokenList } = (0, relay_kit_hooks_1.useTokenList)(relayClient?.baseApiUrl, defaultToTokenAddress && defaultToTokenChainId && !toToken
|
|
69
|
+
? {
|
|
70
|
+
chainIds: [defaultToTokenChainId],
|
|
71
|
+
address: defaultToTokenAddress,
|
|
72
|
+
limit: 1
|
|
73
|
+
}
|
|
74
|
+
: undefined, {
|
|
75
|
+
enabled: !!(defaultToTokenAddress &&
|
|
76
|
+
defaultToTokenChainId &&
|
|
77
|
+
!toToken &&
|
|
78
|
+
relayClient)
|
|
79
|
+
});
|
|
80
|
+
(0, react_1.useEffect)(() => {
|
|
81
|
+
if (fromToken) {
|
|
82
|
+
setResolvedFromToken(fromToken);
|
|
83
|
+
}
|
|
84
|
+
else if (fromTokenList?.[0]) {
|
|
85
|
+
const apiToken = fromTokenList[0];
|
|
86
|
+
const resolved = {
|
|
87
|
+
chainId: apiToken.chainId,
|
|
88
|
+
address: apiToken.address,
|
|
89
|
+
name: apiToken.name,
|
|
90
|
+
symbol: apiToken.symbol,
|
|
91
|
+
decimals: apiToken.decimals,
|
|
92
|
+
logoURI: (0, tokens_js_1.generateTokenImageUrl)(apiToken),
|
|
93
|
+
verified: apiToken.metadata?.verified ?? false
|
|
94
|
+
};
|
|
95
|
+
if (activeTab === 'buy' && !toToken && !resolvedToToken) {
|
|
96
|
+
setResolvedToToken(resolved);
|
|
97
|
+
setToToken?.(resolved);
|
|
98
|
+
}
|
|
99
|
+
else if (activeTab === 'sell') {
|
|
100
|
+
setResolvedFromToken(resolved);
|
|
101
|
+
setFromToken?.(resolved);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}, [
|
|
105
|
+
fromToken,
|
|
106
|
+
fromTokenList,
|
|
107
|
+
setFromToken,
|
|
108
|
+
activeTab,
|
|
109
|
+
toToken,
|
|
110
|
+
resolvedToToken,
|
|
111
|
+
setToToken
|
|
112
|
+
]);
|
|
113
|
+
(0, react_1.useEffect)(() => {
|
|
114
|
+
if (toToken) {
|
|
115
|
+
setResolvedToToken(toToken);
|
|
116
|
+
}
|
|
117
|
+
else if (toTokenList?.[0] && activeTab !== 'sell') {
|
|
118
|
+
const apiToken = toTokenList[0];
|
|
119
|
+
const resolved = {
|
|
120
|
+
chainId: apiToken.chainId,
|
|
121
|
+
address: apiToken.address,
|
|
122
|
+
name: apiToken.name,
|
|
123
|
+
symbol: apiToken.symbol,
|
|
124
|
+
decimals: apiToken.decimals,
|
|
125
|
+
logoURI: (0, tokens_js_1.generateTokenImageUrl)(apiToken),
|
|
126
|
+
verified: apiToken.metadata?.verified ?? false
|
|
127
|
+
};
|
|
128
|
+
setResolvedToToken(resolved);
|
|
129
|
+
setToToken?.(resolved);
|
|
130
|
+
}
|
|
131
|
+
}, [toToken, toTokenList, setToToken, activeTab]);
|
|
132
|
+
(0, react_1.useEffect)(() => {
|
|
133
|
+
setLocalSlippageTolerance(slippageTolerance);
|
|
134
|
+
}, [slippageTolerance]);
|
|
135
|
+
(0, react_1.useEffect)(() => {
|
|
136
|
+
const desiredTradeType = activeTab === 'buy' ? 'EXPECTED_OUTPUT' : 'EXACT_INPUT';
|
|
137
|
+
if (tradeTypeRef.current !== desiredTradeType) {
|
|
138
|
+
setTradeTypeRef.current?.(desiredTradeType);
|
|
139
|
+
}
|
|
140
|
+
}, [activeTab]);
|
|
141
|
+
const handleOpenSlippageConfig = () => {
|
|
142
|
+
onOpenSlippageConfig?.();
|
|
143
|
+
};
|
|
144
|
+
const handleSlippageToleranceChange = (value) => {
|
|
145
|
+
setLocalSlippageTolerance(value);
|
|
146
|
+
};
|
|
147
|
+
const computedDefaultTradeType = defaultTradeType ??
|
|
148
|
+
(activeTab === 'buy' ? 'EXPECTED_OUTPUT' : 'EXACT_INPUT');
|
|
149
|
+
(0, react_1.useEffect)(() => {
|
|
150
|
+
if (resolvedFromToken &&
|
|
151
|
+
'verified' in resolvedFromToken &&
|
|
152
|
+
!resolvedFromToken.verified) {
|
|
153
|
+
const isAlreadyAccepted = (0, localStorage_js_1.alreadyAcceptedToken)(resolvedFromToken);
|
|
154
|
+
if (!isAlreadyAccepted) {
|
|
155
|
+
unverifiedTokens.push({ token: resolvedFromToken, context: 'from' });
|
|
156
|
+
setResolvedFromToken(undefined);
|
|
157
|
+
setFromToken?.(undefined);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (resolvedToToken &&
|
|
161
|
+
'verified' in resolvedToToken &&
|
|
162
|
+
!resolvedToToken.verified) {
|
|
163
|
+
const isAlreadyAccepted = (0, localStorage_js_1.alreadyAcceptedToken)(resolvedToToken);
|
|
164
|
+
if (!isAlreadyAccepted) {
|
|
165
|
+
unverifiedTokens.push({ token: resolvedToToken, context: 'to' });
|
|
166
|
+
setResolvedToToken(undefined);
|
|
167
|
+
setToToken?.(undefined);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}, [resolvedFromToken, resolvedToToken]);
|
|
171
|
+
return ((0, jsx_runtime_1.jsx)(TokenWidgetRenderer_js_1.default, { context: "Swap", transactionModalOpen: transactionModalOpen, setTransactionModalOpen: setTransactionModalOpen, depositAddressModalOpen: depositAddressModalOpen, defaultAmount: defaultAmount, defaultToAddress: defaultToAddress, defaultTradeType: computedDefaultTradeType, toToken: resolvedToToken, setToToken: setResolvedToToken, fromToken: resolvedFromToken, setFromToken: setResolvedFromToken, slippageTolerance: localSlippageTolerance, wallet: wallet, linkedWallets: linkedWallets, multiWalletSupportEnabled: multiWalletSupportEnabled, onSwapError: onSwapError, onAnalyticEvent: onAnalyticEvent, supportedWalletVMs: supportedWalletVMs, useSecureBaseUrl: useSecureBaseUrl, children: ({ quote, steps, swap, setSteps, feeBreakdown, fromToken, setFromToken, toToken, setToToken, error, toDisplayName, address, originAddressOverride: _originAddressOverride, setOriginAddressOverride, recipient, customToAddress, setCustomToAddress, destinationAddressOverride, setDestinationAddressOverride, tradeType, setTradeType, isSameCurrencySameRecipientSwap, allowUnsupportedOrigin, setAllowUnsupportedOrigin, allowUnsupportedRecipient, setAllowUnsupportedRecipient, debouncedInputAmountValue, debouncedAmountInputControls, setAmountInputValue, amountInputValue, amountOutputValue, debouncedOutputAmountValue, debouncedAmountOutputControls, setAmountOutputValue, toBalance, toBalancePending, isLoadingToBalance, isFetchingQuote, isLoadingFromBalance, fromBalance, fromBalancePending, highRelayerServiceFee, relayerFeeProportion, hasInsufficientBalance, isInsufficientLiquidityError, isCapacityExceededError, isCouldNotExecuteError, ctaCopy, isFromNative, timeEstimate, isSvmSwap, isBvmSwap, isValidFromAddress, isValidToAddress, supportsExternalLiquidity, useExternalLiquidity, slippageTolerance, canonicalTimeEstimate, fromChainWalletVMSupported, toChainWalletVMSupported, isRecipientLinked, swapError, recipientWalletSupportsChain, linkedWallet, quoteParameters, setSwapError, setUseExternalLiquidity, invalidateBalanceQueries, invalidateQuoteQuery, quoteInProgress, setQuoteInProgress, abortController, fromTokenPriceData, toTokenPriceData, isLoadingFromTokenPrice, isLoadingToTokenPrice }) => {
|
|
172
|
+
setTradeTypeRef.current = setTradeType;
|
|
173
|
+
tradeTypeRef.current = tradeType;
|
|
174
|
+
(0, react_1.useEffect)(() => {
|
|
175
|
+
tabTokenStateRef.current[activeTab] = {
|
|
176
|
+
fromToken,
|
|
177
|
+
toToken
|
|
178
|
+
};
|
|
179
|
+
}, [activeTab, fromToken, toToken]);
|
|
180
|
+
(0, react_1.useEffect)(() => {
|
|
181
|
+
tabRecipientRef.current[activeTab] = {
|
|
182
|
+
override: typeof destinationAddressOverride === 'string'
|
|
183
|
+
? destinationAddressOverride
|
|
184
|
+
: undefined,
|
|
185
|
+
custom: typeof customToAddress === 'string' ? customToAddress : undefined
|
|
186
|
+
};
|
|
187
|
+
}, [activeTab, destinationAddressOverride, customToAddress]);
|
|
188
|
+
(0, react_1.useEffect)(() => {
|
|
189
|
+
setAllowUnsupportedOrigin(activeTab === 'buy');
|
|
190
|
+
setAllowUnsupportedRecipient(activeTab === 'sell');
|
|
191
|
+
}, [activeTab, setAllowUnsupportedOrigin, setAllowUnsupportedRecipient]);
|
|
192
|
+
(0, react_1.useEffect)(() => {
|
|
193
|
+
if (activeTab === 'buy' &&
|
|
194
|
+
toToken &&
|
|
195
|
+
multiWalletSupportEnabled &&
|
|
196
|
+
linkedWallets &&
|
|
197
|
+
linkedWallets.length > 0 &&
|
|
198
|
+
!destinationAddressOverride &&
|
|
199
|
+
!customToAddress) {
|
|
200
|
+
const toChain = relayClient?.chains?.find((c) => c.id === toToken.chainId);
|
|
201
|
+
if (toChain) {
|
|
202
|
+
const compatibleWallets = linkedWallets.filter((wallet) => {
|
|
203
|
+
return wallet.vmType === toChain.vmType;
|
|
204
|
+
});
|
|
205
|
+
const currentAddressWallet = compatibleWallets.find((w) => w.address.toLowerCase() === address?.toLowerCase());
|
|
206
|
+
const walletToSelect = currentAddressWallet || compatibleWallets[0];
|
|
207
|
+
if (walletToSelect) {
|
|
208
|
+
setDestinationAddressOverride(walletToSelect.address);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}, [
|
|
213
|
+
activeTab,
|
|
214
|
+
toToken,
|
|
215
|
+
multiWalletSupportEnabled,
|
|
216
|
+
linkedWallets,
|
|
217
|
+
destinationAddressOverride,
|
|
218
|
+
customToAddress,
|
|
219
|
+
relayClient?.chains,
|
|
220
|
+
setDestinationAddressOverride,
|
|
221
|
+
address
|
|
222
|
+
]);
|
|
223
|
+
const inputAmountUsd = (0, react_1.useMemo)(() => {
|
|
224
|
+
return ((0, quote_js_1.calculateUsdValue)(fromTokenPriceData?.price, amountInputValue) ??
|
|
225
|
+
null);
|
|
226
|
+
}, [fromTokenPriceData, amountInputValue]);
|
|
227
|
+
const outputAmountUsd = (0, react_1.useMemo)(() => {
|
|
228
|
+
return ((0, quote_js_1.calculateUsdValue)(toTokenPriceData?.price, amountOutputValue) ??
|
|
229
|
+
null);
|
|
230
|
+
}, [toTokenPriceData, amountOutputValue]);
|
|
231
|
+
const percentageOptions = [20, 50];
|
|
232
|
+
const handleMaxAmountClicked = async (amount, percent, bufferAmount) => {
|
|
233
|
+
if (fromToken) {
|
|
234
|
+
const formattedAmount = (0, viem_1.formatUnits)(amount, fromToken?.decimals);
|
|
235
|
+
setAmountInputValue(formattedAmount);
|
|
236
|
+
setTradeType('EXACT_INPUT');
|
|
237
|
+
debouncedAmountOutputControls.cancel();
|
|
238
|
+
debouncedAmountInputControls.flush();
|
|
239
|
+
onAnalyticEvent?.(events_js_1.EventNames.MAX_AMOUNT_CLICKED, {
|
|
240
|
+
percent: percent,
|
|
241
|
+
bufferAmount: bufferAmount ? bufferAmount.toString() : '0',
|
|
242
|
+
chainType: fromChain?.vmType
|
|
243
|
+
});
|
|
244
|
+
if (isUsdInputMode && conversionRate) {
|
|
245
|
+
const numericTokenAmount = Number(formattedAmount);
|
|
246
|
+
if (!isNaN(numericTokenAmount)) {
|
|
247
|
+
const usdEquivalent = numericTokenAmount * conversionRate;
|
|
248
|
+
setUsdInputValue(usdEquivalent.toFixed(2));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
const fromChain = relayClient?.chains?.find((chain) => chain.id === fromToken?.chainId);
|
|
254
|
+
const toChain = relayClient?.chains?.find((chain) => chain.id === toToken?.chainId);
|
|
255
|
+
const handleSetToToken = (0, react_1.useCallback)((token) => {
|
|
256
|
+
if (!token) {
|
|
257
|
+
setToToken(undefined);
|
|
258
|
+
onToTokenChange?.(undefined);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
let _token = token;
|
|
262
|
+
if (!fromChainWalletVMSupported) {
|
|
263
|
+
const newToChain = relayClient?.chains.find((chain) => token?.chainId == chain.id);
|
|
264
|
+
if (newToChain) {
|
|
265
|
+
const _toToken = (0, tokens_js_1.findBridgableToken)(newToChain, _token);
|
|
266
|
+
if (_toToken && _toToken.address != _token?.address) {
|
|
267
|
+
_token = _toToken;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
setToToken(_token);
|
|
272
|
+
onToTokenChange?.(_token);
|
|
273
|
+
}, [fromChainWalletVMSupported, onToTokenChange, relayClient, setToToken]);
|
|
274
|
+
const handleSetFromToken = (0, react_1.useCallback)((token) => {
|
|
275
|
+
if (!token) {
|
|
276
|
+
setFromToken(undefined);
|
|
277
|
+
onFromTokenChange?.(undefined);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
let _token = token;
|
|
281
|
+
const newFromChain = relayClient?.chains.find((chain) => token?.chainId == chain.id);
|
|
282
|
+
if (newFromChain?.vmType &&
|
|
283
|
+
!supportedWalletVMs.includes(newFromChain?.vmType)) {
|
|
284
|
+
setTradeType('EXACT_INPUT');
|
|
285
|
+
const _toToken = (0, tokens_js_1.findBridgableToken)(toChain, toToken);
|
|
286
|
+
if (_toToken && _toToken?.address != toToken?.address) {
|
|
287
|
+
handleSetToToken(_toToken);
|
|
288
|
+
}
|
|
289
|
+
const _fromToken = (0, tokens_js_1.findBridgableToken)(newFromChain, _token);
|
|
290
|
+
if (_fromToken && _fromToken.address != _token?.address) {
|
|
291
|
+
_token = _fromToken;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
setFromToken(_token);
|
|
295
|
+
onFromTokenChange?.(_token);
|
|
296
|
+
}, [
|
|
297
|
+
handleSetToToken,
|
|
298
|
+
onFromTokenChange,
|
|
299
|
+
relayClient,
|
|
300
|
+
setFromToken,
|
|
301
|
+
setTradeType,
|
|
302
|
+
supportedWalletVMs,
|
|
303
|
+
toChain,
|
|
304
|
+
toToken
|
|
305
|
+
]);
|
|
306
|
+
const publicClient = (0, wagmi_1.usePublicClient)({ chainId: fromChain?.id });
|
|
307
|
+
(0, useWalletGuards_js_1.useWalletGuards)({
|
|
308
|
+
multiWalletSupportEnabled,
|
|
309
|
+
allowUnsupportedOrigin,
|
|
310
|
+
allowUnsupportedRecipient,
|
|
311
|
+
fromChain,
|
|
312
|
+
toChain,
|
|
313
|
+
address,
|
|
314
|
+
recipient,
|
|
315
|
+
linkedWallets,
|
|
316
|
+
connectorKeyOverrides,
|
|
317
|
+
onSetPrimaryWallet,
|
|
318
|
+
isValidFromAddress,
|
|
319
|
+
isValidToAddress,
|
|
320
|
+
setOriginAddressOverride,
|
|
321
|
+
setCustomToAddress,
|
|
322
|
+
disablePasteWalletAddressOption,
|
|
323
|
+
customToAddress: customToAddress,
|
|
324
|
+
originAddressOverride: _originAddressOverride,
|
|
325
|
+
destinationAddressOverride: destinationAddressOverride,
|
|
326
|
+
setDestinationAddressOverride
|
|
327
|
+
});
|
|
328
|
+
const promptSwitchRoute = (isCapacityExceededError || isCouldNotExecuteError) &&
|
|
329
|
+
supportsExternalLiquidity &&
|
|
330
|
+
!isSingleChainLocked;
|
|
331
|
+
const isAutoSlippage = slippageTolerance === undefined;
|
|
332
|
+
const isHighPriceImpact = Number(quote?.details?.totalImpact?.percent) < -3.5;
|
|
333
|
+
const totalImpactUsd = quote?.details?.totalImpact?.usd;
|
|
334
|
+
const showHighPriceImpactWarning = Boolean(isHighPriceImpact && totalImpactUsd && Number(totalImpactUsd) <= -10);
|
|
335
|
+
const conversionRate = (0, react_1.useMemo)(() => {
|
|
336
|
+
if (isUsdInputMode) {
|
|
337
|
+
if (fromTokenPriceData?.price && fromTokenPriceData.price > 0) {
|
|
338
|
+
return fromTokenPriceData.price;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
if (amountInputValue &&
|
|
346
|
+
Number(amountInputValue) > 0 &&
|
|
347
|
+
quote?.details?.currencyIn?.amountUsd) {
|
|
348
|
+
const tokenVal = Number(amountInputValue);
|
|
349
|
+
const usdVal = Number(quote.details.currencyIn.amountUsd);
|
|
350
|
+
if (tokenVal > 0 && usdVal > 0) {
|
|
351
|
+
const rate = usdVal / tokenVal;
|
|
352
|
+
return rate;
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}, [
|
|
363
|
+
isUsdInputMode,
|
|
364
|
+
fromTokenPriceData?.price,
|
|
365
|
+
quote?.details?.currencyIn?.amountUsd,
|
|
366
|
+
amountInputValue
|
|
367
|
+
]);
|
|
368
|
+
const toggleInputMode = () => {
|
|
369
|
+
if (!isUsdInputMode) {
|
|
370
|
+
let newUsdInputValue = '';
|
|
371
|
+
let newUsdOutputValue = '';
|
|
372
|
+
if (quote?.details?.currencyIn?.amountUsd &&
|
|
373
|
+
Number(quote.details.currencyIn.amountUsd) > 0) {
|
|
374
|
+
newUsdInputValue = String(Number(quote.details.currencyIn.amountUsd));
|
|
375
|
+
}
|
|
376
|
+
else if (inputAmountUsd && inputAmountUsd > 0) {
|
|
377
|
+
newUsdInputValue = inputAmountUsd.toFixed(2);
|
|
378
|
+
}
|
|
379
|
+
else if (amountInputValue &&
|
|
380
|
+
Number(amountInputValue) > 0 &&
|
|
381
|
+
conversionRate &&
|
|
382
|
+
conversionRate > 0) {
|
|
383
|
+
newUsdInputValue = (Number(amountInputValue) * conversionRate).toFixed(2);
|
|
384
|
+
}
|
|
385
|
+
if (quote?.details?.currencyOut?.amountUsd &&
|
|
386
|
+
Number(quote.details.currencyOut.amountUsd) > 0) {
|
|
387
|
+
newUsdOutputValue = String(Number(quote.details.currencyOut.amountUsd));
|
|
388
|
+
}
|
|
389
|
+
else if (outputAmountUsd && outputAmountUsd > 0) {
|
|
390
|
+
newUsdOutputValue = outputAmountUsd.toFixed(2);
|
|
391
|
+
}
|
|
392
|
+
else if (amountOutputValue &&
|
|
393
|
+
Number(amountOutputValue) > 0 &&
|
|
394
|
+
toTokenPriceData?.price &&
|
|
395
|
+
toTokenPriceData.price > 0) {
|
|
396
|
+
newUsdOutputValue = (Number(amountOutputValue) * toTokenPriceData.price).toFixed(2);
|
|
397
|
+
}
|
|
398
|
+
setTokenInputCache(amountInputValue);
|
|
399
|
+
setUsdInputValue(newUsdInputValue);
|
|
400
|
+
setUsdOutputValue(newUsdOutputValue);
|
|
401
|
+
setIsUsdInputMode(true);
|
|
402
|
+
if (tradeType !== 'EXPECTED_OUTPUT' || !newUsdOutputValue) {
|
|
403
|
+
setTradeType('EXACT_INPUT');
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
if (!usdInputValue && tokenInputCache) {
|
|
408
|
+
setAmountInputValue(tokenInputCache);
|
|
409
|
+
}
|
|
410
|
+
setUsdInputValue('');
|
|
411
|
+
setUsdOutputValue('');
|
|
412
|
+
setIsUsdInputMode(false);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
(0, react_1.useEffect)(() => {
|
|
416
|
+
if (isUsdInputMode) {
|
|
417
|
+
if (conversionRate && conversionRate > 0 && usdInputValue) {
|
|
418
|
+
const usdValue = Number(usdInputValue);
|
|
419
|
+
if (!isNaN(usdValue) && usdValue > 0) {
|
|
420
|
+
const tokenEquivalent = (usdValue / conversionRate).toFixed(fromToken?.decimals ?? 8);
|
|
421
|
+
setAmountInputValue(tokenEquivalent);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
else if (usdInputValue === '' || Number(usdInputValue) === 0) {
|
|
425
|
+
setAmountInputValue('');
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}, [
|
|
429
|
+
isUsdInputMode,
|
|
430
|
+
usdInputValue,
|
|
431
|
+
conversionRate,
|
|
432
|
+
setAmountInputValue,
|
|
433
|
+
fromToken?.decimals
|
|
434
|
+
]);
|
|
435
|
+
(0, react_1.useEffect)(() => {
|
|
436
|
+
if (isUsdInputMode && tradeType === 'EXPECTED_OUTPUT') {
|
|
437
|
+
if (toTokenPriceData?.price &&
|
|
438
|
+
toTokenPriceData.price > 0 &&
|
|
439
|
+
usdOutputValue) {
|
|
440
|
+
const usdValue = Number(usdOutputValue);
|
|
441
|
+
if (!isNaN(usdValue) && usdValue > 0) {
|
|
442
|
+
const tokenEquivalent = (usdValue / toTokenPriceData.price).toFixed(toToken?.decimals ?? 8);
|
|
443
|
+
setAmountOutputValue(tokenEquivalent);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
else if (usdOutputValue === '' || Number(usdOutputValue) === 0) {
|
|
447
|
+
setAmountOutputValue('');
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}, [
|
|
451
|
+
isUsdInputMode,
|
|
452
|
+
tradeType,
|
|
453
|
+
usdOutputValue,
|
|
454
|
+
toTokenPriceData?.price,
|
|
455
|
+
setAmountOutputValue,
|
|
456
|
+
toToken?.decimals
|
|
457
|
+
]);
|
|
458
|
+
(0, react_1.useEffect)(() => {
|
|
459
|
+
if (isUsdInputMode) {
|
|
460
|
+
if (tradeType === 'EXPECTED_OUTPUT') {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
if (quote?.details?.currencyOut?.amountUsd && !isFetchingQuote) {
|
|
464
|
+
const quoteUsdValue = Number(quote.details.currencyOut.amountUsd);
|
|
465
|
+
if (!isNaN(quoteUsdValue) && quoteUsdValue >= 0) {
|
|
466
|
+
setUsdOutputValue(quoteUsdValue.toFixed(2));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else if (toTokenPriceData?.price &&
|
|
470
|
+
toTokenPriceData.price > 0 &&
|
|
471
|
+
amountOutputValue &&
|
|
472
|
+
Number(amountOutputValue) > 0) {
|
|
473
|
+
const tokenAmount = Number(amountOutputValue);
|
|
474
|
+
const usdEquivalent = tokenAmount * toTokenPriceData.price;
|
|
475
|
+
if (!isNaN(usdEquivalent) && usdEquivalent >= 0) {
|
|
476
|
+
setUsdOutputValue(usdEquivalent.toFixed(2));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
else if (!amountOutputValue || Number(amountOutputValue) === 0) {
|
|
480
|
+
setUsdOutputValue('');
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}, [
|
|
484
|
+
isUsdInputMode,
|
|
485
|
+
tradeType,
|
|
486
|
+
quote?.details?.currencyOut?.amountUsd,
|
|
487
|
+
isFetchingQuote,
|
|
488
|
+
toTokenPriceData?.price,
|
|
489
|
+
amountOutputValue
|
|
490
|
+
]);
|
|
491
|
+
(0, react_1.useEffect)(() => {
|
|
492
|
+
if (isUsdInputMode && tradeType === 'EXPECTED_OUTPUT') {
|
|
493
|
+
if (quote?.details?.currencyIn?.amountUsd && !isFetchingQuote) {
|
|
494
|
+
const quoteUsdValue = Number(quote.details.currencyIn.amountUsd);
|
|
495
|
+
if (!isNaN(quoteUsdValue) && quoteUsdValue >= 0) {
|
|
496
|
+
setUsdInputValue(quoteUsdValue.toFixed(2));
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
else if (!amountInputValue || Number(amountInputValue) === 0) {
|
|
500
|
+
setUsdInputValue('');
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}, [
|
|
504
|
+
isUsdInputMode,
|
|
505
|
+
tradeType,
|
|
506
|
+
quote?.details?.currencyIn?.amountUsd,
|
|
507
|
+
isFetchingQuote,
|
|
508
|
+
amountInputValue
|
|
509
|
+
]);
|
|
510
|
+
const recipientLinkedWallet = linkedWallets?.find((wallet) => wallet.address === recipient);
|
|
511
|
+
const handlePrimaryAction = () => {
|
|
512
|
+
if (fromChainWalletVMSupported) {
|
|
513
|
+
if (!isValidToAddress || !isValidFromAddress) {
|
|
514
|
+
if (multiWalletSupportEnabled &&
|
|
515
|
+
(isValidToAddress ||
|
|
516
|
+
(!isValidToAddress && toChainWalletVMSupported))) {
|
|
517
|
+
const chain = !isValidFromAddress ? fromChain : toChain;
|
|
518
|
+
if (!address) {
|
|
519
|
+
onConnectWallet?.();
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
onLinkNewWallet?.({
|
|
523
|
+
chain,
|
|
524
|
+
direction: !isValidFromAddress ? 'from' : 'to'
|
|
525
|
+
})?.then((wallet) => {
|
|
526
|
+
if (!isValidFromAddress) {
|
|
527
|
+
onSetPrimaryWallet?.(wallet.address);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
setDestinationAddressOverride(wallet.address);
|
|
531
|
+
setCustomToAddress(undefined);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
setAddressModalOpen(true);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
swap();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
else {
|
|
545
|
+
if (!isValidToAddress) {
|
|
546
|
+
if (multiWalletSupportEnabled && toChainWalletVMSupported) {
|
|
547
|
+
if (!address) {
|
|
548
|
+
onConnectWallet?.();
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
onLinkNewWallet?.({
|
|
552
|
+
chain: toChain,
|
|
553
|
+
direction: 'to'
|
|
554
|
+
})?.then((wallet) => {
|
|
555
|
+
if (!wallet) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
setDestinationAddressOverride(wallet.address);
|
|
559
|
+
setCustomToAddress(undefined);
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
setAddressModalOpen(true);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
const swapEventData = (0, quote_js_1.getSwapEventData)(quote?.details, quote?.fees, quote?.steps ? quote?.steps : null, linkedWallet?.connector, quoteParameters);
|
|
569
|
+
onAnalyticEvent?.(events_js_1.EventNames.SWAP_CTA_CLICKED, swapEventData);
|
|
570
|
+
setDepositAddressModalOpen(true);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
(0, react_1.useEffect)(() => {
|
|
575
|
+
if (activeTab === 'buy' &&
|
|
576
|
+
!address &&
|
|
577
|
+
!linkedWallets?.length &&
|
|
578
|
+
!fromToken &&
|
|
579
|
+
!defaultFromTokenAddress &&
|
|
580
|
+
!defaultFromTokenChainId &&
|
|
581
|
+
relayClient) {
|
|
582
|
+
const baseUSDC = {
|
|
583
|
+
chainId: 8453,
|
|
584
|
+
address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
585
|
+
name: 'USD Coin',
|
|
586
|
+
symbol: 'USDC',
|
|
587
|
+
decimals: 6,
|
|
588
|
+
logoURI: `${relay_sdk_1.ASSETS_RELAY_API}/icons/currencies/usdc.png`,
|
|
589
|
+
verified: true
|
|
590
|
+
};
|
|
591
|
+
handleSetFromToken(baseUSDC);
|
|
592
|
+
}
|
|
593
|
+
}, [
|
|
594
|
+
activeTab,
|
|
595
|
+
address,
|
|
596
|
+
linkedWallets?.length,
|
|
597
|
+
fromToken,
|
|
598
|
+
defaultFromTokenAddress,
|
|
599
|
+
defaultFromTokenChainId,
|
|
600
|
+
relayClient,
|
|
601
|
+
handleSetFromToken
|
|
602
|
+
]);
|
|
603
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(WidgetContainer_js_1.default, { steps: steps, setSteps: setSteps, quoteInProgress: quoteInProgress, setQuoteInProgress: setQuoteInProgress, transactionModalOpen: transactionModalOpen, setTransactionModalOpen: setTransactionModalOpen, depositAddressModalOpen: depositAddressModalOpen, setDepositAddressModalOpen: setDepositAddressModalOpen, addressModalOpen: addressModalOpen, setAddressModalOpen: setAddressModalOpen, fromToken: fromToken, fromChain: fromChain, toToken: toToken, toChain: toChain, address: address, recipient: recipient, amountInputValue: amountInputValue, amountOutputValue: amountOutputValue, debouncedInputAmountValue: debouncedInputAmountValue, debouncedOutputAmountValue: debouncedOutputAmountValue, tradeType: tradeType, onTransactionModalOpenChange: (open) => {
|
|
604
|
+
if (!open) {
|
|
605
|
+
if (pendingSuccessFlush) {
|
|
606
|
+
setPendingSuccessFlush(false);
|
|
607
|
+
}
|
|
608
|
+
else if (steps) {
|
|
609
|
+
invalidateQuoteQuery();
|
|
610
|
+
}
|
|
611
|
+
if (abortController) {
|
|
612
|
+
abortController.abort();
|
|
613
|
+
}
|
|
614
|
+
setSwapError(null);
|
|
615
|
+
setSteps(null);
|
|
616
|
+
setQuoteInProgress(null);
|
|
617
|
+
}
|
|
618
|
+
else if (pendingSuccessFlush) {
|
|
619
|
+
setPendingSuccessFlush(false);
|
|
620
|
+
}
|
|
621
|
+
}, onDepositAddressModalOpenChange: (open) => {
|
|
622
|
+
if (!open) {
|
|
623
|
+
setSwapError(null);
|
|
624
|
+
if (pendingSuccessFlush) {
|
|
625
|
+
setPendingSuccessFlush(false);
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
invalidateQuoteQuery();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
else if (pendingSuccessFlush) {
|
|
632
|
+
setPendingSuccessFlush(false);
|
|
633
|
+
}
|
|
634
|
+
}, useExternalLiquidity: useExternalLiquidity, slippageTolerance: localSlippageTolerance, swapError: swapError, setSwapError: setSwapError, onSwapSuccess: (data) => {
|
|
635
|
+
setPendingSuccessFlush(true);
|
|
636
|
+
setAmountInputValue('');
|
|
637
|
+
setAmountOutputValue('');
|
|
638
|
+
onSwapSuccess?.(data);
|
|
639
|
+
}, onSwapValidating: onSwapValidating, onAnalyticEvent: onAnalyticEvent, invalidateBalanceQueries: invalidateBalanceQueries, invalidateQuoteQuery: invalidateQuoteQuery, customToAddress: customToAddress, setCustomToAddress: setCustomToAddress, timeEstimate: timeEstimate, wallet: wallet, linkedWallets: linkedWallets, multiWalletSupportEnabled: multiWalletSupportEnabled, children: () => {
|
|
640
|
+
return ((0, jsx_runtime_1.jsx)(index_js_1.Flex, { direction: "column", css: { gap: '3', width: '100%' }, children: (0, jsx_runtime_1.jsx)(Tabs_js_1.TabsRoot, { value: activeTab, onValueChange: (value) => {
|
|
641
|
+
const nextTab = value;
|
|
642
|
+
setAllowUnsupportedOrigin(nextTab === 'buy');
|
|
643
|
+
setAllowUnsupportedRecipient(nextTab === 'sell');
|
|
644
|
+
if (nextTab !== activeTab) {
|
|
645
|
+
tabTokenStateRef.current[activeTab] = {
|
|
646
|
+
fromToken,
|
|
647
|
+
toToken
|
|
648
|
+
};
|
|
649
|
+
tabRecipientRef.current[activeTab] = {
|
|
650
|
+
override: typeof destinationAddressOverride === 'string'
|
|
651
|
+
? destinationAddressOverride
|
|
652
|
+
: undefined,
|
|
653
|
+
custom: typeof customToAddress === 'string'
|
|
654
|
+
? customToAddress
|
|
655
|
+
: undefined
|
|
656
|
+
};
|
|
657
|
+
const currentState = tabTokenStateRef.current[activeTab] ?? {};
|
|
658
|
+
const storedNextState = tabTokenStateRef.current[nextTab] ?? {};
|
|
659
|
+
const storedNextRecipient = tabRecipientRef.current[nextTab] ?? {};
|
|
660
|
+
let nextFromToken = storedNextState.fromToken;
|
|
661
|
+
let nextToToken = storedNextState.toToken;
|
|
662
|
+
if (nextTab === 'sell') {
|
|
663
|
+
const sellToken = nextFromToken ??
|
|
664
|
+
currentState.toToken ??
|
|
665
|
+
toToken ??
|
|
666
|
+
fromToken;
|
|
667
|
+
const receiveToken = nextToToken ?? currentState.fromToken ?? fromToken;
|
|
668
|
+
nextFromToken = sellToken ?? undefined;
|
|
669
|
+
nextToToken = receiveToken ?? undefined;
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
const buyToken = nextToToken ??
|
|
673
|
+
currentState.toToken ??
|
|
674
|
+
toToken ??
|
|
675
|
+
fromToken;
|
|
676
|
+
const payToken = nextFromToken ??
|
|
677
|
+
currentState.fromToken ??
|
|
678
|
+
fromToken ??
|
|
679
|
+
currentState.toToken;
|
|
680
|
+
nextFromToken = payToken ?? undefined;
|
|
681
|
+
nextToToken = buyToken ?? undefined;
|
|
682
|
+
}
|
|
683
|
+
tabTokenStateRef.current[nextTab] = {
|
|
684
|
+
fromToken: nextFromToken,
|
|
685
|
+
toToken: nextToToken
|
|
686
|
+
};
|
|
687
|
+
tabRecipientRef.current[nextTab] = storedNextRecipient;
|
|
688
|
+
handleSetFromToken(nextFromToken);
|
|
689
|
+
handleSetToToken(nextToToken);
|
|
690
|
+
setDestinationAddressOverride(storedNextRecipient.override);
|
|
691
|
+
setCustomToAddress(storedNextRecipient.custom);
|
|
692
|
+
if (nextTab === 'buy' &&
|
|
693
|
+
multiWalletSupportEnabled &&
|
|
694
|
+
linkedWallets &&
|
|
695
|
+
linkedWallets.length > 0 &&
|
|
696
|
+
!storedNextRecipient.override &&
|
|
697
|
+
!storedNextRecipient.custom) {
|
|
698
|
+
const toChain = relayClient?.chains?.find((c) => c.id === nextToToken?.chainId);
|
|
699
|
+
if (toChain) {
|
|
700
|
+
const compatibleWallets = linkedWallets.filter((wallet) => {
|
|
701
|
+
return wallet.vmType === toChain.vmType;
|
|
702
|
+
});
|
|
703
|
+
if (compatibleWallets.length > 0) {
|
|
704
|
+
setDestinationAddressOverride(compatibleWallets[0].address);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
setAmountInputValue('');
|
|
709
|
+
setAmountOutputValue('');
|
|
710
|
+
setUsdInputValue('');
|
|
711
|
+
setUsdOutputValue('');
|
|
712
|
+
setTokenInputCache('');
|
|
713
|
+
setIsUsdInputMode(false);
|
|
714
|
+
debouncedAmountInputControls.cancel();
|
|
715
|
+
debouncedAmountOutputControls.cancel();
|
|
716
|
+
setOriginAddressOverride(undefined);
|
|
717
|
+
}
|
|
718
|
+
setActiveTab(nextTab);
|
|
719
|
+
const desiredTradeType = nextTab === 'buy' ? 'EXPECTED_OUTPUT' : 'EXACT_INPUT';
|
|
720
|
+
if (tradeType !== desiredTradeType) {
|
|
721
|
+
setTradeType(desiredTradeType);
|
|
722
|
+
}
|
|
723
|
+
onAnalyticEvent?.('TAB_SWITCHED', {
|
|
724
|
+
tab: value
|
|
725
|
+
});
|
|
726
|
+
}, children: (0, jsx_runtime_1.jsxs)(index_js_1.Flex, { direction: "column", css: {
|
|
727
|
+
width: '100%',
|
|
728
|
+
overflow: 'hidden',
|
|
729
|
+
border: 'widget-border',
|
|
730
|
+
minWidth: 300,
|
|
731
|
+
maxWidth: 408
|
|
732
|
+
}, children: [(0, jsx_runtime_1.jsxs)(Tabs_js_1.TabsList, { css: {
|
|
733
|
+
backgroundColor: 'transparent',
|
|
734
|
+
p: '0',
|
|
735
|
+
mb: '2'
|
|
736
|
+
}, children: [(0, jsx_runtime_1.jsx)(Tabs_js_1.TabsTrigger, { value: "buy", css: {
|
|
737
|
+
padding: '12px',
|
|
738
|
+
background: 'none',
|
|
739
|
+
border: '1px solid transparent',
|
|
740
|
+
color: 'gray11',
|
|
741
|
+
'&[data-state="active"]': {
|
|
742
|
+
background: 'white',
|
|
743
|
+
borderRadius: '12px',
|
|
744
|
+
borderColor: 'slate.4',
|
|
745
|
+
color: 'gray12'
|
|
746
|
+
},
|
|
747
|
+
'&:not([data-state="active"])': {
|
|
748
|
+
_hover: {
|
|
749
|
+
backgroundColor: 'transparent !important'
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
_dark: {
|
|
753
|
+
'&[data-state="active"]': {
|
|
754
|
+
background: 'gray1',
|
|
755
|
+
borderColor: 'gray.4'
|
|
756
|
+
},
|
|
757
|
+
'&:not([data-state="active"])': {
|
|
758
|
+
_hover: {
|
|
759
|
+
backgroundColor: 'transparent !important'
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}, children: (0, jsx_runtime_1.jsx)(index_js_1.Text, { style: "subtitle1", children: "Buy" }) }), (0, jsx_runtime_1.jsx)(Tabs_js_1.TabsTrigger, { value: "sell", css: {
|
|
764
|
+
padding: '12px',
|
|
765
|
+
background: 'none',
|
|
766
|
+
border: '1px solid transparent',
|
|
767
|
+
color: 'gray11',
|
|
768
|
+
'&[data-state="active"]': {
|
|
769
|
+
background: 'white',
|
|
770
|
+
borderRadius: '12px',
|
|
771
|
+
borderColor: 'slate.4',
|
|
772
|
+
color: 'gray12'
|
|
773
|
+
},
|
|
774
|
+
'&:not([data-state="active"])': {
|
|
775
|
+
_hover: {
|
|
776
|
+
backgroundColor: 'transparent !important'
|
|
777
|
+
}
|
|
778
|
+
},
|
|
779
|
+
_dark: {
|
|
780
|
+
'&[data-state="active"]': {
|
|
781
|
+
background: 'gray1',
|
|
782
|
+
borderColor: 'gray.4'
|
|
783
|
+
},
|
|
784
|
+
'&:not([data-state="active"])': {
|
|
785
|
+
_hover: {
|
|
786
|
+
backgroundColor: 'transparent !important'
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}, children: "Sell" })] }), (0, jsx_runtime_1.jsx)(BuyTabContent_js_1.default, { slippageTolerance: localSlippageTolerance,
|
|
791
|
+
onOpenSlippageConfig: handleOpenSlippageConfig,
|
|
792
|
+
onSlippageToleranceChange: handleSlippageToleranceChange,
|
|
793
|
+
isUsdInputMode,
|
|
794
|
+
usdOutputValue,
|
|
795
|
+
tradeType,
|
|
796
|
+
amountOutputValue,
|
|
797
|
+
amountInputValue,
|
|
798
|
+
outputAmountUsd,
|
|
799
|
+
setUsdOutputValue,
|
|
800
|
+
setTradeType,
|
|
801
|
+
setAmountOutputValue,
|
|
802
|
+
setAmountInputValue,
|
|
803
|
+
setUsdInputValue,
|
|
804
|
+
toggleInputMode,
|
|
805
|
+
debouncedAmountOutputControls,
|
|
806
|
+
toToken,
|
|
807
|
+
fromToken,
|
|
808
|
+
quote,
|
|
809
|
+
isFetchingQuote,
|
|
810
|
+
isLoadingToTokenPrice,
|
|
811
|
+
toTokenPriceData,
|
|
812
|
+
handleSetFromToken,
|
|
813
|
+
handleSetToToken,
|
|
814
|
+
feeBreakdown,
|
|
815
|
+
isLoadingFromBalance,
|
|
816
|
+
fromBalance,
|
|
817
|
+
fromBalancePending,
|
|
818
|
+
toBalance,
|
|
819
|
+
isLoadingToBalance,
|
|
820
|
+
toBalancePending,
|
|
821
|
+
hasInsufficientBalance,
|
|
822
|
+
address,
|
|
823
|
+
multiWalletSupportEnabled,
|
|
824
|
+
linkedWallets,
|
|
825
|
+
onSetPrimaryWallet,
|
|
826
|
+
setOriginAddressOverride,
|
|
827
|
+
onConnectWallet,
|
|
828
|
+
onLinkNewWallet,
|
|
829
|
+
disablePasteWalletAddressOption,
|
|
830
|
+
setAddressModalOpen,
|
|
831
|
+
fromChain,
|
|
832
|
+
toChain,
|
|
833
|
+
toChainWalletVMSupported,
|
|
834
|
+
fromChainWalletVMSupported,
|
|
835
|
+
supportedWalletVMs,
|
|
836
|
+
recipient,
|
|
837
|
+
setCustomToAddress,
|
|
838
|
+
setDestinationAddressOverride,
|
|
839
|
+
isValidToAddress,
|
|
840
|
+
isRecipientLinked,
|
|
841
|
+
toDisplayName,
|
|
842
|
+
isValidFromAddress,
|
|
843
|
+
recipientWalletSupportsChain,
|
|
844
|
+
recipientLinkedWallet,
|
|
845
|
+
lockToToken,
|
|
846
|
+
lockFromToken,
|
|
847
|
+
isSingleChainLocked,
|
|
848
|
+
lockChainId,
|
|
849
|
+
popularChainIds,
|
|
850
|
+
transactionModalOpen,
|
|
851
|
+
depositAddressModalOpen,
|
|
852
|
+
error,
|
|
853
|
+
isInsufficientLiquidityError,
|
|
854
|
+
isSameCurrencySameRecipientSwap,
|
|
855
|
+
isCapacityExceededError,
|
|
856
|
+
isCouldNotExecuteError,
|
|
857
|
+
supportsExternalLiquidity,
|
|
858
|
+
showHighPriceImpactWarning,
|
|
859
|
+
disableSwapButton: promptSwitchRoute,
|
|
860
|
+
onPrimaryAction: handlePrimaryAction,
|
|
861
|
+
debouncedInputAmountValue,
|
|
862
|
+
debouncedOutputAmountValue,
|
|
863
|
+
timeEstimate,
|
|
864
|
+
relayerFeeProportion,
|
|
865
|
+
highRelayerServiceFee,
|
|
866
|
+
onAnalyticEvent,
|
|
867
|
+
toChainVmType: toChain?.vmType,
|
|
868
|
+
ctaCopy }), (0, jsx_runtime_1.jsx)(SellTabContent_js_1.default, { slippageTolerance: localSlippageTolerance,
|
|
869
|
+
onOpenSlippageConfig: handleOpenSlippageConfig,
|
|
870
|
+
onSlippageToleranceChange: handleSlippageToleranceChange,
|
|
871
|
+
disableInputAutoFocus,
|
|
872
|
+
isUsdInputMode,
|
|
873
|
+
usdInputValue,
|
|
874
|
+
tradeType,
|
|
875
|
+
amountInputValue,
|
|
876
|
+
amountOutputValue,
|
|
877
|
+
conversionRate,
|
|
878
|
+
inputAmountUsd,
|
|
879
|
+
setUsdInputValue,
|
|
880
|
+
setTradeType,
|
|
881
|
+
setTokenInputCache,
|
|
882
|
+
setAmountInputValue,
|
|
883
|
+
setAmountOutputValue,
|
|
884
|
+
setUsdOutputValue,
|
|
885
|
+
toggleInputMode,
|
|
886
|
+
debouncedAmountInputControls,
|
|
887
|
+
fromToken,
|
|
888
|
+
toToken,
|
|
889
|
+
quote,
|
|
890
|
+
isFetchingQuote,
|
|
891
|
+
fromTokenPriceData,
|
|
892
|
+
isLoadingFromTokenPrice,
|
|
893
|
+
handleSetFromToken,
|
|
894
|
+
handleSetToToken,
|
|
895
|
+
feeBreakdown,
|
|
896
|
+
fromBalance,
|
|
897
|
+
isLoadingFromBalance,
|
|
898
|
+
toBalance,
|
|
899
|
+
isLoadingToBalance,
|
|
900
|
+
toBalancePending,
|
|
901
|
+
hasInsufficientBalance,
|
|
902
|
+
fromBalancePending,
|
|
903
|
+
address,
|
|
904
|
+
multiWalletSupportEnabled,
|
|
905
|
+
linkedWallets,
|
|
906
|
+
onSetPrimaryWallet,
|
|
907
|
+
setOriginAddressOverride,
|
|
908
|
+
onConnectWallet,
|
|
909
|
+
onLinkNewWallet,
|
|
910
|
+
disablePasteWalletAddressOption,
|
|
911
|
+
setAddressModalOpen,
|
|
912
|
+
fromChain,
|
|
913
|
+
toChain,
|
|
914
|
+
fromChainWalletVMSupported,
|
|
915
|
+
toChainWalletVMSupported,
|
|
916
|
+
supportedWalletVMs,
|
|
917
|
+
recipient,
|
|
918
|
+
setCustomToAddress,
|
|
919
|
+
setDestinationAddressOverride,
|
|
920
|
+
isValidToAddress,
|
|
921
|
+
isRecipientLinked,
|
|
922
|
+
toDisplayName,
|
|
923
|
+
isValidFromAddress,
|
|
924
|
+
recipientWalletSupportsChain,
|
|
925
|
+
recipientLinkedWallet,
|
|
926
|
+
lockToToken,
|
|
927
|
+
lockFromToken,
|
|
928
|
+
isSingleChainLocked,
|
|
929
|
+
lockChainId,
|
|
930
|
+
popularChainIds,
|
|
931
|
+
transactionModalOpen,
|
|
932
|
+
depositAddressModalOpen,
|
|
933
|
+
error,
|
|
934
|
+
isInsufficientLiquidityError,
|
|
935
|
+
isSameCurrencySameRecipientSwap,
|
|
936
|
+
isCapacityExceededError,
|
|
937
|
+
isCouldNotExecuteError,
|
|
938
|
+
supportsExternalLiquidity,
|
|
939
|
+
showHighPriceImpactWarning,
|
|
940
|
+
disableSwapButton: promptSwitchRoute,
|
|
941
|
+
onPrimaryAction: handlePrimaryAction,
|
|
942
|
+
debouncedInputAmountValue,
|
|
943
|
+
debouncedOutputAmountValue,
|
|
944
|
+
percentOptions: percentageOptions,
|
|
945
|
+
onMaxAmountClicked: handleMaxAmountClicked,
|
|
946
|
+
publicClient,
|
|
947
|
+
isFromNative,
|
|
948
|
+
getFeeBufferAmount: nativeMaxAmount_js_1.getFeeBufferAmount,
|
|
949
|
+
timeEstimate,
|
|
950
|
+
relayerFeeProportion,
|
|
951
|
+
highRelayerServiceFee,
|
|
952
|
+
onAnalyticEvent,
|
|
953
|
+
toChainVmType: toChain?.vmType,
|
|
954
|
+
ctaCopy }), promptSwitchRoute ? ((0, jsx_runtime_1.jsx)(index_js_1.Button, { color: "primary", cta: true, css: { flexGrow: '1', justifyContent: 'center' }, onClick: () => {
|
|
955
|
+
setUseExternalLiquidity(true);
|
|
956
|
+
onAnalyticEvent?.(events_js_1.EventNames.CTA_SWITCH_ROUTE_CLICKED);
|
|
957
|
+
}, children: "Switch Route" })) : null] }) }) }));
|
|
958
|
+
} }), (0, jsx_runtime_1.jsx)(UnverifiedTokenModal_js_1.UnverifiedTokenModal, { open: unverifiedTokens.length > 0, onOpenChange: () => { }, data: unverifiedTokens.length > 0 ? unverifiedTokens[0] : undefined, onDecline: (token, context) => {
|
|
959
|
+
const tokens = unverifiedTokens.filter((unverifiedToken) => !(unverifiedToken.context === context &&
|
|
960
|
+
unverifiedToken.token.address === token?.address &&
|
|
961
|
+
unverifiedToken.token.chainId === token?.chainId));
|
|
962
|
+
setUnverifiedTokens(tokens);
|
|
963
|
+
}, onAcceptToken: (token, context) => {
|
|
964
|
+
if (token) {
|
|
965
|
+
if (context === 'to') {
|
|
966
|
+
onAnalyticEvent?.(events_js_1.EventNames.SWAP_TOKEN_SELECT, {
|
|
967
|
+
direction: 'output',
|
|
968
|
+
token_symbol: token.symbol
|
|
969
|
+
});
|
|
970
|
+
if (token.address === fromToken?.address &&
|
|
971
|
+
token.chainId === fromToken?.chainId &&
|
|
972
|
+
address === recipient &&
|
|
973
|
+
(!lockToToken || !fromToken)) {
|
|
974
|
+
handleSetToToken(fromToken);
|
|
975
|
+
handleSetFromToken(toToken);
|
|
976
|
+
}
|
|
977
|
+
else {
|
|
978
|
+
handleSetToToken(token);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
else if (context === 'from') {
|
|
982
|
+
onAnalyticEvent?.(events_js_1.EventNames.SWAP_TOKEN_SELECT, {
|
|
983
|
+
direction: 'input',
|
|
984
|
+
token_symbol: token.symbol
|
|
985
|
+
});
|
|
986
|
+
if (token.address === toToken?.address &&
|
|
987
|
+
token.chainId === toToken?.chainId &&
|
|
988
|
+
address === recipient &&
|
|
989
|
+
(!lockToToken || !fromToken)) {
|
|
990
|
+
handleSetFromToken(toToken);
|
|
991
|
+
handleSetToToken(fromToken);
|
|
992
|
+
}
|
|
993
|
+
else {
|
|
994
|
+
handleSetFromToken(token);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
const tokens = unverifiedTokens.filter((unverifiedToken) => !(unverifiedToken.token.address === token?.address &&
|
|
999
|
+
unverifiedToken.token.chainId === token?.chainId));
|
|
1000
|
+
setUnverifiedTokens(tokens);
|
|
1001
|
+
} })] }));
|
|
1002
|
+
} }));
|
|
1003
|
+
};
|
|
1004
|
+
exports.default = TokenWidget;
|
|
1005
|
+
//# sourceMappingURL=index.js.map
|