@ensofinance/checkout-widget 0.1.8 → 0.1.9
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 +24133 -25422
- package/dist/checkout-widget.umd.js +59 -65
- package/dist/index.d.ts +1 -3
- package/package.json +2 -2
- package/src/assets/usdc.webp +0 -0
- package/src/assets/usdt.webp +0 -0
- package/src/components/AmountInput.tsx +25 -41
- package/src/components/ChakraProvider.tsx +13 -36
- package/src/components/Checkout.tsx +0 -3
- package/src/components/CurrencySwapDisplay.tsx +22 -59
- package/src/components/DepositProcessing.tsx +1 -1
- package/src/components/ExchangeConfirmSecurity.tsx +1 -1
- package/src/components/QuoteParameters.tsx +1 -1
- package/src/components/TransactionDetailRow.tsx +2 -2
- package/src/components/cards/ExchangeCard.tsx +1 -1
- package/src/components/cards/OptionCard.tsx +1 -2
- package/src/components/cards/WalletCard.tsx +1 -1
- package/src/components/modal.tsx +3 -3
- package/src/components/steps/ExchangeFlow.tsx +1404 -231
- package/src/components/steps/FlowSelector.tsx +60 -117
- package/src/components/steps/WalletFlow/WalletAmountStep.tsx +2 -2
- package/src/components/steps/WalletFlow/WalletConfirmStep.tsx +51 -92
- package/src/components/steps/WalletFlow/WalletFlow.tsx +16 -17
- package/src/components/steps/WalletFlow/WalletQuoteStep.tsx +2 -2
- package/src/components/steps/WalletFlow/WalletTokenStep.tsx +4 -6
- package/src/components/ui/index.tsx +6 -23
- package/src/components/ui/toaster.tsx +1 -2
- package/src/types/index.ts +0 -97
- package/src/util/constants.tsx +0 -27
- package/src/util/enso-hooks.tsx +61 -75
- package/dist/checkout-widget.es.js.map +0 -1
- package/dist/checkout-widget.umd.js.map +0 -1
- package/src/assets/providers/alchemypay.svg +0 -21
- package/src/assets/providers/banxa.svg +0 -21
- package/src/assets/providers/binanceconnect.svg +0 -14
- package/src/assets/providers/kryptonim.svg +0 -6
- package/src/assets/providers/mercuryo.svg +0 -21
- package/src/assets/providers/moonpay.svg +0 -14
- package/src/assets/providers/stripe.svg +0 -16
- package/src/assets/providers/swapped.svg +0 -1
- package/src/assets/providers/topper.svg +0 -14
- package/src/assets/providers/transak.svg +0 -21
- package/src/assets/providers/unlimit.svg +0 -21
- package/src/components/steps/CardBuyFlow/CardBuyFlow.tsx +0 -412
- package/src/components/steps/CardBuyFlow/ChooseAmountStep.tsx +0 -352
- package/src/components/steps/CardBuyFlow/OpenWidgetStep.tsx +0 -193
- package/src/components/steps/SmartAccountFlow.tsx +0 -372
- package/src/components/steps/shared/ChooseAmountStep.tsx +0 -325
- package/src/components/steps/shared/SignUserOpStep.tsx +0 -117
- package/src/components/steps/shared/TrackUserOpStep.tsx +0 -625
- package/src/components/steps/shared/exchangeIntegration.ts +0 -19
- package/src/components/steps/shared/types.ts +0 -22
- package/src/components/ui/transitions.tsx +0 -16
- package/src/enso-api/model/bridgeTransactionResponse.ts +0 -37
- package/src/enso-api/model/bridgeTransactionResponseStatus.ts +0 -25
- package/src/enso-api/model/ensoEvent.ts +0 -30
- package/src/enso-api/model/ensoMetadata.ts +0 -23
- package/src/enso-api/model/layerZeroControllerCheckBridgeTransactionParams.ts +0 -21
- package/src/enso-api/model/layerZeroMessageStatus.ts +0 -39
- package/src/enso-api/model/refundDetails.ts +0 -21
- package/src/util/meld-hooks.tsx +0 -533
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Box, Icon, Skeleton, Text } from "@chakra-ui/react";
|
|
2
2
|
import { X, AlertCircle } from "lucide-react";
|
|
3
|
-
import {
|
|
3
|
+
import { useContext, useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { useAccount } from "wagmi";
|
|
5
5
|
import { IconButton } from "../ui";
|
|
6
6
|
import {
|
|
@@ -17,58 +17,29 @@ import { CheckoutContext } from "../Checkout";
|
|
|
17
17
|
import { WalletCard, OptionCard } from "../cards";
|
|
18
18
|
import { WalletStatus } from "../cards/WalletCard";
|
|
19
19
|
import { useWalletIcon, useSmartAccountBalances } from "@/util/enso-hooks";
|
|
20
|
-
import ExchangeFlow
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
import ExchangeFlow, {
|
|
21
|
+
WithdrawalStep,
|
|
22
|
+
EXCHANGE_ICON_BY_TYPE,
|
|
23
|
+
ExchangeToIntegrationType,
|
|
24
|
+
} from "@/components/steps/ExchangeFlow";
|
|
23
25
|
import WalletFlow, {
|
|
24
26
|
WalletFlowStep,
|
|
25
27
|
} from "@/components/steps/WalletFlow/WalletFlow";
|
|
26
|
-
import {
|
|
27
|
-
isMeldCardBuySupportedChain,
|
|
28
|
-
useCountryCode,
|
|
29
|
-
useMeldSupportedCrypto,
|
|
30
|
-
} from "@/util/meld-hooks";
|
|
31
|
-
import { useAppStore } from "@/store";
|
|
32
|
-
import mastercardIcon from "@/assets/mastercard.png";
|
|
33
|
-
import visaIcon from "@/assets/visa.png";
|
|
34
|
-
import {
|
|
35
|
-
ExchangeToIntegrationType,
|
|
36
|
-
EXCHANGE_ICON_BY_TYPE,
|
|
37
|
-
} from "./shared/exchangeIntegration";
|
|
38
|
-
// Card brand icons
|
|
39
|
-
const CARD_ICONS = [mastercardIcon, visaIcon];
|
|
40
|
-
|
|
41
|
-
type FlowLaunchState = {
|
|
42
|
-
flow: string;
|
|
43
|
-
presetAmount?: boolean;
|
|
44
|
-
} | null;
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
limit: string;
|
|
50
|
-
delay: string;
|
|
51
|
-
icons: string[];
|
|
52
|
-
disabled?: boolean;
|
|
53
|
-
} & {
|
|
54
|
-
flow: string;
|
|
55
|
-
firstStep?: number;
|
|
29
|
+
const FLOWS = {
|
|
30
|
+
exchange: ExchangeFlow,
|
|
31
|
+
wallet: WalletFlow,
|
|
56
32
|
};
|
|
57
33
|
|
|
58
34
|
const FlowSelector = () => {
|
|
59
|
-
const { handleClose, enableExchange,
|
|
35
|
+
const { handleClose, enableExchange, enforceFlow } =
|
|
60
36
|
useContext(CheckoutContext);
|
|
61
|
-
const [
|
|
37
|
+
const [flow, setFlow] = useState("");
|
|
38
|
+
const [initialStep, setInitialStep] = useState<string | number>("");
|
|
62
39
|
const [enforceError, setEnforceError] = useState<string | null>(null);
|
|
63
40
|
|
|
64
41
|
const { total, isLoading } = useWalletBalance();
|
|
65
42
|
const { address } = useAccount();
|
|
66
|
-
const chainIdOut = useAppStore((s) => s.chainIdOut);
|
|
67
|
-
const { countryCode } = useCountryCode();
|
|
68
|
-
const { data: supportedCryptos = [] } = useMeldSupportedCrypto({
|
|
69
|
-
countryCode,
|
|
70
|
-
enabled: !!enableCardBuy && !!chainIdOut,
|
|
71
|
-
});
|
|
72
43
|
|
|
73
44
|
const { walletIcon, walletDisplayName } = useWalletIcon();
|
|
74
45
|
|
|
@@ -76,25 +47,6 @@ const FlowSelector = () => {
|
|
|
76
47
|
const { total: smartAccountTotal, isLoading: isLoadingSmartAccount } =
|
|
77
48
|
useSmartAccountBalances(1);
|
|
78
49
|
|
|
79
|
-
// Check if card buy is available for this chain
|
|
80
|
-
const isCardBuyAvailable =
|
|
81
|
-
enableCardBuy &&
|
|
82
|
-
chainIdOut &&
|
|
83
|
-
isMeldCardBuySupportedChain(chainIdOut, supportedCryptos);
|
|
84
|
-
|
|
85
|
-
const handleSetFlow = useCallback((nextFlow: string) => {
|
|
86
|
-
if (!nextFlow) {
|
|
87
|
-
setFlowLaunch(null);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setFlowLaunch({ flow: nextFlow });
|
|
92
|
-
}, []);
|
|
93
|
-
|
|
94
|
-
const handleCardBuyDepositDetected = useCallback(() => {
|
|
95
|
-
setFlowLaunch({ flow: "smart-account", presetAmount: true });
|
|
96
|
-
}, []);
|
|
97
|
-
|
|
98
50
|
// Handle enforceFlow on mount
|
|
99
51
|
useEffect(() => {
|
|
100
52
|
if (!enforceFlow) return;
|
|
@@ -106,15 +58,14 @@ const FlowSelector = () => {
|
|
|
106
58
|
);
|
|
107
59
|
return;
|
|
108
60
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
61
|
+
setFlow("exchange");
|
|
62
|
+
setInitialStep(WithdrawalStep.ChooseExchange);
|
|
112
63
|
} else if (enforceFlow === "wallet") {
|
|
113
64
|
if (address) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
65
|
+
setFlow("wallet");
|
|
66
|
+
setInitialStep(WalletFlowStep.SelectToken);
|
|
117
67
|
}
|
|
68
|
+
// If no address, we'll show the wallet connection prompt in the UI
|
|
118
69
|
}
|
|
119
70
|
}, [enforceFlow, enableExchange, address]);
|
|
120
71
|
|
|
@@ -135,7 +86,37 @@ const FlowSelector = () => {
|
|
|
135
86
|
}, [address]);
|
|
136
87
|
|
|
137
88
|
const OPTIONS = useMemo(() => {
|
|
138
|
-
const options:
|
|
89
|
+
const options: {
|
|
90
|
+
id: string;
|
|
91
|
+
title: string;
|
|
92
|
+
limit: string;
|
|
93
|
+
delay: string;
|
|
94
|
+
icons: string[];
|
|
95
|
+
flow: string;
|
|
96
|
+
firstStep: string | number;
|
|
97
|
+
disabled?: boolean;
|
|
98
|
+
}[] = [
|
|
99
|
+
// {
|
|
100
|
+
// id: "1",
|
|
101
|
+
// title: "Crypto Transfer",
|
|
102
|
+
// limit: address ? "No Limit" : "Connect wallet to proceed",
|
|
103
|
+
// delay: address ? "Instant - 2 min" : "",
|
|
104
|
+
// icons: [RabbyIcon, MetamaskIcon],
|
|
105
|
+
// flow: "mainFlow",
|
|
106
|
+
// firstStep: "selectToken",
|
|
107
|
+
// disabled: !address,
|
|
108
|
+
// },
|
|
109
|
+
// {
|
|
110
|
+
// id: "3",
|
|
111
|
+
// title: "Deposit with card",
|
|
112
|
+
// limit: "$10,000 limit",
|
|
113
|
+
// delay: "5 min",
|
|
114
|
+
// icons: [MastercardIcon, VisaIcon],
|
|
115
|
+
// flow: "",
|
|
116
|
+
// firstStep: "",
|
|
117
|
+
// disabled: true,
|
|
118
|
+
// },
|
|
119
|
+
];
|
|
139
120
|
|
|
140
121
|
// Add Smart Balance option if balance > $20
|
|
141
122
|
if (!isLoadingSmartAccount && smartAccountTotal > 20) {
|
|
@@ -145,12 +126,12 @@ const FlowSelector = () => {
|
|
|
145
126
|
limit: formatUSD(smartAccountTotal),
|
|
146
127
|
delay: "2 min",
|
|
147
128
|
icons: [],
|
|
148
|
-
flow: "
|
|
129
|
+
flow: "exchange",
|
|
130
|
+
firstStep: WithdrawalStep.ChooseBalanceAsset,
|
|
149
131
|
});
|
|
150
132
|
}
|
|
151
133
|
|
|
152
|
-
|
|
153
|
-
if (Array.isArray(enableExchange) && enableExchange.length > 0) {
|
|
134
|
+
if (Array.isArray(enableExchange) && enableExchange.length > 0)
|
|
154
135
|
options.unshift({
|
|
155
136
|
id: "exchange",
|
|
156
137
|
title: "Connect Exchange",
|
|
@@ -165,51 +146,16 @@ const FlowSelector = () => {
|
|
|
165
146
|
)
|
|
166
147
|
.filter(Boolean),
|
|
167
148
|
flow: "exchange",
|
|
149
|
+
// Start at ChooseExchange to allow picking among multiple integrations
|
|
150
|
+
firstStep: WithdrawalStep.ChooseExchange,
|
|
168
151
|
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Add card buy option (MELD)
|
|
172
|
-
if (isCardBuyAvailable) {
|
|
173
|
-
options.push({
|
|
174
|
-
id: "card-buy",
|
|
175
|
-
title: "Buy with Card",
|
|
176
|
-
limit: "$10,000 limit",
|
|
177
|
-
delay: "1-5 min",
|
|
178
|
-
icons: CARD_ICONS,
|
|
179
|
-
flow: "card-buy",
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
152
|
return options;
|
|
184
|
-
}, [
|
|
185
|
-
enableExchange,
|
|
186
|
-
isCardBuyAvailable,
|
|
187
|
-
isLoadingSmartAccount,
|
|
188
|
-
smartAccountTotal,
|
|
189
|
-
]);
|
|
153
|
+
}, [address, enableExchange, smartAccountTotal, isLoadingSmartAccount]);
|
|
190
154
|
|
|
191
|
-
|
|
192
|
-
case "exchange":
|
|
193
|
-
return <ExchangeFlow setFlow={handleSetFlow} />;
|
|
194
|
-
|
|
195
|
-
case "smart-account":
|
|
196
|
-
return (
|
|
197
|
-
<SmartAccountFlow
|
|
198
|
-
setFlow={handleSetFlow}
|
|
199
|
-
presetAmount={flowLaunch.presetAmount}
|
|
200
|
-
/>
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
case "card-buy":
|
|
204
|
-
return (
|
|
205
|
-
<CardBuyFlow
|
|
206
|
-
setFlow={handleSetFlow}
|
|
207
|
-
onCardBuyDepositDetected={handleCardBuyDepositDetected}
|
|
208
|
-
/>
|
|
209
|
-
);
|
|
155
|
+
const FlowComponent = flow && FLOWS[flow];
|
|
210
156
|
|
|
211
|
-
|
|
212
|
-
|
|
157
|
+
if (FlowComponent) {
|
|
158
|
+
return <FlowComponent setFlow={setFlow} initialStep={initialStep} />;
|
|
213
159
|
}
|
|
214
160
|
|
|
215
161
|
// Error state for enforced exchange mode with no exchanges configured
|
|
@@ -329,9 +275,7 @@ const FlowSelector = () => {
|
|
|
329
275
|
status={WalletStatus.CONNECTED}
|
|
330
276
|
badge={walletDisplayName}
|
|
331
277
|
onClick={() => {
|
|
332
|
-
|
|
333
|
-
flow: "wallet",
|
|
334
|
-
});
|
|
278
|
+
setFlow("wallet");
|
|
335
279
|
}}
|
|
336
280
|
/>
|
|
337
281
|
}
|
|
@@ -350,9 +294,8 @@ const FlowSelector = () => {
|
|
|
350
294
|
icons={option.icons}
|
|
351
295
|
onClick={() => {
|
|
352
296
|
if (option.disabled) return;
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
});
|
|
297
|
+
setFlow(option.flow);
|
|
298
|
+
setInitialStep(option.firstStep);
|
|
356
299
|
}}
|
|
357
300
|
/>
|
|
358
301
|
))}
|
|
@@ -10,7 +10,7 @@ import { normalizeValue, denormalizeValue } from "@/util";
|
|
|
10
10
|
import { precisionizeNumber, getPositiveDecimalValue } from "@/util/common";
|
|
11
11
|
import { useTokenBalance } from "@/util/wallet";
|
|
12
12
|
import { useAppDetails } from "@/util/enso-hooks";
|
|
13
|
-
const WalletAmountStep = ({ setStep }: { setStep: (step:
|
|
13
|
+
const WalletAmountStep = ({ setStep }: { setStep: (step: string) => void }) => {
|
|
14
14
|
const [amountInput, setAmountInput] = useState<AmountInputValue>({
|
|
15
15
|
tokenAmount: "",
|
|
16
16
|
usdAmount: "10.10",
|
|
@@ -124,7 +124,7 @@ const WalletAmountStep = ({ setStep }: { setStep: (step: number) => void }) => {
|
|
|
124
124
|
/>
|
|
125
125
|
|
|
126
126
|
<Button
|
|
127
|
-
onClick={() => setStep(
|
|
127
|
+
onClick={() => setStep("quote")}
|
|
128
128
|
disabled={isAmountInvalid}
|
|
129
129
|
>
|
|
130
130
|
Continue
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Box, Table, Text, Image } from "@chakra-ui/react";
|
|
2
|
-
import { useEffect, useState, useMemo, useCallback
|
|
2
|
+
import { useEffect, useState, useMemo, useCallback } from "react";
|
|
3
3
|
import { useAccount } from "wagmi";
|
|
4
|
-
import { useCallsStatus } from "wagmi/experimental";
|
|
5
4
|
import { Address } from "viem";
|
|
6
5
|
import { BodyWrapper } from "@/components/ui/styled";
|
|
7
6
|
import { Button } from "@/components/ui";
|
|
8
7
|
import { CircleTimer } from "@/components/CircleTimer";
|
|
9
8
|
import { TransactionDetailRow } from "@/components/TransactionDetailRow";
|
|
10
9
|
import DepositProcessing from "@/components/DepositProcessing";
|
|
11
|
-
import { useSendTxns, useRouteData, useAppDetails
|
|
10
|
+
import { useSendTxns, useRouteData, useAppDetails } from "@/util/enso-hooks";
|
|
12
11
|
import { compareCaseInsensitive, getChainIcon } from "@/util";
|
|
13
12
|
import { getChainEtherscanUrl } from "@/util/common";
|
|
14
13
|
import { useTrackTx, useTxByHash } from "@/util/tx-tracker";
|
|
@@ -20,7 +19,7 @@ import { ETH_ADDRESS } from "@/util/constants";
|
|
|
20
19
|
import SuccessIcon from "@/assets/success.svg";
|
|
21
20
|
import FailIcon from "@/assets/fail.svg";
|
|
22
21
|
|
|
23
|
-
type TransferStatus = "
|
|
22
|
+
type TransferStatus = "processing" | "success" | "failed" | "idle";
|
|
24
23
|
|
|
25
24
|
const useOperationsCalls = () => {
|
|
26
25
|
const { chainIdIn, tokenIn, amountIn } = useAppDetails();
|
|
@@ -71,18 +70,16 @@ const useOperationsCalls = () => {
|
|
|
71
70
|
const WalletConfirmStep = ({
|
|
72
71
|
setStep,
|
|
73
72
|
}: {
|
|
74
|
-
setStep: (step:
|
|
73
|
+
setStep: (step: string) => void;
|
|
75
74
|
}) => {
|
|
76
75
|
const [status, setStatus] = useState<TransferStatus>("idle");
|
|
77
76
|
const [isTimerFinished, setIsTimerFinished] = useState(false);
|
|
78
77
|
const { address } = useAccount();
|
|
79
78
|
const [trackingHash, setTrackingHash] = useState("");
|
|
80
|
-
const [
|
|
81
|
-
const calledRef = useRef(false);
|
|
79
|
+
const [called, setCalled] = useState(false);
|
|
82
80
|
|
|
83
81
|
const { chainIdIn, chainIdOut } = useAppDetails();
|
|
84
82
|
const { calls } = useOperationsCalls();
|
|
85
|
-
const isCrosschain = chainIdIn !== chainIdOut;
|
|
86
83
|
|
|
87
84
|
const { sendTxns, ready } = useSendTxns({
|
|
88
85
|
calls,
|
|
@@ -90,78 +87,30 @@ const WalletConfirmStep = ({
|
|
|
90
87
|
chainId: chainIdIn,
|
|
91
88
|
});
|
|
92
89
|
|
|
90
|
+
// const [trackingHash, setTrackingHash] = useState("");
|
|
93
91
|
const { track } = useTrackTx();
|
|
94
92
|
|
|
95
|
-
const
|
|
96
|
-
id: bundleId as string,
|
|
97
|
-
query: {
|
|
98
|
-
enabled: !!bundleId,
|
|
99
|
-
refetchInterval: (query) =>
|
|
100
|
-
query.state.data?.status === "success" ? false : 2000,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
if (!callsStatus.data || callsStatus.data.status !== "success") return;
|
|
106
|
-
|
|
107
|
-
const receipt = callsStatus.data.receipts?.[0];
|
|
108
|
-
const hash = receipt?.transactionHash;
|
|
93
|
+
const isCrosschain = chainIdIn !== chainIdOut;
|
|
109
94
|
|
|
110
|
-
|
|
95
|
+
const onTxSend = useCallback(
|
|
96
|
+
(hash: string) => {
|
|
97
|
+
setStatus("processing");
|
|
111
98
|
setTrackingHash(hash);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
setStatus("success");
|
|
129
|
-
}, [callsStatus.data, isCrosschain, chainIdIn, track]);
|
|
130
|
-
|
|
131
|
-
const onStep = useCallback(
|
|
132
|
-
(step: TxStep) => {
|
|
133
|
-
switch (step.type) {
|
|
134
|
-
case "approving":
|
|
135
|
-
setStatus("approving");
|
|
136
|
-
break;
|
|
137
|
-
case "executing":
|
|
138
|
-
setStatus("executing");
|
|
139
|
-
break;
|
|
140
|
-
case "confirmed": {
|
|
141
|
-
setStatus("processing");
|
|
142
|
-
setTrackingHash(step.hash);
|
|
143
|
-
track({
|
|
144
|
-
hash: step.hash as `0x${string}`,
|
|
145
|
-
isActive: true,
|
|
146
|
-
chainId: chainIdIn,
|
|
147
|
-
crosschain: isCrosschain,
|
|
148
|
-
status: isCrosschain
|
|
149
|
-
? "(0/4) Waiting for source transaction completion"
|
|
150
|
-
: "Transaction in progress",
|
|
151
|
-
message: "Transaction confirmed",
|
|
152
|
-
onConfirmed: () => {
|
|
153
|
-
setStatus("success");
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
case "atomic":
|
|
159
|
-
setBundleId(step.bundleId);
|
|
160
|
-
setStatus("processing");
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
99
|
+
track({
|
|
100
|
+
hash: hash as `0x${string}`,
|
|
101
|
+
isActive: true,
|
|
102
|
+
chainId: chainIdIn,
|
|
103
|
+
crosschain: isCrosschain,
|
|
104
|
+
status: isCrosschain
|
|
105
|
+
? "(0/4) Waiting for source transaction completion"
|
|
106
|
+
: "Transaction in progess",
|
|
107
|
+
message: "Transaction confirmed",
|
|
108
|
+
onConfirmed: () => {
|
|
109
|
+
setStatus("success");
|
|
110
|
+
},
|
|
111
|
+
});
|
|
163
112
|
},
|
|
164
|
-
[chainIdIn,
|
|
113
|
+
[chainIdIn, chainIdOut],
|
|
165
114
|
);
|
|
166
115
|
|
|
167
116
|
const onFail = useCallback((error: any) => {
|
|
@@ -171,11 +120,12 @@ const WalletConfirmStep = ({
|
|
|
171
120
|
|
|
172
121
|
// Initiate the transaction when wallet is ready
|
|
173
122
|
useEffect(() => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
sendTxns(
|
|
123
|
+
console.log(called, ready);
|
|
124
|
+
if (!called && ready) {
|
|
125
|
+
sendTxns(onTxSend, onFail);
|
|
126
|
+
setCalled(true);
|
|
177
127
|
}
|
|
178
|
-
}, [ready, sendTxns,
|
|
128
|
+
}, [called, ready, sendTxns, onTxSend]);
|
|
179
129
|
|
|
180
130
|
const handleTimerFinish = () => {
|
|
181
131
|
setIsTimerFinished(true);
|
|
@@ -183,11 +133,14 @@ const WalletConfirmStep = ({
|
|
|
183
133
|
|
|
184
134
|
const handleNewDeposit = () => {
|
|
185
135
|
// Reset to initial step or handle new deposit logic
|
|
186
|
-
setStep(
|
|
136
|
+
setStep("selectToken");
|
|
187
137
|
};
|
|
188
138
|
|
|
189
139
|
const handleRetry = () => {
|
|
190
|
-
|
|
140
|
+
// Reset to previous step to retry the transfer
|
|
141
|
+
// setStatus("processing");
|
|
142
|
+
// setIsTimerFinished(false);
|
|
143
|
+
setStep("quote");
|
|
191
144
|
};
|
|
192
145
|
|
|
193
146
|
const tx = useTxByHash(trackingHash);
|
|
@@ -199,14 +152,26 @@ const WalletConfirmStep = ({
|
|
|
199
152
|
chainId: chainIdIn,
|
|
200
153
|
});
|
|
201
154
|
|
|
155
|
+
// useEffect(() => {
|
|
156
|
+
// if (status === "processing") {
|
|
157
|
+
// // Simulate transfer processing - randomly succeed or fail after timer
|
|
158
|
+
// const timer = setTimeout(() => {
|
|
159
|
+
// const shouldSucceed = Math.random() > 0.3; // 70% success rate for demo
|
|
160
|
+
// setStatus(shouldSucceed ? "success" : "failed");
|
|
161
|
+
// }, 2500); // 2.5 seconds processing time
|
|
162
|
+
|
|
163
|
+
// return () => clearTimeout(timer);
|
|
164
|
+
// }
|
|
165
|
+
// }, [status]);
|
|
166
|
+
|
|
202
167
|
const getStatusColor = () => {
|
|
203
168
|
switch (status) {
|
|
204
169
|
case "success":
|
|
205
|
-
return "
|
|
170
|
+
return "#14AE5C";
|
|
206
171
|
case "failed":
|
|
207
|
-
return "
|
|
172
|
+
return "#E84142";
|
|
208
173
|
default:
|
|
209
|
-
return "
|
|
174
|
+
return "#1E171F";
|
|
210
175
|
}
|
|
211
176
|
};
|
|
212
177
|
|
|
@@ -216,10 +181,6 @@ const WalletConfirmStep = ({
|
|
|
216
181
|
return "Success";
|
|
217
182
|
case "failed":
|
|
218
183
|
return "Failed";
|
|
219
|
-
case "approving":
|
|
220
|
-
return "Approving token access...";
|
|
221
|
-
case "executing":
|
|
222
|
-
return "Confirm transaction in wallet";
|
|
223
184
|
case "idle":
|
|
224
185
|
return "Awaiting wallet approval";
|
|
225
186
|
default:
|
|
@@ -231,8 +192,6 @@ const WalletConfirmStep = ({
|
|
|
231
192
|
switch (status) {
|
|
232
193
|
case "processing":
|
|
233
194
|
case "idle":
|
|
234
|
-
case "approving":
|
|
235
|
-
case "executing":
|
|
236
195
|
return (
|
|
237
196
|
<CircleTimer
|
|
238
197
|
start={status === "processing"}
|
|
@@ -249,7 +208,7 @@ const WalletConfirmStep = ({
|
|
|
249
208
|
>
|
|
250
209
|
<Image
|
|
251
210
|
src={SuccessIcon}
|
|
252
|
-
boxShadow="0px 0px 20px
|
|
211
|
+
boxShadow="0px 0px 20px #14AE5C"
|
|
253
212
|
borderRadius="90%"
|
|
254
213
|
width="58px"
|
|
255
214
|
height="58px"
|
|
@@ -266,7 +225,7 @@ const WalletConfirmStep = ({
|
|
|
266
225
|
>
|
|
267
226
|
<Image
|
|
268
227
|
src={FailIcon}
|
|
269
|
-
boxShadow="0px 0px 20px
|
|
228
|
+
boxShadow="0px 0px 20px #E84142"
|
|
270
229
|
borderRadius="90%"
|
|
271
230
|
width="58px"
|
|
272
231
|
height="58px"
|
|
@@ -9,13 +9,12 @@ import { CheckoutContext } from "@/components/Checkout";
|
|
|
9
9
|
import Modal from "@/components/modal";
|
|
10
10
|
import { IconButton } from "@/components/ui";
|
|
11
11
|
import { HeaderWrapper, HeaderTitle } from "@/components/ui/styled";
|
|
12
|
-
import { AnimatedStep } from "@/components/ui/transitions";
|
|
13
12
|
|
|
14
13
|
export enum WalletFlowStep {
|
|
15
|
-
SelectToken,
|
|
16
|
-
SelectAmount,
|
|
17
|
-
Quote,
|
|
18
|
-
ConfirmTransfer,
|
|
14
|
+
SelectToken = "selectToken",
|
|
15
|
+
SelectAmount = "selectAmount",
|
|
16
|
+
Quote = "quote",
|
|
17
|
+
ConfirmTransfer = "confirmTransfer",
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
const walletSteps = [
|
|
@@ -35,6 +34,10 @@ const WalletFlow = ({
|
|
|
35
34
|
const [currentStep, setCurrentStep] = useState<WalletFlowStep>(initialStep);
|
|
36
35
|
const { handleClose, enforceFlow } = useContext(CheckoutContext);
|
|
37
36
|
|
|
37
|
+
const handleSetStep = (step: WalletFlowStep | string) => {
|
|
38
|
+
setCurrentStep(step as WalletFlowStep);
|
|
39
|
+
};
|
|
40
|
+
|
|
38
41
|
const handleBackClick = () => {
|
|
39
42
|
const index = walletSteps.findIndex((step) => step === currentStep) - 1;
|
|
40
43
|
if (index >= 0) {
|
|
@@ -47,15 +50,15 @@ const WalletFlow = ({
|
|
|
47
50
|
const currentStepComponent = (() => {
|
|
48
51
|
switch (currentStep) {
|
|
49
52
|
case WalletFlowStep.SelectToken:
|
|
50
|
-
return <WalletTokenStep setStep={
|
|
53
|
+
return <WalletTokenStep setStep={handleSetStep} />;
|
|
51
54
|
case WalletFlowStep.SelectAmount:
|
|
52
|
-
return <WalletAmountStep setStep={
|
|
55
|
+
return <WalletAmountStep setStep={handleSetStep} />;
|
|
53
56
|
case WalletFlowStep.Quote:
|
|
54
|
-
return <WalletQuoteStep setStep={
|
|
57
|
+
return <WalletQuoteStep setStep={handleSetStep} />;
|
|
55
58
|
case WalletFlowStep.ConfirmTransfer:
|
|
56
|
-
return <WalletConfirmStep setStep={
|
|
59
|
+
return <WalletConfirmStep setStep={handleSetStep} />;
|
|
57
60
|
default:
|
|
58
|
-
return <WalletTokenStep setStep={
|
|
61
|
+
return <WalletTokenStep setStep={handleSetStep} />;
|
|
59
62
|
}
|
|
60
63
|
})();
|
|
61
64
|
|
|
@@ -75,7 +78,7 @@ const WalletFlow = ({
|
|
|
75
78
|
>
|
|
76
79
|
<Icon
|
|
77
80
|
as={ChevronLeft}
|
|
78
|
-
color="
|
|
81
|
+
color="gray"
|
|
79
82
|
width={"16px"}
|
|
80
83
|
height={"16px"}
|
|
81
84
|
/>
|
|
@@ -102,7 +105,7 @@ const WalletFlow = ({
|
|
|
102
105
|
>
|
|
103
106
|
<Icon
|
|
104
107
|
as={X}
|
|
105
|
-
color="
|
|
108
|
+
color="gray"
|
|
106
109
|
width={"16px"}
|
|
107
110
|
height={"16px"}
|
|
108
111
|
/>
|
|
@@ -110,11 +113,7 @@ const WalletFlow = ({
|
|
|
110
113
|
)}
|
|
111
114
|
</HeaderWrapper>
|
|
112
115
|
</Modal.Header>
|
|
113
|
-
<Modal.Body>
|
|
114
|
-
<AnimatedStep key={currentStep}>
|
|
115
|
-
{currentStepComponent}
|
|
116
|
-
</AnimatedStep>
|
|
117
|
-
</Modal.Body>
|
|
116
|
+
<Modal.Body>{currentStepComponent}</Modal.Body>
|
|
118
117
|
</>
|
|
119
118
|
);
|
|
120
119
|
};
|
|
@@ -7,7 +7,7 @@ import { useAppDetails, useRouteData } from "@/util/enso-hooks";
|
|
|
7
7
|
import { useChainName } from "@/util/common";
|
|
8
8
|
import QuoteParameters from "@/components/QuoteParameters";
|
|
9
9
|
|
|
10
|
-
const WalletQuoteStep = ({ setStep }: { setStep: (step:
|
|
10
|
+
const WalletQuoteStep = ({ setStep }: { setStep: (step: string) => void }) => {
|
|
11
11
|
const { chainIdIn } = useAppDetails();
|
|
12
12
|
|
|
13
13
|
const { routeLoading, usdAmountIn, routeData } = useRouteData();
|
|
@@ -58,7 +58,7 @@ const WalletQuoteStep = ({ setStep }: { setStep: (step: number) => void }) => {
|
|
|
58
58
|
onClick={
|
|
59
59
|
!routeLoading
|
|
60
60
|
? () => {
|
|
61
|
-
setStep(
|
|
61
|
+
setStep("confirmTransfer");
|
|
62
62
|
}
|
|
63
63
|
: () => {}
|
|
64
64
|
}
|
|
@@ -7,7 +7,7 @@ import { useAppStore } from "@/store";
|
|
|
7
7
|
import { useWalletBalance } from "@/enso-api/api";
|
|
8
8
|
import { formatNumber, formatUSD, normalizeValue } from "@/util";
|
|
9
9
|
|
|
10
|
-
const WalletAssetStep = ({ setStep }: { setStep: (step:
|
|
10
|
+
const WalletAssetStep = ({ setStep }: { setStep: (step: string) => void }) => {
|
|
11
11
|
const setSelectedIntegration = useAppStore(
|
|
12
12
|
(state) => state.setSelectedIntegration,
|
|
13
13
|
);
|
|
@@ -21,10 +21,8 @@ const WalletAssetStep = ({ setStep }: { setStep: (step: number) => void }) => {
|
|
|
21
21
|
|
|
22
22
|
const filteredHoldings = holdingsList?.filter(
|
|
23
23
|
(asset) =>
|
|
24
|
-
!(
|
|
25
|
-
|
|
26
|
-
asset.chainId === chainIdOut
|
|
27
|
-
),
|
|
24
|
+
!(asset.token.toLowerCase() === tokenOut.toLowerCase() &&
|
|
25
|
+
asset.chainId === chainIdOut),
|
|
28
26
|
);
|
|
29
27
|
|
|
30
28
|
useEffect(() => {
|
|
@@ -72,7 +70,7 @@ const WalletAssetStep = ({ setStep }: { setStep: (step: number) => void }) => {
|
|
|
72
70
|
</Box>
|
|
73
71
|
<Button
|
|
74
72
|
onClick={() => {
|
|
75
|
-
setStep(
|
|
73
|
+
setStep("selectAmount");
|
|
76
74
|
}}
|
|
77
75
|
disabled={!tokenIn}
|
|
78
76
|
>
|