astra-modal-test 1.0.10 → 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-DyormRqe.js → SwapController-Ck3TYcMp.js} +1 -1
  3. package/dist/{add-C1zIRxeS.js → add-BmBLHIEe.js} +1 -1
  4. package/dist/{all-wallets-5a2U9fLw.js → all-wallets-H2aaJ2oP.js} +1 -1
  5. package/dist/{app-store-2IKrZeLe.js → app-store-Bvhe1BkA.js} +1 -1
  6. package/dist/{apple-DH9ESSKX.js → apple-BCIKns5c.js} +1 -1
  7. package/dist/{arrow-bottom-circle-Cy5Gjca4.js → arrow-bottom-circle-Dpcn0z0p.js} +1 -1
  8. package/dist/{arrow-bottom-BxAPS43J.js → arrow-bottom-i1ChNkSf.js} +1 -1
  9. package/dist/{arrow-left-CBX7JaHB.js → arrow-left-Dj8tzUf6.js} +1 -1
  10. package/dist/{arrow-right-G72bt1-M.js → arrow-right-DVd3R-0K.js} +1 -1
  11. package/dist/{arrow-top-DCkQG0Dq.js → arrow-top-DcD5wbZL.js} +1 -1
  12. package/dist/astra-sdk.es.js +1 -1
  13. package/dist/{bank-FNxAUs8r.js → bank-CToLOTy3.js} +1 -1
  14. package/dist/{bin-B-c2CIPW.js → bin-D8m48Dk5.js} +1 -1
  15. package/dist/{bitcoin-jk4NLDu1.js → bitcoin-y6S4LO0p.js} +1 -1
  16. package/dist/{browser-D6w0J78l.js → browser-DRhVaQQT.js} +1 -1
  17. package/dist/{card-BLWRKU-r.js → card-BK0q3S4W.js} +1 -1
  18. package/dist/{ccip-DkYvh7hg.js → ccip-CH1B6Zeh.js} +1 -1
  19. package/dist/{checkmark-C1pTfaGr.js → checkmark-C7H1vH4H.js} +1 -1
  20. package/dist/{checkmark-bold-UzogCu8g.js → checkmark-bold-DfvIWKpu.js} +1 -1
  21. package/dist/{chevron-bottom-w_rMAO7x.js → chevron-bottom-CcAEP6cD.js} +1 -1
  22. package/dist/{chevron-left-DGNJGxiP.js → chevron-left-DMnhSBVl.js} +1 -1
  23. package/dist/{chevron-right-VFQCvCyG.js → chevron-right-pPhw9ZBC.js} +1 -1
  24. package/dist/{chevron-top-DVhFmsKp.js → chevron-top-DjqOCRAL.js} +1 -1
  25. package/dist/{chrome-store-BkYX3All.js → chrome-store-B-9bRAPM.js} +1 -1
  26. package/dist/{circle-B1A3j4eP.js → circle-SPbxfVZq.js} +1 -1
  27. package/dist/{clock-BKr-VHDU.js → clock-BLAT4wv4.js} +1 -1
  28. package/dist/{close-BEacRQ8Q.js → close-D1AyyJzy.js} +1 -1
  29. package/dist/{coinPlaceholder-0ZwtMAHl.js → coinPlaceholder-DGk1in74.js} +1 -1
  30. package/dist/{compass-pulK-BFi.js → compass-C0-SVkSt.js} +1 -1
  31. package/dist/{copy-MWCQE0T4.js → copy-CPcvwITz.js} +1 -1
  32. package/dist/{cursor-C2GVfUuM.js → cursor-ChlOWEcO.js} +1 -1
  33. package/dist/{cursor-transparent-Co_5p0du.js → cursor-transparent-BJsEpe-G.js} +1 -1
  34. package/dist/{desktop-C91EoSqM.js → desktop-Z8iZvVCW.js} +1 -1
  35. package/dist/{disconnect-BWg1-rml.js → disconnect-DkPQjiLk.js} +1 -1
  36. package/dist/{discord-Bi0Bfa_e.js → discord-CwRdgvGZ.js} +1 -1
  37. package/dist/{email-U2WCRPFh.js → email-DA_5xt-j.js} +1 -1
  38. package/dist/{embedded-wallet-B6P0kU9A.js → embedded-wallet-DYnGl5tL.js} +1 -1
  39. package/dist/{ethereum-BeZyayQW.js → ethereum-Dwse3Umc.js} +1 -1
  40. package/dist/{etherscan-BQTsufjv.js → etherscan-CNmwyrRn.js} +1 -1
  41. package/dist/{exclamation-triangle-JT-YKNXX.js → exclamation-triangle-CU8gn-bU.js} +1 -1
  42. package/dist/{extension-TnYLHoFA.js → extension-rikwXWrg.js} +1 -1
  43. package/dist/{external-link-Dhgai9sc.js → external-link-mDp8JVE0.js} +1 -1
  44. package/dist/{facebook-C6XFGRDw.js → facebook-c0IS1D9G.js} +1 -1
  45. package/dist/{farcaster-CvYbxZQq.js → farcaster-DpvSDnGl.js} +1 -1
  46. package/dist/{filters-DwVRjAav.js → filters-B42-1BLn.js} +1 -1
  47. package/dist/{github-BVZSx-z9.js → github-DvjZxkXF.js} +1 -1
  48. package/dist/{google-NbJiQLc5.js → google-CLHf_zAz.js} +1 -1
  49. package/dist/{help-circle-Cum2UOMJ.js → help-circle-BI5xgPAz.js} +1 -1
  50. package/dist/{id-kRR6YgVc.js → id-BxI79dX4.js} +1 -1
  51. package/dist/{image-BWUCRAmp.js → image-Cr1qAxG-.js} +1 -1
  52. package/dist/{index-D-T7kk3G.js → index-C0USsgDi.js} +1 -1
  53. package/dist/{index-Dq0LIBEh.js → index-C49-8bCQ.js} +1 -1
  54. package/dist/{index-DSX3HrTS.js → index-CH4T0JAz.js} +1 -1
  55. package/dist/{index-BDE-2VTp.js → index-CWAoFGd1.js} +6 -6
  56. package/dist/{index-RFYbqmu0.js → index-C_3PUMa7.js} +1 -1
  57. package/dist/{index-BZZHE-1t.js → index-D7jufxlk.js} +1 -1
  58. package/dist/{index-CIr4zlVp.js → index-DZiQey0J.js} +1 -1
  59. package/dist/{index-DQ5AZLMt.js → index-DtAG8k9M.js} +1 -1
  60. package/dist/{index-2vYoun4O.js → index-Zh6wUpmX.js} +4007 -3984
  61. package/dist/{index-BjLIiJQa.js → index-utoSbRla.js} +1 -1
  62. package/dist/{info-Br-SBtj3.js → info-BUp5BYav.js} +1 -1
  63. package/dist/{info-circle-Ew4RoR_Q.js → info-circle-D5anzkYK.js} +1 -1
  64. package/dist/{lightbulb-BRBVOE_b.js → lightbulb-DmuhLv29.js} +1 -1
  65. package/dist/{mail-Dzi4AncY.js → mail-D2hRmmgi.js} +1 -1
  66. package/dist/{mobile-BGGxQ5be.js → mobile-Cq-9uJHv.js} +1 -1
  67. package/dist/{more-BmNaKbYJ.js → more-DJMBaB2z.js} +1 -1
  68. package/dist/{network-placeholder-EMiMf4q1.js → network-placeholder-3ip1roR0.js} +1 -1
  69. package/dist/{nftPlaceholder-CvSqy3Sd.js → nftPlaceholder-C7r74zYS.js} +1 -1
  70. package/dist/{off-DF9uz0Nc.js → off-CJE6Z_MK.js} +1 -1
  71. package/dist/{onramp-cKzTmKku.js → onramp-BMRgbt2I.js} +1 -1
  72. package/dist/{play-store-CGxW4MgL.js → play-store-CxusWynI.js} +1 -1
  73. package/dist/{plus-CQ6wWkN0.js → plus-Bjkqj5g6.js} +1 -1
  74. package/dist/{qr-code-VBqx9nAF.js → qr-code-4C0zboga.js} +1 -1
  75. package/dist/{receive-CVzkHmKR.js → receive-Cc8moHBZ.js} +1 -1
  76. package/dist/{recycle-horizontal-Oq1YtvUx.js → recycle-horizontal-BdSgk84g.js} +1 -1
  77. package/dist/{refresh-BDlGAzmY.js → refresh-BsRodAS7.js} +1 -1
  78. package/dist/{reown-logo-BlIpXIlG.js → reown-logo-DOVlqCDK.js} +1 -1
  79. package/dist/{search-DfmCmp0m.js → search-BIyHtky-.js} +1 -1
  80. package/dist/{secp256k1-CsKSDHNi.js → secp256k1-B2Gq-iIr.js} +1 -1
  81. package/dist/{send-BXudz514.js → send-9eSi58hW.js} +1 -1
  82. package/dist/{send-Cz0L5LmE.js → send-CBFTcYtn.js} +3 -3
  83. package/dist/{socials-CDOh8MRf.js → socials-CeOJULFV.js} +1 -1
  84. package/dist/{solana-CbiyOE-8.js → solana-BNptwYvn.js} +1 -1
  85. package/dist/{swapHorizontal-DyU1TH_e.js → swapHorizontal-COlgqyzt.js} +1 -1
  86. package/dist/{swapHorizontalBold-CGXW7Ocj.js → swapHorizontalBold-Odce2JOe.js} +1 -1
  87. package/dist/{swapHorizontalMedium-2KTcj67d.js → swapHorizontalMedium-B9nkEBPD.js} +1 -1
  88. package/dist/{swapHorizontalRoundedBold-TxFtmmda.js → swapHorizontalRoundedBold-DPMzz6nz.js} +1 -1
  89. package/dist/{swapVertical-BKD6lxM3.js → swapVertical-FqQP9GBP.js} +1 -1
  90. package/dist/{swaps-BuGsEQaI.js → swaps-BG9GOayX.js} +3 -3
  91. package/dist/{telegram-CAsl9DeG.js → telegram-BMY9Hs9Z.js} +1 -1
  92. package/dist/{three-dots-BoE2aHZi.js → three-dots-DDKmexHU.js} +1 -1
  93. package/dist/{transactions-C1NtsnD6.js → transactions-C_GII6kW.js} +1 -1
  94. package/dist/{twitch-CvkZZxgT.js → twitch-x_s0neNg.js} +1 -1
  95. package/dist/{twitterIcon-CrhnOl_O.js → twitterIcon-CKsSxEuJ.js} +1 -1
  96. package/dist/{ui-BJcuThPA.js → ui-CZH-vf5h.js} +2 -2
  97. package/dist/{user-BZRWUXG7.js → user-CZfvQDJ_.js} +1 -1
  98. package/dist/{verify-y9F4DcJ4.js → verify-Bnvbadnx.js} +1 -1
  99. package/dist/{verify-filled-X_8-BhMk.js → verify-filled-CnEopkW-.js} +1 -1
  100. package/dist/{w3m-modal-BX--v1Nc.js → w3m-modal-DkI2TPJW.js} +2 -2
  101. package/dist/{wallet-CIaVVkjQ.js → wallet-B3oN4n4q.js} +1 -1
  102. package/dist/{wallet-placeholder-Cq1ofde1.js → wallet-placeholder-CI0oiAcd.js} +1 -1
  103. package/dist/{walletconnect-CINzSCJ3.js → walletconnect-D4vMcjqO.js} +1 -1
  104. package/dist/{warning-circle-BvBNhMKH.js → warning-circle-DjI8aRBs.js} +1 -1
  105. package/dist/{x-xHY7JehW.js → x-BgRWY62H.js} +1 -1
  106. package/dist/{x-mark-DEmnBt6u.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,653 +0,0 @@
1
- import { memo } from "react";
2
- import styled from "styled-components";
3
- import useStore from "../store";
4
- import { Form, Button, Select, Flex, 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 useParseInvoice from "../hooks/useParseInvoice";
10
- import EllipsisMiddle from "./EllipsisMiddle";
11
- import { useBridgeContract } from "../hooks/useContract";
12
- import { useGetReserveInfo } from "../hooks/useLspApi";
13
- import ConnectButton from "./ConnectButton";
14
- import Decimal from "decimal.js";
15
- import { useGetMinAndMax } from "../hooks/useGetMinAndMax";
16
- import { numberWithCommas, getParsedError } from "../utils";
17
- import AstraNetwork from "./AstraNetwork";
18
- import IconTip from "../assets/tip.svg";
19
- import IconArrowRight from "../assets/arrow-right.svg";
20
- import { AvalibleBalance } from "./CommonStyle";
21
- import { toLightning, bridgeIntervalStatus } from "../apis/lspApi";
22
-
23
- const WrapperToLightning = styled.div``;
24
-
25
- const FormItem = styled(Form.Item)``;
26
-
27
- const ClearAuthWrapper = styled.div`
28
- display: flex;
29
- gap: 10px;
30
- padding: 10px 20px;
31
- justify-content: space-between;
32
- align-items: flex-start;
33
- align-self: stretch;
34
- color: #fff;
35
- font-family: "Clash Display";
36
- font-size: 14px;
37
- font-style: normal;
38
- font-weight: 400;
39
- border-radius: 24px;
40
- border: 1px solid #333;
41
- background: rgba(51, 51, 51, 0.2);
42
- backdrop-filter: blur(25px);
43
- .clear-auth {
44
- color: #caff33;
45
- font-family: "Clash Display";
46
- font-size: 14px;
47
- font-style: normal;
48
- font-weight: 500;
49
- line-height: normal;
50
- text-decoration-line: underline;
51
- text-decoration-style: solid;
52
- text-decoration-skip-ink: none;
53
- text-decoration-thickness: auto;
54
- text-underline-offset: auto;
55
- text-underline-position: from-font;
56
- }
57
- `;
58
-
59
- const AstraSelect = styled(Select)`
60
- width: 60px !important;
61
- .astra-select-selector {
62
- padding: 0 0px !important;
63
- }
64
- .astra-select-selection-item {
65
- display: flex !important;
66
- align-items: center;
67
- justify-content: center;
68
- }
69
- .astra-select-arrow {
70
- color: #fff;
71
- }
72
- `;
73
-
74
- const BalanceFlex = styled(Flex)`
75
- .available_token_balance {
76
- font-size: 12px;
77
- color: #fff;
78
- }
79
- `;
80
- const AstraSendingReceived = styled.div`
81
- padding: 8px 20px;
82
- border-radius: 12px;
83
- background: rgba(166, 166, 166, 0.1);
84
- margin-bottom: 14px;
85
- @media (max-width: 768px) {
86
- padding: 8px 10px;
87
- border-radius: 12px;
88
- background: rgba(166, 166, 166, 0.1);
89
- margin-bottom: 14px;
90
- }
91
- `;
92
- const AstraFormItemOther = styled.div`
93
- padding: 0 20px;
94
- @media (max-width: 768px) {
95
- padding: 0 10px;
96
- }
97
- `;
98
- const AstraButton = styled(Button)`
99
- width: 100%;
100
- display: flex;
101
- justify-content: space-between;
102
- padding: 0 30px;
103
- font-size: 16px;
104
- line-height: 42px;
105
- `;
106
-
107
- function ToLightning({
108
- messageApi,
109
- setResultModalShow,
110
- setResultModalRequest,
111
- }) {
112
- const {
113
- receiveArgs,
114
- allAssetPairs,
115
- targetNetwork,
116
- setCurrentAssetPair,
117
- currentAssetPair,
118
- setAstraModalShow,
119
- astraModalShow,
120
- } = useStore();
121
- const account = useAccount();
122
- const { switchChain } = useSwitchChain();
123
- const [form] = Form.useForm();
124
- const [submitLoading, setSubmitLoading] = useState(false);
125
- const [approveLoading, setApproveLoading] = useState(false);
126
- const { filterdAssetPairs, validationError } = useMemo(() => {
127
- const filtered = allAssetPairs.filter((pair) => {
128
- return pair.asset.assetId === receiveArgs.assetId;
129
- });
130
-
131
- // 校验资产是否支持
132
- let error = null;
133
- if (allAssetPairs.length > 0 && filtered.length === 0) {
134
- const supportedAssets = allAssetPairs
135
- .map(
136
- (pair) =>
137
- `${pair.asset.name} (${pair.asset.assetId.substring(0, 8)}...)`
138
- )
139
- .join(", ");
140
- error = `Asset "${receiveArgs.assetId.substring(
141
- 0,
142
- 8
143
- )}..." is not supported. Supported assets: ${supportedAssets}`;
144
- }
145
-
146
- return { filterdAssetPairs: filtered, validationError: error };
147
- }, [allAssetPairs, receiveArgs.assetId]);
148
-
149
- const { reserveInfo, loading: reserveInfoLoading } = useGetReserveInfo(
150
- targetNetwork,
151
- currentAssetPair
152
- );
153
- const { min, max, unitName } = useGetMinAndMax("evmToLightning", reserveInfo);
154
-
155
- const tokenBalanceRet = useBalance({
156
- address: account?.address,
157
- token: currentAssetPair?.token?.address,
158
- query: {
159
- enabled:
160
- !!currentAssetPair?.token?.address &&
161
- !!account?.address &&
162
- astraModalShow,
163
- },
164
- formatUnits: currentAssetPair?.token?.decimal,
165
- scopeKey: "token",
166
- });
167
-
168
- const mainnetBalanceRet = useBalance({
169
- address: account?.address,
170
- query: {
171
- enabled: !!account?.address && astraModalShow,
172
- },
173
- formatUnits: "ether",
174
- });
175
-
176
- const {
177
- formatAssetAmt,
178
- tokenAmt,
179
- formatTokenAmt,
180
- hashlock,
181
- parseInvoiceLoading,
182
- isExpired,
183
- } = useParseInvoice(receiveArgs?.invoice);
184
-
185
- const {
186
- allowanceRet,
187
- formatAllowance,
188
- onReloadAllowance,
189
- onApprove,
190
- onDeposit,
191
- } = useBridgeContract(account);
192
-
193
- const serviceFee = useMemo(() => {
194
- if (!reserveInfo?.toAssetBaseFee) {
195
- return 0;
196
- }
197
- return new Decimal(reserveInfo?.toAssetBaseFee.toString())
198
- .div(10 ** 18)
199
- .toFixed(8)
200
- .replace(/\.?0+$/, "");
201
- }, [reserveInfo?.toAssetBaseFee]);
202
-
203
- const onAssetPairChange = useCallback(
204
- (pairId) => {
205
- const selectedPair = pairId
206
- ? allAssetPairs.find((pair) => pair.pairId === pairId)
207
- : null;
208
- setCurrentAssetPair(selectedPair);
209
- },
210
- [allAssetPairs, setCurrentAssetPair]
211
- );
212
-
213
- const onCheckBalance = useCallback(async () => {
214
- const tokenBalance = tokenBalanceRet?.data?.value || 0;
215
- const mainetBalance = mainnetBalanceRet?.data?.value || 0;
216
-
217
- if (
218
- new Decimal(mainetBalance.toString()).lt(
219
- new Decimal(reserveInfo?.toAssetBaseFee?.toString())
220
- )
221
- ) {
222
- throw new Error("Insufficient balance to pay service fee.");
223
- }
224
- if (
225
- new Decimal(tokenBalance.toString()).lt(new Decimal(tokenAmt.toString()))
226
- ) {
227
- throw new Error("Insufficient available balance.");
228
- }
229
-
230
- if (
231
- new Decimal(formatAssetAmt.toString()).gt(new Decimal(max.toString()))
232
- ) {
233
- throw new Error(`The maximum amount is ${max} ${unitName}.`);
234
- }
235
- if (
236
- new Decimal(formatAssetAmt.toString()).lt(new Decimal(min.toString()))
237
- ) {
238
- throw new Error(`The minimum amount is ${min} ${unitName}.`);
239
- }
240
- }, [
241
- formatAssetAmt,
242
- mainnetBalanceRet?.data?.value,
243
- max,
244
- min,
245
- reserveInfo?.toAssetBaseFee,
246
- tokenAmt,
247
- tokenBalanceRet?.data?.value,
248
- unitName,
249
- ]);
250
-
251
- const handleApprove = useCallback(
252
- async (approveAmt) => {
253
- try {
254
- setApproveLoading(true);
255
- await onCheckBalance();
256
- const approveTx = await onApprove(approveAmt);
257
- if (approveTx) {
258
- messageApi.open({
259
- type: "success",
260
- content: approveAmt == 0 ? "Clear Auth success" : "Approve success",
261
- });
262
- }
263
- } catch (e) {
264
- const error = e.message;
265
-
266
- if (error.includes("User rejected")) {
267
- messageApi.error("User reject the request.");
268
- } else {
269
- if (error.includes("does not match the target chain")) {
270
- switchChain(
271
- { chainId: targetNetwork.id },
272
- {
273
- onSuccess: () => {
274
- messageApi.success(
275
- `Switch chain ${targetNetwork.name} success, please try again.`
276
- );
277
- },
278
- }
279
- );
280
- } else {
281
- messageApi.error(e.message);
282
- }
283
- }
284
- } finally {
285
- setApproveLoading(false);
286
- onReloadAllowance();
287
- }
288
- },
289
- [
290
- messageApi,
291
- onApprove,
292
- onCheckBalance,
293
- onReloadAllowance,
294
- switchChain,
295
- targetNetwork.id,
296
- targetNetwork.name,
297
- ]
298
- );
299
-
300
- const memoBtn = useMemo(() => {
301
- if (!account?.address) {
302
- return <ConnectButton />;
303
- }
304
- if (Number(allowanceRet) < Number(tokenAmt)) {
305
- return (
306
- <AstraButton
307
- type="primary"
308
- disabled={validationError}
309
- onClick={() => {
310
- handleApprove(tokenAmt);
311
- }}
312
- loading={approveLoading}
313
- >
314
- <span>Approve</span>
315
- <img src={IconArrowRight} alt="" />
316
- </AstraButton>
317
- );
318
- } else {
319
- return (
320
- <AstraButton
321
- type="primary"
322
- disabled={validationError}
323
- loading={submitLoading}
324
- htmlType="submit"
325
- >
326
- <span>
327
- {submitLoading ? "Waiting for Confirmation..." : "Deposit"}
328
- </span>
329
- <img src={IconArrowRight} alt="" />
330
- </AstraButton>
331
- );
332
- }
333
- }, [
334
- account?.address,
335
- allowanceRet,
336
- approveLoading,
337
- handleApprove,
338
- submitLoading,
339
- tokenAmt,
340
- validationError,
341
- ]);
342
-
343
- // const fixedChannelBalance = useMemo(() => {
344
- // if (reserveInfo) {
345
- // return balanceToFixed(
346
- // reserveInfo.maxAsset,
347
- // currentAssetPair?.asset?.decimal
348
- // );
349
- // }
350
- // return 0;
351
- // }, [currentAssetPair?.asset?.decimal, reserveInfo]);
352
-
353
- const onFinish = useCallback(async () => {
354
- try {
355
- if (!account?.address) {
356
- return;
357
- }
358
- if (isExpired) {
359
- throw new Error("The invoice has expired.");
360
- }
361
- setSubmitLoading(true);
362
- await onCheckBalance();
363
- const bridgeIntervalRet = await bridgeIntervalStatus({
364
- address: account?.address,
365
- });
366
- if (bridgeIntervalRet.code !== 200) {
367
- throw new Error(bridgeIntervalRet.data);
368
- }
369
- const bridgeIntervalData = bridgeIntervalRet.data;
370
- if (!bridgeIntervalData?.isAllowed) {
371
- const remainingMinutes = Math.ceil(
372
- bridgeIntervalData.remainingSeconds / 60
373
- );
374
- throw new Error(
375
- `Bridge interval not met. Please wait ${remainingMinutes} more minute(s).`
376
- );
377
- }
378
- const {
379
- effectiveSatsBalance,
380
- satsCapacity,
381
- localAssetbalance,
382
- localAssetCapacity,
383
- } = reserveInfo;
384
-
385
- if (
386
- effectiveSatsBalance < satsCapacity * 0.1 ||
387
- localAssetbalance < localAssetCapacity * 0.1
388
- ) {
389
- throw new Error("Channel not enough balance.");
390
- }
391
-
392
- await onReloadAllowance();
393
-
394
- if (Number(allowanceRet) < Number(tokenAmt)) {
395
- const approveTx = await onApprove(Number.tokenAmt);
396
- if (approveTx) {
397
- messageApi.open({
398
- type: "success",
399
- content: "Approve success",
400
- });
401
- }
402
- }
403
-
404
- const decodedInvoice = window.lightningPayReq.decode(
405
- receiveArgs?.invoice
406
- );
407
- const lspNodePubKey = decodedInvoice?.payeeNodeKey;
408
-
409
- const depositArgs = {
410
- hashlock,
411
- fromAddr: account.address,
412
- toAddr: reserveInfo.lspAddress,
413
- pairId: currentAssetPair.pairId,
414
- amount: tokenAmt,
415
- timeLock: reserveInfo?.evm2LightningDeltaSecond,
416
- toLightning: true,
417
- fee: reserveInfo?.toAssetBaseFee,
418
- signature: "0x",
419
- nodePubkey: lspNodePubKey,
420
- };
421
-
422
- const tx = await onDeposit(depositArgs);
423
- const request = {
424
- pairId: currentAssetPair.pairId,
425
- chainId: targetNetwork.id,
426
- lnInvoice: receiveArgs?.invoice,
427
- amount: tokenAmt,
428
- depositTx: tx,
429
- };
430
- const retToEVM = await toLightning(request);
431
- if (retToEVM.code !== 200) {
432
- throw new Error("Payment failed");
433
- }
434
- if (tx) {
435
- setResultModalRequest({
436
- txHash: tx,
437
- timestamp: Date.now(),
438
- formatTokenAmt,
439
- request,
440
- });
441
- setAstraModalShow(false);
442
- setResultModalShow(true);
443
- }
444
- } catch (e) {
445
- const error = getParsedError(e);
446
- if (error.includes("does not match the target chain")) {
447
- switchChain(
448
- { chainId: targetNetwork.id },
449
- {
450
- onSuccess: () => {
451
- messageApi.success(
452
- `Switch chain ${targetNetwork.name} success, please try again.`
453
- );
454
- },
455
- }
456
- );
457
- } else {
458
- messageApi.error(error);
459
- }
460
- } finally {
461
- setSubmitLoading(false);
462
- }
463
- }, [
464
- account?.address,
465
- isExpired,
466
- onCheckBalance,
467
- reserveInfo,
468
- onReloadAllowance,
469
- allowanceRet,
470
- tokenAmt,
471
- receiveArgs?.invoice,
472
- hashlock,
473
- currentAssetPair,
474
- targetNetwork.id,
475
- targetNetwork.name,
476
- onDeposit,
477
- onApprove,
478
- messageApi,
479
- setResultModalRequest,
480
- formatTokenAmt,
481
- setAstraModalShow,
482
- setResultModalShow,
483
- switchChain,
484
- ]);
485
-
486
- const onClearAuth = useCallback(async () => {
487
- await handleApprove(0);
488
- }, [handleApprove]);
489
-
490
- useEffect(() => {
491
- if (filterdAssetPairs?.length > 0) {
492
- setCurrentAssetPair(filterdAssetPairs[0]);
493
- form.setFieldValue("sending", filterdAssetPairs?.[0]?.pairId);
494
- } else {
495
- setCurrentAssetPair(null);
496
- form.setFieldValue("sending", "");
497
- }
498
- }, [filterdAssetPairs, form, setCurrentAssetPair]);
499
-
500
- return (
501
- <>
502
- <WrapperToLightning>
503
- <Spin spinning={reserveInfoLoading || parseInvoiceLoading}>
504
- {validationError && (
505
- <div
506
- style={{
507
- padding: "12px 16px",
508
- marginBottom: "16px",
509
- borderRadius: "8px",
510
- background: "rgba(255, 77, 79, 0.1)",
511
- border: "1px solid rgba(255, 77, 79, 0.3)",
512
- color: "#ff4d4f",
513
- fontSize: "14px",
514
- lineHeight: "1.5",
515
- }}
516
- >
517
- ⚠️ {validationError}
518
- </div>
519
- )}
520
- <Form
521
- name="basic"
522
- form={form}
523
- colon={false}
524
- style={{
525
- width: "100%",
526
- }}
527
- onFinish={onFinish}
528
- autoComplete="off"
529
- >
530
- <AstraNetwork
531
- messageApi={messageApi}
532
- balance={mainnetBalanceRet?.data}
533
- />
534
- <AstraSendingReceived>
535
- <FormItem label="Sending">
536
- <Flex justify="end" align="center" gap="5px">
537
- {filterdAssetPairs?.length > 0 && (
538
- <FormItem name="sending" noStyle>
539
- <AstraSelect
540
- variant="borderless"
541
- options={filterdAssetPairs.map((pair) => ({
542
- value: pair.pairId,
543
- label: (
544
- <AstraImage
545
- name={pair.token.name}
546
- width="22px"
547
- height="22px"
548
- />
549
- ),
550
- }))}
551
- onChange={onAssetPairChange}
552
- ></AstraSelect>
553
- </FormItem>
554
- )}
555
- <span className="fw500">{formatTokenAmt}</span>
556
- <span className="fw500">{currentAssetPair?.token?.name}</span>
557
- </Flex>
558
- <BalanceFlex justify="end" align="center" gap="5px">
559
- <span className="available_token_balance">
560
- Available:{" "}
561
- <AvalibleBalance>
562
- {tokenBalanceRet?.data?.formatted
563
- ? numberWithCommas(
564
- new Decimal(
565
- tokenBalanceRet?.data?.formatted
566
- ).toFixed(4, Decimal.ROUND_DOWN)
567
- )
568
- : 0}
569
- </AvalibleBalance>
570
- &nbsp;
571
- {tokenBalanceRet?.data?.symbol}
572
- </span>
573
- </BalanceFlex>
574
- </FormItem>
575
-
576
- <FormItem label="Receiving" style={{ marginBottom: 0 }}>
577
- <Flex justify="end" align="center" gap="5px">
578
- <AstraImage name={"Lightning"} />
579
- <span className="colorcaff33">{formatAssetAmt}</span>
580
- <span className="colorcaff33">
581
- {currentAssetPair?.asset?.name}
582
- </span>
583
- </Flex>
584
- </FormItem>
585
- </AstraSendingReceived>
586
- <AstraFormItemOther>
587
- <FormItem label="Service fee">
588
- <Flex justify="end" align="center" gap="5px">
589
- <span>{serviceFee}</span>
590
- <AstraImage
591
- name={targetNetwork?.name}
592
- width="22px"
593
- height="22px"
594
- />
595
- </Flex>
596
- </FormItem>
597
-
598
- <FormItem label="Receiving LN invoice">
599
- <Flex justify="end">
600
- <EllipsisMiddle copyable suffixCount={10}>
601
- {receiveArgs?.invoice}
602
- </EllipsisMiddle>
603
- </Flex>
604
- </FormItem>
605
-
606
- <FormItem label="Route">
607
- <Flex justify="end" align="center" gap="5px">
608
- <AstraImage
609
- name={targetNetwork?.name}
610
- width="22px"
611
- height="22px"
612
- />
613
- <DoubleRightOutlined style={{ color: "#caff33" }} />
614
- <AstraImage name="Lightning" />
615
- </Flex>
616
- </FormItem>
617
- </AstraFormItemOther>
618
- <FormItem
619
- label={null}
620
- labelCol={{ span: 0 }}
621
- wrapperCol={{ span: 24 }}
622
- >
623
- <Flex justify="center">{memoBtn}</Flex>
624
- </FormItem>
625
- </Form>
626
- </Spin>
627
-
628
- {Number(formatAllowance) &&
629
- Number(tokenAmt) > Number(formatAllowance) ? (
630
- <ClearAuthWrapper>
631
- <img src={IconTip} alt="tip" />
632
- <span>
633
- Your remaining authorization to Astra is {formatAllowance}{" "}
634
- {currentAssetPair?.token?.name}. To transact more, clear the
635
- current authorization and approve the new amount.
636
- <Button
637
- type="link"
638
- loading={approveLoading}
639
- onClick={onClearAuth}
640
- className="clear-auth"
641
- >
642
- Clear Authorization
643
- </Button>{" "}
644
- </span>
645
- </ClearAuthWrapper>
646
- ) : (
647
- <></>
648
- )}
649
- </WrapperToLightning>
650
- </>
651
- );
652
- }
653
- export default memo(ToLightning);