astra-modal-test 1.0.9 → 1.0.11

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.
Files changed (167) hide show
  1. package/README.md +118 -148
  2. package/dist/{SwapController-rSbURdpJ.js → SwapController-Ck3TYcMp.js} +1 -1
  3. package/dist/{add-CpqI0qih.js → add-BmBLHIEe.js} +1 -1
  4. package/dist/{all-wallets-BCS6tMyX.js → all-wallets-H2aaJ2oP.js} +1 -1
  5. package/dist/{app-store-BJcpQsmn.js → app-store-Bvhe1BkA.js} +1 -1
  6. package/dist/{apple-BYXq8xra.js → apple-BCIKns5c.js} +1 -1
  7. package/dist/{arrow-bottom-circle-7zz6Cez4.js → arrow-bottom-circle-Dpcn0z0p.js} +1 -1
  8. package/dist/{arrow-bottom-DyDya01u.js → arrow-bottom-i1ChNkSf.js} +1 -1
  9. package/dist/{arrow-left-DFjTrDxq.js → arrow-left-Dj8tzUf6.js} +1 -1
  10. package/dist/{arrow-right-BeKBpPGZ.js → arrow-right-DVd3R-0K.js} +1 -1
  11. package/dist/{arrow-top-C8kkMQwd.js → arrow-top-DcD5wbZL.js} +1 -1
  12. package/dist/astra-sdk.es.js +1 -1
  13. package/dist/{bank-FSmmDSOr.js → bank-CToLOTy3.js} +1 -1
  14. package/dist/{bin-BxSWmf4U.js → bin-D8m48Dk5.js} +1 -1
  15. package/dist/{bitcoin-DOtAY1tg.js → bitcoin-y6S4LO0p.js} +1 -1
  16. package/dist/{browser-CxU-j1-l.js → browser-DRhVaQQT.js} +1 -1
  17. package/dist/{card-CjYkck9C.js → card-BK0q3S4W.js} +1 -1
  18. package/dist/{ccip-Dzjn7iUj.js → ccip-CH1B6Zeh.js} +1 -1
  19. package/dist/{checkmark-BQzWjMBG.js → checkmark-C7H1vH4H.js} +1 -1
  20. package/dist/{checkmark-bold-CydTLhCY.js → checkmark-bold-DfvIWKpu.js} +1 -1
  21. package/dist/{chevron-bottom-CA607zpT.js → chevron-bottom-CcAEP6cD.js} +1 -1
  22. package/dist/{chevron-left-BGmBZSZo.js → chevron-left-DMnhSBVl.js} +1 -1
  23. package/dist/{chevron-right-NBRpcLa8.js → chevron-right-pPhw9ZBC.js} +1 -1
  24. package/dist/{chevron-top-Cw5I5ZOR.js → chevron-top-DjqOCRAL.js} +1 -1
  25. package/dist/{chrome-store-Bg96vfCc.js → chrome-store-B-9bRAPM.js} +1 -1
  26. package/dist/{circle-D_QW929y.js → circle-SPbxfVZq.js} +1 -1
  27. package/dist/{clock-o4gqCbWO.js → clock-BLAT4wv4.js} +1 -1
  28. package/dist/{close-z2Y-xc4H.js → close-D1AyyJzy.js} +1 -1
  29. package/dist/{coinPlaceholder-D_9U8ws8.js → coinPlaceholder-DGk1in74.js} +1 -1
  30. package/dist/{compass-BVM30Hj-.js → compass-C0-SVkSt.js} +1 -1
  31. package/dist/{copy-BvKR_En_.js → copy-CPcvwITz.js} +1 -1
  32. package/dist/{cursor-DKFz2C-k.js → cursor-ChlOWEcO.js} +1 -1
  33. package/dist/{cursor-transparent-DwsHTJdY.js → cursor-transparent-BJsEpe-G.js} +1 -1
  34. package/dist/{desktop-_hiZGUrG.js → desktop-Z8iZvVCW.js} +1 -1
  35. package/dist/{disconnect-DbmK87x7.js → disconnect-DkPQjiLk.js} +1 -1
  36. package/dist/{discord-CGEs_Ewv.js → discord-CwRdgvGZ.js} +1 -1
  37. package/dist/{email-B64OZpkU.js → email-DA_5xt-j.js} +1 -1
  38. package/dist/{embedded-wallet-CdFJiA0M.js → embedded-wallet-DYnGl5tL.js} +1 -1
  39. package/dist/{ethereum-ByYB2hkU.js → ethereum-Dwse3Umc.js} +1 -1
  40. package/dist/{etherscan-BbjvIHaL.js → etherscan-CNmwyrRn.js} +1 -1
  41. package/dist/{exclamation-triangle-CdD-9Mg9.js → exclamation-triangle-CU8gn-bU.js} +1 -1
  42. package/dist/{extension-CwWz_fIf.js → extension-rikwXWrg.js} +1 -1
  43. package/dist/{external-link-B-H5cp6t.js → external-link-mDp8JVE0.js} +1 -1
  44. package/dist/{facebook-BCVDL-tg.js → facebook-c0IS1D9G.js} +1 -1
  45. package/dist/{farcaster-jtO1GaIa.js → farcaster-DpvSDnGl.js} +1 -1
  46. package/dist/{filters-D-d663Tl.js → filters-B42-1BLn.js} +1 -1
  47. package/dist/{github-GYbnMtDL.js → github-DvjZxkXF.js} +1 -1
  48. package/dist/{google-D0T6MiMp.js → google-CLHf_zAz.js} +1 -1
  49. package/dist/{help-circle-S_PJYnAb.js → help-circle-BI5xgPAz.js} +1 -1
  50. package/dist/{id-ovWduNYl.js → id-BxI79dX4.js} +1 -1
  51. package/dist/{image-DWMmztGY.js → image-Cr1qAxG-.js} +1 -1
  52. package/dist/{index-RJEV23nN.js → index-C0USsgDi.js} +1 -1
  53. package/dist/{index-D49QXkg7.js → index-C49-8bCQ.js} +1 -1
  54. package/dist/{index-DEIfu1o6.js → index-CH4T0JAz.js} +1 -1
  55. package/dist/{index-CJ7s8Rmk.js → index-CWAoFGd1.js} +6 -6
  56. package/dist/{index-3RuZHNxg.js → index-C_3PUMa7.js} +1 -1
  57. package/dist/{index-Dv7m_bJu.js → index-D7jufxlk.js} +1 -1
  58. package/dist/{index-BrVBbGpA.js → index-DZiQey0J.js} +1 -1
  59. package/dist/{index-CXZjl-KY.js → index-DtAG8k9M.js} +1 -1
  60. package/dist/{index-DpJh5yXk.js → index-Zh6wUpmX.js} +4008 -3984
  61. package/dist/{index-CTtOlAw3.js → index-utoSbRla.js} +1 -1
  62. package/dist/{info-B_t5Wxs5.js → info-BUp5BYav.js} +1 -1
  63. package/dist/{info-circle-BE3c4h9q.js → info-circle-D5anzkYK.js} +1 -1
  64. package/dist/{lightbulb-WY74qWMh.js → lightbulb-DmuhLv29.js} +1 -1
  65. package/dist/{mail-BZffBQJn.js → mail-D2hRmmgi.js} +1 -1
  66. package/dist/{mobile-BzoKYXrP.js → mobile-Cq-9uJHv.js} +1 -1
  67. package/dist/{more-DLl0U_yq.js → more-DJMBaB2z.js} +1 -1
  68. package/dist/{network-placeholder-GUlJsW90.js → network-placeholder-3ip1roR0.js} +1 -1
  69. package/dist/{nftPlaceholder-URobOrrj.js → nftPlaceholder-C7r74zYS.js} +1 -1
  70. package/dist/{off-Dd3KIizg.js → off-CJE6Z_MK.js} +1 -1
  71. package/dist/{onramp-D3nPDHgs.js → onramp-BMRgbt2I.js} +1 -1
  72. package/dist/{play-store-DQcCWm53.js → play-store-CxusWynI.js} +1 -1
  73. package/dist/{plus-CBsitvpf.js → plus-Bjkqj5g6.js} +1 -1
  74. package/dist/{qr-code-BLKOY5TH.js → qr-code-4C0zboga.js} +1 -1
  75. package/dist/{receive-Cs7OrQ5H.js → receive-Cc8moHBZ.js} +1 -1
  76. package/dist/{recycle-horizontal-DA3_DhRi.js → recycle-horizontal-BdSgk84g.js} +1 -1
  77. package/dist/{refresh-DA83X8jf.js → refresh-BsRodAS7.js} +1 -1
  78. package/dist/{reown-logo-CYujsMCS.js → reown-logo-DOVlqCDK.js} +1 -1
  79. package/dist/{search-dhyszWwL.js → search-BIyHtky-.js} +1 -1
  80. package/dist/{secp256k1-BzR-XYTV.js → secp256k1-B2Gq-iIr.js} +1 -1
  81. package/dist/{send-Djdyyp-y.js → send-9eSi58hW.js} +1 -1
  82. package/dist/{send-Dio4rhmI.js → send-CBFTcYtn.js} +3 -3
  83. package/dist/{socials-CyiUMsk1.js → socials-CeOJULFV.js} +1 -1
  84. package/dist/{solana-B01U90Av.js → solana-BNptwYvn.js} +1 -1
  85. package/dist/{swapHorizontal-BazEPj1l.js → swapHorizontal-COlgqyzt.js} +1 -1
  86. package/dist/{swapHorizontalBold-DOjBCDPH.js → swapHorizontalBold-Odce2JOe.js} +1 -1
  87. package/dist/{swapHorizontalMedium-Bp7rqwQ_.js → swapHorizontalMedium-B9nkEBPD.js} +1 -1
  88. package/dist/{swapHorizontalRoundedBold-fXXQeesr.js → swapHorizontalRoundedBold-DPMzz6nz.js} +1 -1
  89. package/dist/{swapVertical-lb6FRfr-.js → swapVertical-FqQP9GBP.js} +1 -1
  90. package/dist/{swaps-DXWgEjt_.js → swaps-BG9GOayX.js} +3 -3
  91. package/dist/{telegram-Cw3woU3F.js → telegram-BMY9Hs9Z.js} +1 -1
  92. package/dist/{three-dots-CrS1ZJoA.js → three-dots-DDKmexHU.js} +1 -1
  93. package/dist/{transactions-ClKYRDBc.js → transactions-C_GII6kW.js} +1 -1
  94. package/dist/{twitch-BTFS8sbh.js → twitch-x_s0neNg.js} +1 -1
  95. package/dist/{twitterIcon-BEey2zuH.js → twitterIcon-CKsSxEuJ.js} +1 -1
  96. package/dist/{ui-xSZiungl.js → ui-CZH-vf5h.js} +2 -2
  97. package/dist/{user-fcwj6TqA.js → user-CZfvQDJ_.js} +1 -1
  98. package/dist/{verify-BLatL5Dw.js → verify-Bnvbadnx.js} +1 -1
  99. package/dist/{verify-filled-DPYDyDVg.js → verify-filled-CnEopkW-.js} +1 -1
  100. package/dist/{w3m-modal-IpSIarQs.js → w3m-modal-DkI2TPJW.js} +2 -2
  101. package/dist/{wallet-Cgmznx42.js → wallet-B3oN4n4q.js} +1 -1
  102. package/dist/{wallet-placeholder-B7P5m3g1.js → wallet-placeholder-CI0oiAcd.js} +1 -1
  103. package/dist/{walletconnect-DPJfWPxF.js → walletconnect-D4vMcjqO.js} +1 -1
  104. package/dist/{warning-circle-yU7or6qZ.js → warning-circle-DjI8aRBs.js} +1 -1
  105. package/dist/{x-Cr3BPl_T.js → x-BgRWY62H.js} +1 -1
  106. package/dist/{x-mark-CZyZTZeg.js → x-mark-Cdqd-Hm4.js} +1 -1
  107. package/package.json +6 -1
  108. package/.github/workflows/code-quality.yml +0 -43
  109. package/.github/workflows/publish.yml +0 -64
  110. package/eslint.config.mjs +0 -41
  111. package/index.html +0 -13
  112. package/public/font/ClashDisplay-Variable.ttf +0 -0
  113. package/public/font/ClashDisplay-Variable.woff +0 -0
  114. package/public/font/ClashDisplay-Variable.woff2 +0 -0
  115. package/public/vite.svg +0 -1
  116. package/src/App.css +0 -170
  117. package/src/apis/lspApi.js +0 -82
  118. package/src/apis/request.js +0 -59
  119. package/src/assets/arrow-right.svg +0 -3
  120. package/src/assets/astr.svg +0 -13
  121. package/src/assets/bridge-loading.png +0 -0
  122. package/src/assets/ln.png +0 -0
  123. package/src/assets/network/Arbitrum.png +0 -0
  124. package/src/assets/network/Polygon.png +0 -0
  125. package/src/assets/network/Solana.png +0 -0
  126. package/src/assets/network/base.png +0 -0
  127. package/src/assets/network/botanix.png +0 -0
  128. package/src/assets/network/bsc.svg +0 -13
  129. package/src/assets/network/eth.png +0 -0
  130. package/src/assets/network/lighting.png +0 -0
  131. package/src/assets/network/ligtning.svg +0 -22
  132. package/src/assets/network/solona.png +0 -0
  133. package/src/assets/pay.png +0 -0
  134. package/src/assets/powerby.svg +0 -14
  135. package/src/assets/react.svg +0 -1
  136. package/src/assets/success.svg +0 -3
  137. package/src/assets/tip.svg +0 -5
  138. package/src/assets/tokens/sol.png +0 -0
  139. package/src/assets/tokens/usdc.png +0 -0
  140. package/src/assets/tokens/usdt.png +0 -0
  141. package/src/comps/AstraImage.jsx +0 -37
  142. package/src/comps/AstraModal.jsx +0 -202
  143. package/src/comps/AstraModalLogo.jsx +0 -29
  144. package/src/comps/AstraNetwork.jsx +0 -261
  145. package/src/comps/CheckErc20Button.jsx +0 -28
  146. package/src/comps/CommonStyle.jsx +0 -4
  147. package/src/comps/ConnectButton.jsx +0 -19
  148. package/src/comps/EllipsisMiddle.jsx +0 -42
  149. package/src/comps/ResultModal.jsx +0 -312
  150. package/src/comps/ToLightning.jsx +0 -653
  151. package/src/comps/ToToken.jsx +0 -550
  152. package/src/constants/index.js +0 -21
  153. package/src/font/ClashDisplay-Variable.ttf +0 -0
  154. package/src/font/ClashDisplay-Variable.woff +0 -0
  155. package/src/font/ClashDisplay-Variable.woff2 +0 -0
  156. package/src/hooks/useContract.js +0 -179
  157. package/src/hooks/useGetMinAndMax.js +0 -48
  158. package/src/hooks/useLspApi.js +0 -70
  159. package/src/hooks/useParseInvoice.js +0 -95
  160. package/src/index.css +0 -69
  161. package/src/index.jsx +0 -161
  162. package/src/lib/bolt11.min.js +0 -1
  163. package/src/main.jsx +0 -75
  164. package/src/store/index.js +0 -25
  165. package/src/theme.js +0 -108
  166. package/src/utils/index.js +0 -267
  167. package/vite.config.js +0 -50
@@ -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
- &nbsp;
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);
@@ -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