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.
- package/README.md +118 -148
- package/dist/{SwapController-rSbURdpJ.js → SwapController-Ck3TYcMp.js} +1 -1
- package/dist/{add-CpqI0qih.js → add-BmBLHIEe.js} +1 -1
- package/dist/{all-wallets-BCS6tMyX.js → all-wallets-H2aaJ2oP.js} +1 -1
- package/dist/{app-store-BJcpQsmn.js → app-store-Bvhe1BkA.js} +1 -1
- package/dist/{apple-BYXq8xra.js → apple-BCIKns5c.js} +1 -1
- package/dist/{arrow-bottom-circle-7zz6Cez4.js → arrow-bottom-circle-Dpcn0z0p.js} +1 -1
- package/dist/{arrow-bottom-DyDya01u.js → arrow-bottom-i1ChNkSf.js} +1 -1
- package/dist/{arrow-left-DFjTrDxq.js → arrow-left-Dj8tzUf6.js} +1 -1
- package/dist/{arrow-right-BeKBpPGZ.js → arrow-right-DVd3R-0K.js} +1 -1
- package/dist/{arrow-top-C8kkMQwd.js → arrow-top-DcD5wbZL.js} +1 -1
- package/dist/astra-sdk.es.js +1 -1
- package/dist/{bank-FSmmDSOr.js → bank-CToLOTy3.js} +1 -1
- package/dist/{bin-BxSWmf4U.js → bin-D8m48Dk5.js} +1 -1
- package/dist/{bitcoin-DOtAY1tg.js → bitcoin-y6S4LO0p.js} +1 -1
- package/dist/{browser-CxU-j1-l.js → browser-DRhVaQQT.js} +1 -1
- package/dist/{card-CjYkck9C.js → card-BK0q3S4W.js} +1 -1
- package/dist/{ccip-Dzjn7iUj.js → ccip-CH1B6Zeh.js} +1 -1
- package/dist/{checkmark-BQzWjMBG.js → checkmark-C7H1vH4H.js} +1 -1
- package/dist/{checkmark-bold-CydTLhCY.js → checkmark-bold-DfvIWKpu.js} +1 -1
- package/dist/{chevron-bottom-CA607zpT.js → chevron-bottom-CcAEP6cD.js} +1 -1
- package/dist/{chevron-left-BGmBZSZo.js → chevron-left-DMnhSBVl.js} +1 -1
- package/dist/{chevron-right-NBRpcLa8.js → chevron-right-pPhw9ZBC.js} +1 -1
- package/dist/{chevron-top-Cw5I5ZOR.js → chevron-top-DjqOCRAL.js} +1 -1
- package/dist/{chrome-store-Bg96vfCc.js → chrome-store-B-9bRAPM.js} +1 -1
- package/dist/{circle-D_QW929y.js → circle-SPbxfVZq.js} +1 -1
- package/dist/{clock-o4gqCbWO.js → clock-BLAT4wv4.js} +1 -1
- package/dist/{close-z2Y-xc4H.js → close-D1AyyJzy.js} +1 -1
- package/dist/{coinPlaceholder-D_9U8ws8.js → coinPlaceholder-DGk1in74.js} +1 -1
- package/dist/{compass-BVM30Hj-.js → compass-C0-SVkSt.js} +1 -1
- package/dist/{copy-BvKR_En_.js → copy-CPcvwITz.js} +1 -1
- package/dist/{cursor-DKFz2C-k.js → cursor-ChlOWEcO.js} +1 -1
- package/dist/{cursor-transparent-DwsHTJdY.js → cursor-transparent-BJsEpe-G.js} +1 -1
- package/dist/{desktop-_hiZGUrG.js → desktop-Z8iZvVCW.js} +1 -1
- package/dist/{disconnect-DbmK87x7.js → disconnect-DkPQjiLk.js} +1 -1
- package/dist/{discord-CGEs_Ewv.js → discord-CwRdgvGZ.js} +1 -1
- package/dist/{email-B64OZpkU.js → email-DA_5xt-j.js} +1 -1
- package/dist/{embedded-wallet-CdFJiA0M.js → embedded-wallet-DYnGl5tL.js} +1 -1
- package/dist/{ethereum-ByYB2hkU.js → ethereum-Dwse3Umc.js} +1 -1
- package/dist/{etherscan-BbjvIHaL.js → etherscan-CNmwyrRn.js} +1 -1
- package/dist/{exclamation-triangle-CdD-9Mg9.js → exclamation-triangle-CU8gn-bU.js} +1 -1
- package/dist/{extension-CwWz_fIf.js → extension-rikwXWrg.js} +1 -1
- package/dist/{external-link-B-H5cp6t.js → external-link-mDp8JVE0.js} +1 -1
- package/dist/{facebook-BCVDL-tg.js → facebook-c0IS1D9G.js} +1 -1
- package/dist/{farcaster-jtO1GaIa.js → farcaster-DpvSDnGl.js} +1 -1
- package/dist/{filters-D-d663Tl.js → filters-B42-1BLn.js} +1 -1
- package/dist/{github-GYbnMtDL.js → github-DvjZxkXF.js} +1 -1
- package/dist/{google-D0T6MiMp.js → google-CLHf_zAz.js} +1 -1
- package/dist/{help-circle-S_PJYnAb.js → help-circle-BI5xgPAz.js} +1 -1
- package/dist/{id-ovWduNYl.js → id-BxI79dX4.js} +1 -1
- package/dist/{image-DWMmztGY.js → image-Cr1qAxG-.js} +1 -1
- package/dist/{index-RJEV23nN.js → index-C0USsgDi.js} +1 -1
- package/dist/{index-D49QXkg7.js → index-C49-8bCQ.js} +1 -1
- package/dist/{index-DEIfu1o6.js → index-CH4T0JAz.js} +1 -1
- package/dist/{index-CJ7s8Rmk.js → index-CWAoFGd1.js} +6 -6
- package/dist/{index-3RuZHNxg.js → index-C_3PUMa7.js} +1 -1
- package/dist/{index-Dv7m_bJu.js → index-D7jufxlk.js} +1 -1
- package/dist/{index-BrVBbGpA.js → index-DZiQey0J.js} +1 -1
- package/dist/{index-CXZjl-KY.js → index-DtAG8k9M.js} +1 -1
- package/dist/{index-DpJh5yXk.js → index-Zh6wUpmX.js} +4008 -3984
- package/dist/{index-CTtOlAw3.js → index-utoSbRla.js} +1 -1
- package/dist/{info-B_t5Wxs5.js → info-BUp5BYav.js} +1 -1
- package/dist/{info-circle-BE3c4h9q.js → info-circle-D5anzkYK.js} +1 -1
- package/dist/{lightbulb-WY74qWMh.js → lightbulb-DmuhLv29.js} +1 -1
- package/dist/{mail-BZffBQJn.js → mail-D2hRmmgi.js} +1 -1
- package/dist/{mobile-BzoKYXrP.js → mobile-Cq-9uJHv.js} +1 -1
- package/dist/{more-DLl0U_yq.js → more-DJMBaB2z.js} +1 -1
- package/dist/{network-placeholder-GUlJsW90.js → network-placeholder-3ip1roR0.js} +1 -1
- package/dist/{nftPlaceholder-URobOrrj.js → nftPlaceholder-C7r74zYS.js} +1 -1
- package/dist/{off-Dd3KIizg.js → off-CJE6Z_MK.js} +1 -1
- package/dist/{onramp-D3nPDHgs.js → onramp-BMRgbt2I.js} +1 -1
- package/dist/{play-store-DQcCWm53.js → play-store-CxusWynI.js} +1 -1
- package/dist/{plus-CBsitvpf.js → plus-Bjkqj5g6.js} +1 -1
- package/dist/{qr-code-BLKOY5TH.js → qr-code-4C0zboga.js} +1 -1
- package/dist/{receive-Cs7OrQ5H.js → receive-Cc8moHBZ.js} +1 -1
- package/dist/{recycle-horizontal-DA3_DhRi.js → recycle-horizontal-BdSgk84g.js} +1 -1
- package/dist/{refresh-DA83X8jf.js → refresh-BsRodAS7.js} +1 -1
- package/dist/{reown-logo-CYujsMCS.js → reown-logo-DOVlqCDK.js} +1 -1
- package/dist/{search-dhyszWwL.js → search-BIyHtky-.js} +1 -1
- package/dist/{secp256k1-BzR-XYTV.js → secp256k1-B2Gq-iIr.js} +1 -1
- package/dist/{send-Djdyyp-y.js → send-9eSi58hW.js} +1 -1
- package/dist/{send-Dio4rhmI.js → send-CBFTcYtn.js} +3 -3
- package/dist/{socials-CyiUMsk1.js → socials-CeOJULFV.js} +1 -1
- package/dist/{solana-B01U90Av.js → solana-BNptwYvn.js} +1 -1
- package/dist/{swapHorizontal-BazEPj1l.js → swapHorizontal-COlgqyzt.js} +1 -1
- package/dist/{swapHorizontalBold-DOjBCDPH.js → swapHorizontalBold-Odce2JOe.js} +1 -1
- package/dist/{swapHorizontalMedium-Bp7rqwQ_.js → swapHorizontalMedium-B9nkEBPD.js} +1 -1
- package/dist/{swapHorizontalRoundedBold-fXXQeesr.js → swapHorizontalRoundedBold-DPMzz6nz.js} +1 -1
- package/dist/{swapVertical-lb6FRfr-.js → swapVertical-FqQP9GBP.js} +1 -1
- package/dist/{swaps-DXWgEjt_.js → swaps-BG9GOayX.js} +3 -3
- package/dist/{telegram-Cw3woU3F.js → telegram-BMY9Hs9Z.js} +1 -1
- package/dist/{three-dots-CrS1ZJoA.js → three-dots-DDKmexHU.js} +1 -1
- package/dist/{transactions-ClKYRDBc.js → transactions-C_GII6kW.js} +1 -1
- package/dist/{twitch-BTFS8sbh.js → twitch-x_s0neNg.js} +1 -1
- package/dist/{twitterIcon-BEey2zuH.js → twitterIcon-CKsSxEuJ.js} +1 -1
- package/dist/{ui-xSZiungl.js → ui-CZH-vf5h.js} +2 -2
- package/dist/{user-fcwj6TqA.js → user-CZfvQDJ_.js} +1 -1
- package/dist/{verify-BLatL5Dw.js → verify-Bnvbadnx.js} +1 -1
- package/dist/{verify-filled-DPYDyDVg.js → verify-filled-CnEopkW-.js} +1 -1
- package/dist/{w3m-modal-IpSIarQs.js → w3m-modal-DkI2TPJW.js} +2 -2
- package/dist/{wallet-Cgmznx42.js → wallet-B3oN4n4q.js} +1 -1
- package/dist/{wallet-placeholder-B7P5m3g1.js → wallet-placeholder-CI0oiAcd.js} +1 -1
- package/dist/{walletconnect-DPJfWPxF.js → walletconnect-D4vMcjqO.js} +1 -1
- package/dist/{warning-circle-yU7or6qZ.js → warning-circle-DjI8aRBs.js} +1 -1
- package/dist/{x-Cr3BPl_T.js → x-BgRWY62H.js} +1 -1
- package/dist/{x-mark-CZyZTZeg.js → x-mark-Cdqd-Hm4.js} +1 -1
- package/package.json +6 -1
- package/.github/workflows/code-quality.yml +0 -43
- package/.github/workflows/publish.yml +0 -64
- 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,
|
|
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
|
-
}
|