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/hooks/useContract.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useChainId,
|
|
3
|
-
useReadContract,
|
|
4
|
-
useWriteContract,
|
|
5
|
-
useConfig,
|
|
6
|
-
usePublicClient,
|
|
7
|
-
} from "wagmi";
|
|
8
|
-
import { waitForTransactionReceipt, readContract } from "@wagmi/core";
|
|
9
|
-
import { useMemo, useCallback } from "react";
|
|
10
|
-
import { useGetContractConfig } from "./useLspApi";
|
|
11
|
-
import useStore from "../store";
|
|
12
|
-
import { formatAssetByDecimal, toBytes32 } from "../utils";
|
|
13
|
-
export function useBridgeContract(account) {
|
|
14
|
-
const chainId = useChainId();
|
|
15
|
-
const publicClient = usePublicClient();
|
|
16
|
-
const { contractConfig } = useGetContractConfig();
|
|
17
|
-
|
|
18
|
-
const config = useMemo(() => {
|
|
19
|
-
if (!contractConfig) return null;
|
|
20
|
-
return contractConfig[chainId];
|
|
21
|
-
}, [chainId, contractConfig]);
|
|
22
|
-
|
|
23
|
-
const { currentAssetPair } = useStore();
|
|
24
|
-
|
|
25
|
-
const bridgeContractConfig = useMemo(() => {
|
|
26
|
-
return {
|
|
27
|
-
address: config?.Bridge?.address,
|
|
28
|
-
abi: config?.Bridge?.abi,
|
|
29
|
-
query: {
|
|
30
|
-
enabled: !!config && !!account?.address,
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
}, [account?.address, config]);
|
|
34
|
-
|
|
35
|
-
const tokenContractConfig = useMemo(() => {
|
|
36
|
-
return {
|
|
37
|
-
address: currentAssetPair?.token?.address,
|
|
38
|
-
abi: config?.USDT?.abi,
|
|
39
|
-
query: {
|
|
40
|
-
enabled: !!currentAssetPair && !!account?.address,
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}, [account?.address, config?.USDT?.abi, currentAssetPair]);
|
|
44
|
-
|
|
45
|
-
const {
|
|
46
|
-
data: allowanceRet,
|
|
47
|
-
isLoading: allowanceLoading,
|
|
48
|
-
refetch: onReloadAllowance,
|
|
49
|
-
} = useReadContract({
|
|
50
|
-
...tokenContractConfig,
|
|
51
|
-
functionName: "allowance",
|
|
52
|
-
args: [account?.address, config?.Bridge?.address],
|
|
53
|
-
scopeKey: "allowance",
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
const formatAllowance = useMemo(() => {
|
|
57
|
-
if (!allowanceRet) return 0;
|
|
58
|
-
return formatAssetByDecimal(
|
|
59
|
-
allowanceRet?.toString(),
|
|
60
|
-
currentAssetPair?.token?.decimal
|
|
61
|
-
);
|
|
62
|
-
}, [allowanceRet, currentAssetPair?.token?.decimal]);
|
|
63
|
-
|
|
64
|
-
const wagmiConfig = useConfig();
|
|
65
|
-
const { writeContractAsync } = useWriteContract();
|
|
66
|
-
|
|
67
|
-
const onApprove = useCallback(
|
|
68
|
-
async (approveAmount, wait = true) => {
|
|
69
|
-
//console.log("🚀 ~ onApprove ~ approveAmount:", approveAmount, config?.address)
|
|
70
|
-
const tx = await writeContractAsync({
|
|
71
|
-
...tokenContractConfig,
|
|
72
|
-
functionName: "approve",
|
|
73
|
-
args: [config?.Bridge?.address, BigInt(approveAmount)],
|
|
74
|
-
chainId: chainId,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (wait) {
|
|
78
|
-
await waitForTransactionReceipt(
|
|
79
|
-
wagmiConfig,
|
|
80
|
-
{
|
|
81
|
-
hash: tx,
|
|
82
|
-
},
|
|
83
|
-
1
|
|
84
|
-
);
|
|
85
|
-
if (onReloadAllowance) {
|
|
86
|
-
await onReloadAllowance();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return tx;
|
|
90
|
-
},
|
|
91
|
-
[
|
|
92
|
-
chainId,
|
|
93
|
-
config?.Bridge?.address,
|
|
94
|
-
onReloadAllowance,
|
|
95
|
-
tokenContractConfig,
|
|
96
|
-
wagmiConfig,
|
|
97
|
-
writeContractAsync,
|
|
98
|
-
]
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
const onDeposit = useCallback(
|
|
102
|
-
async (
|
|
103
|
-
{
|
|
104
|
-
hashlock,
|
|
105
|
-
nodePubkey,
|
|
106
|
-
fromAddr,
|
|
107
|
-
toAddr,
|
|
108
|
-
pairId,
|
|
109
|
-
amount,
|
|
110
|
-
timeLock,
|
|
111
|
-
fee,
|
|
112
|
-
toLightning = true,
|
|
113
|
-
signature = "0x",
|
|
114
|
-
},
|
|
115
|
-
) => {
|
|
116
|
-
const contractInfo = await readContract(wagmiConfig, {
|
|
117
|
-
...bridgeContractConfig,
|
|
118
|
-
functionName: "getContractByKey",
|
|
119
|
-
args: [hashlock],
|
|
120
|
-
});
|
|
121
|
-
if (contractInfo?.hashlock === hashlock) {
|
|
122
|
-
throw new Error("Invoice already exists.");
|
|
123
|
-
}
|
|
124
|
-
const args = [
|
|
125
|
-
hashlock,
|
|
126
|
-
toBytes32(nodePubkey),
|
|
127
|
-
fromAddr,
|
|
128
|
-
toAddr,
|
|
129
|
-
pairId,
|
|
130
|
-
BigInt(amount),
|
|
131
|
-
timeLock,
|
|
132
|
-
fee,
|
|
133
|
-
toLightning,
|
|
134
|
-
signature,
|
|
135
|
-
];
|
|
136
|
-
const depositGas = await publicClient.estimateContractGas({
|
|
137
|
-
...bridgeContractConfig,
|
|
138
|
-
functionName: "deposit",
|
|
139
|
-
args: args,
|
|
140
|
-
value: fee,
|
|
141
|
-
account: account?.address,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const gasLimit = BigInt(Math.floor(Number(depositGas) * 1.2));
|
|
145
|
-
const tx = await writeContractAsync({
|
|
146
|
-
...bridgeContractConfig,
|
|
147
|
-
functionName: "deposit",
|
|
148
|
-
args: args,
|
|
149
|
-
value: fee,
|
|
150
|
-
chainId: chainId,
|
|
151
|
-
gas: gasLimit,
|
|
152
|
-
});
|
|
153
|
-
console.log(`🚀 ~ onDeposit ~ tx: ${tx}, will wait for 1 confirm`);
|
|
154
|
-
await waitForTransactionReceipt(
|
|
155
|
-
wagmiConfig,
|
|
156
|
-
{
|
|
157
|
-
hash: tx,
|
|
158
|
-
},
|
|
159
|
-
1
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
// if (onReloadAllowance && reloadAllowance) {
|
|
163
|
-
// onReloadAllowance();
|
|
164
|
-
// }
|
|
165
|
-
//}
|
|
166
|
-
return tx;
|
|
167
|
-
},
|
|
168
|
-
[chainId, account?.address, bridgeContractConfig, publicClient, wagmiConfig, writeContractAsync]
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
allowanceRet,
|
|
173
|
-
formatAllowance,
|
|
174
|
-
allowanceLoading,
|
|
175
|
-
onReloadAllowance,
|
|
176
|
-
onApprove,
|
|
177
|
-
onDeposit,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { balanceToFixed } from "../constants";
|
|
3
|
-
import useStore from "../store";
|
|
4
|
-
export const useGetMinAndMax = (payDirection,reserveInfo) => {
|
|
5
|
-
const { currentAssetPair } = useStore();
|
|
6
|
-
// console.log("🚀 ~ useGetMinAndMax ~ currentAssetPair:",reserveInfo )
|
|
7
|
-
const fixedLocalChannelBalance = useMemo(() => {
|
|
8
|
-
if (reserveInfo) {
|
|
9
|
-
return balanceToFixed(reserveInfo.maxAsset, currentAssetPair?.asset?.decimal);
|
|
10
|
-
}
|
|
11
|
-
return 0;
|
|
12
|
-
}, [currentAssetPair?.asset?.decimal, reserveInfo]);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const fixedRemoteChannelBalance = useMemo(()=>{
|
|
16
|
-
if(reserveInfo){
|
|
17
|
-
return balanceToFixed(reserveInfo?.remoteAssetbalance, currentAssetPair?.asset?.decimal);
|
|
18
|
-
}
|
|
19
|
-
return 0;
|
|
20
|
-
},[currentAssetPair?.asset?.decimal, reserveInfo])
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const max = useMemo(()=>{
|
|
24
|
-
if(payDirection==="evmToLightning"){
|
|
25
|
-
const value = Math.min(reserveInfo?.max, Number(fixedLocalChannelBalance));
|
|
26
|
-
return value
|
|
27
|
-
}else{
|
|
28
|
-
const lspBalance = balanceToFixed(reserveInfo?.maxToken, currentAssetPair?.token?.decimal);
|
|
29
|
-
const value = Math.min(reserveInfo?.max, Number(fixedRemoteChannelBalance), Number(lspBalance));
|
|
30
|
-
return value
|
|
31
|
-
}
|
|
32
|
-
},[currentAssetPair?.token?.decimal, fixedLocalChannelBalance, fixedRemoteChannelBalance, payDirection, reserveInfo?.max, reserveInfo?.maxToken])
|
|
33
|
-
|
|
34
|
-
const min = useMemo(()=>{
|
|
35
|
-
return Number(max)<Number(reserveInfo?.min)? Number(max): Number(reserveInfo?.min)
|
|
36
|
-
},[reserveInfo?.min,max])
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const unitName = useMemo(()=>{
|
|
42
|
-
if(payDirection==="evmToLightning"){
|
|
43
|
-
return currentAssetPair?.token?.name;
|
|
44
|
-
}
|
|
45
|
-
return currentAssetPair?.asset?.name;
|
|
46
|
-
},[currentAssetPair, payDirection])
|
|
47
|
-
return { min, max, unitName };
|
|
48
|
-
};
|
package/src/hooks/useLspApi.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { useRequest } from "ahooks";
|
|
2
|
-
import { useEffect, useMemo } from "react";
|
|
3
|
-
import { getPairs, getReserveInfo, getContractConfig } from "../apis/lspApi";
|
|
4
|
-
import useStore from "../store";
|
|
5
|
-
export const useGetPairs = () => {
|
|
6
|
-
const { setCurrentAssetPair, setAllAssetPairs, targetNetwork, astraApiUrl } =
|
|
7
|
-
useStore();
|
|
8
|
-
const { data, run, loading, refresh, cancel } = useRequest(
|
|
9
|
-
() => getPairs({ chainId: targetNetwork?.id }),
|
|
10
|
-
{
|
|
11
|
-
refreshDeps: [targetNetwork?.id, astraApiUrl],
|
|
12
|
-
ready: !!targetNetwork?.id && !!astraApiUrl,
|
|
13
|
-
}
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (data?.data?.pairs) {
|
|
18
|
-
setAllAssetPairs(data?.data?.pairs);
|
|
19
|
-
//setCurrentAssetPair(data?.data?.pairs[0]);
|
|
20
|
-
}
|
|
21
|
-
}, [data?.data?.pairs, setAllAssetPairs, setCurrentAssetPair]);
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
summary: data?.data || null,
|
|
25
|
-
loading,
|
|
26
|
-
run,
|
|
27
|
-
refresh,
|
|
28
|
-
cancel,
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const useGetReserveInfo = (targetNetwork, currentAssetPair) => {
|
|
33
|
-
/* const assetId = useMemo(() => {
|
|
34
|
-
return currentAssetPair?.asset?.assetId
|
|
35
|
-
}, [currentAssetPair?.asset?.assetId]) */
|
|
36
|
-
const chainId = useMemo(() => {
|
|
37
|
-
return targetNetwork?.id;
|
|
38
|
-
}, [targetNetwork?.id]);
|
|
39
|
-
|
|
40
|
-
const pairId = useMemo(() => {
|
|
41
|
-
return currentAssetPair?.pairId;
|
|
42
|
-
}, [currentAssetPair]);
|
|
43
|
-
|
|
44
|
-
const { data, loading, refresh } = useRequest(
|
|
45
|
-
() => getReserveInfo({ chainId: chainId, pairId: pairId }),
|
|
46
|
-
{
|
|
47
|
-
refreshDeps: [chainId, pairId],
|
|
48
|
-
ready: !!chainId && !!pairId,
|
|
49
|
-
debounceWait: 300,
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
reserveInfo: data?.data,
|
|
55
|
-
loading: pairId ? loading : false,
|
|
56
|
-
refresh,
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
export const useGetContractConfig = () => {
|
|
60
|
-
const { data, loading, refresh } = useRequest(() => getContractConfig(), {
|
|
61
|
-
refreshDeps: [],
|
|
62
|
-
ready: true,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
contractConfig: data?.data,
|
|
67
|
-
loading,
|
|
68
|
-
refresh,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useState } from "react";
|
|
2
|
-
import "../lib/bolt11.min.js";
|
|
3
|
-
import useStore from "../store";
|
|
4
|
-
import { invoiceToAssetInfo } from "../utils";
|
|
5
|
-
// import { useEffect } from "react";
|
|
6
|
-
import Decimal from "decimal.js";
|
|
7
|
-
import { useDebounceEffect } from "ahooks";
|
|
8
|
-
// window.decode = decode;
|
|
9
|
-
function getPaymentHash(requestObject) {
|
|
10
|
-
// go through the tags and find the 'payment_hash' tagName and return the 'data'
|
|
11
|
-
const paymentHash = requestObject.tags.find(
|
|
12
|
-
(tag) => tag.tagName === "payment_hash"
|
|
13
|
-
);
|
|
14
|
-
if (!paymentHash) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return "0x" + paymentHash.data.toString();
|
|
18
|
-
}
|
|
19
|
-
export default function useParseInvoice(invoice) {
|
|
20
|
-
const [assetAmt, setAssetAmt] = useState(0);
|
|
21
|
-
const [hashlock, setHashlock] = useState("");
|
|
22
|
-
const { currentAssetPair } = useStore();
|
|
23
|
-
const [isExpired, setIsExpired] = useState(false);
|
|
24
|
-
const [parseInvoiceLoading, setParseInvoiceLoading] = useState(false);
|
|
25
|
-
const formatAssetAmt = useMemo(() => {
|
|
26
|
-
if (assetAmt && currentAssetPair) {
|
|
27
|
-
const decimal = currentAssetPair.asset.decimal;
|
|
28
|
-
return new Decimal(assetAmt).div(10 ** decimal).toFixed(decimal);
|
|
29
|
-
}
|
|
30
|
-
return 0;
|
|
31
|
-
}, [assetAmt, currentAssetPair]);
|
|
32
|
-
|
|
33
|
-
const tokenAmt = useMemo(() => {
|
|
34
|
-
if (currentAssetPair) {
|
|
35
|
-
const decimal = currentAssetPair.token.decimal;
|
|
36
|
-
return new Decimal(formatAssetAmt).mul(10 ** decimal).toFixed(0);
|
|
37
|
-
}
|
|
38
|
-
return 0;
|
|
39
|
-
}, [currentAssetPair, formatAssetAmt]);
|
|
40
|
-
|
|
41
|
-
const formatTokenAmt = useMemo(() => {
|
|
42
|
-
if (currentAssetPair) {
|
|
43
|
-
const decimal = currentAssetPair.token.decimal;
|
|
44
|
-
const displayDecimal = currentAssetPair.asset.decimal;
|
|
45
|
-
return new Decimal(tokenAmt)
|
|
46
|
-
.div(10 ** decimal)
|
|
47
|
-
.toFixed(displayDecimal, Decimal.ROUND_DOWN);
|
|
48
|
-
}
|
|
49
|
-
return 0;
|
|
50
|
-
}, [currentAssetPair, tokenAmt]);
|
|
51
|
-
|
|
52
|
-
const parseInvoice = useCallback(async () => {
|
|
53
|
-
try {
|
|
54
|
-
setParseInvoiceLoading(true);
|
|
55
|
-
const decoded = window.lightningPayReq.decode(invoice);
|
|
56
|
-
if (decoded.timeExpireDate < Math.floor(Date.now() / 1000)) {
|
|
57
|
-
setIsExpired(true);
|
|
58
|
-
}
|
|
59
|
-
//const numMsat = decoded.millisatoshis;
|
|
60
|
-
const { amount: amt } = await invoiceToAssetInfo({
|
|
61
|
-
payReq: invoice,
|
|
62
|
-
assetId: currentAssetPair.asset.assetId,
|
|
63
|
-
});
|
|
64
|
-
setAssetAmt(amt);
|
|
65
|
-
const hashlock = getPaymentHash(decoded);
|
|
66
|
-
setHashlock(hashlock);
|
|
67
|
-
} catch (e) {
|
|
68
|
-
console.log(e.message);
|
|
69
|
-
setAssetAmt(0);
|
|
70
|
-
} finally {
|
|
71
|
-
setParseInvoiceLoading(false);
|
|
72
|
-
}
|
|
73
|
-
}, [currentAssetPair, invoice]);
|
|
74
|
-
useDebounceEffect(
|
|
75
|
-
() => {
|
|
76
|
-
if (invoice && currentAssetPair) {
|
|
77
|
-
parseInvoice();
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
[currentAssetPair, invoice, parseInvoice],
|
|
81
|
-
{
|
|
82
|
-
wait: 500,
|
|
83
|
-
}
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
assetAmt,
|
|
88
|
-
formatAssetAmt,
|
|
89
|
-
tokenAmt,
|
|
90
|
-
formatTokenAmt,
|
|
91
|
-
hashlock,
|
|
92
|
-
parseInvoiceLoading,
|
|
93
|
-
isExpired,
|
|
94
|
-
};
|
|
95
|
-
}
|
package/src/index.css
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
:root {
|
|
2
|
-
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
|
3
|
-
line-height: 1.5;
|
|
4
|
-
font-weight: 400;
|
|
5
|
-
|
|
6
|
-
color-scheme: light dark;
|
|
7
|
-
color: rgba(255, 255, 255, 0.87);
|
|
8
|
-
background-color: rgba(26, 26, 26, 0.5);
|
|
9
|
-
|
|
10
|
-
font-synthesis: none;
|
|
11
|
-
text-rendering: optimizeLegibility;
|
|
12
|
-
-webkit-font-smoothing: antialiased;
|
|
13
|
-
-moz-osx-font-smoothing: grayscale;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/* a {
|
|
17
|
-
font-weight: 500;
|
|
18
|
-
color: #646cff;
|
|
19
|
-
text-decoration: inherit;
|
|
20
|
-
}
|
|
21
|
-
a:hover {
|
|
22
|
-
color: #535bf2;
|
|
23
|
-
} */
|
|
24
|
-
|
|
25
|
-
body {
|
|
26
|
-
margin: 0;
|
|
27
|
-
display: flex;
|
|
28
|
-
place-items: center;
|
|
29
|
-
min-width: 320px;
|
|
30
|
-
min-height: 100vh;
|
|
31
|
-
background-color: #041011;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
h1 {
|
|
35
|
-
font-size: 3.2em;
|
|
36
|
-
line-height: 1.1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/* button {
|
|
40
|
-
border-radius: 8px;
|
|
41
|
-
border: 1px solid transparent;
|
|
42
|
-
padding: 0.6em 1.2em;
|
|
43
|
-
font-size: 1em;
|
|
44
|
-
font-weight: 500;
|
|
45
|
-
font-family: inherit;
|
|
46
|
-
background-color: #1a1a1a;
|
|
47
|
-
cursor: pointer;
|
|
48
|
-
transition: border-color 0.25s;
|
|
49
|
-
}
|
|
50
|
-
button:hover {
|
|
51
|
-
border-color: #646cff;
|
|
52
|
-
}
|
|
53
|
-
button:focus,
|
|
54
|
-
button:focus-visible {
|
|
55
|
-
outline: 4px auto -webkit-focus-ring-color;
|
|
56
|
-
} */
|
|
57
|
-
|
|
58
|
-
@media (prefers-color-scheme: light) {
|
|
59
|
-
:root {
|
|
60
|
-
color: #213547;
|
|
61
|
-
background-color: #ffffff;
|
|
62
|
-
}
|
|
63
|
-
a:hover {
|
|
64
|
-
color: #747bff;
|
|
65
|
-
}
|
|
66
|
-
button {
|
|
67
|
-
background-color: #f9f9f9;
|
|
68
|
-
}
|
|
69
|
-
}
|
package/src/index.jsx
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
// import { Button } from "antd";
|
|
2
|
-
import { ConfigProvider, theme } from "antd";
|
|
3
|
-
import { createAppKit } from "@reown/appkit/react";
|
|
4
|
-
import { WagmiProvider } from "wagmi";
|
|
5
|
-
import {
|
|
6
|
-
sepolia,
|
|
7
|
-
baseSepolia,
|
|
8
|
-
base,
|
|
9
|
-
bsc,
|
|
10
|
-
botanixTestnet,
|
|
11
|
-
} from "@reown/appkit/networks";
|
|
12
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
13
|
-
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
|
|
14
|
-
import AstraDialog from "./comps/AstraModal.jsx";
|
|
15
|
-
import useStore from "./store/index.js";
|
|
16
|
-
import { themeConfig } from "./theme.js";
|
|
17
|
-
import { MODAL_DISPLAY_TYPE } from "./constants/index.js";
|
|
18
|
-
import IconEthNetwork from "./assets/network/eth.png";
|
|
19
|
-
import IconBaseNetwork from "./assets/network/base.png";
|
|
20
|
-
import IconBotanixNetwork from "./assets/network/botanix.png";
|
|
21
|
-
import { useLayoutEffect, useMemo, useRef } from "react";
|
|
22
|
-
|
|
23
|
-
const defaultMetadata = {
|
|
24
|
-
name: "Lnfi",
|
|
25
|
-
description: "Lnfi",
|
|
26
|
-
url: "https://www.lnfi.network/", // origin must match your domain & subdomain
|
|
27
|
-
icons: ["https://avatars.githubusercontent.com/u/37784886"],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const API_URL_MAP = {
|
|
31
|
-
// development: "https://devof-astralsp.unift.xyz/",
|
|
32
|
-
development: "https://devof-nodeflow-bridge-api.unift.xyz/",
|
|
33
|
-
production: "https://api.astra-labs.io/",
|
|
34
|
-
};
|
|
35
|
-
// 3. Set the networks
|
|
36
|
-
|
|
37
|
-
let wagmiAdapter = null;
|
|
38
|
-
|
|
39
|
-
export default function AstraProvider({
|
|
40
|
-
projectId,
|
|
41
|
-
metadata,
|
|
42
|
-
adapter,
|
|
43
|
-
env = "production",
|
|
44
|
-
apiUrl = "https://api.astra-labs.io/",
|
|
45
|
-
children,
|
|
46
|
-
}) {
|
|
47
|
-
const networks = useMemo(() => {
|
|
48
|
-
return env === "development" ? [sepolia, baseSepolia] : [bsc, base];
|
|
49
|
-
}, [env]);
|
|
50
|
-
// const transports = useMemo(()=>{
|
|
51
|
-
// return env==='development'? {
|
|
52
|
-
// [sepolia.id]: http(`https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
53
|
-
// [baseSepolia.id]: http(`https://base-sepolia.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
54
|
-
// }:{
|
|
55
|
-
// [bsc.id]: http(`https://bnb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
56
|
-
// [base.id]: http(`https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
57
|
-
// }
|
|
58
|
-
// },[env])
|
|
59
|
-
const { setAstrApiUrl } = useStore();
|
|
60
|
-
const queryClient = new QueryClient();
|
|
61
|
-
const appKit = useRef(null);
|
|
62
|
-
if (!wagmiAdapter) {
|
|
63
|
-
wagmiAdapter = adapter
|
|
64
|
-
? adapter
|
|
65
|
-
: new WagmiAdapter({
|
|
66
|
-
networks,
|
|
67
|
-
// transports: transports,
|
|
68
|
-
projectId: projectId,
|
|
69
|
-
pollingInterval: 8_000,
|
|
70
|
-
cacheTime: 6_000,
|
|
71
|
-
ssr: false,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
useLayoutEffect(() => {
|
|
75
|
-
if (!appKit.current) {
|
|
76
|
-
appKit.current = createAppKit({
|
|
77
|
-
adapters: [wagmiAdapter],
|
|
78
|
-
networks,
|
|
79
|
-
chainImages: {
|
|
80
|
-
[sepolia.id]: IconEthNetwork,
|
|
81
|
-
[baseSepolia.id]: IconBaseNetwork,
|
|
82
|
-
[botanixTestnet.id]: IconBotanixNetwork,
|
|
83
|
-
},
|
|
84
|
-
debug: false,
|
|
85
|
-
themeMode: "dark",
|
|
86
|
-
projectId: projectId,
|
|
87
|
-
metadata: metadata || defaultMetadata,
|
|
88
|
-
featuredWalletIds: [
|
|
89
|
-
"c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96",
|
|
90
|
-
"971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709",
|
|
91
|
-
"8a0ee50d1f22f6651afcae7eb4253e52a3310b90af5daef78a8c4929a9bb99d4",
|
|
92
|
-
],
|
|
93
|
-
features: {
|
|
94
|
-
analytics: false,
|
|
95
|
-
swaps: false,
|
|
96
|
-
onramp: false,
|
|
97
|
-
socials: [],
|
|
98
|
-
email: false,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
const finalApiUrl = API_URL_MAP[env] || apiUrl;
|
|
103
|
-
setAstrApiUrl(finalApiUrl);
|
|
104
|
-
}, [apiUrl, env, metadata, networks, projectId, setAstrApiUrl]);
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<>
|
|
108
|
-
<>
|
|
109
|
-
<ConfigProvider
|
|
110
|
-
theme={{
|
|
111
|
-
algorithm: theme.darkAlgorithm,
|
|
112
|
-
cssVar: false,
|
|
113
|
-
...themeConfig,
|
|
114
|
-
}}
|
|
115
|
-
prefixCls="astra"
|
|
116
|
-
>
|
|
117
|
-
<WagmiProvider config={wagmiAdapter.wagmiConfig}>
|
|
118
|
-
<QueryClientProvider client={queryClient}>
|
|
119
|
-
<>{children}</>
|
|
120
|
-
</QueryClientProvider>
|
|
121
|
-
</WagmiProvider>
|
|
122
|
-
</ConfigProvider>
|
|
123
|
-
</>
|
|
124
|
-
</>
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export const AstraModal = AstraDialog;
|
|
129
|
-
// eslint-disable-next-line react-refresh/only-export-components
|
|
130
|
-
export function astraReceive({ invoice, assetId }) {
|
|
131
|
-
//evm2lightning
|
|
132
|
-
const store = useStore;
|
|
133
|
-
|
|
134
|
-
// 校验将在组件内部进行(因为需要等待 allAssetPairs 加载)
|
|
135
|
-
// 这里只设置参数,由 ToLightning 组件负责校验和显示错误
|
|
136
|
-
store.setState(() => ({
|
|
137
|
-
astraModalShow: true,
|
|
138
|
-
receiveArgs: { invoice, assetId },
|
|
139
|
-
modalDisplayType: MODAL_DISPLAY_TYPE.TO_LIGHTNING,
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// eslint-disable-next-line react-refresh/only-export-components
|
|
144
|
-
export function astraSend({
|
|
145
|
-
amount,
|
|
146
|
-
assetId,
|
|
147
|
-
onAstraInvoice,
|
|
148
|
-
waitConfirm = true,
|
|
149
|
-
}) {
|
|
150
|
-
// lightning2evm
|
|
151
|
-
const store = useStore;
|
|
152
|
-
|
|
153
|
-
// 校验将在组件内部进行(因为需要等待 allAssetPairs 加载)
|
|
154
|
-
// 这里只设置参数,由 ToToken 组件负责校验和显示错误
|
|
155
|
-
store.setState(() => ({
|
|
156
|
-
astraModalShow: true,
|
|
157
|
-
sendArgs: { amount, assetId, waitConfirm },
|
|
158
|
-
modalDisplayType: MODAL_DISPLAY_TYPE.TO_EVM,
|
|
159
|
-
onAstraInvoice,
|
|
160
|
-
}));
|
|
161
|
-
}
|