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
|
@@ -4,7 +4,7 @@ import useStore from "../store";
|
|
|
4
4
|
import { Form, Button, Select, Flex, 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 useParseInvoice from "../hooks/useParseInvoice";
|
|
10
10
|
import EllipsisMiddle from "./EllipsisMiddle";
|
|
@@ -12,10 +12,14 @@ import { useBridgeContract } from "../hooks/useContract";
|
|
|
12
12
|
import { useGetReserveInfo } from "../hooks/useLspApi";
|
|
13
13
|
import ConnectButton from "./ConnectButton";
|
|
14
14
|
import Decimal from "decimal.js";
|
|
15
|
-
import {
|
|
15
|
+
import { useGetMinAndMax } from "../hooks/useGetMinAndMax";
|
|
16
|
+
import { numberWithCommas, getParsedError } from "../utils";
|
|
16
17
|
import AstraNetwork from "./AstraNetwork";
|
|
17
18
|
import IconTip from "../assets/tip.svg";
|
|
18
19
|
import IconArrowRight from "../assets/arrow-right.svg";
|
|
20
|
+
import { AvalibleBalance } from "./CommonStyle";
|
|
21
|
+
import { toLightning, bridgeIntervalStatus } from "../apis/lspApi";
|
|
22
|
+
|
|
19
23
|
const WrapperToLightning = styled.div``;
|
|
20
24
|
|
|
21
25
|
const FormItem = styled(Form.Item)``;
|
|
@@ -99,6 +103,7 @@ const AstraButton = styled(Button)`
|
|
|
99
103
|
font-size: 16px;
|
|
100
104
|
line-height: 42px;
|
|
101
105
|
`;
|
|
106
|
+
|
|
102
107
|
function ToLightning({
|
|
103
108
|
messageApi,
|
|
104
109
|
setResultModalShow,
|
|
@@ -111,9 +116,11 @@ function ToLightning({
|
|
|
111
116
|
setCurrentAssetPair,
|
|
112
117
|
currentAssetPair,
|
|
113
118
|
setAstraModalShow,
|
|
119
|
+
astraModalShow,
|
|
114
120
|
} = useStore();
|
|
115
121
|
|
|
116
122
|
const account = useAccount();
|
|
123
|
+
const { switchChain } = useSwitchChain();
|
|
117
124
|
const [form] = Form.useForm();
|
|
118
125
|
const [submitLoading, setSubmitLoading] = useState(false);
|
|
119
126
|
const [approveLoading, setApproveLoading] = useState(false);
|
|
@@ -127,34 +134,36 @@ function ToLightning({
|
|
|
127
134
|
targetNetwork,
|
|
128
135
|
currentAssetPair
|
|
129
136
|
);
|
|
137
|
+
const { min, max, unitName } = useGetMinAndMax("evmToLightning", reserveInfo);
|
|
130
138
|
|
|
131
139
|
const tokenBalanceRet = useBalance({
|
|
132
140
|
address: account?.address,
|
|
133
141
|
token: currentAssetPair?.token?.address,
|
|
134
|
-
|
|
142
|
+
query: {
|
|
143
|
+
enabled:
|
|
144
|
+
!!currentAssetPair?.token?.address &&
|
|
145
|
+
!!account?.address &&
|
|
146
|
+
astraModalShow,
|
|
147
|
+
},
|
|
135
148
|
formatUnits: currentAssetPair?.token?.decimal,
|
|
136
149
|
scopeKey: "token",
|
|
137
150
|
});
|
|
138
151
|
|
|
139
152
|
const mainnetBalanceRet = useBalance({
|
|
140
153
|
address: account?.address,
|
|
141
|
-
|
|
154
|
+
query: {
|
|
155
|
+
enabled: !!account?.address && astraModalShow,
|
|
156
|
+
},
|
|
142
157
|
formatUnits: "ether",
|
|
143
|
-
scopeKey: "mainnet",
|
|
144
158
|
});
|
|
145
159
|
|
|
146
|
-
const serviceFee = useMemo(() => {
|
|
147
|
-
const recieveBaseFee = reserveInfo?.toAssetBaseFee || 0;
|
|
148
|
-
return new Decimal(recieveBaseFee.toString()).div(10 ** 18).toFixed(4);
|
|
149
|
-
}, [reserveInfo?.toAssetBaseFee]);
|
|
150
|
-
|
|
151
160
|
const {
|
|
152
|
-
assetAmt,
|
|
153
161
|
formatAssetAmt,
|
|
154
162
|
tokenAmt,
|
|
155
163
|
formatTokenAmt,
|
|
156
164
|
hashlock,
|
|
157
165
|
parseInvoiceLoading,
|
|
166
|
+
isExpired,
|
|
158
167
|
} = useParseInvoice(receiveArgs?.invoice);
|
|
159
168
|
|
|
160
169
|
const {
|
|
@@ -165,6 +174,16 @@ function ToLightning({
|
|
|
165
174
|
onDeposit,
|
|
166
175
|
} = useBridgeContract(account);
|
|
167
176
|
|
|
177
|
+
const serviceFee = useMemo(() => {
|
|
178
|
+
if (!reserveInfo?.toAssetBaseFee) {
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
return new Decimal(reserveInfo?.toAssetBaseFee.toString())
|
|
182
|
+
.div(10 ** 18)
|
|
183
|
+
.toFixed(8)
|
|
184
|
+
.replace(/\.?0+$/, "");
|
|
185
|
+
}, [reserveInfo?.toAssetBaseFee]);
|
|
186
|
+
|
|
168
187
|
const onAssetPairChange = useCallback(
|
|
169
188
|
(pairId) => {
|
|
170
189
|
const selectedPair = pairId
|
|
@@ -178,31 +197,41 @@ function ToLightning({
|
|
|
178
197
|
const onCheckBalance = useCallback(async () => {
|
|
179
198
|
const tokenBalance = tokenBalanceRet?.data?.value || 0;
|
|
180
199
|
const mainetBalance = mainnetBalanceRet?.data?.value || 0;
|
|
181
|
-
|
|
200
|
+
|
|
182
201
|
if (
|
|
183
|
-
|
|
184
|
-
|
|
202
|
+
new Decimal(mainetBalance.toString()).lt(
|
|
203
|
+
new Decimal(reserveInfo?.toAssetBaseFee?.toString())
|
|
204
|
+
)
|
|
185
205
|
) {
|
|
186
206
|
throw new Error("Insufficient balance to pay service fee.");
|
|
187
207
|
}
|
|
188
|
-
if (
|
|
208
|
+
if (
|
|
209
|
+
new Decimal(tokenBalance.toString()).lt(new Decimal(tokenAmt.toString()))
|
|
210
|
+
) {
|
|
189
211
|
throw new Error("Insufficient available balance.");
|
|
190
212
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
)} ${currentAssetPair?.asset?.symbol}.`
|
|
197
|
-
);
|
|
213
|
+
|
|
214
|
+
if (
|
|
215
|
+
new Decimal(formatAssetAmt.toString()).gt(new Decimal(max.toString()))
|
|
216
|
+
) {
|
|
217
|
+
throw new Error(`The maximum amount is ${max} ${unitName}.`);
|
|
198
218
|
}
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
219
|
+
if (
|
|
220
|
+
new Decimal(formatAssetAmt.toString()).lt(new Decimal(min.toString()))
|
|
221
|
+
) {
|
|
222
|
+
throw new Error(`The minimum amount is ${min} ${unitName}.`);
|
|
203
223
|
}
|
|
204
|
-
}, [
|
|
205
|
-
|
|
224
|
+
}, [
|
|
225
|
+
formatAssetAmt,
|
|
226
|
+
mainnetBalanceRet?.data?.value,
|
|
227
|
+
max,
|
|
228
|
+
min,
|
|
229
|
+
reserveInfo?.toAssetBaseFee,
|
|
230
|
+
tokenAmt,
|
|
231
|
+
tokenBalanceRet?.data?.value,
|
|
232
|
+
unitName,
|
|
233
|
+
]);
|
|
234
|
+
|
|
206
235
|
const handleApprove = useCallback(
|
|
207
236
|
async (approveAmt) => {
|
|
208
237
|
try {
|
|
@@ -217,17 +246,39 @@ function ToLightning({
|
|
|
217
246
|
}
|
|
218
247
|
} catch (e) {
|
|
219
248
|
const error = e.message;
|
|
249
|
+
|
|
220
250
|
if (error.includes("User rejected")) {
|
|
221
251
|
messageApi.error("User reject the request.");
|
|
222
252
|
} else {
|
|
223
|
-
|
|
253
|
+
if (error.includes("does not match the target chain")) {
|
|
254
|
+
switchChain(
|
|
255
|
+
{ chainId: targetNetwork.id },
|
|
256
|
+
{
|
|
257
|
+
onSuccess: () => {
|
|
258
|
+
messageApi.success(
|
|
259
|
+
`Switch chain ${targetNetwork.name} success, please try again.`
|
|
260
|
+
);
|
|
261
|
+
},
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
} else {
|
|
265
|
+
messageApi.error(e.message);
|
|
266
|
+
}
|
|
224
267
|
}
|
|
225
268
|
} finally {
|
|
226
269
|
setApproveLoading(false);
|
|
227
270
|
onReloadAllowance();
|
|
228
271
|
}
|
|
229
272
|
},
|
|
230
|
-
[
|
|
273
|
+
[
|
|
274
|
+
messageApi,
|
|
275
|
+
onApprove,
|
|
276
|
+
onCheckBalance,
|
|
277
|
+
onReloadAllowance,
|
|
278
|
+
switchChain,
|
|
279
|
+
targetNetwork.id,
|
|
280
|
+
targetNetwork.name,
|
|
281
|
+
]
|
|
231
282
|
);
|
|
232
283
|
|
|
233
284
|
const memoBtn = useMemo(() => {
|
|
@@ -240,7 +291,7 @@ function ToLightning({
|
|
|
240
291
|
type="primary"
|
|
241
292
|
// disabled={btnDisabled}
|
|
242
293
|
onClick={() => {
|
|
243
|
-
handleApprove(
|
|
294
|
+
handleApprove(tokenAmt);
|
|
244
295
|
}}
|
|
245
296
|
loading={approveLoading}
|
|
246
297
|
>
|
|
@@ -272,30 +323,59 @@ function ToLightning({
|
|
|
272
323
|
tokenAmt,
|
|
273
324
|
]);
|
|
274
325
|
|
|
326
|
+
// const fixedChannelBalance = useMemo(() => {
|
|
327
|
+
// if (reserveInfo) {
|
|
328
|
+
// return balanceToFixed(
|
|
329
|
+
// reserveInfo.maxAsset,
|
|
330
|
+
// currentAssetPair?.asset?.decimal
|
|
331
|
+
// );
|
|
332
|
+
// }
|
|
333
|
+
// return 0;
|
|
334
|
+
// }, [currentAssetPair?.asset?.decimal, reserveInfo]);
|
|
335
|
+
|
|
275
336
|
const onFinish = useCallback(async () => {
|
|
276
337
|
try {
|
|
277
338
|
if (!account?.address) {
|
|
278
339
|
return;
|
|
279
340
|
}
|
|
341
|
+
if (isExpired) {
|
|
342
|
+
throw new Error("The invoice has expired.");
|
|
343
|
+
}
|
|
280
344
|
setSubmitLoading(true);
|
|
281
345
|
await onCheckBalance();
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
) {
|
|
346
|
+
const bridgeIntervalRet = await bridgeIntervalStatus({
|
|
347
|
+
address: account?.address,
|
|
348
|
+
});
|
|
349
|
+
if (bridgeIntervalRet.code !== 200) {
|
|
350
|
+
throw new Error(bridgeIntervalRet.data);
|
|
351
|
+
}
|
|
352
|
+
const bridgeIntervalData = bridgeIntervalRet.data;
|
|
353
|
+
if (!bridgeIntervalData?.isAllowed) {
|
|
354
|
+
const remainingMinutes = Math.ceil(
|
|
355
|
+
bridgeIntervalData.remainingSeconds / 60
|
|
356
|
+
);
|
|
286
357
|
throw new Error(
|
|
287
|
-
`
|
|
288
|
-
reserveInfo?.min
|
|
289
|
-
} and ${formatAssetByDecimal(
|
|
290
|
-
reserveInfo?.maxAsset,
|
|
291
|
-
currentAssetPair.asset.decimal
|
|
292
|
-
)}`
|
|
358
|
+
`Bridge interval not met. Please wait ${remainingMinutes} more minute(s).`
|
|
293
359
|
);
|
|
294
360
|
}
|
|
361
|
+
const {
|
|
362
|
+
effectiveSatsBalance,
|
|
363
|
+
satsCapacity,
|
|
364
|
+
localAssetbalance,
|
|
365
|
+
localAssetCapacity,
|
|
366
|
+
} = reserveInfo;
|
|
367
|
+
|
|
368
|
+
if (
|
|
369
|
+
effectiveSatsBalance < satsCapacity * 0.1 ||
|
|
370
|
+
localAssetbalance < localAssetCapacity * 0.1
|
|
371
|
+
) {
|
|
372
|
+
throw new Error("Channel not enough balance.");
|
|
373
|
+
}
|
|
374
|
+
|
|
295
375
|
await onReloadAllowance();
|
|
296
376
|
|
|
297
377
|
if (Number(allowanceRet) < Number(tokenAmt)) {
|
|
298
|
-
const approveTx = await onApprove(Number.
|
|
378
|
+
const approveTx = await onApprove(Number.tokenAmt);
|
|
299
379
|
if (approveTx) {
|
|
300
380
|
messageApi.open({
|
|
301
381
|
type: "success",
|
|
@@ -304,26 +384,37 @@ function ToLightning({
|
|
|
304
384
|
}
|
|
305
385
|
}
|
|
306
386
|
|
|
387
|
+
const decodedInvoice = window.lightningPayReq.decode(
|
|
388
|
+
receiveArgs?.invoice
|
|
389
|
+
);
|
|
390
|
+
const lspNodePubKey = decodedInvoice?.payeeNodeKey;
|
|
391
|
+
|
|
307
392
|
const depositArgs = {
|
|
308
393
|
hashlock,
|
|
309
394
|
fromAddr: account.address,
|
|
310
395
|
toAddr: reserveInfo.lspAddress,
|
|
311
|
-
|
|
396
|
+
pairId: currentAssetPair.pairId,
|
|
312
397
|
amount: tokenAmt,
|
|
313
|
-
timeLock: reserveInfo?.
|
|
398
|
+
timeLock: reserveInfo?.evm2LightningDeltaSecond,
|
|
314
399
|
toLightning: true,
|
|
315
400
|
fee: reserveInfo?.toAssetBaseFee,
|
|
316
401
|
signature: "0x",
|
|
402
|
+
nodePubkey: lspNodePubKey,
|
|
317
403
|
};
|
|
404
|
+
|
|
318
405
|
const tx = await onDeposit(depositArgs);
|
|
406
|
+
const request = {
|
|
407
|
+
pairId: currentAssetPair.pairId,
|
|
408
|
+
chainId: targetNetwork.id,
|
|
409
|
+
lnInvoice: receiveArgs?.invoice,
|
|
410
|
+
amount: tokenAmt,
|
|
411
|
+
depositTx: tx,
|
|
412
|
+
};
|
|
413
|
+
const retToEVM = await toLightning(request);
|
|
414
|
+
if (retToEVM.code !== 200) {
|
|
415
|
+
throw new Error("Payment failed");
|
|
416
|
+
}
|
|
319
417
|
if (tx) {
|
|
320
|
-
const request = {
|
|
321
|
-
assetId: currentAssetPair.asset.assetId,
|
|
322
|
-
chainId: targetNetwork.id,
|
|
323
|
-
lnInvoice: receiveArgs?.invoice,
|
|
324
|
-
amount: tokenAmt,
|
|
325
|
-
depositTx: tx,
|
|
326
|
-
};
|
|
327
418
|
setResultModalRequest({
|
|
328
419
|
txHash: tx,
|
|
329
420
|
timestamp: Date.now(),
|
|
@@ -334,16 +425,46 @@ function ToLightning({
|
|
|
334
425
|
setResultModalShow(true);
|
|
335
426
|
}
|
|
336
427
|
} catch (e) {
|
|
337
|
-
const error = e
|
|
338
|
-
if (error.includes("
|
|
339
|
-
|
|
428
|
+
const error = getParsedError(e);
|
|
429
|
+
if (error.includes("does not match the target chain")) {
|
|
430
|
+
switchChain(
|
|
431
|
+
{ chainId: targetNetwork.id },
|
|
432
|
+
{
|
|
433
|
+
onSuccess: () => {
|
|
434
|
+
messageApi.success(
|
|
435
|
+
`Switch chain ${targetNetwork.name} success, please try again.`
|
|
436
|
+
);
|
|
437
|
+
},
|
|
438
|
+
}
|
|
439
|
+
);
|
|
340
440
|
} else {
|
|
341
|
-
messageApi.error(
|
|
441
|
+
messageApi.error(error);
|
|
342
442
|
}
|
|
343
443
|
} finally {
|
|
344
444
|
setSubmitLoading(false);
|
|
345
445
|
}
|
|
346
|
-
}, [
|
|
446
|
+
}, [
|
|
447
|
+
account?.address,
|
|
448
|
+
isExpired,
|
|
449
|
+
onCheckBalance,
|
|
450
|
+
reserveInfo,
|
|
451
|
+
onReloadAllowance,
|
|
452
|
+
allowanceRet,
|
|
453
|
+
tokenAmt,
|
|
454
|
+
receiveArgs?.invoice,
|
|
455
|
+
hashlock,
|
|
456
|
+
currentAssetPair,
|
|
457
|
+
targetNetwork.id,
|
|
458
|
+
targetNetwork.name,
|
|
459
|
+
onDeposit,
|
|
460
|
+
onApprove,
|
|
461
|
+
messageApi,
|
|
462
|
+
setResultModalRequest,
|
|
463
|
+
formatTokenAmt,
|
|
464
|
+
setAstraModalShow,
|
|
465
|
+
setResultModalShow,
|
|
466
|
+
switchChain,
|
|
467
|
+
]);
|
|
347
468
|
|
|
348
469
|
const onClearAuth = useCallback(async () => {
|
|
349
470
|
await handleApprove(0);
|
|
@@ -364,12 +485,6 @@ function ToLightning({
|
|
|
364
485
|
name="basic"
|
|
365
486
|
form={form}
|
|
366
487
|
colon={false}
|
|
367
|
-
// labelCol={{
|
|
368
|
-
// span: 8,
|
|
369
|
-
// }}
|
|
370
|
-
// wrapperCol={{
|
|
371
|
-
// span: 16,
|
|
372
|
-
// }}
|
|
373
488
|
style={{
|
|
374
489
|
width: "100%",
|
|
375
490
|
}}
|
|
@@ -383,34 +498,46 @@ function ToLightning({
|
|
|
383
498
|
<AstraSendingReceived>
|
|
384
499
|
<FormItem label="Sending">
|
|
385
500
|
<Flex justify="end" align="center" gap="5px">
|
|
386
|
-
|
|
387
|
-
<
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
501
|
+
{filterdAssetPairs?.length > 0 && (
|
|
502
|
+
<FormItem name="sending" noStyle>
|
|
503
|
+
<AstraSelect
|
|
504
|
+
variant="borderless"
|
|
505
|
+
options={filterdAssetPairs.map((pair) => ({
|
|
506
|
+
value: pair.pairId,
|
|
507
|
+
label: (
|
|
508
|
+
<AstraImage
|
|
509
|
+
name={pair.token.name}
|
|
510
|
+
width="22px"
|
|
511
|
+
height="22px"
|
|
512
|
+
/>
|
|
513
|
+
),
|
|
514
|
+
}))}
|
|
515
|
+
onChange={onAssetPairChange}
|
|
516
|
+
></AstraSelect>
|
|
517
|
+
</FormItem>
|
|
518
|
+
)}
|
|
402
519
|
<span className="fw500">{formatTokenAmt}</span>
|
|
403
520
|
<span className="fw500">{currentAssetPair?.token?.name}</span>
|
|
404
521
|
</Flex>
|
|
405
522
|
<BalanceFlex justify="end" align="center" gap="5px">
|
|
406
523
|
<span className="available_token_balance">
|
|
407
|
-
Available:
|
|
524
|
+
Available:{" "}
|
|
525
|
+
<AvalibleBalance>
|
|
526
|
+
{tokenBalanceRet?.data?.formatted
|
|
527
|
+
? numberWithCommas(
|
|
528
|
+
new Decimal(
|
|
529
|
+
tokenBalanceRet?.data?.formatted
|
|
530
|
+
).toFixed(4, Decimal.ROUND_DOWN)
|
|
531
|
+
)
|
|
532
|
+
: 0}
|
|
533
|
+
</AvalibleBalance>
|
|
534
|
+
|
|
408
535
|
{tokenBalanceRet?.data?.symbol}
|
|
409
536
|
</span>
|
|
410
537
|
</BalanceFlex>
|
|
411
538
|
</FormItem>
|
|
412
539
|
|
|
413
|
-
<FormItem label="
|
|
540
|
+
<FormItem label="Receiving" style={{ marginBottom: 0 }}>
|
|
414
541
|
<Flex justify="end" align="center" gap="5px">
|
|
415
542
|
<AstraImage name={"Lightning"} />
|
|
416
543
|
<span className="colorcaff33">{formatAssetAmt}</span>
|