astra-modal-test 1.0.0 → 1.0.1

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 (32) hide show
  1. package/dist/astra-sdk.es.js +5 -4
  2. package/dist/astra-sdk.umd.js +734 -732
  3. package/dist/{ccip-Bpb4GlU6.mjs → ccip-CFEKJ3Ks.js} +1 -1
  4. package/dist/font/ClashDisplay-Variable.ttf +0 -0
  5. package/dist/font/ClashDisplay-Variable.woff +0 -0
  6. package/dist/font/ClashDisplay-Variable.woff2 +0 -0
  7. package/dist/{index-CEtKkuP2.mjs → index-BDeAs3SQ.js} +2 -2
  8. package/dist/{index-CbWGAz3l.mjs → index-C4tezYWF.js} +2 -2
  9. package/dist/{index-DRPxIWUd.mjs → index-CJ3Ye6uH.js} +2 -2
  10. package/dist/{index-h9_6XS0r.mjs → index-CnmhaFbj.js} +2 -2
  11. package/dist/{index-BTsa09iy.mjs → index-tp9lcU8A.js} +32901 -30185
  12. package/dist/{w3m-modal-R9m1z1SQ.mjs → w3m-modal-BVQPTRZq.js} +1 -1
  13. package/{eslint.config.js → eslint.config.mjs} +2 -0
  14. package/package.json +3 -2
  15. package/public/font/ClashDisplay-Variable.ttf +0 -0
  16. package/public/font/ClashDisplay-Variable.woff +0 -0
  17. package/public/font/ClashDisplay-Variable.woff2 +0 -0
  18. package/src/comps/AstraModal.jsx +17 -28
  19. package/src/comps/AstraModalLogo.jsx +10 -37
  20. package/src/comps/AstraNetwork.jsx +22 -5
  21. package/src/comps/ConnectButton.jsx +2 -3
  22. package/src/comps/ResultModal.jsx +12 -13
  23. package/src/comps/ToLightning.jsx +36 -48
  24. package/src/comps/ToToken.jsx +46 -60
  25. package/src/constants/contracts/abi/bridge.js +55 -20
  26. package/src/constants/contracts/abi/watcher.js +6 -92
  27. package/src/constants/contracts/index.js +4 -4
  28. package/src/hooks/useContract.js +14 -1
  29. package/src/index.jsx +41 -33
  30. package/src/main.jsx +4 -4
  31. package/dist/secp256k1-3OC5y4qp.mjs +0 -1578
  32. /package/dist/{hooks.module-BBZfodGH.mjs → hooks.module-BBZfodGH.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { i as v, b as y, O as w, M as s, C as h, aW as k, E as g, x as p, R as u, S as b, U as C, l as x, d as E, g as A, aX as L, f as m, c as N, aY as T } from "./index-BTsa09iy.mjs";
1
+ import { i as v, b as y, O as w, M as s, C as h, aW as k, E as g, x as p, R as u, S as b, U as C, l as x, d as E, g as A, aX as L, f as m, c as N, aY as T } from "./index-tp9lcU8A.js";
2
2
  const O = v`
3
3
  :host {
4
4
  z-index: var(--w3m-z-index);
@@ -28,6 +28,8 @@ export default [
28
28
  ...react.configs.recommended.rules,
29
29
  ...react.configs['jsx-runtime'].rules,
30
30
  ...reactHooks.configs.recommended.rules,
31
+ 'react-hooks/rules-of-hooks': 'error',
32
+ 'react-hooks/exhaustive-deps': 'warn',
31
33
  'react/jsx-no-target-blank': 'off',
32
34
  'react-refresh/only-export-components': [
33
35
  'warn',
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "astra-modal-test",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/astra-sdk.es.js",
6
+ "type":"module",
6
7
  "scripts": {
7
8
  "dev": "vite",
8
9
  "build": "vite build",
@@ -40,7 +41,7 @@
40
41
  "@vitejs/plugin-react": "^4.3.4",
41
42
  "eslint": "^9.15.0",
42
43
  "eslint-plugin-react": "^7.37.2",
43
- "eslint-plugin-react-hooks": "^5.0.0",
44
+ "eslint-plugin-react-hooks": "^5.1.0",
44
45
  "eslint-plugin-react-refresh": "^0.4.14",
45
46
  "globals": "^15.12.0",
46
47
  "vite": "^6.0.3",
@@ -10,31 +10,13 @@ import ToLightning from "./ToLightning.jsx";
10
10
  import ToToken from "./ToToken.jsx";
11
11
  import { useGetPairs } from "../hooks/useLspApi.js";
12
12
  import ResultModal from "./ResultModal.jsx";
13
-
14
- // 全局样式
15
- // const GlobalStyle = createGlobalStyle`
16
- // @font-face {
17
- // font-family: ClashDisplay;
18
- // src: url(../font/ClashDisplay-Variable.ttf);
19
- // }
20
- // * {
21
- // font-family: ClashDisplay;
22
- // font-weight: 400;
23
- // }
24
- // `;
13
+ import ClashDisplayFont from "../font/ClashDisplay-Variable.ttf";
25
14
  const GlobalStyle = createGlobalStyle`
26
15
  @font-face {
27
16
  font-family: 'ClashDisplay';
28
- src: url('../font/ClashDisplay-Variable.ttf') format('truetype');
29
- font-weight: normal;
30
- font-style: normal;
31
- }
32
-
33
- body {
34
- font-family: 'ClashDisplay', sans-serif;
17
+ src: url(${ClashDisplayFont});
35
18
  }
36
19
  `;
37
- // Modal 标题容器
38
20
  const ModalTitleWrapper = styled.div`
39
21
  .astra-logo {
40
22
  width: 26px;
@@ -46,9 +28,12 @@ const ModalTitleWrapper = styled.div`
46
28
  }
47
29
  `;
48
30
 
49
- // 自定义 Modal 样式
50
31
  const StyledModal = styled(Modal)`
32
+ * {
33
+ font-family: "ClashDisplay";
34
+ }
51
35
  .astra-modal-content {
36
+ font-family: "Clash Display", sans-serif !important;
52
37
  background: rgba(51, 51, 51, 0.2);
53
38
  border: 1px solid;
54
39
  border-image-source: linear-gradient(
@@ -70,15 +55,20 @@ const StyledModal = styled(Modal)`
70
55
  .colorcaff33 {
71
56
  color: #caff33;
72
57
  }
58
+ .astra-col {
59
+ font-family: "ClashDisplay";
60
+ }
61
+ .astra-typography {
62
+ font-family: "ClashDisplay";
63
+ }
73
64
  }
74
65
 
75
- // 媒体查询样式
76
66
  @media (max-width: 768px) {
77
67
  font-size: 10px;
78
68
 
79
69
  .astra-modal-content {
80
70
  padding: 20px 10px;
81
-
71
+ background: rgba(51, 51, 51, 1);
82
72
  .astra-modal-header .modal-title {
83
73
  font-size: 18px;
84
74
  }
@@ -104,7 +94,7 @@ const StyledModal = styled(Modal)`
104
94
  @media (max-width: 575px) {
105
95
  .astra-modal-content {
106
96
  padding: 15px 8px;
107
-
97
+ background: rgba(51, 51, 51, 0.2);
108
98
  .astra-modal-header .modal-title {
109
99
  font-size: 16px;
110
100
  }
@@ -116,12 +106,12 @@ const ModalWrapper = styled.div`
116
106
  padding-top: 10px;
117
107
  `;
118
108
 
119
- // 主组件
120
109
  export default function AstraModal({ astraApiUri }) {
121
110
  const chains = useChains();
122
111
  const chainId = useChainId();
123
112
  const {
124
113
  setTargetNetwork,
114
+ targetNetwork,
125
115
  setAstraModalShow,
126
116
  astraModalShow,
127
117
  modalDisplayType,
@@ -159,8 +149,8 @@ export default function AstraModal({ astraApiUri }) {
159
149
  <Flex align="center">
160
150
  <span className="modal-title">
161
151
  {modalDisplayType === MODAL_DISPLAY_TYPE.TO_LIGHTNING
162
- ? "Ethereum to Lightning"
163
- : "Lightning to Ethereum"}
152
+ ? `${targetNetwork?.name} to Lightning`
153
+ : `Lightning to ${targetNetwork?.name}`}
164
154
  </span>
165
155
  </Flex>
166
156
  </ModalTitleWrapper>
@@ -169,7 +159,6 @@ export default function AstraModal({ astraApiUri }) {
169
159
  footer={null}
170
160
  open={astraModalShow}
171
161
  onCancel={onCancel}
172
- centered
173
162
  maskClosable={false}
174
163
  zIndex={998}
175
164
  mask={false}
@@ -1,32 +1,15 @@
1
1
  import styled from "styled-components";
2
2
  import { Select, Form, Flex, Spin, Button } from "antd";
3
- import { useAccount, useChains, useChainId, useSwitchChain } from "wagmi";
4
- import EllipsisMiddle from "./EllipsisMiddle";
5
- import AstraImg from "./AstraImage";
6
- import { useCallback, useMemo, useState } from "react";
7
- import Decimal from "decimal.js";
8
3
  import IconPowerby from "../assets/powerby.svg";
9
- const AstraSelect = styled(Select)`
10
- width: 60px !important;
11
- .astra-select-selector {
12
- padding: 0 0px !important;
13
- }
14
- .astra-select-selection-item {
15
- display: flex !important;
16
- align-items: center;
17
- justify-content: center;
18
- }
19
- .astra-select-arrow {
20
- color: #fff;
21
- }
22
- `;
23
- const AstraAccount = styled.div`
4
+ const AstraLogo = styled.div`
5
+ margin-top: 24px;
6
+ display: flex;
7
+ align-items: flex-end;
8
+ gap: 5px;
9
+ font-size: 14px;
10
+ justify-content: center;
24
11
  color: #fff;
25
- text-align: center;
26
- font-family: "ClashDisplay";
27
- font-size: 16px;
28
- font-style: normal;
29
- font-weight: 400;
12
+ font-family: ClashDisplay;
30
13
  `;
31
14
  const BalanceFlex = styled(Flex)`
32
15
  .available_token_balance {
@@ -36,18 +19,8 @@ const BalanceFlex = styled(Flex)`
36
19
  `;
37
20
  export default function AstraModalLogo({ messageApi, balance }) {
38
21
  return (
39
- <div
40
- style={{
41
- marginTop: "24px",
42
- display: "flex",
43
- alignItems: "flex-end",
44
- gap: "5px",
45
- fontSize: "14px",
46
- justifyContent: "center",
47
- color: "#fff",
48
- }}
49
- >
22
+ <AstraLogo>
50
23
  Power By <img src={IconPowerby} alt="" />
51
- </div>
24
+ </AstraLogo>
52
25
  );
53
26
  }
@@ -1,9 +1,10 @@
1
1
  import styled from "styled-components";
2
- import { Select, Form, Flex, Spin, Button } from "antd";
3
- import { useAccount, useChains, useChainId, useSwitchChain } from "wagmi";
2
+ import { Select, Form, Flex, Spin, Space } from "antd";
3
+ import { useAccount, useChains, useChainId, useSwitchChain, useDisconnect } from "wagmi";
4
4
  import EllipsisMiddle from "./EllipsisMiddle";
5
5
  import AstraImg from "./AstraImage";
6
6
  import { useCallback, useMemo, useState } from "react";
7
+ import { DisconnectOutlined } from '@ant-design/icons'
7
8
  import Decimal from "decimal.js";
8
9
  const AstraSelect = styled(Select)`
9
10
  width: 60px !important;
@@ -33,6 +34,14 @@ const BalanceFlex = styled(Flex)`
33
34
  color: #fff;
34
35
  }
35
36
  `;
37
+
38
+ const StyledDisconnectOutlined = styled(DisconnectOutlined)`
39
+ color: rgba(202, 255, 51, 1);
40
+ cursor: pointer;
41
+ &:hover {
42
+ color:red;
43
+ }
44
+ `;
36
45
  const FormItemPair = styled(Form.Item)`
37
46
  padding: 8px 20px 8px 10px;
38
47
  border-radius: 12px;
@@ -51,6 +60,7 @@ export default function AstraNetwork({ messageApi, balance }) {
51
60
  const account = useAccount();
52
61
  const chains = useChains();
53
62
  const chainId = useChainId();
63
+ const { disconnect } = useDisconnect();
54
64
  const { switchChainAsync } = useSwitchChain();
55
65
  const [loading, setLoading] = useState(false);
56
66
  const onNetWorkChange = useCallback(
@@ -96,9 +106,16 @@ export default function AstraNetwork({ messageApi, balance }) {
96
106
  <Flex justify="end">
97
107
  <AstraAccount>
98
108
  {account?.address ? (
99
- <EllipsisMiddle suffixCount={8}>
100
- {account?.address}
101
- </EllipsisMiddle>
109
+ <>
110
+ <Space>
111
+ <EllipsisMiddle suffixCount={8}>
112
+ {account?.address}
113
+ </EllipsisMiddle>
114
+ <StyledDisconnectOutlined onClick={() => disconnect()} />
115
+ </Space>
116
+ </>
117
+
118
+
102
119
  ) : (
103
120
  "Connect Wallet"
104
121
  )}
@@ -22,13 +22,12 @@ export default function ConnectButton() {
22
22
  button.style.border = "none";
23
23
  button.style.fontFamily = "ClashDisplay";
24
24
  }
25
- clearInterval(interval); // 找到目标后停止轮询
25
+ clearInterval(interval);
26
26
  }
27
27
  }
28
28
  }
29
- }, 100); // 每 100 毫秒检查一次
29
+ }, 100);
30
30
 
31
- // 如果需要,可以设置轮询的最大时间限制
32
31
  setTimeout(() => clearInterval(interval), 5000);
33
32
  }
34
33
  }, []);
@@ -1,4 +1,4 @@
1
- import { Modal, Flex, Button } from "antd";
1
+ import { Modal, Flex } from "antd";
2
2
  import { useCallback, useEffect, useState } from "react";
3
3
  import styled from "styled-components";
4
4
  import { MODAL_DISPLAY_TYPE } from "../constants/index.js";
@@ -9,7 +9,7 @@ import AstraImg from "./AstraImage.jsx";
9
9
  import IconBridgeLoading from "../assets/bridge-loading.png";
10
10
  import IconSuccess from "../assets/success.svg";
11
11
  import AstraModalLogo from "./AstraModalLogo.jsx";
12
- import { toLightning, toEVM } from "../apis/lspApi";
12
+ import { toLightning } from "../apis/lspApi";
13
13
  const ModalWrapper = styled.div``;
14
14
  const BridgeDetail = styled.div`
15
15
  padding: 10px 20px;
@@ -51,15 +51,10 @@ const ModalTitle = styled.div`
51
51
  flex: 1;
52
52
  }
53
53
  `;
54
- // 自定义 Modal 样式
55
54
  const StyledModal = styled(Modal)`
56
- @font-face {
55
+ * {
57
56
  font-family: "ClashDisplay";
58
- src: url("../font/ClashDisplay-Variable.ttf") format("truetype");
59
- font-weight: normal;
60
- font-style: normal;
61
57
  }
62
- font-family: "ClashDisplay", sans-serif;
63
58
  .astra-modal-content {
64
59
  background: rgba(51, 51, 51, 0.2);
65
60
  border: 1px solid;
@@ -82,15 +77,20 @@ const StyledModal = styled(Modal)`
82
77
  .colorcaff33 {
83
78
  color: #caff33;
84
79
  }
80
+ .astra-col {
81
+ font-family: "ClashDisplay";
82
+ }
83
+ .astra-typography {
84
+ font-family: "ClashDisplay";
85
+ }
85
86
  }
86
87
 
87
- // 媒体查询样式
88
88
  @media (max-width: 768px) {
89
89
  font-size: 12px;
90
90
 
91
91
  .astra-modal-content {
92
92
  padding: 20px 10px;
93
-
93
+ background: rgba(51, 51, 51, 0.2);
94
94
  .astra-modal-header .modal-title {
95
95
  font-size: 18px;
96
96
  }
@@ -100,7 +100,7 @@ const StyledModal = styled(Modal)`
100
100
  @media (max-width: 575px) {
101
101
  .astra-modal-content {
102
102
  padding: 15px 8px;
103
-
103
+ background: rgba(51, 51, 51, 0.2);
104
104
  .astra-modal-header .modal-title {
105
105
  font-size: 16px;
106
106
  }
@@ -168,7 +168,6 @@ export default function ResultModal({
168
168
  footer={null}
169
169
  open={resultModalShow}
170
170
  onCancel={onCancel}
171
- centered
172
171
  maskClosable={false}
173
172
  mask={false}
174
173
  zIndex={998}
@@ -190,7 +189,7 @@ export default function ResultModal({
190
189
  <BridgeDetailItem justify="space-between" align="center">
191
190
  <div>Value</div>
192
191
  <div className="lightning">
193
- {numberWithCommas(requestData?.formatTokenAmt)}LUSD
192
+ {numberWithCommas(requestData?.formatTokenAmt)}{" "}LUSD
194
193
  </div>
195
194
  </BridgeDetailItem>
196
195
  </BridgeDetail>
@@ -133,15 +133,15 @@ function ToLightning({
133
133
  token: currentAssetPair?.token?.address,
134
134
  enabled: !!currentAssetPair?.token?.address && !!account?.address,
135
135
  formatUnits: currentAssetPair?.token?.decimal,
136
+ scopeKey: "token",
136
137
  });
137
138
 
138
139
  const mainnetBalanceRet = useBalance({
139
140
  address: account?.address,
140
141
  enabled: !!account?.address,
141
142
  formatUnits: "ether",
143
+ scopeKey: "mainnet",
142
144
  });
143
- //console.log('mainnetBalanceRet', mainnetBalanceRet)
144
- // console.log('tokenRet', tokenBalanceRet);
145
145
 
146
146
  const serviceFee = useMemo(() => {
147
147
  const recieveBaseFee = reserveInfo?.toAssetBaseFee || 0;
@@ -175,10 +175,39 @@ function ToLightning({
175
175
  [allAssetPairs, setCurrentAssetPair]
176
176
  );
177
177
 
178
+ const onCheckBalance = useCallback(async () => {
179
+ const tokenBalance = tokenBalanceRet?.data?.value || 0;
180
+ const mainetBalance = mainnetBalanceRet?.data?.value || 0;
181
+
182
+ if (
183
+ !Number(mainetBalance) ||
184
+ Number(mainetBalance) < Number(reserveInfo?.toAssetBaseFee)
185
+ ) {
186
+ throw new Error("Insufficient balance to pay service fee.");
187
+ }
188
+ if (Number(tokenBalance) < Number(tokenAmt)) {
189
+ throw new Error("Insufficient available balance.");
190
+ }
191
+ if (Number(assetAmt) > Number(reserveInfo?.maxAsset)) {
192
+ throw new Error(
193
+ `The maximum amount is ${formatAssetByDecimal(
194
+ reserveInfo?.maxAsset,
195
+ currentAssetPair.asset.decimal
196
+ )} ${currentAssetPair?.asset?.symbol}.`
197
+ );
198
+ }
199
+ if (Number(formatAssetAmt) < reserveInfo.min) {
200
+ throw new Error(
201
+ `The minimum amount is ${reserveInfo?.min} ${currentAssetPair?.asset?.symbol}.`
202
+ );
203
+ }
204
+ }, [assetAmt, currentAssetPair, formatAssetAmt, mainnetBalanceRet?.data?.value, reserveInfo, tokenAmt, tokenBalanceRet?.data?.value]);
205
+
178
206
  const handleApprove = useCallback(
179
207
  async (approveAmt) => {
180
208
  try {
181
209
  setApproveLoading(true);
210
+ await onCheckBalance();
182
211
  const approveTx = await onApprove(approveAmt);
183
212
  if (approveTx) {
184
213
  messageApi.open({
@@ -198,30 +227,9 @@ function ToLightning({
198
227
  onReloadAllowance();
199
228
  }
200
229
  },
201
- [messageApi, onApprove, onReloadAllowance]
230
+ [messageApi, onApprove, onCheckBalance, onReloadAllowance]
202
231
  );
203
232
 
204
- const btnDisabled = useMemo(() => {
205
- if (filterdAssetPairs?.length === 0) {
206
- return true;
207
- }
208
- const tokenBalance = tokenBalanceRet?.data?.value || 0;
209
- const mainetBalance = mainnetBalanceRet?.data?.value || 0;
210
- if (
211
- !Number(tokenBalance) ||
212
- Number(tokenBalance) < Number(tokenAmt) ||
213
- Number(mainetBalance) < Number(reserveInfo?.toAssetBaseFee)
214
- ) {
215
- return true;
216
- }
217
- }, [
218
- filterdAssetPairs?.length,
219
- mainnetBalanceRet?.data?.value,
220
- reserveInfo?.toAssetBaseFee,
221
- tokenAmt,
222
- tokenBalanceRet?.data?.value,
223
- ]);
224
-
225
233
  const memoBtn = useMemo(() => {
226
234
  if (!account?.address) {
227
235
  return <ConnectButton />;
@@ -230,7 +238,7 @@ function ToLightning({
230
238
  return (
231
239
  <AstraButton
232
240
  type="primary"
233
- disabled={btnDisabled}
241
+ // disabled={btnDisabled}
234
242
  onClick={() => {
235
243
  handleApprove(Number.MAX_SAFE_INTEGER);
236
244
  }}
@@ -244,7 +252,7 @@ function ToLightning({
244
252
  return (
245
253
  <AstraButton
246
254
  type="primary"
247
- disabled={btnDisabled}
255
+ // disabled={btnDisabled}
248
256
  loading={submitLoading}
249
257
  htmlType="submit"
250
258
  >
@@ -259,7 +267,6 @@ function ToLightning({
259
267
  account?.address,
260
268
  allowanceRet,
261
269
  approveLoading,
262
- btnDisabled,
263
270
  handleApprove,
264
271
  submitLoading,
265
272
  tokenAmt,
@@ -271,6 +278,7 @@ function ToLightning({
271
278
  return;
272
279
  }
273
280
  setSubmitLoading(true);
281
+ await onCheckBalance();
274
282
  if (
275
283
  BigInt(assetAmt) > BigInt(reserveInfo?.maxAsset) ||
276
284
  Number(formatAssetAmt) < reserveInfo.min
@@ -307,7 +315,6 @@ function ToLightning({
307
315
  fee: reserveInfo?.toAssetBaseFee,
308
316
  signature: "0x",
309
317
  };
310
- console.log("depositArgs", depositArgs);
311
318
  const tx = await onDeposit(depositArgs);
312
319
  if (tx) {
313
320
  const request = {
@@ -336,26 +343,7 @@ function ToLightning({
336
343
  } finally {
337
344
  setSubmitLoading(false);
338
345
  }
339
- }, [
340
- account.address,
341
- assetAmt,
342
- reserveInfo,
343
- formatAssetAmt,
344
- onReloadAllowance,
345
- allowanceRet,
346
- tokenAmt,
347
- hashlock,
348
- currentAssetPair,
349
- onDeposit,
350
- onApprove,
351
- messageApi,
352
- targetNetwork.id,
353
- receiveArgs?.invoice,
354
- setResultModalRequest,
355
- formatTokenAmt,
356
- setAstraModalShow,
357
- setResultModalShow,
358
- ]);
346
+ }, [account.address, onCheckBalance, assetAmt, reserveInfo, formatAssetAmt, onReloadAllowance, allowanceRet, tokenAmt, hashlock, currentAssetPair, onDeposit, onApprove, messageApi, targetNetwork.id, receiveArgs?.invoice, setResultModalRequest, formatTokenAmt, setAstraModalShow, setResultModalShow]);
359
347
 
360
348
  const onClearAuth = useCallback(async () => {
361
349
  await handleApprove(0);
@@ -120,19 +120,46 @@ function ToToken({ messageApi }) {
120
120
  formatUnits: "ether",
121
121
  });
122
122
 
123
- const btnDisabled = useMemo(() => {
124
- if (filterdAssetPairs?.length === 0) {
125
- return true;
126
- }
123
+ // const btnDisabled = useMemo(() => {
124
+ // if (filterdAssetPairs?.length === 0) {
125
+ // return true;
126
+ // }
127
+ // const mainetBalance = mainnetBalanceRet?.data?.value || 0;
128
+ // if (Number(mainetBalance) < Number(reserveInfo?.toTokenBaseFee)) {
129
+ // return true;
130
+ // }
131
+ // }, [
132
+ // filterdAssetPairs?.length,
133
+ // mainnetBalanceRet?.data?.value,
134
+ // reserveInfo?.toTokenBaseFee,
135
+ // ]);
136
+
137
+ const onCheckBalance = useCallback(async ()=>{
127
138
  const mainetBalance = mainnetBalanceRet?.data?.value || 0;
139
+ const max = Math.min(
140
+ Number(
141
+ formatAssetByDecimal(
142
+ reserveInfo?.maxToken,
143
+ currentAssetPair.token.decimal
144
+ )
145
+ ),
146
+ reserveInfo.max
147
+ );
128
148
  if (Number(mainetBalance) < Number(reserveInfo?.toTokenBaseFee)) {
129
- return true;
149
+ throw new Error('Insufficient balance to pay service fee.')
130
150
  }
131
- }, [
132
- filterdAssetPairs?.length,
133
- mainnetBalanceRet?.data?.value,
134
- reserveInfo?.toTokenBaseFee,
135
- ]);
151
+
152
+ if(sendArgs.amount < reserveInfo.min){
153
+ throw new Error(`The minimum amount is ${reserveInfo.min} ${currentAssetPair?.asset?.symbol}`)
154
+ }
155
+ if (sendArgs.amount > max) {
156
+ throw new Error(
157
+ `The maximum amount is ${max} ${currentAssetPair?.asset?.symbol}`
158
+ );
159
+ }
160
+
161
+ },[currentAssetPair, mainnetBalanceRet?.data?.value, reserveInfo?.max, reserveInfo?.maxToken, reserveInfo?.min, reserveInfo?.toTokenBaseFee, sendArgs.amount])
162
+
136
163
 
137
164
  const onResetInvoice = useCallback(() => {
138
165
  setIsInvoiceExpired(false);
@@ -154,22 +181,8 @@ function ToToken({ messageApi }) {
154
181
  try {
155
182
  setSubmitLoading(true);
156
183
  onResetInvoice();
157
- const max = Math.min(
158
- Number(
159
- formatAssetByDecimal(
160
- reserveInfo?.maxToken,
161
- currentAssetPair.token.decimal
162
- )
163
- ),
164
- reserveInfo.max
165
- );
166
-
167
- if (sendArgs.amount > max || sendArgs.amount < reserveInfo.min) {
168
- throw new Error(
169
- `Amount should be between ${reserveInfo.min} and ${max}`
170
- );
171
- }
172
-
184
+ await onCheckBalance();
185
+
173
186
  const retGetSignature = await getSignature({
174
187
  chainId: targetNetwork.id,
175
188
  amount: sendArgs.amount,
@@ -214,14 +227,7 @@ function ToToken({ messageApi }) {
214
227
  hashlock: signatureRes.hashlock,
215
228
  depositTx: tx,
216
229
  };
217
- // setResultModalRequest({
218
- // txHash: tx,
219
- // timestamp: Date.now(),
220
- // formatTokenAmt: sendArgs.amount,
221
- // request
222
- // })
223
- // setAstraModalShow(false)
224
- // setResultModalShow(true);
230
+
225
231
  const retToEVM = await toEVM(request);
226
232
  if (retToEVM.code === 200) {
227
233
  messageApi.success("Submit success.");
@@ -241,17 +247,7 @@ function ToToken({ messageApi }) {
241
247
  } finally {
242
248
  setSubmitLoading(false);
243
249
  }
244
- }, [
245
- onResetInvoice,
246
- reserveInfo,
247
- currentAssetPair,
248
- sendArgs.amount,
249
- sendArgs.waitConfirm,
250
- targetNetwork.id,
251
- account.address,
252
- onDeposit,
253
- messageApi,
254
- ]);
250
+ }, [onResetInvoice, onCheckBalance, targetNetwork?.id, sendArgs?.amount, sendArgs?.waitConfirm, currentAssetPair?.pairName, currentAssetPair?.asset?.assetId, account?.address, onDeposit, messageApi]);
255
251
 
256
252
  const btn = useMemo(() => {
257
253
  if (!account?.address) {
@@ -265,11 +261,12 @@ function ToToken({ messageApi }) {
265
261
  ) : (
266
262
  <SubmitBtn
267
263
  type="primary"
268
- disabled={isInvoiceExpired || btnDisabled}
264
+ disabled={isInvoiceExpired}
269
265
  loading={payInvoiceLoading}
270
266
  onClick={async () => {
271
267
  setPayInvoiceLoading(true);
272
- await onAstraInvoice(sendInvoice, tx)
268
+ const txUrl = `${targetNetwork?.blockExplorers?.default.url}/tx/${tx}`
269
+ await onAstraInvoice(sendInvoice, tx, txUrl)
273
270
  .catch((e) => {
274
271
  messageApi.error(e.message);
275
272
  setPayInvoiceLoading(false);
@@ -291,25 +288,14 @@ function ToToken({ messageApi }) {
291
288
  type="primary"
292
289
  htmlType="submit"
293
290
  loading={submitLoading}
294
- disabled={isInvoiceExpired || btnDisabled}
291
+ disabled={isInvoiceExpired}
295
292
  >
296
293
  <span>{submitLoading ? "Waiting for Confirmation" : "Submit"}</span>
297
294
  <img src={IconArrowRight} alt="" />
298
295
  </SubmitBtn>
299
296
  );
300
297
  }
301
- }, [
302
- account?.address,
303
- btnDisabled,
304
- isInvoiceExpired,
305
- messageApi,
306
- onAstraInvoice,
307
- payInvoiceLoading,
308
- sendInvoice,
309
- setAstraModalShow,
310
- submitLoading,
311
- tx,
312
- ]);
298
+ }, [account?.address, isInvoiceExpired, messageApi, onAstraInvoice, payInvoiceLoading, sendInvoice, setAstraModalShow, submitLoading, targetNetwork?.blockExplorers?.default.url, tx]);
313
299
 
314
300
  const onExpired = useCallback(() => {
315
301
  setIsInvoiceExpired(true);