astra-modal-test 1.0.5 → 1.0.7
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/.github/workflows/code-quality.yml +43 -0
- package/.github/workflows/publish.yml +64 -0
- package/README.md +204 -0
- package/dist/SwapController-CsNqEWIM.js +447 -0
- package/dist/add-Dm_oSEbv.js +19 -0
- package/dist/all-wallets-DfLlzQJ3.js +10 -0
- package/dist/app-store-BMdJkp6P.js +21 -0
- package/dist/apple-BetlVMKw.js +22 -0
- package/dist/arrow-bottom-BddPptxy.js +12 -0
- package/dist/arrow-bottom-circle-CvdJJniv.js +15 -0
- package/dist/arrow-left-Bbq-z1nQ.js +12 -0
- package/dist/arrow-right-Bu4_SVLC.js +12 -0
- package/dist/arrow-top-CynlXB-M.js +12 -0
- package/dist/astra-sdk.es.js +4 -4
- package/dist/bank-B9QscNnS.js +18 -0
- package/dist/bin-v-tshf8_.js +8 -0
- package/dist/bitcoin-C01gkYyN.js +17 -0
- package/dist/browser-9uNaCY31.js +18 -0
- package/dist/card-hKR9lRzU.js +18 -0
- package/dist/{ccip-oZOrZYR9.js → ccip-CUCziAPw.js} +52 -49
- package/dist/checkmark-D1M40aM5.js +15 -0
- package/dist/checkmark-bold-1_UGl24m.js +12 -0
- package/dist/chevron-bottom-BleoRNRL.js +12 -0
- package/dist/chevron-left-C9JMU-3B.js +12 -0
- package/dist/chevron-right-Daue4WBx.js +12 -0
- package/dist/chevron-top-yuXekbUC.js +12 -0
- package/dist/chrome-store-BsUFRR7F.js +65 -0
- package/dist/circle-BCxdhM5X.js +8 -0
- package/dist/clock-7a-DWZQa.js +12 -0
- package/dist/close-DMQYuJ0z.js +12 -0
- package/dist/clsx.m-DCYaa4RU.js +20 -0
- package/dist/coinPlaceholder-DjQ-HnSH.js +12 -0
- package/dist/compass-AMecXNVm.js +12 -0
- package/dist/copy-CgIPGYbU.js +19 -0
- package/dist/cursor-DpYbTNcO.js +7 -0
- package/dist/cursor-transparent-C8iPJkn8.js +16 -0
- package/dist/desktop-BWVQVGng.js +13 -0
- package/dist/disconnect-C6IQRrtF.js +12 -0
- package/dist/discord-gH3i-QsC.js +21 -0
- package/dist/email-BxYwJC5T.js +10 -0
- package/dist/embedded-wallet-DCcVNgkc.js +464 -0
- package/dist/ethereum-CGWsmZaC.js +14 -0
- package/dist/etherscan-D4EFsAJ4.js +10 -0
- package/dist/exclamation-triangle-DNwQ1Xq6.js +8 -0
- package/dist/extension-DxQPsN2z.js +12 -0
- package/dist/external-link-BeEzrdgR.js +12 -0
- package/dist/facebook-B2Ix8_d3.js +30 -0
- package/dist/farcaster-BB83p8dC.js +16 -0
- package/dist/filters-PzdIomB1.js +12 -0
- package/dist/github-gcp1rxX0.js +22 -0
- package/dist/google-Qv9lTZcz.js +22 -0
- package/dist/help-circle-BLXTMjzX.js +16 -0
- package/dist/id-BHg2CRhj.js +16 -0
- package/dist/image-DWi1V30x.js +8 -0
- package/dist/index-4lbsZ6RQ.js +33 -0
- package/dist/index-64U3D9_n.js +21034 -0
- package/dist/index-CRU49I0g.js +15911 -0
- package/dist/index-ChxXyuZj.js +572 -0
- package/dist/index-ClS956E1.js +74511 -0
- package/dist/index-Cs4fWw01.js +386 -0
- package/dist/index-DfWqgW4h.js +709 -0
- package/dist/index-VYNI76FM.js +315 -0
- package/dist/index-qfkTLN90.js +10785 -0
- package/dist/index-r2ztgVN2.js +1060 -0
- package/dist/index-wvh7Yd5J.js +70 -0
- package/dist/info-Bl5tmiBJ.js +7 -0
- package/dist/info-circle-D2uYywg-.js +16 -0
- package/dist/lightbulb-HvXH2AVF.js +7 -0
- package/dist/mail-DXOPfnog.js +12 -0
- package/dist/mobile-Dd0Gj4vZ.js +13 -0
- package/dist/more-DYcnClbB.js +15 -0
- package/dist/network-placeholder-CfRZGQfi.js +18 -0
- package/dist/nftPlaceholder-DHmFkY55.js +12 -0
- package/dist/off-CG2Y30qN.js +8 -0
- package/dist/onramp-DoAMTeNm.js +917 -0
- package/dist/play-store-B5EYBQto.js +36 -0
- package/dist/plus-DPo25_zL.js +17 -0
- package/dist/qr-code-BRTO19PL.js +10 -0
- package/dist/receive-BvclNdV_.js +179 -0
- package/dist/recycle-horizontal-ng_b2eJV.js +13 -0
- package/dist/refresh-3kiwRV0w.js +12 -0
- package/dist/reown-logo-_9cuIfJD.js +16 -0
- package/dist/search-CoJvIxpi.js +12 -0
- package/dist/secp256k1-wZyK2iIX.js +1257 -0
- package/dist/send-BVKGSR-Z.js +19 -0
- package/dist/send-Bkj5YtHe.js +1039 -0
- package/dist/socials-DL42HlL5.js +589 -0
- package/dist/solana-BjP-_Ioa.js +17 -0
- package/dist/swapHorizontal-Do3uBbum.js +12 -0
- package/dist/swapHorizontalBold-D7N75BE-.js +12 -0
- package/dist/swapHorizontalMedium-BahEVO2x.js +20 -0
- package/dist/swapHorizontalRoundedBold-D6Hoi132.js +12 -0
- package/dist/swapVertical-P-fnrADh.js +12 -0
- package/dist/swaps-DZgbVJZ2.js +1713 -0
- package/dist/telegram-DmaL2iB8.js +20 -0
- package/dist/three-dots-oXyAsUA6.js +9 -0
- package/dist/transactions-BjB5yZN7.js +35 -0
- package/dist/twitch-0UGrMr2K.js +22 -0
- package/dist/twitterIcon-B97KAbaJ.js +10 -0
- package/dist/ui-r6nnVhBA.js +812 -0
- package/dist/user-BG1yp56Q.js +7 -0
- package/dist/verify-CgzkMSuV.js +12 -0
- package/dist/verify-filled-D-TRpWtN.js +12 -0
- package/dist/w3m-modal-Drsibcs0.js +1041 -0
- package/dist/wallet-CAHsZdfj.js +12 -0
- package/dist/wallet-placeholder-agbbreqw.js +18 -0
- package/dist/walletconnect-Yd8iXqY9.js +36 -0
- package/dist/warning-circle-C0hqC6h_.js +16 -0
- package/dist/x-mark-D9_ai2sI.js +7 -0
- package/dist/x-z6v1Jegg.js +16 -0
- package/eslint.config.mjs +1 -1
- package/package.json +14 -13
- package/src/apis/lspApi.js +47 -24
- package/src/assets/ln.png +0 -0
- package/src/assets/network/Arbitrum.png +0 -0
- package/src/assets/network/Polygon.png +0 -0
- package/src/assets/network/Solana.png +0 -0
- package/src/assets/network/botanix.png +0 -0
- package/src/assets/network/bsc.svg +13 -0
- package/src/assets/pay.png +0 -0
- package/src/assets/tokens/usdc.png +0 -0
- package/src/assets/tokens/usdt.png +0 -0
- package/src/comps/AstraImage.jsx +17 -3
- package/src/comps/AstraModal.jsx +22 -16
- package/src/comps/AstraModalLogo.jsx +9 -9
- package/src/comps/AstraNetwork.jsx +174 -45
- package/src/comps/CheckErc20Button.jsx +1 -1
- package/src/comps/CommonStyle.jsx +4 -0
- package/src/comps/ConnectButton.jsx +16 -33
- package/src/comps/ResultModal.jsx +45 -39
- package/src/comps/ToLightning.jsx +207 -80
- package/src/comps/ToToken.jsx +278 -217
- package/src/constants/index.js +20 -4
- package/src/hooks/useContract.js +164 -125
- package/src/hooks/useGetMinAndMax.js +48 -0
- package/src/hooks/useLspApi.js +56 -39
- package/src/hooks/useParseInvoice.js +82 -72
- package/src/index.jsx +43 -10
- package/src/main.jsx +36 -5
- package/src/utils/index.js +136 -24
- package/vite.config.js +7 -1
- package/dist/astra-sdk.umd.js +0 -12578
- package/dist/hooks.module-BBZfodGH.js +0 -506
- package/dist/index-BKKAfRrw.js +0 -87520
- package/dist/index-C2MAIRET.js +0 -2929
- package/dist/index-CsRxokSv.js +0 -445
- package/dist/index-DQ6iiHxJ.js +0 -13720
- package/dist/index-SJhlkSif.js +0 -133
- package/dist/w3m-modal-CYJpmgnf.js +0 -267
- package/src/constants/contracts/abi/bridge.js +0 -1281
- package/src/constants/contracts/abi/index.js +0 -3
- package/src/constants/contracts/abi/usdt.js +0 -130
- package/src/constants/contracts/abi/watcher.js +0 -437
- package/src/constants/contracts/index.js +0 -37
package/src/comps/ToToken.jsx
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { memo } from "react";
|
|
2
2
|
import styled from "styled-components";
|
|
3
3
|
import useStore from "../store";
|
|
4
|
-
import { Form, Button, Select, Flex, QRCode, Statistic } from "antd";
|
|
4
|
+
import { Form, Button, Select, Flex, QRCode, Statistic, Spin } from "antd";
|
|
5
5
|
import { useCallback, useEffect, useState, useMemo } from "react";
|
|
6
6
|
import AstraImage from "./AstraImage";
|
|
7
|
-
import { useAccount, useBalance } from "wagmi";
|
|
7
|
+
import { useAccount, useBalance, useSwitchChain } from "wagmi";
|
|
8
8
|
import { DoubleRightOutlined } from "@ant-design/icons";
|
|
9
9
|
import EllipsisMiddle from "./EllipsisMiddle";
|
|
10
10
|
import { useBridgeContract } from "../hooks/useContract";
|
|
11
11
|
import { useGetReserveInfo } from "../hooks/useLspApi";
|
|
12
|
-
import { toEVM, getSignature } from "../apis/lspApi";
|
|
12
|
+
import { toEVM, getSignature, bridgeIntervalStatus } from "../apis/lspApi";
|
|
13
|
+
import { useGetMinAndMax } from "../hooks/useGetMinAndMax";
|
|
13
14
|
import Decimal from "decimal.js";
|
|
14
15
|
import ConnectButton from "./ConnectButton";
|
|
15
|
-
import {
|
|
16
|
+
import { getParsedError, numberWithCommas } from "../utils";
|
|
16
17
|
import AstraNetwork from "./AstraNetwork";
|
|
17
18
|
import IconArrowRight from "../assets/arrow-right.svg";
|
|
19
|
+
import { AvalibleBalance } from "./CommonStyle";
|
|
20
|
+
|
|
18
21
|
const { Countdown } = Statistic;
|
|
19
22
|
const WrapperToLightning = styled.div``;
|
|
20
23
|
|
|
@@ -84,6 +87,7 @@ function ToToken({ messageApi }) {
|
|
|
84
87
|
currentAssetPair,
|
|
85
88
|
onAstraInvoice,
|
|
86
89
|
setAstraModalShow,
|
|
90
|
+
astraModalShow,
|
|
87
91
|
} = useStore();
|
|
88
92
|
|
|
89
93
|
const [sendInvoice, setSendInvoice] = useState("");
|
|
@@ -94,79 +98,84 @@ function ToToken({ messageApi }) {
|
|
|
94
98
|
const [invoiceExpired, setInvoiceExpired] = useState(0);
|
|
95
99
|
const [isInvoiceExpired, setIsInvoiceExpired] = useState(false);
|
|
96
100
|
const [payInvoiceLoading, setPayInvoiceLoading] = useState(false);
|
|
101
|
+
|
|
102
|
+
const { switchChain } = useSwitchChain();
|
|
103
|
+
|
|
97
104
|
const filterdAssetPairs = useMemo(() => {
|
|
98
105
|
return allAssetPairs.filter((pair) => {
|
|
99
106
|
return pair.asset.assetId === sendArgs.assetId;
|
|
100
107
|
});
|
|
101
108
|
}, [allAssetPairs, sendArgs.assetId]);
|
|
102
109
|
// console.log("🚀 ~ ToLightning ~ allAssetPairs:", allAssetPairs, receiveArgs);
|
|
103
|
-
const { reserveInfo } = useGetReserveInfo(
|
|
110
|
+
const { reserveInfo, loading: reserveInfoLoading } = useGetReserveInfo(
|
|
111
|
+
targetNetwork,
|
|
112
|
+
currentAssetPair
|
|
113
|
+
);
|
|
114
|
+
const { min, max, unitName } = useGetMinAndMax("lightningToEvm", reserveInfo);
|
|
115
|
+
const { onDeposit } = useBridgeContract(account);
|
|
104
116
|
|
|
105
117
|
const serviceFee = useMemo(() => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
if (!reserveInfo?.toAssetBaseFee) {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
return new Decimal(reserveInfo?.toAssetBaseFee.toString())
|
|
122
|
+
.div(10 ** 18)
|
|
123
|
+
.toFixed(8)
|
|
124
|
+
.replace(/\.?0+$/, "");
|
|
125
|
+
}, [reserveInfo?.toAssetBaseFee]);
|
|
109
126
|
|
|
110
127
|
const tokenBalanceRet = useBalance({
|
|
111
128
|
address: account?.address,
|
|
112
129
|
token: currentAssetPair?.token?.address,
|
|
113
|
-
|
|
130
|
+
query: {
|
|
131
|
+
enabled:
|
|
132
|
+
!!currentAssetPair?.token?.address &&
|
|
133
|
+
!!account?.address &&
|
|
134
|
+
astraModalShow,
|
|
135
|
+
},
|
|
114
136
|
formatUnits: currentAssetPair?.token?.decimal,
|
|
137
|
+
scopeKey: "tokenBalance",
|
|
115
138
|
});
|
|
116
139
|
|
|
117
140
|
const mainnetBalanceRet = useBalance({
|
|
118
141
|
address: account?.address,
|
|
119
|
-
|
|
142
|
+
query: {
|
|
143
|
+
enabled: !!account?.address && astraModalShow,
|
|
144
|
+
},
|
|
120
145
|
formatUnits: "ether",
|
|
121
146
|
});
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
// if (filterdAssetPairs?.length === 0) {
|
|
125
|
-
// return true;
|
|
126
|
-
// }
|
|
127
|
-
// const mainetBalance = mainnetBalanceRet?.data?.value || 0;
|
|
128
|
-
// if (Number(mainetBalance) < Number(reserveInfo?.toTokenBaseFee)) {
|
|
129
|
-
// return true;
|
|
130
|
-
// }
|
|
131
|
-
// }, [
|
|
132
|
-
// filterdAssetPairs?.length,
|
|
133
|
-
// mainnetBalanceRet?.data?.value,
|
|
134
|
-
// reserveInfo?.toTokenBaseFee,
|
|
135
|
-
// ]);
|
|
136
|
-
|
|
137
|
-
const onCheckBalance = useCallback(async ()=>{
|
|
148
|
+
const onCheckBalance = useCallback(async () => {
|
|
138
149
|
const mainetBalance = mainnetBalanceRet?.data?.value || 0;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)
|
|
146
|
-
reserveInfo.max
|
|
147
|
-
);
|
|
148
|
-
if (Number(mainetBalance) < Number(reserveInfo?.toTokenBaseFee)) {
|
|
149
|
-
throw new Error('Insufficient balance to pay service fee.')
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
new Decimal(mainetBalance.toString()).lt(
|
|
153
|
+
new Decimal(reserveInfo?.toAssetBaseFee?.toString())
|
|
154
|
+
)
|
|
155
|
+
) {
|
|
156
|
+
throw new Error("Insufficient balance to pay service fee.");
|
|
150
157
|
}
|
|
151
|
-
|
|
152
|
-
if(sendArgs.amount <
|
|
153
|
-
throw new Error(`The minimum amount is ${
|
|
158
|
+
|
|
159
|
+
if (Number(sendArgs.amount) < Number(min)) {
|
|
160
|
+
throw new Error(`The minimum amount is ${min} ${unitName}`);
|
|
154
161
|
}
|
|
155
|
-
if (sendArgs.amount > max) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
`The maximum amount is ${max} ${currentAssetPair?.asset?.symbol}`
|
|
158
|
-
);
|
|
162
|
+
if (Number(sendArgs.amount) > Number(max)) {
|
|
163
|
+
throw new Error(`The maximum amount is ${max} ${unitName}`);
|
|
159
164
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
}, [
|
|
166
|
+
mainnetBalanceRet?.data?.value,
|
|
167
|
+
reserveInfo?.toAssetBaseFee,
|
|
168
|
+
sendArgs?.amount,
|
|
169
|
+
min,
|
|
170
|
+
max,
|
|
171
|
+
unitName,
|
|
172
|
+
]);
|
|
163
173
|
|
|
164
174
|
const onResetInvoice = useCallback(() => {
|
|
165
175
|
setIsInvoiceExpired(false);
|
|
166
176
|
setInvoiceExpired(0);
|
|
167
177
|
setSendInvoice("");
|
|
168
178
|
}, []);
|
|
169
|
-
const { onDeposit } = useBridgeContract(account);
|
|
170
179
|
|
|
171
180
|
const onAssetPairChange = useCallback(
|
|
172
181
|
(pairId) => {
|
|
@@ -175,18 +184,34 @@ function ToToken({ messageApi }) {
|
|
|
175
184
|
: null;
|
|
176
185
|
setCurrentAssetPair(selectedPair);
|
|
177
186
|
},
|
|
178
|
-
|
|
187
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
188
|
+
[allAssetPairs]
|
|
179
189
|
);
|
|
190
|
+
|
|
180
191
|
const onFinish = useCallback(async () => {
|
|
181
192
|
try {
|
|
182
193
|
setSubmitLoading(true);
|
|
183
194
|
onResetInvoice();
|
|
184
195
|
await onCheckBalance();
|
|
185
|
-
|
|
196
|
+
const bridgeIntervalRet = await bridgeIntervalStatus({
|
|
197
|
+
address: account?.address,
|
|
198
|
+
});
|
|
199
|
+
if (bridgeIntervalRet.code !== 200) {
|
|
200
|
+
throw new Error(bridgeIntervalRet.data);
|
|
201
|
+
}
|
|
202
|
+
const bridgeIntervalData = bridgeIntervalRet.data;
|
|
203
|
+
if (!bridgeIntervalData?.isAllowed) {
|
|
204
|
+
const remainingMinutes = Math.ceil(
|
|
205
|
+
bridgeIntervalData.remainingSeconds / 60
|
|
206
|
+
);
|
|
207
|
+
throw new Error(
|
|
208
|
+
`Bridge interval not met. Please wait ${remainingMinutes} more minute(s).`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
186
211
|
const retGetSignature = await getSignature({
|
|
187
212
|
chainId: targetNetwork.id,
|
|
188
213
|
amount: sendArgs.amount,
|
|
189
|
-
|
|
214
|
+
pairId: currentAssetPair?.pairId,
|
|
190
215
|
});
|
|
191
216
|
if (retGetSignature?.code !== 200) {
|
|
192
217
|
throw new Error(retGetSignature?.msg);
|
|
@@ -195,59 +220,74 @@ function ToToken({ messageApi }) {
|
|
|
195
220
|
const hashlock = signatureRes.hashlock;
|
|
196
221
|
const fromAddr = signatureRes.lspAddress;
|
|
197
222
|
|
|
198
|
-
const
|
|
223
|
+
const pairId = signatureRes.pairId;
|
|
199
224
|
const amount = BigInt(signatureRes.amtInContract);
|
|
200
225
|
const timeLock = BigInt(signatureRes.deltaSecond);
|
|
201
226
|
const expiredAt = Date.now() + Number(timeLock) * 1000;
|
|
227
|
+
const lspNodePubKey = signatureRes.lspNodePubKey;
|
|
202
228
|
setInvoiceExpired(expiredAt);
|
|
203
229
|
const signature = signatureRes.signature;
|
|
204
|
-
const fee =
|
|
230
|
+
const fee = signatureRes.fee;
|
|
205
231
|
|
|
206
232
|
const depositArgs = {
|
|
207
233
|
hashlock,
|
|
208
234
|
fromAddr,
|
|
209
235
|
toAddr: account.address,
|
|
210
|
-
|
|
236
|
+
pairId: pairId,
|
|
211
237
|
amount: amount,
|
|
212
238
|
timeLock: timeLock,
|
|
213
239
|
toLightning: false,
|
|
214
240
|
fee: fee,
|
|
215
241
|
signature,
|
|
242
|
+
nodePubkey: lspNodePubKey,
|
|
216
243
|
};
|
|
244
|
+
const tx = await onDeposit(depositArgs, true, false);
|
|
245
|
+
setTx(tx);
|
|
246
|
+
if (tx) {
|
|
247
|
+
const request = {
|
|
248
|
+
pairId: pairId,
|
|
249
|
+
amount: sendArgs.amount,
|
|
250
|
+
chainId: targetNetwork.id,
|
|
251
|
+
hashlock: signatureRes.hashlock,
|
|
252
|
+
depositTx: tx,
|
|
253
|
+
};
|
|
217
254
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const request = {
|
|
223
|
-
assetId: currentAssetPair?.asset?.assetId,
|
|
224
|
-
amount: sendArgs.amount,
|
|
225
|
-
chainId: targetNetwork.id,
|
|
226
|
-
pairName: currentAssetPair?.pairName,
|
|
227
|
-
hashlock: signatureRes.hashlock,
|
|
228
|
-
depositTx: tx,
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const retToEVM = await toEVM(request);
|
|
232
|
-
if (retToEVM.code === 200) {
|
|
233
|
-
messageApi.success("Submit success.");
|
|
234
|
-
setSendInvoice(retToEVM.data.invoice);
|
|
235
|
-
}
|
|
255
|
+
const retToEVM = await toEVM(request);
|
|
256
|
+
if (retToEVM.code === 200) {
|
|
257
|
+
messageApi.success("Submit success.");
|
|
258
|
+
setSendInvoice(retToEVM.data.invoice);
|
|
236
259
|
}
|
|
237
|
-
} else {
|
|
238
|
-
//TODO
|
|
239
260
|
}
|
|
240
261
|
} catch (e) {
|
|
241
|
-
const error = e
|
|
242
|
-
if (error.includes("
|
|
243
|
-
|
|
262
|
+
const error = getParsedError(e);
|
|
263
|
+
if (error.includes("does not match the target chain")) {
|
|
264
|
+
switchChain(
|
|
265
|
+
{ chainId: targetNetwork.id },
|
|
266
|
+
{
|
|
267
|
+
onSuccess: () => {
|
|
268
|
+
messageApi.success(
|
|
269
|
+
`Switch chain ${targetNetwork.name} success, please try again.`
|
|
270
|
+
);
|
|
271
|
+
},
|
|
272
|
+
}
|
|
273
|
+
);
|
|
244
274
|
} else {
|
|
245
|
-
messageApi.error(
|
|
275
|
+
messageApi.error(error);
|
|
246
276
|
}
|
|
247
277
|
} finally {
|
|
248
278
|
setSubmitLoading(false);
|
|
249
279
|
}
|
|
250
|
-
}, [
|
|
280
|
+
}, [
|
|
281
|
+
onResetInvoice,
|
|
282
|
+
onCheckBalance,
|
|
283
|
+
targetNetwork,
|
|
284
|
+
sendArgs?.amount,
|
|
285
|
+
currentAssetPair?.pairId,
|
|
286
|
+
account?.address,
|
|
287
|
+
onDeposit,
|
|
288
|
+
messageApi,
|
|
289
|
+
switchChain,
|
|
290
|
+
]);
|
|
251
291
|
|
|
252
292
|
const btn = useMemo(() => {
|
|
253
293
|
if (!account?.address) {
|
|
@@ -265,7 +305,7 @@ function ToToken({ messageApi }) {
|
|
|
265
305
|
loading={payInvoiceLoading}
|
|
266
306
|
onClick={async () => {
|
|
267
307
|
setPayInvoiceLoading(true);
|
|
268
|
-
const txUrl = `${targetNetwork?.blockExplorers?.default.url}/tx/${tx}
|
|
308
|
+
const txUrl = `${targetNetwork?.blockExplorers?.default.url}/tx/${tx}`;
|
|
269
309
|
await onAstraInvoice(sendInvoice, tx, txUrl)
|
|
270
310
|
.catch((e) => {
|
|
271
311
|
messageApi.error(e.message);
|
|
@@ -290,12 +330,23 @@ function ToToken({ messageApi }) {
|
|
|
290
330
|
loading={submitLoading}
|
|
291
331
|
disabled={isInvoiceExpired}
|
|
292
332
|
>
|
|
293
|
-
<span>{submitLoading ? "Waiting for Confirmation" : "
|
|
333
|
+
<span>{submitLoading ? "Waiting for Confirmation" : "Withdraw"}</span>
|
|
294
334
|
<img src={IconArrowRight} alt="" />
|
|
295
335
|
</SubmitBtn>
|
|
296
336
|
);
|
|
297
337
|
}
|
|
298
|
-
}, [
|
|
338
|
+
}, [
|
|
339
|
+
account?.address,
|
|
340
|
+
isInvoiceExpired,
|
|
341
|
+
messageApi,
|
|
342
|
+
onAstraInvoice,
|
|
343
|
+
payInvoiceLoading,
|
|
344
|
+
sendInvoice,
|
|
345
|
+
setAstraModalShow,
|
|
346
|
+
submitLoading,
|
|
347
|
+
targetNetwork?.blockExplorers?.default.url,
|
|
348
|
+
tx,
|
|
349
|
+
]);
|
|
299
350
|
|
|
300
351
|
const onExpired = useCallback(() => {
|
|
301
352
|
setIsInvoiceExpired(true);
|
|
@@ -306,147 +357,157 @@ function ToToken({ messageApi }) {
|
|
|
306
357
|
setCurrentAssetPair(filterdAssetPairs[0]);
|
|
307
358
|
form.setFieldValue("received", filterdAssetPairs?.[0]?.pairId);
|
|
308
359
|
}
|
|
309
|
-
|
|
360
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
361
|
+
}, [filterdAssetPairs, form]);
|
|
310
362
|
return (
|
|
311
363
|
<WrapperToLightning>
|
|
312
|
-
<
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
// wrapperCol={{
|
|
320
|
-
// span: 16,
|
|
321
|
-
// }}
|
|
322
|
-
style={{
|
|
323
|
-
width: "100%",
|
|
324
|
-
}}
|
|
325
|
-
initialValues={{
|
|
326
|
-
remember: true,
|
|
327
|
-
}}
|
|
328
|
-
onFinish={onFinish}
|
|
329
|
-
autoComplete="off"
|
|
330
|
-
>
|
|
331
|
-
<AstraNetwork
|
|
332
|
-
messageApi={messageApi}
|
|
333
|
-
balance={mainnetBalanceRet?.data}
|
|
334
|
-
/>
|
|
335
|
-
<AstraSendingReceived>
|
|
336
|
-
<FormItem label="Sending">
|
|
337
|
-
<Flex justify="end" align="center" gap="5px">
|
|
338
|
-
<AstraImage name={"Lightning"} />
|
|
339
|
-
<span className="fw500 colorcaff33">{sendArgs?.amount}</span>
|
|
340
|
-
<span className="fw500 colorcaff33">
|
|
341
|
-
{currentAssetPair?.asset?.name}
|
|
342
|
-
</span>
|
|
343
|
-
</Flex>
|
|
344
|
-
</FormItem>
|
|
345
|
-
|
|
346
|
-
<FormItem label="Received" style={{ marginBottom: 0 }}>
|
|
347
|
-
<Flex justify="end" align="center" gap="5px">
|
|
348
|
-
<FormItem name="received" noStyle className="form-item-pair">
|
|
349
|
-
<AstraSelect
|
|
350
|
-
variant="borderless"
|
|
351
|
-
options={filterdAssetPairs.map((pair) => ({
|
|
352
|
-
value: pair.pairId,
|
|
353
|
-
label: (
|
|
354
|
-
<AstraImage
|
|
355
|
-
name={pair.token.name}
|
|
356
|
-
width="22px"
|
|
357
|
-
height="22px"
|
|
358
|
-
/>
|
|
359
|
-
),
|
|
360
|
-
}))}
|
|
361
|
-
onChange={onAssetPairChange}
|
|
362
|
-
></AstraSelect>
|
|
363
|
-
</FormItem>
|
|
364
|
-
<span>{sendArgs?.amount}</span>
|
|
365
|
-
<span>{currentAssetPair?.token?.name}</span>
|
|
366
|
-
</Flex>
|
|
367
|
-
<BalanceFlex justify="end" align="center" gap="5px">
|
|
368
|
-
<span className="available_token_balance">
|
|
369
|
-
Available:{tokenBalanceRet?.data?.formatted}{" "}
|
|
370
|
-
{tokenBalanceRet?.data?.symbol}
|
|
371
|
-
</span>
|
|
372
|
-
</BalanceFlex>
|
|
373
|
-
</FormItem>
|
|
374
|
-
</AstraSendingReceived>
|
|
375
|
-
<AstraFormItemOther>
|
|
376
|
-
<FormItem label="Service fee">
|
|
377
|
-
<Flex justify="end" align="center" gap="5px">
|
|
378
|
-
<span>{serviceFee}</span>
|
|
379
|
-
<AstraImage
|
|
380
|
-
name={targetNetwork?.name}
|
|
381
|
-
width="24px"
|
|
382
|
-
height="24px"
|
|
383
|
-
/>
|
|
384
|
-
</Flex>
|
|
385
|
-
</FormItem>
|
|
386
|
-
|
|
387
|
-
<FormItem label="Receiving address">
|
|
388
|
-
<Flex justify="end" align="center" gap="5px">
|
|
389
|
-
<AstraImage name={targetNetwork?.name} />
|
|
390
|
-
<EllipsisMiddle suffixCount={6}>
|
|
391
|
-
{account?.address ?? "--"}
|
|
392
|
-
</EllipsisMiddle>
|
|
393
|
-
</Flex>
|
|
394
|
-
</FormItem>
|
|
395
|
-
<FormItem label="Route">
|
|
396
|
-
<Flex justify="end" align="center" gap="5px">
|
|
397
|
-
<AstraImage name="Lightning" />
|
|
398
|
-
<DoubleRightOutlined style={{ color: "#caff33" }} />
|
|
399
|
-
<AstraImage
|
|
400
|
-
name={targetNetwork?.name}
|
|
401
|
-
width="24px"
|
|
402
|
-
height="24px"
|
|
403
|
-
/>
|
|
404
|
-
</Flex>
|
|
405
|
-
</FormItem>
|
|
406
|
-
</AstraFormItemOther>
|
|
407
|
-
{sendInvoice && (
|
|
408
|
-
<>
|
|
409
|
-
<QRCodeWrapper
|
|
410
|
-
justify="center"
|
|
411
|
-
align="center"
|
|
412
|
-
gap="10px"
|
|
413
|
-
vertical={true}
|
|
414
|
-
>
|
|
415
|
-
<QRCode
|
|
416
|
-
type="svg"
|
|
417
|
-
size={200}
|
|
418
|
-
errorLevel="M"
|
|
419
|
-
iconSize={40}
|
|
420
|
-
value={sendInvoice}
|
|
421
|
-
bordered={false}
|
|
422
|
-
status={isInvoiceExpired ? "expired" : "active"}
|
|
423
|
-
/>
|
|
424
|
-
<Countdown
|
|
425
|
-
title="Invoice expires in"
|
|
426
|
-
valueStyle={{
|
|
427
|
-
color: "#caff33",
|
|
428
|
-
fontSize: "14px",
|
|
429
|
-
textAlign: "center",
|
|
430
|
-
}}
|
|
431
|
-
value={invoiceExpired}
|
|
432
|
-
onFinish={onExpired}
|
|
433
|
-
/>
|
|
434
|
-
</QRCodeWrapper>
|
|
435
|
-
</>
|
|
436
|
-
)}
|
|
437
|
-
|
|
438
|
-
<FormItem
|
|
439
|
-
label={null}
|
|
440
|
-
labelCol={{
|
|
441
|
-
span: 0,
|
|
364
|
+
<Spin spinning={reserveInfoLoading}>
|
|
365
|
+
<Form
|
|
366
|
+
name="basic"
|
|
367
|
+
form={form}
|
|
368
|
+
colon={false}
|
|
369
|
+
style={{
|
|
370
|
+
width: "100%",
|
|
442
371
|
}}
|
|
443
|
-
|
|
444
|
-
|
|
372
|
+
initialValues={{
|
|
373
|
+
remember: true,
|
|
445
374
|
}}
|
|
375
|
+
onFinish={onFinish}
|
|
376
|
+
autoComplete="off"
|
|
446
377
|
>
|
|
447
|
-
<
|
|
448
|
-
|
|
449
|
-
|
|
378
|
+
<AstraNetwork
|
|
379
|
+
messageApi={messageApi}
|
|
380
|
+
balance={mainnetBalanceRet?.data}
|
|
381
|
+
/>
|
|
382
|
+
<AstraSendingReceived>
|
|
383
|
+
<FormItem label="Sending">
|
|
384
|
+
<Flex justify="end" align="center" gap="5px">
|
|
385
|
+
<AstraImage name={"Lightning"} />
|
|
386
|
+
<span className="fw500 colorcaff33">{sendArgs?.amount}</span>
|
|
387
|
+
<span className="fw500 colorcaff33">
|
|
388
|
+
{currentAssetPair?.asset?.name}
|
|
389
|
+
</span>
|
|
390
|
+
</Flex>
|
|
391
|
+
</FormItem>
|
|
392
|
+
|
|
393
|
+
<FormItem label="Receiving" style={{ marginBottom: 0 }}>
|
|
394
|
+
<Flex justify="end" align="center" gap="5px">
|
|
395
|
+
{filterdAssetPairs.length > 0 && (
|
|
396
|
+
<FormItem name="received" noStyle className="form-item-pair">
|
|
397
|
+
<AstraSelect
|
|
398
|
+
variant="borderless"
|
|
399
|
+
options={filterdAssetPairs.map((pair) => ({
|
|
400
|
+
value: pair.pairId,
|
|
401
|
+
label: (
|
|
402
|
+
<AstraImage
|
|
403
|
+
name={pair.token.name}
|
|
404
|
+
width="22px"
|
|
405
|
+
height="22px"
|
|
406
|
+
/>
|
|
407
|
+
),
|
|
408
|
+
}))}
|
|
409
|
+
onChange={onAssetPairChange}
|
|
410
|
+
></AstraSelect>
|
|
411
|
+
</FormItem>
|
|
412
|
+
)}
|
|
413
|
+
<span>{sendArgs?.amount}</span>
|
|
414
|
+
<span>{currentAssetPair?.token?.name}</span>
|
|
415
|
+
</Flex>
|
|
416
|
+
<BalanceFlex justify="end" align="center" gap="5px">
|
|
417
|
+
<span className="available_token_balance">
|
|
418
|
+
Available:
|
|
419
|
+
<AvalibleBalance>
|
|
420
|
+
|
|
421
|
+
{tokenBalanceRet?.data?.formatted
|
|
422
|
+
? numberWithCommas(
|
|
423
|
+
new Decimal(tokenBalanceRet?.data?.formatted).toFixed(
|
|
424
|
+
4,
|
|
425
|
+
Decimal.ROUND_DOWN
|
|
426
|
+
)
|
|
427
|
+
)
|
|
428
|
+
: 0}
|
|
429
|
+
</AvalibleBalance>
|
|
430
|
+
{tokenBalanceRet?.data?.symbol}
|
|
431
|
+
</span>
|
|
432
|
+
</BalanceFlex>
|
|
433
|
+
</FormItem>
|
|
434
|
+
</AstraSendingReceived>
|
|
435
|
+
<AstraFormItemOther>
|
|
436
|
+
<FormItem label="Service fee">
|
|
437
|
+
<Flex justify="end" align="center" gap="5px">
|
|
438
|
+
<span>{serviceFee}</span>
|
|
439
|
+
<AstraImage
|
|
440
|
+
name={targetNetwork?.name}
|
|
441
|
+
width="24px"
|
|
442
|
+
height="24px"
|
|
443
|
+
/>
|
|
444
|
+
</Flex>
|
|
445
|
+
</FormItem>
|
|
446
|
+
|
|
447
|
+
<FormItem label="Receiving address">
|
|
448
|
+
<Flex justify="end" align="center" gap="5px">
|
|
449
|
+
<AstraImage name={targetNetwork?.name} />
|
|
450
|
+
<EllipsisMiddle suffixCount={6}>
|
|
451
|
+
{account?.address ?? "--"}
|
|
452
|
+
</EllipsisMiddle>
|
|
453
|
+
</Flex>
|
|
454
|
+
</FormItem>
|
|
455
|
+
<FormItem label="Route">
|
|
456
|
+
<Flex justify="end" align="center" gap="5px">
|
|
457
|
+
<AstraImage name="Lightning" />
|
|
458
|
+
<DoubleRightOutlined style={{ color: "#caff33" }} />
|
|
459
|
+
<AstraImage
|
|
460
|
+
name={targetNetwork?.name}
|
|
461
|
+
width="24px"
|
|
462
|
+
height="24px"
|
|
463
|
+
/>
|
|
464
|
+
</Flex>
|
|
465
|
+
</FormItem>
|
|
466
|
+
</AstraFormItemOther>
|
|
467
|
+
{sendInvoice && (
|
|
468
|
+
<>
|
|
469
|
+
<QRCodeWrapper
|
|
470
|
+
justify="center"
|
|
471
|
+
align="center"
|
|
472
|
+
gap="10px"
|
|
473
|
+
vertical={true}
|
|
474
|
+
>
|
|
475
|
+
<QRCode
|
|
476
|
+
type="svg"
|
|
477
|
+
size={200}
|
|
478
|
+
errorLevel="M"
|
|
479
|
+
iconSize={40}
|
|
480
|
+
value={sendInvoice}
|
|
481
|
+
bordered={false}
|
|
482
|
+
status={isInvoiceExpired ? "expired" : "active"}
|
|
483
|
+
/>
|
|
484
|
+
<Countdown
|
|
485
|
+
title="Invoice expires in"
|
|
486
|
+
valueStyle={{
|
|
487
|
+
color: "#caff33",
|
|
488
|
+
fontSize: "14px",
|
|
489
|
+
textAlign: "center",
|
|
490
|
+
}}
|
|
491
|
+
value={invoiceExpired}
|
|
492
|
+
onFinish={onExpired}
|
|
493
|
+
/>
|
|
494
|
+
</QRCodeWrapper>
|
|
495
|
+
</>
|
|
496
|
+
)}
|
|
497
|
+
|
|
498
|
+
<FormItem
|
|
499
|
+
label={null}
|
|
500
|
+
labelCol={{
|
|
501
|
+
span: 0,
|
|
502
|
+
}}
|
|
503
|
+
wrapperCol={{
|
|
504
|
+
span: 24,
|
|
505
|
+
}}
|
|
506
|
+
>
|
|
507
|
+
<Flex justify="center"> {btn}</Flex>
|
|
508
|
+
</FormItem>
|
|
509
|
+
</Form>
|
|
510
|
+
</Spin>
|
|
450
511
|
</WrapperToLightning>
|
|
451
512
|
);
|
|
452
513
|
}
|
package/src/constants/index.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
2
|
+
Decimal.set({
|
|
3
|
+
toExpNeg: -20,
|
|
4
|
+
toExpPos: 40,
|
|
5
|
+
});
|
|
1
6
|
export const MODAL_DISPLAY_TYPE = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
7
|
+
DEFAULT: 0,
|
|
8
|
+
TO_LIGHTNING: 1,
|
|
9
|
+
TO_EVM: 2,
|
|
10
|
+
};
|
|
11
|
+
export const ALCHEMY_KEY = "ClvXGqSMvZ6nEb_G5ekJGsZwNdsp72oz";
|
|
12
|
+
|
|
13
|
+
export function balanceToFixed(balance, decimals) {
|
|
14
|
+
const fixedBalance = balance
|
|
15
|
+
? new Decimal(balance)
|
|
16
|
+
.div(10 ** decimals)
|
|
17
|
+
.toFixed(decimals, Decimal.ROUND_DOWN)
|
|
18
|
+
.toString()
|
|
19
|
+
: 0;
|
|
20
|
+
return fixedBalance;
|
|
21
|
+
}
|