astra-modal-test 1.0.10 → 1.0.12
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/README.md +206 -134
- package/dist/{SwapController-DyormRqe.js → SwapController-mYFErPzx.js} +1 -1
- package/dist/{add-C1zIRxeS.js → add-CXtFvysR.js} +1 -1
- package/dist/{all-wallets-5a2U9fLw.js → all-wallets-B9fFXw5x.js} +1 -1
- package/dist/{app-store-2IKrZeLe.js → app-store-BXf1yvR8.js} +1 -1
- package/dist/{apple-DH9ESSKX.js → apple-DtcOcX1n.js} +1 -1
- package/dist/{arrow-bottom-BxAPS43J.js → arrow-bottom-BXeLKqSV.js} +1 -1
- package/dist/{arrow-bottom-circle-Cy5Gjca4.js → arrow-bottom-circle-BVUU200N.js} +1 -1
- package/dist/{arrow-left-CBX7JaHB.js → arrow-left-LguJPyNR.js} +1 -1
- package/dist/{arrow-right-G72bt1-M.js → arrow-right-D9kKZzGG.js} +1 -1
- package/dist/{arrow-top-DCkQG0Dq.js → arrow-top-C5JcaCqz.js} +1 -1
- package/dist/{bank-FNxAUs8r.js → bank-DgbCzr0A.js} +1 -1
- package/dist/{bin-B-c2CIPW.js → bin-ykHym2bC.js} +1 -1
- package/dist/{bitcoin-jk4NLDu1.js → bitcoin-B8jzy_uV.js} +1 -1
- package/dist/{browser-D6w0J78l.js → browser-Bk8u8PAA.js} +1 -1
- package/dist/{card-BLWRKU-r.js → card-DcwQMUca.js} +1 -1
- package/dist/ccip-CwJvuExU.js +239 -0
- package/dist/{checkmark-C1pTfaGr.js → checkmark-D3aEYZ8B.js} +1 -1
- package/dist/{checkmark-bold-UzogCu8g.js → checkmark-bold-5H7N-CDG.js} +1 -1
- package/dist/{chevron-bottom-w_rMAO7x.js → chevron-bottom-BA3C4MR1.js} +1 -1
- package/dist/{chevron-left-DGNJGxiP.js → chevron-left-BX18UWKM.js} +1 -1
- package/dist/{chevron-right-VFQCvCyG.js → chevron-right-DG7ovxTe.js} +1 -1
- package/dist/{chevron-top-DVhFmsKp.js → chevron-top-DHfev7lV.js} +1 -1
- package/dist/{chrome-store-BkYX3All.js → chrome-store-BSVzpGdu.js} +1 -1
- package/dist/{circle-B1A3j4eP.js → circle-SYFB9f2-.js} +1 -1
- package/dist/{clock-BKr-VHDU.js → clock-Cygqlf1g.js} +1 -1
- package/dist/{close-BEacRQ8Q.js → close-B43cuuko.js} +1 -1
- package/dist/{coinPlaceholder-0ZwtMAHl.js → coinPlaceholder-BHdR6bKb.js} +1 -1
- package/dist/{compass-pulK-BFi.js → compass-7S6b6wyA.js} +1 -1
- package/dist/{copy-MWCQE0T4.js → copy-CT53bEwd.js} +1 -1
- package/dist/{cursor-transparent-Co_5p0du.js → cursor-transparent-LmjzjsFm.js} +1 -1
- package/dist/{cursor-C2GVfUuM.js → cursor-vtqRnrF7.js} +1 -1
- package/dist/{desktop-C91EoSqM.js → desktop-Doa7TQsq.js} +1 -1
- package/dist/{disconnect-BWg1-rml.js → disconnect-C5G6Ncu_.js} +1 -1
- package/dist/{discord-Bi0Bfa_e.js → discord-DX7Cl3Ko.js} +1 -1
- package/dist/{email-U2WCRPFh.js → email-CyHWh9wL.js} +1 -1
- package/dist/{embedded-wallet-B6P0kU9A.js → embedded-wallet-BZQImi7s.js} +8 -8
- package/dist/{ethereum-BeZyayQW.js → ethereum-Bwvtk5-_.js} +1 -1
- package/dist/{etherscan-BQTsufjv.js → etherscan-CyVRICvw.js} +1 -1
- package/dist/{exclamation-triangle-JT-YKNXX.js → exclamation-triangle-BDbPL3nL.js} +1 -1
- package/dist/{extension-TnYLHoFA.js → extension-Cx3t2k-R.js} +1 -1
- package/dist/{external-link-Dhgai9sc.js → external-link-DZCYpOZI.js} +1 -1
- package/dist/{facebook-C6XFGRDw.js → facebook-BEnPrhG3.js} +1 -1
- package/dist/{farcaster-CvYbxZQq.js → farcaster-DyBPLb_k.js} +1 -1
- package/dist/{filters-DwVRjAav.js → filters-CTwxivn_.js} +1 -1
- package/dist/{github-BVZSx-z9.js → github-kzQb61pT.js} +1 -1
- package/dist/{google-NbJiQLc5.js → google-DSC-rYNu.js} +1 -1
- package/dist/{help-circle-Cum2UOMJ.js → help-circle-C5XfimVx.js} +1 -1
- package/dist/{id-kRR6YgVc.js → id-B9fQOT4E.js} +1 -1
- package/dist/{image-BWUCRAmp.js → image-1CCj36XM.js} +1 -1
- package/dist/{index-RFYbqmu0.js → index-Bjik7E9u.js} +1 -1
- package/dist/{index-DQ5AZLMt.js → index-C1fgrzi0.js} +16 -16
- package/dist/{index-BZZHE-1t.js → index-CyeGBcX0.js} +1 -1
- package/dist/{index-Dq0LIBEh.js → index-DKEMW9N8.js} +25 -25
- package/dist/{index-2vYoun4O.js → index-LucuShOc.js} +45292 -56275
- package/dist/{info-Br-SBtj3.js → info-Begf9tO0.js} +1 -1
- package/dist/{info-circle-Ew4RoR_Q.js → info-circle-Bo1H2OXh.js} +1 -1
- package/dist/{lightbulb-BRBVOE_b.js → lightbulb-C-SU_z2I.js} +1 -1
- package/dist/{mail-Dzi4AncY.js → mail-CXsYiNAT.js} +1 -1
- package/dist/{mobile-BGGxQ5be.js → mobile-C7bUjgog.js} +1 -1
- package/dist/{more-BmNaKbYJ.js → more-29BC-wmy.js} +1 -1
- package/dist/{network-placeholder-EMiMf4q1.js → network-placeholder-B-x3-6jN.js} +1 -1
- package/dist/{nftPlaceholder-CvSqy3Sd.js → nftPlaceholder-pM-Hmswq.js} +1 -1
- package/dist/nodeflow-sdk.es.js +15 -0
- package/dist/{off-DF9uz0Nc.js → off-DEa_uc7_.js} +1 -1
- package/dist/{onramp-cKzTmKku.js → onramp-ZXqyloYt.js} +10 -10
- package/dist/{play-store-CGxW4MgL.js → play-store-WgSEpEI1.js} +1 -1
- package/dist/{plus-CQ6wWkN0.js → plus-u4UZhYAg.js} +1 -1
- package/dist/{qr-code-VBqx9nAF.js → qr-code-DxZGxoPE.js} +1 -1
- package/dist/{receive-CVzkHmKR.js → receive-Ct_mQWzk.js} +1 -1
- package/dist/{recycle-horizontal-Oq1YtvUx.js → recycle-horizontal-BWVpmHJc.js} +1 -1
- package/dist/{refresh-BDlGAzmY.js → refresh-gi4TfgEU.js} +1 -1
- package/dist/{reown-logo-BlIpXIlG.js → reown-logo-Bg731n4w.js} +1 -1
- package/dist/{search-DfmCmp0m.js → search-BQv7DVJG.js} +1 -1
- package/dist/{send-BXudz514.js → send-BzmnFT2p.js} +1 -1
- package/dist/{send-Cz0L5LmE.js → send-CyxKtrQ9.js} +17 -17
- package/dist/{socials-CDOh8MRf.js → socials-vziOn4zi.js} +5 -5
- package/dist/{solana-CbiyOE-8.js → solana-Dz48awbr.js} +1 -1
- package/dist/{swapHorizontal-DyU1TH_e.js → swapHorizontal-Cwe1PoMp.js} +1 -1
- package/dist/{swapHorizontalBold-CGXW7Ocj.js → swapHorizontalBold-Dxu58sRG.js} +1 -1
- package/dist/{swapHorizontalMedium-2KTcj67d.js → swapHorizontalMedium-DOZZthlB.js} +1 -1
- package/dist/{swapHorizontalRoundedBold-TxFtmmda.js → swapHorizontalRoundedBold-BkIZQXnD.js} +1 -1
- package/dist/{swapVertical-BKD6lxM3.js → swapVertical-LSq66ctC.js} +1 -1
- package/dist/{swaps-BuGsEQaI.js → swaps-C2EO6dQA.js} +9 -9
- package/dist/{telegram-CAsl9DeG.js → telegram-ITq9s69Y.js} +1 -1
- package/dist/{three-dots-BoE2aHZi.js → three-dots-JH3A1TFR.js} +1 -1
- package/dist/{transactions-C1NtsnD6.js → transactions-DpMVZVap.js} +1 -1
- package/dist/{twitch-CvkZZxgT.js → twitch-BKs5FlDf.js} +1 -1
- package/dist/{twitterIcon-CrhnOl_O.js → twitterIcon-CCXEj_Nv.js} +1 -1
- package/dist/{ui-BJcuThPA.js → ui-D5ULRvGt.js} +6 -6
- package/dist/{user-BZRWUXG7.js → user-CBgAUjZv.js} +1 -1
- package/dist/{verify-y9F4DcJ4.js → verify-BPlPPkhG.js} +1 -1
- package/dist/{verify-filled-X_8-BhMk.js → verify-filled-qTRg0OWM.js} +1 -1
- package/dist/{w3m-modal-BX--v1Nc.js → w3m-modal-DSdDfy32.js} +27 -27
- package/dist/{wallet-CIaVVkjQ.js → wallet-BuDEi_8z.js} +1 -1
- package/dist/{wallet-placeholder-Cq1ofde1.js → wallet-placeholder-D4DKTuB_.js} +1 -1
- package/dist/{walletconnect-CINzSCJ3.js → walletconnect-Dt3q5XFc.js} +1 -1
- package/dist/{warning-circle-BvBNhMKH.js → warning-circle-B8Fkc0_4.js} +1 -1
- package/dist/{x-xHY7JehW.js → x-Cm_V3zUI.js} +1 -1
- package/dist/{x-mark-DEmnBt6u.js → x-mark-BVvwdxda.js} +1 -1
- package/package.json +11 -10
- package/.github/workflows/code-quality.yml +0 -43
- package/.github/workflows/publish.yml +0 -64
- package/dist/astra-sdk.es.js +0 -9
- package/dist/ccip-DkYvh7hg.js +0 -149
- package/dist/clsx.m-DCYaa4RU.js +0 -20
- package/dist/index-BDE-2VTp.js +0 -315
- package/dist/index-BjLIiJQa.js +0 -21034
- package/dist/index-CIr4zlVp.js +0 -386
- package/dist/index-ChxXyuZj.js +0 -572
- package/dist/index-D-T7kk3G.js +0 -15911
- package/dist/index-DSX3HrTS.js +0 -10785
- package/dist/secp256k1-CsKSDHNi.js +0 -1257
- package/eslint.config.mjs +0 -41
- package/index.html +0 -13
- package/public/font/ClashDisplay-Variable.ttf +0 -0
- package/public/font/ClashDisplay-Variable.woff +0 -0
- package/public/font/ClashDisplay-Variable.woff2 +0 -0
- package/public/vite.svg +0 -1
- package/src/App.css +0 -170
- package/src/apis/lspApi.js +0 -82
- package/src/apis/request.js +0 -59
- package/src/assets/arrow-right.svg +0 -3
- package/src/assets/astr.svg +0 -13
- package/src/assets/bridge-loading.png +0 -0
- 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/base.png +0 -0
- package/src/assets/network/botanix.png +0 -0
- package/src/assets/network/bsc.svg +0 -13
- package/src/assets/network/eth.png +0 -0
- package/src/assets/network/lighting.png +0 -0
- package/src/assets/network/ligtning.svg +0 -22
- package/src/assets/network/solona.png +0 -0
- package/src/assets/pay.png +0 -0
- package/src/assets/powerby.svg +0 -14
- package/src/assets/react.svg +0 -1
- package/src/assets/success.svg +0 -3
- package/src/assets/tip.svg +0 -5
- package/src/assets/tokens/sol.png +0 -0
- package/src/assets/tokens/usdc.png +0 -0
- package/src/assets/tokens/usdt.png +0 -0
- package/src/comps/AstraImage.jsx +0 -37
- package/src/comps/AstraModal.jsx +0 -202
- package/src/comps/AstraModalLogo.jsx +0 -29
- package/src/comps/AstraNetwork.jsx +0 -261
- package/src/comps/CheckErc20Button.jsx +0 -28
- package/src/comps/CommonStyle.jsx +0 -4
- package/src/comps/ConnectButton.jsx +0 -19
- package/src/comps/EllipsisMiddle.jsx +0 -42
- package/src/comps/ResultModal.jsx +0 -312
- package/src/comps/ToLightning.jsx +0 -653
- package/src/comps/ToToken.jsx +0 -550
- package/src/constants/index.js +0 -21
- package/src/font/ClashDisplay-Variable.ttf +0 -0
- package/src/font/ClashDisplay-Variable.woff +0 -0
- package/src/font/ClashDisplay-Variable.woff2 +0 -0
- package/src/hooks/useContract.js +0 -179
- package/src/hooks/useGetMinAndMax.js +0 -48
- package/src/hooks/useLspApi.js +0 -70
- package/src/hooks/useParseInvoice.js +0 -95
- package/src/index.css +0 -69
- package/src/index.jsx +0 -161
- package/src/lib/bolt11.min.js +0 -1
- package/src/main.jsx +0 -75
- package/src/store/index.js +0 -25
- package/src/theme.js +0 -108
- package/src/utils/index.js +0 -267
- package/vite.config.js +0 -50
package/src/comps/ToToken.jsx
DELETED
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
import { memo } from "react";
|
|
2
|
-
import styled from "styled-components";
|
|
3
|
-
import useStore from "../store";
|
|
4
|
-
import { Form, Button, Select, Flex, QRCode, Statistic, Spin } from "antd";
|
|
5
|
-
import { useCallback, useEffect, useState, useMemo } from "react";
|
|
6
|
-
import AstraImage from "./AstraImage";
|
|
7
|
-
import { useAccount, useBalance, useSwitchChain } from "wagmi";
|
|
8
|
-
import { DoubleRightOutlined } from "@ant-design/icons";
|
|
9
|
-
import EllipsisMiddle from "./EllipsisMiddle";
|
|
10
|
-
import { useBridgeContract } from "../hooks/useContract";
|
|
11
|
-
import { useGetReserveInfo } from "../hooks/useLspApi";
|
|
12
|
-
import { toEVM, getSignature, bridgeIntervalStatus } from "../apis/lspApi";
|
|
13
|
-
import { useGetMinAndMax } from "../hooks/useGetMinAndMax";
|
|
14
|
-
import Decimal from "decimal.js";
|
|
15
|
-
import ConnectButton from "./ConnectButton";
|
|
16
|
-
import { getParsedError, numberWithCommas } from "../utils";
|
|
17
|
-
import AstraNetwork from "./AstraNetwork";
|
|
18
|
-
import IconArrowRight from "../assets/arrow-right.svg";
|
|
19
|
-
import { AvalibleBalance } from "./CommonStyle";
|
|
20
|
-
|
|
21
|
-
const { Countdown } = Statistic;
|
|
22
|
-
const WrapperToLightning = styled.div``;
|
|
23
|
-
|
|
24
|
-
const FormItem = styled(Form.Item)`
|
|
25
|
-
.ant-form-item-label {
|
|
26
|
-
text-align: right;
|
|
27
|
-
}
|
|
28
|
-
`;
|
|
29
|
-
const AstraSelect = styled(Select)`
|
|
30
|
-
width: 60px !important;
|
|
31
|
-
.astra-select-selector {
|
|
32
|
-
padding: 0 0px !important;
|
|
33
|
-
}
|
|
34
|
-
.astra-select-selection-item {
|
|
35
|
-
display: flex !important;
|
|
36
|
-
align-items: center;
|
|
37
|
-
justify-content: center;
|
|
38
|
-
}
|
|
39
|
-
.astra-select-arrow {
|
|
40
|
-
color: #fff;
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
const QRCodeWrapper = styled(Flex)`
|
|
44
|
-
/* margin-bottom: 20px; */
|
|
45
|
-
`;
|
|
46
|
-
|
|
47
|
-
const SubmitBtn = styled(Button)`
|
|
48
|
-
width: 100%;
|
|
49
|
-
display: flex;
|
|
50
|
-
justify-content: space-between;
|
|
51
|
-
padding: 0 30px;
|
|
52
|
-
font-size: 16px;
|
|
53
|
-
line-height: 42px;
|
|
54
|
-
margin-top: 10px;
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
const BalanceFlex = styled(Flex)`
|
|
58
|
-
.available_token_balance {
|
|
59
|
-
font-size: 12px;
|
|
60
|
-
color: #fff;
|
|
61
|
-
}
|
|
62
|
-
`;
|
|
63
|
-
const AstraSendingReceived = styled.div`
|
|
64
|
-
padding: 8px 20px;
|
|
65
|
-
border-radius: 12px;
|
|
66
|
-
background: rgba(166, 166, 166, 0.1);
|
|
67
|
-
margin-bottom: 14px;
|
|
68
|
-
@media (max-width: 768px) {
|
|
69
|
-
padding: 8px 10px;
|
|
70
|
-
border-radius: 12px;
|
|
71
|
-
background: rgba(166, 166, 166, 0.1);
|
|
72
|
-
margin-bottom: 14px;
|
|
73
|
-
}
|
|
74
|
-
`;
|
|
75
|
-
const AstraFormItemOther = styled.div`
|
|
76
|
-
padding: 0 20px;
|
|
77
|
-
@media (max-width: 768px) {
|
|
78
|
-
padding: 0 10px;
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
81
|
-
function ToToken({ messageApi }) {
|
|
82
|
-
const {
|
|
83
|
-
sendArgs,
|
|
84
|
-
allAssetPairs,
|
|
85
|
-
targetNetwork,
|
|
86
|
-
setCurrentAssetPair,
|
|
87
|
-
currentAssetPair,
|
|
88
|
-
onAstraInvoice,
|
|
89
|
-
setAstraModalShow,
|
|
90
|
-
astraModalShow,
|
|
91
|
-
} = useStore();
|
|
92
|
-
const [sendInvoice, setSendInvoice] = useState("");
|
|
93
|
-
const [tx, setTx] = useState("");
|
|
94
|
-
const account = useAccount();
|
|
95
|
-
const [form] = Form.useForm();
|
|
96
|
-
const [submitLoading, setSubmitLoading] = useState(false);
|
|
97
|
-
const [invoiceExpired, setInvoiceExpired] = useState(0);
|
|
98
|
-
const [isInvoiceExpired, setIsInvoiceExpired] = useState(false);
|
|
99
|
-
const [payInvoiceLoading, setPayInvoiceLoading] = useState(false);
|
|
100
|
-
|
|
101
|
-
const { switchChain } = useSwitchChain();
|
|
102
|
-
|
|
103
|
-
const { filterdAssetPairs, validationError } = useMemo(() => {
|
|
104
|
-
const filtered = allAssetPairs.filter((pair) => {
|
|
105
|
-
return pair.asset.assetId === sendArgs.assetId;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// 校验资产是否支持
|
|
109
|
-
let error = null;
|
|
110
|
-
if (allAssetPairs.length > 0 && filtered.length === 0) {
|
|
111
|
-
const supportedAssets = allAssetPairs
|
|
112
|
-
.map(
|
|
113
|
-
(pair) =>
|
|
114
|
-
`${pair.asset.name} (${pair.asset.assetId.substring(0, 8)}...)`
|
|
115
|
-
)
|
|
116
|
-
.join(", ");
|
|
117
|
-
error = `Asset "${sendArgs.assetId.substring(
|
|
118
|
-
0,
|
|
119
|
-
8
|
|
120
|
-
)}..." is not supported. Supported assets: ${supportedAssets}`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return { filterdAssetPairs: filtered, validationError: error };
|
|
124
|
-
}, [allAssetPairs, sendArgs.assetId]);
|
|
125
|
-
// console.log("🚀 ~ ToLightning ~ allAssetPairs:", allAssetPairs, receiveArgs);
|
|
126
|
-
const { reserveInfo, loading: reserveInfoLoading } = useGetReserveInfo(
|
|
127
|
-
targetNetwork,
|
|
128
|
-
currentAssetPair
|
|
129
|
-
);
|
|
130
|
-
const { min, max, unitName } = useGetMinAndMax("lightningToEvm", reserveInfo);
|
|
131
|
-
const { onDeposit } = useBridgeContract(account);
|
|
132
|
-
|
|
133
|
-
const serviceFee = useMemo(() => {
|
|
134
|
-
if (!reserveInfo?.toAssetBaseFee) {
|
|
135
|
-
return 0;
|
|
136
|
-
}
|
|
137
|
-
return new Decimal(reserveInfo?.toAssetBaseFee.toString())
|
|
138
|
-
.div(10 ** 18)
|
|
139
|
-
.toFixed(8)
|
|
140
|
-
.replace(/\.?0+$/, "");
|
|
141
|
-
}, [reserveInfo?.toAssetBaseFee]);
|
|
142
|
-
|
|
143
|
-
const tokenBalanceRet = useBalance({
|
|
144
|
-
address: account?.address,
|
|
145
|
-
token: currentAssetPair?.token?.address,
|
|
146
|
-
query: {
|
|
147
|
-
enabled:
|
|
148
|
-
!!currentAssetPair?.token?.address &&
|
|
149
|
-
!!account?.address &&
|
|
150
|
-
astraModalShow,
|
|
151
|
-
},
|
|
152
|
-
formatUnits: currentAssetPair?.token?.decimal,
|
|
153
|
-
scopeKey: "tokenBalance",
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const mainnetBalanceRet = useBalance({
|
|
157
|
-
address: account?.address,
|
|
158
|
-
query: {
|
|
159
|
-
enabled: !!account?.address && astraModalShow,
|
|
160
|
-
},
|
|
161
|
-
formatUnits: "ether",
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
const onCheckBalance = useCallback(async () => {
|
|
165
|
-
const mainetBalance = mainnetBalanceRet?.data?.value || 0;
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
new Decimal(mainetBalance.toString()).lt(
|
|
169
|
-
new Decimal(reserveInfo?.toAssetBaseFee?.toString())
|
|
170
|
-
)
|
|
171
|
-
) {
|
|
172
|
-
throw new Error("Insufficient balance to pay service fee.");
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (Number(sendArgs.amount) < Number(min)) {
|
|
176
|
-
throw new Error(`The minimum amount is ${min} ${unitName}`);
|
|
177
|
-
}
|
|
178
|
-
if (Number(sendArgs.amount) > Number(max)) {
|
|
179
|
-
throw new Error(`The maximum amount is ${max} ${unitName}`);
|
|
180
|
-
}
|
|
181
|
-
}, [
|
|
182
|
-
mainnetBalanceRet?.data?.value,
|
|
183
|
-
reserveInfo?.toAssetBaseFee,
|
|
184
|
-
sendArgs?.amount,
|
|
185
|
-
min,
|
|
186
|
-
max,
|
|
187
|
-
unitName,
|
|
188
|
-
]);
|
|
189
|
-
|
|
190
|
-
const onResetInvoice = useCallback(() => {
|
|
191
|
-
setIsInvoiceExpired(false);
|
|
192
|
-
setInvoiceExpired(0);
|
|
193
|
-
setSendInvoice("");
|
|
194
|
-
}, []);
|
|
195
|
-
|
|
196
|
-
const onAssetPairChange = useCallback(
|
|
197
|
-
(pairId) => {
|
|
198
|
-
const selectedPair = pairId
|
|
199
|
-
? allAssetPairs.find((pair) => pair.pairId === pairId)
|
|
200
|
-
: null;
|
|
201
|
-
setCurrentAssetPair(selectedPair);
|
|
202
|
-
},
|
|
203
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
204
|
-
[allAssetPairs]
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
const onFinish = useCallback(async () => {
|
|
208
|
-
try {
|
|
209
|
-
setSubmitLoading(true);
|
|
210
|
-
onResetInvoice();
|
|
211
|
-
await onCheckBalance();
|
|
212
|
-
const bridgeIntervalRet = await bridgeIntervalStatus({
|
|
213
|
-
address: account?.address,
|
|
214
|
-
});
|
|
215
|
-
if (bridgeIntervalRet.code !== 200) {
|
|
216
|
-
throw new Error(bridgeIntervalRet.data);
|
|
217
|
-
}
|
|
218
|
-
const bridgeIntervalData = bridgeIntervalRet.data;
|
|
219
|
-
if (!bridgeIntervalData?.isAllowed) {
|
|
220
|
-
const remainingMinutes = Math.ceil(
|
|
221
|
-
bridgeIntervalData.remainingSeconds / 60
|
|
222
|
-
);
|
|
223
|
-
throw new Error(
|
|
224
|
-
`Bridge interval not met. Please wait ${remainingMinutes} more minute(s).`
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
const retGetSignature = await getSignature({
|
|
228
|
-
chainId: targetNetwork.id,
|
|
229
|
-
amount: sendArgs.amount,
|
|
230
|
-
pairId: currentAssetPair?.pairId,
|
|
231
|
-
});
|
|
232
|
-
if (retGetSignature?.code !== 200) {
|
|
233
|
-
throw new Error(retGetSignature?.msg);
|
|
234
|
-
}
|
|
235
|
-
const signatureRes = retGetSignature?.data;
|
|
236
|
-
const hashlock = signatureRes.hashlock;
|
|
237
|
-
const fromAddr = signatureRes.lspAddress;
|
|
238
|
-
|
|
239
|
-
const pairId = signatureRes.pairId;
|
|
240
|
-
const amount = BigInt(signatureRes.amtInContract);
|
|
241
|
-
const timeLock = BigInt(signatureRes.deltaSecond);
|
|
242
|
-
const expiredAt = Date.now() + Number(timeLock) * 1000;
|
|
243
|
-
const lspNodePubKey = signatureRes.lspNodePubKey;
|
|
244
|
-
setInvoiceExpired(expiredAt);
|
|
245
|
-
const signature = signatureRes.signature;
|
|
246
|
-
const fee = signatureRes.fee;
|
|
247
|
-
|
|
248
|
-
const depositArgs = {
|
|
249
|
-
hashlock,
|
|
250
|
-
fromAddr,
|
|
251
|
-
toAddr: account.address,
|
|
252
|
-
pairId: pairId,
|
|
253
|
-
amount: amount,
|
|
254
|
-
timeLock: timeLock,
|
|
255
|
-
toLightning: false,
|
|
256
|
-
fee: fee,
|
|
257
|
-
signature,
|
|
258
|
-
nodePubkey: lspNodePubKey,
|
|
259
|
-
};
|
|
260
|
-
const tx = await onDeposit(depositArgs, true, false);
|
|
261
|
-
setTx(tx);
|
|
262
|
-
if (tx) {
|
|
263
|
-
const request = {
|
|
264
|
-
pairId: pairId,
|
|
265
|
-
amount: sendArgs.amount,
|
|
266
|
-
chainId: targetNetwork.id,
|
|
267
|
-
hashlock: signatureRes.hashlock,
|
|
268
|
-
depositTx: tx,
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const retToEVM = await toEVM(request);
|
|
272
|
-
if (retToEVM.code === 200) {
|
|
273
|
-
messageApi.success("Submit success.");
|
|
274
|
-
setSendInvoice(retToEVM.data.invoice);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
} catch (e) {
|
|
278
|
-
const error = getParsedError(e);
|
|
279
|
-
if (error.includes("does not match the target chain")) {
|
|
280
|
-
switchChain(
|
|
281
|
-
{ chainId: targetNetwork.id },
|
|
282
|
-
{
|
|
283
|
-
onSuccess: () => {
|
|
284
|
-
messageApi.success(
|
|
285
|
-
`Switch chain ${targetNetwork.name} success, please try again.`
|
|
286
|
-
);
|
|
287
|
-
},
|
|
288
|
-
}
|
|
289
|
-
);
|
|
290
|
-
} else {
|
|
291
|
-
messageApi.error(error);
|
|
292
|
-
}
|
|
293
|
-
} finally {
|
|
294
|
-
setSubmitLoading(false);
|
|
295
|
-
}
|
|
296
|
-
}, [
|
|
297
|
-
onResetInvoice,
|
|
298
|
-
onCheckBalance,
|
|
299
|
-
targetNetwork,
|
|
300
|
-
sendArgs?.amount,
|
|
301
|
-
currentAssetPair?.pairId,
|
|
302
|
-
account?.address,
|
|
303
|
-
onDeposit,
|
|
304
|
-
messageApi,
|
|
305
|
-
switchChain,
|
|
306
|
-
]);
|
|
307
|
-
|
|
308
|
-
const btn = useMemo(() => {
|
|
309
|
-
if (!account?.address) {
|
|
310
|
-
return <ConnectButton />;
|
|
311
|
-
}
|
|
312
|
-
if (sendInvoice) {
|
|
313
|
-
return submitLoading ? (
|
|
314
|
-
<SubmitBtn type="primary" loading={submitLoading}>
|
|
315
|
-
<span>Waiting for Confirmation</span>
|
|
316
|
-
</SubmitBtn>
|
|
317
|
-
) : (
|
|
318
|
-
<SubmitBtn
|
|
319
|
-
type="primary"
|
|
320
|
-
disabled={isInvoiceExpired}
|
|
321
|
-
loading={payInvoiceLoading}
|
|
322
|
-
onClick={async () => {
|
|
323
|
-
setPayInvoiceLoading(true);
|
|
324
|
-
const txUrl = `${targetNetwork?.blockExplorers?.default.url}/tx/${tx}`;
|
|
325
|
-
await onAstraInvoice(sendInvoice, tx, txUrl)
|
|
326
|
-
.catch((e) => {
|
|
327
|
-
messageApi.error(e.message);
|
|
328
|
-
setPayInvoiceLoading(false);
|
|
329
|
-
return;
|
|
330
|
-
})
|
|
331
|
-
.finally(() => {
|
|
332
|
-
setPayInvoiceLoading(false);
|
|
333
|
-
});
|
|
334
|
-
setAstraModalShow(false);
|
|
335
|
-
}}
|
|
336
|
-
>
|
|
337
|
-
<span>Pay Invoice</span>
|
|
338
|
-
<img src={IconArrowRight} alt="" />
|
|
339
|
-
</SubmitBtn>
|
|
340
|
-
);
|
|
341
|
-
} else {
|
|
342
|
-
return (
|
|
343
|
-
<SubmitBtn
|
|
344
|
-
type="primary"
|
|
345
|
-
htmlType="submit"
|
|
346
|
-
loading={submitLoading}
|
|
347
|
-
disabled={isInvoiceExpired || validationError}
|
|
348
|
-
>
|
|
349
|
-
<span>{submitLoading ? "Waiting for Confirmation" : "Withdraw"}</span>
|
|
350
|
-
<img src={IconArrowRight} alt="" />
|
|
351
|
-
</SubmitBtn>
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
}, [
|
|
355
|
-
account?.address,
|
|
356
|
-
isInvoiceExpired,
|
|
357
|
-
messageApi,
|
|
358
|
-
onAstraInvoice,
|
|
359
|
-
payInvoiceLoading,
|
|
360
|
-
sendInvoice,
|
|
361
|
-
setAstraModalShow,
|
|
362
|
-
submitLoading,
|
|
363
|
-
targetNetwork?.blockExplorers?.default.url,
|
|
364
|
-
tx,
|
|
365
|
-
validationError,
|
|
366
|
-
]);
|
|
367
|
-
|
|
368
|
-
const onExpired = useCallback(() => {
|
|
369
|
-
setIsInvoiceExpired(true);
|
|
370
|
-
}, []);
|
|
371
|
-
|
|
372
|
-
useEffect(() => {
|
|
373
|
-
if (filterdAssetPairs?.length > 0) {
|
|
374
|
-
setCurrentAssetPair(filterdAssetPairs[0]);
|
|
375
|
-
form.setFieldValue("received", filterdAssetPairs?.[0]?.pairId);
|
|
376
|
-
} else {
|
|
377
|
-
setCurrentAssetPair(null);
|
|
378
|
-
form.setFieldValue("received", "");
|
|
379
|
-
}
|
|
380
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
381
|
-
}, [filterdAssetPairs, form]);
|
|
382
|
-
return (
|
|
383
|
-
<WrapperToLightning>
|
|
384
|
-
<Spin spinning={reserveInfoLoading}>
|
|
385
|
-
{validationError && (
|
|
386
|
-
<div
|
|
387
|
-
style={{
|
|
388
|
-
padding: "12px 16px",
|
|
389
|
-
marginBottom: "16px",
|
|
390
|
-
borderRadius: "8px",
|
|
391
|
-
background: "rgba(255, 77, 79, 0.1)",
|
|
392
|
-
border: "1px solid rgba(255, 77, 79, 0.3)",
|
|
393
|
-
color: "#ff4d4f",
|
|
394
|
-
fontSize: "14px",
|
|
395
|
-
lineHeight: "1.5",
|
|
396
|
-
}}
|
|
397
|
-
>
|
|
398
|
-
⚠️ {validationError}
|
|
399
|
-
</div>
|
|
400
|
-
)}
|
|
401
|
-
<Form
|
|
402
|
-
name="basic"
|
|
403
|
-
form={form}
|
|
404
|
-
colon={false}
|
|
405
|
-
style={{
|
|
406
|
-
width: "100%",
|
|
407
|
-
}}
|
|
408
|
-
initialValues={{
|
|
409
|
-
remember: true,
|
|
410
|
-
}}
|
|
411
|
-
onFinish={onFinish}
|
|
412
|
-
autoComplete="off"
|
|
413
|
-
>
|
|
414
|
-
<AstraNetwork
|
|
415
|
-
messageApi={messageApi}
|
|
416
|
-
balance={mainnetBalanceRet?.data}
|
|
417
|
-
/>
|
|
418
|
-
<AstraSendingReceived>
|
|
419
|
-
<FormItem label="Sending">
|
|
420
|
-
<Flex justify="end" align="center" gap="5px">
|
|
421
|
-
<AstraImage name={"Lightning"} />
|
|
422
|
-
<span className="fw500 colorcaff33">{sendArgs?.amount}</span>
|
|
423
|
-
<span className="fw500 colorcaff33">
|
|
424
|
-
{currentAssetPair?.asset?.name}
|
|
425
|
-
</span>
|
|
426
|
-
</Flex>
|
|
427
|
-
</FormItem>
|
|
428
|
-
|
|
429
|
-
<FormItem label="Receiving" style={{ marginBottom: 0 }}>
|
|
430
|
-
<Flex justify="end" align="center" gap="5px">
|
|
431
|
-
{filterdAssetPairs.length > 0 && (
|
|
432
|
-
<FormItem name="received" noStyle className="form-item-pair">
|
|
433
|
-
<AstraSelect
|
|
434
|
-
variant="borderless"
|
|
435
|
-
options={filterdAssetPairs.map((pair) => ({
|
|
436
|
-
value: pair.pairId,
|
|
437
|
-
label: (
|
|
438
|
-
<AstraImage
|
|
439
|
-
name={pair.token.name}
|
|
440
|
-
width="22px"
|
|
441
|
-
height="22px"
|
|
442
|
-
/>
|
|
443
|
-
),
|
|
444
|
-
}))}
|
|
445
|
-
onChange={onAssetPairChange}
|
|
446
|
-
></AstraSelect>
|
|
447
|
-
</FormItem>
|
|
448
|
-
)}
|
|
449
|
-
<span>{sendArgs?.amount}</span>
|
|
450
|
-
<span>{currentAssetPair?.token?.name}</span>
|
|
451
|
-
</Flex>
|
|
452
|
-
<BalanceFlex justify="end" align="center" gap="5px">
|
|
453
|
-
<span className="available_token_balance">
|
|
454
|
-
Available:
|
|
455
|
-
<AvalibleBalance>
|
|
456
|
-
|
|
457
|
-
{tokenBalanceRet?.data?.formatted
|
|
458
|
-
? numberWithCommas(
|
|
459
|
-
new Decimal(tokenBalanceRet?.data?.formatted).toFixed(
|
|
460
|
-
4,
|
|
461
|
-
Decimal.ROUND_DOWN
|
|
462
|
-
)
|
|
463
|
-
)
|
|
464
|
-
: 0}
|
|
465
|
-
</AvalibleBalance>
|
|
466
|
-
{tokenBalanceRet?.data?.symbol}
|
|
467
|
-
</span>
|
|
468
|
-
</BalanceFlex>
|
|
469
|
-
</FormItem>
|
|
470
|
-
</AstraSendingReceived>
|
|
471
|
-
<AstraFormItemOther>
|
|
472
|
-
<FormItem label="Service fee">
|
|
473
|
-
<Flex justify="end" align="center" gap="5px">
|
|
474
|
-
<span>{serviceFee}</span>
|
|
475
|
-
<AstraImage
|
|
476
|
-
name={targetNetwork?.name}
|
|
477
|
-
width="24px"
|
|
478
|
-
height="24px"
|
|
479
|
-
/>
|
|
480
|
-
</Flex>
|
|
481
|
-
</FormItem>
|
|
482
|
-
|
|
483
|
-
<FormItem label="Receiving address">
|
|
484
|
-
<Flex justify="end" align="center" gap="5px">
|
|
485
|
-
<AstraImage name={targetNetwork?.name} />
|
|
486
|
-
<EllipsisMiddle suffixCount={6}>
|
|
487
|
-
{account?.address ?? "--"}
|
|
488
|
-
</EllipsisMiddle>
|
|
489
|
-
</Flex>
|
|
490
|
-
</FormItem>
|
|
491
|
-
<FormItem label="Route">
|
|
492
|
-
<Flex justify="end" align="center" gap="5px">
|
|
493
|
-
<AstraImage name="Lightning" />
|
|
494
|
-
<DoubleRightOutlined style={{ color: "#caff33" }} />
|
|
495
|
-
<AstraImage
|
|
496
|
-
name={targetNetwork?.name}
|
|
497
|
-
width="24px"
|
|
498
|
-
height="24px"
|
|
499
|
-
/>
|
|
500
|
-
</Flex>
|
|
501
|
-
</FormItem>
|
|
502
|
-
</AstraFormItemOther>
|
|
503
|
-
{sendInvoice && (
|
|
504
|
-
<>
|
|
505
|
-
<QRCodeWrapper
|
|
506
|
-
justify="center"
|
|
507
|
-
align="center"
|
|
508
|
-
gap="10px"
|
|
509
|
-
vertical={true}
|
|
510
|
-
>
|
|
511
|
-
<QRCode
|
|
512
|
-
type="svg"
|
|
513
|
-
size={200}
|
|
514
|
-
errorLevel="M"
|
|
515
|
-
iconSize={40}
|
|
516
|
-
value={sendInvoice}
|
|
517
|
-
bordered={false}
|
|
518
|
-
status={isInvoiceExpired ? "expired" : "active"}
|
|
519
|
-
/>
|
|
520
|
-
<Countdown
|
|
521
|
-
title="Invoice expires in"
|
|
522
|
-
valueStyle={{
|
|
523
|
-
color: "#caff33",
|
|
524
|
-
fontSize: "14px",
|
|
525
|
-
textAlign: "center",
|
|
526
|
-
}}
|
|
527
|
-
value={invoiceExpired}
|
|
528
|
-
onFinish={onExpired}
|
|
529
|
-
/>
|
|
530
|
-
</QRCodeWrapper>
|
|
531
|
-
</>
|
|
532
|
-
)}
|
|
533
|
-
|
|
534
|
-
<FormItem
|
|
535
|
-
label={null}
|
|
536
|
-
labelCol={{
|
|
537
|
-
span: 0,
|
|
538
|
-
}}
|
|
539
|
-
wrapperCol={{
|
|
540
|
-
span: 24,
|
|
541
|
-
}}
|
|
542
|
-
>
|
|
543
|
-
<Flex justify="center"> {btn}</Flex>
|
|
544
|
-
</FormItem>
|
|
545
|
-
</Form>
|
|
546
|
-
</Spin>
|
|
547
|
-
</WrapperToLightning>
|
|
548
|
-
);
|
|
549
|
-
}
|
|
550
|
-
export default memo(ToToken);
|
package/src/constants/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import Decimal from "decimal.js";
|
|
2
|
-
Decimal.set({
|
|
3
|
-
toExpNeg: -20,
|
|
4
|
-
toExpPos: 40,
|
|
5
|
-
});
|
|
6
|
-
export const MODAL_DISPLAY_TYPE = {
|
|
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
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|