@ensofinance/checkout-widget 0.0.12 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checkout-widget.es.js +14486 -13826
- package/dist/checkout-widget.es.js.map +1 -1
- package/dist/checkout-widget.umd.js +44 -43
- package/dist/checkout-widget.umd.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/orval.config.ts +40 -6
- package/package.json +1 -1
- package/src/components/BridgeFee.tsx +3 -3
- package/src/components/Checkout.tsx +5 -53
- package/src/components/ExchangeConfirmSecurity.tsx +16 -3
- package/src/components/QuoteParameters.tsx +84 -65
- package/src/components/TransactionDetailRow.tsx +6 -5
- package/src/components/cards/AssetCard.tsx +2 -2
- package/src/components/cards/OptionCard.tsx +2 -0
- package/src/components/steps/ExchangeFlow.tsx +414 -135
- package/src/components/steps/{InitialStep.tsx → FlowSelector.tsx} +76 -33
- package/src/components/steps/WalletFlow/WalletAmountStep.tsx +214 -0
- package/src/components/steps/{WalletConfirmStep.tsx → WalletFlow/WalletConfirmStep.tsx} +107 -156
- package/src/components/steps/WalletFlow/WalletFlow.tsx +116 -0
- package/src/components/steps/{QuoteStep.tsx → WalletFlow/WalletQuoteStep.tsx} +9 -58
- package/src/components/steps/WalletFlow/WalletTokenStep.tsx +75 -0
- package/src/components/ui/index.tsx +0 -3
- package/src/enso-api/api.ts +192 -3
- package/src/enso-api/custom-instance.ts +1 -0
- package/src/enso-api/index.ts +29 -118
- package/src/enso-api/model/approveActionDto.ts +17 -0
- package/src/enso-api/model/approveArgsDto.ts +22 -0
- package/src/enso-api/model/approveArgsDtoAmount.ts +16 -0
- package/src/enso-api/model/balanceActionDto.ts +17 -0
- package/src/enso-api/model/balanceArgsDto.ts +15 -0
- package/src/enso-api/model/borrowActionDto.ts +18 -0
- package/src/enso-api/model/borrowArgsDto.ts +22 -0
- package/src/enso-api/model/borrowArgsDtoAmountOut.ts +16 -0
- package/src/enso-api/model/bridgeActionDto.ts +19 -0
- package/src/enso-api/model/bridgeArgsDto.ts +29 -0
- package/src/enso-api/model/bridgeArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/bridgeArgsDtoCallbackItem.ts +64 -0
- package/src/enso-api/model/bundleControllerBundleShortcutTransactionBodyItem.ts +69 -0
- package/src/enso-api/model/callActionDto.ts +18 -0
- package/src/enso-api/model/callArgsDto.ts +29 -0
- package/src/enso-api/model/callArgsDtoArgsItem.ts +17 -0
- package/src/enso-api/model/callArgsDtoArgsItemAnyOf.ts +12 -0
- package/src/enso-api/model/callArgsDtoValue.ts +16 -0
- package/src/enso-api/model/callOutput.ts +15 -0
- package/src/enso-api/model/depositActionDto.ts +18 -0
- package/src/enso-api/model/depositArgsDto.ts +28 -0
- package/src/enso-api/model/depositArgsDtoAmountIn.ts +20 -0
- package/src/enso-api/model/depositArgsDtoAmountInOneOfItem.ts +13 -0
- package/src/enso-api/model/depositArgsDtoTokenIn.ts +15 -0
- package/src/enso-api/model/depositArgsDtoTokenOut.ts +15 -0
- package/src/enso-api/model/depositCLMMActionDto.ts +18 -0
- package/src/enso-api/model/depositCLMMArgsDto.ts +30 -0
- package/src/enso-api/model/depositCLMMArgsDtoAmountInItem.ts +17 -0
- package/src/enso-api/model/depositCLMMArgsDtoAmountInItemAnyOf.ts +12 -0
- package/src/enso-api/model/ensoFeeActionDto.ts +17 -0
- package/src/enso-api/model/ensoFeeArgsDto.ts +20 -0
- package/src/enso-api/model/ensoFeeArgsDtoAmount.ts +16 -0
- package/src/enso-api/model/feeActionDto.ts +17 -0
- package/src/enso-api/model/feeArgsDto.ts +22 -0
- package/src/enso-api/model/feeArgsDtoAmount.ts +16 -0
- package/src/enso-api/model/harvestActionDto.ts +19 -0
- package/src/enso-api/model/harvestArgsDto.ts +17 -0
- package/src/enso-api/model/index.ts +115 -4
- package/src/enso-api/model/mergeActionDto.ts +17 -0
- package/src/enso-api/model/mergeArgsDto.ts +22 -0
- package/src/enso-api/model/mergeArgsDtoAmountInItem.ts +13 -0
- package/src/enso-api/model/minAmountOutActionDto.ts +17 -0
- package/src/enso-api/model/minAmountOutArgsDto.ts +19 -0
- package/src/enso-api/model/minAmountOutArgsDtoAmountOut.ts +16 -0
- package/src/enso-api/model/minAmountOutArgsDtoMinAmountOut.ts +16 -0
- package/src/enso-api/model/multiDepositActionDto.ts +18 -0
- package/src/enso-api/model/multiDepositArgsDto.ts +24 -0
- package/src/enso-api/model/multiDepositArgsDtoAmountInItem.ts +17 -0
- package/src/enso-api/model/multiDepositArgsDtoAmountInItemAnyOf.ts +12 -0
- package/src/enso-api/model/multiOutSingleDepositActionDto.ts +18 -0
- package/src/enso-api/model/multiOutSingleDepositArgsDto.ts +24 -0
- package/src/enso-api/model/multiOutSingleDepositArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/multiRedeemActionDto.ts +18 -0
- package/src/enso-api/model/multiRedeemArgs2Dto.ts +24 -0
- package/src/enso-api/model/multiRedeemArgs2DtoAmountIn.ts +16 -0
- package/src/enso-api/model/nontokenizedControllerRouteNontokenizedShorcutTransactionParams.ts +8 -0
- package/src/enso-api/model/nontokenizedControllerRouteNontokenizedShorcutTransactionRoutingStrategy.ts +1 -0
- package/src/enso-api/model/nontokenizedRouteShortcutTransaction.ts +31 -0
- package/src/enso-api/model/paymasterFeeActionDto.ts +17 -0
- package/src/enso-api/model/paymasterFeeArgsDto.ts +18 -0
- package/src/enso-api/model/paymasterFeeArgsDtoAmount.ts +16 -0
- package/src/enso-api/model/permitTransferFromActionDto.ts +18 -0
- package/src/enso-api/model/permitTransferFromArgsDto.ts +29 -0
- package/src/enso-api/model/permitTransferFromArgsDtoAmount.ts +20 -0
- package/src/enso-api/model/permitTransferFromArgsDtoAmountOneOfItem.ts +13 -0
- package/src/enso-api/model/permitTransferFromArgsDtoToken.ts +15 -0
- package/src/enso-api/model/positionModel.ts +14 -0
- package/src/enso-api/model/redeemActionDto.ts +18 -0
- package/src/enso-api/model/redeemArgsDto.ts +25 -0
- package/src/enso-api/model/redeemArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/redeemArgsDtoTokenOut.ts +15 -0
- package/src/enso-api/model/redeemCLMMActionDto.ts +18 -0
- package/src/enso-api/model/redeemCLMMArgsDto.ts +24 -0
- package/src/enso-api/model/redeemCLMMArgsDtoLiquidity.ts +16 -0
- package/src/enso-api/model/repayActionDto.ts +18 -0
- package/src/enso-api/model/repayArgsDto.ts +22 -0
- package/src/enso-api/model/repayArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/routeActionDto.ts +20 -0
- package/src/enso-api/model/routeArgsDto.ts +38 -0
- package/src/enso-api/model/routeArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/singleDepositActionDto.ts +18 -0
- package/src/enso-api/model/singleDepositArgsDto.ts +24 -0
- package/src/enso-api/model/singleDepositArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/singleRedeemActionDto.ts +18 -0
- package/src/enso-api/model/singleRedeemArgs2Dto.ts +24 -0
- package/src/enso-api/model/singleRedeemArgs2DtoAmountIn.ts +16 -0
- package/src/enso-api/model/slippageActionDto.ts +17 -0
- package/src/enso-api/model/slippageArgsDto.ts +18 -0
- package/src/enso-api/model/slippageArgsDtoAmountOut.ts +16 -0
- package/src/enso-api/model/splitActionDto.ts +17 -0
- package/src/enso-api/model/splitArgsDto.ts +22 -0
- package/src/enso-api/model/splitArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/swapActionDto.ts +18 -0
- package/src/enso-api/model/swapArgsDto.ts +30 -0
- package/src/enso-api/model/swapArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/tokenizedMultiDepositActionDto.ts +18 -0
- package/src/enso-api/model/tokenizedMultiDepositArgsDto.ts +24 -0
- package/src/enso-api/model/tokenizedMultiDepositArgsDtoAmountInItem.ts +17 -0
- package/src/enso-api/model/tokenizedMultiDepositArgsDtoAmountInItemAnyOf.ts +14 -0
- package/src/enso-api/model/tokenizedMultiRedeemActionDto.ts +18 -0
- package/src/enso-api/model/tokenizedMultiRedeemArgsDto.ts +24 -0
- package/src/enso-api/model/tokenizedMultiRedeemArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/tokenizedSingleDepositActionDto.ts +18 -0
- package/src/enso-api/model/tokenizedSingleDepositArgsDto.ts +24 -0
- package/src/enso-api/model/tokenizedSingleDepositArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/tokenizedSingleRedeemActionDto.ts +18 -0
- package/src/enso-api/model/tokenizedSingleRedeemArgsDto.ts +24 -0
- package/src/enso-api/model/tokenizedSingleRedeemArgsDtoAmountIn.ts +16 -0
- package/src/enso-api/model/tokensControllerTokensLiquidityType.ts +19 -0
- package/src/enso-api/model/tokensControllerTokensParams.ts +6 -0
- package/src/enso-api/model/transferActionDto.ts +18 -0
- package/src/enso-api/model/transferArgsDto.ts +22 -0
- package/src/enso-api/model/transferArgsDtoAmount.ts +16 -0
- package/src/enso-api/model/transferFromActionDto.ts +18 -0
- package/src/enso-api/model/transferFromArgsDto.ts +24 -0
- package/src/enso-api/model/transferFromArgsDtoAmount.ts +16 -0
- package/src/index.ts +1 -0
- package/src/store.ts +13 -5
- package/src/types/index.ts +9 -3
- package/src/util/common.tsx +4 -1
- package/src/util/enso-hooks.tsx +137 -14
- package/src/util/wallet.tsx +2 -69
- package/src/components/steps/WalletAmountStep.tsx +0 -267
- package/src/components/steps/WalletTokenStep.tsx +0 -128
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box, Icon, Skeleton } from "@chakra-ui/react";
|
|
2
2
|
import { X } from "lucide-react";
|
|
3
|
-
import { useContext, useMemo } from "react";
|
|
3
|
+
import { useContext, useMemo, useState } from "react";
|
|
4
4
|
import { useAccount } from "wagmi";
|
|
5
5
|
import { IconButton } from "../ui";
|
|
6
6
|
import {
|
|
@@ -16,18 +16,33 @@ import Modal from "../modal";
|
|
|
16
16
|
import { CheckoutContext } from "../Checkout";
|
|
17
17
|
import { WalletCard, OptionCard } from "../cards";
|
|
18
18
|
import { WalletStatus } from "../cards/WalletCard";
|
|
19
|
-
import { useWalletIcon } from "@/util/enso-hooks";
|
|
20
|
-
import
|
|
19
|
+
import { useWalletIcon, useSmartAccountBalances } from "@/util/enso-hooks";
|
|
20
|
+
import ExchangeFlow, {
|
|
21
|
+
WithdrawalStep,
|
|
22
|
+
EXCHANGE_ICON_BY_TYPE,
|
|
23
|
+
ExchangeToIntegrationType,
|
|
24
|
+
} from "@/components/steps/ExchangeFlow";
|
|
25
|
+
import WalletFlow from "@/components/steps/WalletFlow/WalletFlow";
|
|
21
26
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
const FLOWS = {
|
|
28
|
+
exchangeFlow: ExchangeFlow,
|
|
29
|
+
walletFlow: WalletFlow,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const FlowSelector = () => {
|
|
33
|
+
const { handleClose, enableExchange } = useContext(CheckoutContext);
|
|
34
|
+
const [flow, setFlow] = useState("");
|
|
35
|
+
const [initialStep, setInitialStep] = useState<string | number>("");
|
|
25
36
|
|
|
26
37
|
const { total, isLoading } = useWalletBalance();
|
|
27
38
|
const { address } = useAccount();
|
|
28
39
|
|
|
29
40
|
const { walletIcon, walletDisplayName } = useWalletIcon();
|
|
30
41
|
|
|
42
|
+
// Get smart account balances
|
|
43
|
+
const { total: smartAccountTotal, isLoading: isLoadingSmartAccount } =
|
|
44
|
+
useSmartAccountBalances(1);
|
|
45
|
+
|
|
31
46
|
const formattedBalance = useMemo(() => {
|
|
32
47
|
if (isLoading)
|
|
33
48
|
return (
|
|
@@ -52,7 +67,7 @@ const InitialStep = () => {
|
|
|
52
67
|
delay: string;
|
|
53
68
|
icons: string[];
|
|
54
69
|
flow: string;
|
|
55
|
-
firstStep: string;
|
|
70
|
+
firstStep: string | number;
|
|
56
71
|
disabled?: boolean;
|
|
57
72
|
}[] = [
|
|
58
73
|
// {
|
|
@@ -77,18 +92,51 @@ const InitialStep = () => {
|
|
|
77
92
|
// },
|
|
78
93
|
];
|
|
79
94
|
|
|
80
|
-
if
|
|
95
|
+
// Add Smart Balance option if balance > $20
|
|
96
|
+
if (!isLoadingSmartAccount && smartAccountTotal > 20) {
|
|
97
|
+
options.push({
|
|
98
|
+
id: "smart-balance",
|
|
99
|
+
title: "Smart Account Balance",
|
|
100
|
+
limit: formatUSD(smartAccountTotal),
|
|
101
|
+
delay: "2 min",
|
|
102
|
+
icons: [],
|
|
103
|
+
flow: "exchangeFlow",
|
|
104
|
+
firstStep: WithdrawalStep.ChooseBalanceAsset,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
console.log(
|
|
108
|
+
enableExchange,
|
|
109
|
+
enableExchange.map(
|
|
110
|
+
(integration) => EXCHANGE_ICON_BY_TYPE[integration],
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
if (Array.isArray(enableExchange) && enableExchange.length > 0)
|
|
81
115
|
options.unshift({
|
|
82
|
-
id: "
|
|
116
|
+
id: "exchange",
|
|
83
117
|
title: "Connect Exchange",
|
|
84
118
|
limit: "No Limit",
|
|
85
119
|
delay: "2 min",
|
|
86
|
-
icons:
|
|
120
|
+
icons: enableExchange
|
|
121
|
+
.map(
|
|
122
|
+
(integration) =>
|
|
123
|
+
EXCHANGE_ICON_BY_TYPE[
|
|
124
|
+
ExchangeToIntegrationType[integration]
|
|
125
|
+
],
|
|
126
|
+
)
|
|
127
|
+
.filter(Boolean),
|
|
87
128
|
flow: "exchangeFlow",
|
|
88
|
-
|
|
129
|
+
// Start at ChooseExchange to allow picking among multiple integrations
|
|
130
|
+
firstStep: WithdrawalStep.ChooseExchange,
|
|
89
131
|
});
|
|
90
132
|
return options;
|
|
91
|
-
}, [address,
|
|
133
|
+
}, [address, enableExchange, smartAccountTotal, isLoadingSmartAccount]);
|
|
134
|
+
|
|
135
|
+
const FlowComponent = flow && FLOWS[flow];
|
|
136
|
+
|
|
137
|
+
if (FlowComponent) {
|
|
138
|
+
return <FlowComponent setFlow={setFlow} initialStep={initialStep} />;
|
|
139
|
+
}
|
|
92
140
|
|
|
93
141
|
return (
|
|
94
142
|
<>
|
|
@@ -124,8 +172,7 @@ const InitialStep = () => {
|
|
|
124
172
|
status={WalletStatus.CONNECTED}
|
|
125
173
|
badge={walletDisplayName}
|
|
126
174
|
onClick={() => {
|
|
127
|
-
setFlow("
|
|
128
|
-
setStep("selectToken");
|
|
175
|
+
setFlow("walletFlow");
|
|
129
176
|
}}
|
|
130
177
|
/>
|
|
131
178
|
}
|
|
@@ -135,24 +182,20 @@ const InitialStep = () => {
|
|
|
135
182
|
<>
|
|
136
183
|
<Divider />
|
|
137
184
|
<ListWrapper>
|
|
138
|
-
{OPTIONS.map((option) =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
return optionCard;
|
|
155
|
-
})}
|
|
185
|
+
{OPTIONS.map((option) => (
|
|
186
|
+
<OptionCard
|
|
187
|
+
key={option.id}
|
|
188
|
+
title={option.title}
|
|
189
|
+
limit={option.limit}
|
|
190
|
+
delay={option.delay}
|
|
191
|
+
icons={option.icons}
|
|
192
|
+
onClick={() => {
|
|
193
|
+
if (option.disabled) return;
|
|
194
|
+
setFlow(option.flow);
|
|
195
|
+
setInitialStep(option.firstStep);
|
|
196
|
+
}}
|
|
197
|
+
/>
|
|
198
|
+
))}
|
|
156
199
|
</ListWrapper>
|
|
157
200
|
</>
|
|
158
201
|
)}
|
|
@@ -162,4 +205,4 @@ const InitialStep = () => {
|
|
|
162
205
|
);
|
|
163
206
|
};
|
|
164
207
|
|
|
165
|
-
export default
|
|
208
|
+
export default FlowSelector;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { Box, Icon, Text } from "@chakra-ui/react";
|
|
2
|
+
import { BodyWrapper } from "@/components/ui/styled";
|
|
3
|
+
import { ArrowDownUpIcon } from "lucide-react";
|
|
4
|
+
import { useState, useEffect, useMemo } from "react";
|
|
5
|
+
import { Address } from "viem";
|
|
6
|
+
import { useAppStore } from "@/store";
|
|
7
|
+
import { Button, IconButton, Tab, Input } from "@/components/ui";
|
|
8
|
+
import CurrencySwapDisplay from "@/components/CurrencySwapDisplay";
|
|
9
|
+
import { useEnsoPrice } from "@/enso-api/api";
|
|
10
|
+
import {
|
|
11
|
+
normalizeValue,
|
|
12
|
+
denormalizeValue,
|
|
13
|
+
formatNumber,
|
|
14
|
+
formatUSD,
|
|
15
|
+
} from "@/util";
|
|
16
|
+
import { useTokenBalance } from "@/util/wallet";
|
|
17
|
+
import { useAppDetails } from "@/util/enso-hooks";
|
|
18
|
+
|
|
19
|
+
type InputMode = "usd" | "token";
|
|
20
|
+
|
|
21
|
+
const percentageOptions = [
|
|
22
|
+
{ label: "25%", value: 25 },
|
|
23
|
+
{ label: "50%", value: 50 },
|
|
24
|
+
{ label: "75%", value: 75 },
|
|
25
|
+
{ label: "Max", value: 100 },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const WalletAmountStep = ({ setStep }: { setStep: (step: string) => void }) => {
|
|
29
|
+
const [usdValue, setUsdValue] = useState<string>("10.10");
|
|
30
|
+
// const [tokenAmount, setTokenAmount] = useState<string>("");
|
|
31
|
+
const [inputMode, setInputMode] = useState<InputMode>("usd");
|
|
32
|
+
|
|
33
|
+
const setAmountIn = useAppStore((state) => state.setAmountIn);
|
|
34
|
+
const amountIn = useAppStore((state) => state.amountIn);
|
|
35
|
+
const [initialLoad, setInitialLoad] = useState(true);
|
|
36
|
+
const {
|
|
37
|
+
tokenInData,
|
|
38
|
+
effectiveTokenOutData,
|
|
39
|
+
tokenIn,
|
|
40
|
+
chainIdOut,
|
|
41
|
+
chainIdIn,
|
|
42
|
+
} = useAppDetails();
|
|
43
|
+
|
|
44
|
+
const { data: priceData } = useEnsoPrice(chainIdIn, tokenIn);
|
|
45
|
+
|
|
46
|
+
const tokenValue = useMemo(() => {
|
|
47
|
+
return normalizeValue(amountIn, tokenInData?.decimals);
|
|
48
|
+
}, [amountIn, tokenInData?.decimals]);
|
|
49
|
+
|
|
50
|
+
const balanceIn = useTokenBalance(tokenIn as Address, chainIdIn);
|
|
51
|
+
|
|
52
|
+
// Handle percentage selection
|
|
53
|
+
const handlePercentageSelect = (percent: number) => {
|
|
54
|
+
if (!balanceIn || !priceData || !tokenInData?.decimals) {
|
|
55
|
+
setUsdValue("0.00");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const amountToSet = (
|
|
60
|
+
(BigInt(balanceIn) * BigInt(percent)) /
|
|
61
|
+
BigInt(100)
|
|
62
|
+
).toString();
|
|
63
|
+
|
|
64
|
+
setAmountIn(amountToSet);
|
|
65
|
+
setUsdValue(
|
|
66
|
+
(
|
|
67
|
+
+normalizeValue(amountToSet, tokenInData?.decimals) * priceData
|
|
68
|
+
).toFixed(2),
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (initialLoad && priceData && tokenInData && +balanceIn > 0) {
|
|
74
|
+
setInitialLoad(false);
|
|
75
|
+
handlePercentageSelect(100);
|
|
76
|
+
}
|
|
77
|
+
}, [balanceIn, initialLoad, priceData, tokenInData, balanceIn]);
|
|
78
|
+
|
|
79
|
+
// Handle input change based on current mode
|
|
80
|
+
const handleInputChange = (value: string) => {
|
|
81
|
+
if (inputMode === "usd") {
|
|
82
|
+
const cleanUsd = value.replace("$", "");
|
|
83
|
+
// Clean the input from usd sign
|
|
84
|
+
console.log(cleanUsd, priceData, tokenInData?.decimals);
|
|
85
|
+
setUsdValue(cleanUsd);
|
|
86
|
+
setAmountIn(
|
|
87
|
+
denormalizeValue(
|
|
88
|
+
(parseFloat(cleanUsd) / priceData).toString(),
|
|
89
|
+
tokenInData?.decimals,
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
setAmountIn(denormalizeValue(value, tokenInData?.decimals));
|
|
94
|
+
setUsdValue((parseFloat(value) * priceData).toFixed(2));
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Toggle between USD and token input modes
|
|
99
|
+
const handleToggleMode = () => {
|
|
100
|
+
setInputMode(inputMode === "usd" ? "token" : "usd");
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Get input placeholder and display value
|
|
104
|
+
const getInputDisplay = () => {
|
|
105
|
+
const formattedValue = formatNumber(tokenValue);
|
|
106
|
+
const safeUsdValue = parseFloat(usdValue) > 0 ? usdValue : 0;
|
|
107
|
+
|
|
108
|
+
if (inputMode === "usd") {
|
|
109
|
+
return {
|
|
110
|
+
placeholder: "$10.00",
|
|
111
|
+
displayValue: safeUsdValue ? `$${safeUsdValue}` : "",
|
|
112
|
+
equivalentValue: tokenValue
|
|
113
|
+
? `${formattedValue} ${tokenInData?.symbol}`
|
|
114
|
+
: "—",
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
placeholder: "0.00",
|
|
120
|
+
displayValue: formattedValue,
|
|
121
|
+
equivalentValue: formatUSD(safeUsdValue),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const { placeholder, displayValue, equivalentValue } = getInputDisplay();
|
|
126
|
+
const notEnoughBalance = +balanceIn < +amountIn;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<BodyWrapper>
|
|
130
|
+
<Box display={"flex"} flexDirection={"column"} gap={"8px"}>
|
|
131
|
+
<Box
|
|
132
|
+
display={"flex"}
|
|
133
|
+
flexDirection={"column"}
|
|
134
|
+
gap={"8px"}
|
|
135
|
+
alignItems={"center"}
|
|
136
|
+
padding={"25.5px"}
|
|
137
|
+
>
|
|
138
|
+
{/* Main Input */}
|
|
139
|
+
<Input
|
|
140
|
+
inputMode="decimal"
|
|
141
|
+
marginY={"8px"}
|
|
142
|
+
variant={"text"}
|
|
143
|
+
placeholder={placeholder}
|
|
144
|
+
value={displayValue}
|
|
145
|
+
onChange={(e) => handleInputChange(e.target.value)}
|
|
146
|
+
/>
|
|
147
|
+
|
|
148
|
+
{/* Toggle Button and Equivalent Display */}
|
|
149
|
+
<Box
|
|
150
|
+
display={"flex"}
|
|
151
|
+
gap={"3"}
|
|
152
|
+
alignItems={"center"}
|
|
153
|
+
onClick={handleToggleMode}
|
|
154
|
+
_hover={{ background: "bg.subtle" }}
|
|
155
|
+
cursor={"pointer"}
|
|
156
|
+
borderRadius={"lg"}
|
|
157
|
+
px={"3"}
|
|
158
|
+
>
|
|
159
|
+
<IconButton
|
|
160
|
+
minWidth={"24px"}
|
|
161
|
+
minHeight={"24px"}
|
|
162
|
+
maxWidth={"24px"}
|
|
163
|
+
background={"transparent"}
|
|
164
|
+
>
|
|
165
|
+
<Icon
|
|
166
|
+
as={ArrowDownUpIcon}
|
|
167
|
+
color="gray"
|
|
168
|
+
width={"16px"}
|
|
169
|
+
height={"16px"}
|
|
170
|
+
/>
|
|
171
|
+
</IconButton>
|
|
172
|
+
|
|
173
|
+
{/* Small equivalent value display */}
|
|
174
|
+
<Text fontSize="sm" color="fg.muted">
|
|
175
|
+
{equivalentValue}
|
|
176
|
+
</Text>
|
|
177
|
+
</Box>
|
|
178
|
+
</Box>
|
|
179
|
+
|
|
180
|
+
<Box
|
|
181
|
+
display={"flex"}
|
|
182
|
+
gap={"4px"}
|
|
183
|
+
justifyContent={"center"}
|
|
184
|
+
paddingBottom={"35px"}
|
|
185
|
+
>
|
|
186
|
+
{percentageOptions.map((option) => (
|
|
187
|
+
<Tab
|
|
188
|
+
key={option.label}
|
|
189
|
+
onClick={() => handlePercentageSelect(option.value)}
|
|
190
|
+
>
|
|
191
|
+
{option.label}
|
|
192
|
+
</Tab>
|
|
193
|
+
))}
|
|
194
|
+
</Box>
|
|
195
|
+
</Box>
|
|
196
|
+
|
|
197
|
+
<CurrencySwapDisplay
|
|
198
|
+
tokenOut={effectiveTokenOutData}
|
|
199
|
+
tokenIn={tokenInData}
|
|
200
|
+
chainIdIn={chainIdIn}
|
|
201
|
+
chainIdOut={chainIdOut}
|
|
202
|
+
/>
|
|
203
|
+
|
|
204
|
+
<Button
|
|
205
|
+
onClick={() => setStep("quote")}
|
|
206
|
+
disabled={notEnoughBalance}
|
|
207
|
+
>
|
|
208
|
+
Continue
|
|
209
|
+
</Button>
|
|
210
|
+
</BodyWrapper>
|
|
211
|
+
);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export default WalletAmountStep;
|