astra-modal-test 1.0.5 → 1.0.7
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/.github/workflows/code-quality.yml +43 -0
- package/.github/workflows/publish.yml +64 -0
- package/README.md +204 -0
- package/dist/SwapController-CsNqEWIM.js +447 -0
- package/dist/add-Dm_oSEbv.js +19 -0
- package/dist/all-wallets-DfLlzQJ3.js +10 -0
- package/dist/app-store-BMdJkp6P.js +21 -0
- package/dist/apple-BetlVMKw.js +22 -0
- package/dist/arrow-bottom-BddPptxy.js +12 -0
- package/dist/arrow-bottom-circle-CvdJJniv.js +15 -0
- package/dist/arrow-left-Bbq-z1nQ.js +12 -0
- package/dist/arrow-right-Bu4_SVLC.js +12 -0
- package/dist/arrow-top-CynlXB-M.js +12 -0
- package/dist/astra-sdk.es.js +4 -4
- package/dist/bank-B9QscNnS.js +18 -0
- package/dist/bin-v-tshf8_.js +8 -0
- package/dist/bitcoin-C01gkYyN.js +17 -0
- package/dist/browser-9uNaCY31.js +18 -0
- package/dist/card-hKR9lRzU.js +18 -0
- package/dist/{ccip-oZOrZYR9.js → ccip-CUCziAPw.js} +52 -49
- package/dist/checkmark-D1M40aM5.js +15 -0
- package/dist/checkmark-bold-1_UGl24m.js +12 -0
- package/dist/chevron-bottom-BleoRNRL.js +12 -0
- package/dist/chevron-left-C9JMU-3B.js +12 -0
- package/dist/chevron-right-Daue4WBx.js +12 -0
- package/dist/chevron-top-yuXekbUC.js +12 -0
- package/dist/chrome-store-BsUFRR7F.js +65 -0
- package/dist/circle-BCxdhM5X.js +8 -0
- package/dist/clock-7a-DWZQa.js +12 -0
- package/dist/close-DMQYuJ0z.js +12 -0
- package/dist/clsx.m-DCYaa4RU.js +20 -0
- package/dist/coinPlaceholder-DjQ-HnSH.js +12 -0
- package/dist/compass-AMecXNVm.js +12 -0
- package/dist/copy-CgIPGYbU.js +19 -0
- package/dist/cursor-DpYbTNcO.js +7 -0
- package/dist/cursor-transparent-C8iPJkn8.js +16 -0
- package/dist/desktop-BWVQVGng.js +13 -0
- package/dist/disconnect-C6IQRrtF.js +12 -0
- package/dist/discord-gH3i-QsC.js +21 -0
- package/dist/email-BxYwJC5T.js +10 -0
- package/dist/embedded-wallet-DCcVNgkc.js +464 -0
- package/dist/ethereum-CGWsmZaC.js +14 -0
- package/dist/etherscan-D4EFsAJ4.js +10 -0
- package/dist/exclamation-triangle-DNwQ1Xq6.js +8 -0
- package/dist/extension-DxQPsN2z.js +12 -0
- package/dist/external-link-BeEzrdgR.js +12 -0
- package/dist/facebook-B2Ix8_d3.js +30 -0
- package/dist/farcaster-BB83p8dC.js +16 -0
- package/dist/filters-PzdIomB1.js +12 -0
- package/dist/github-gcp1rxX0.js +22 -0
- package/dist/google-Qv9lTZcz.js +22 -0
- package/dist/help-circle-BLXTMjzX.js +16 -0
- package/dist/id-BHg2CRhj.js +16 -0
- package/dist/image-DWi1V30x.js +8 -0
- package/dist/index-4lbsZ6RQ.js +33 -0
- package/dist/index-64U3D9_n.js +21034 -0
- package/dist/index-CRU49I0g.js +15911 -0
- package/dist/index-ChxXyuZj.js +572 -0
- package/dist/index-ClS956E1.js +74511 -0
- package/dist/index-Cs4fWw01.js +386 -0
- package/dist/index-DfWqgW4h.js +709 -0
- package/dist/index-VYNI76FM.js +315 -0
- package/dist/index-qfkTLN90.js +10785 -0
- package/dist/index-r2ztgVN2.js +1060 -0
- package/dist/index-wvh7Yd5J.js +70 -0
- package/dist/info-Bl5tmiBJ.js +7 -0
- package/dist/info-circle-D2uYywg-.js +16 -0
- package/dist/lightbulb-HvXH2AVF.js +7 -0
- package/dist/mail-DXOPfnog.js +12 -0
- package/dist/mobile-Dd0Gj4vZ.js +13 -0
- package/dist/more-DYcnClbB.js +15 -0
- package/dist/network-placeholder-CfRZGQfi.js +18 -0
- package/dist/nftPlaceholder-DHmFkY55.js +12 -0
- package/dist/off-CG2Y30qN.js +8 -0
- package/dist/onramp-DoAMTeNm.js +917 -0
- package/dist/play-store-B5EYBQto.js +36 -0
- package/dist/plus-DPo25_zL.js +17 -0
- package/dist/qr-code-BRTO19PL.js +10 -0
- package/dist/receive-BvclNdV_.js +179 -0
- package/dist/recycle-horizontal-ng_b2eJV.js +13 -0
- package/dist/refresh-3kiwRV0w.js +12 -0
- package/dist/reown-logo-_9cuIfJD.js +16 -0
- package/dist/search-CoJvIxpi.js +12 -0
- package/dist/secp256k1-wZyK2iIX.js +1257 -0
- package/dist/send-BVKGSR-Z.js +19 -0
- package/dist/send-Bkj5YtHe.js +1039 -0
- package/dist/socials-DL42HlL5.js +589 -0
- package/dist/solana-BjP-_Ioa.js +17 -0
- package/dist/swapHorizontal-Do3uBbum.js +12 -0
- package/dist/swapHorizontalBold-D7N75BE-.js +12 -0
- package/dist/swapHorizontalMedium-BahEVO2x.js +20 -0
- package/dist/swapHorizontalRoundedBold-D6Hoi132.js +12 -0
- package/dist/swapVertical-P-fnrADh.js +12 -0
- package/dist/swaps-DZgbVJZ2.js +1713 -0
- package/dist/telegram-DmaL2iB8.js +20 -0
- package/dist/three-dots-oXyAsUA6.js +9 -0
- package/dist/transactions-BjB5yZN7.js +35 -0
- package/dist/twitch-0UGrMr2K.js +22 -0
- package/dist/twitterIcon-B97KAbaJ.js +10 -0
- package/dist/ui-r6nnVhBA.js +812 -0
- package/dist/user-BG1yp56Q.js +7 -0
- package/dist/verify-CgzkMSuV.js +12 -0
- package/dist/verify-filled-D-TRpWtN.js +12 -0
- package/dist/w3m-modal-Drsibcs0.js +1041 -0
- package/dist/wallet-CAHsZdfj.js +12 -0
- package/dist/wallet-placeholder-agbbreqw.js +18 -0
- package/dist/walletconnect-Yd8iXqY9.js +36 -0
- package/dist/warning-circle-C0hqC6h_.js +16 -0
- package/dist/x-mark-D9_ai2sI.js +7 -0
- package/dist/x-z6v1Jegg.js +16 -0
- package/eslint.config.mjs +1 -1
- package/package.json +14 -13
- package/src/apis/lspApi.js +47 -24
- 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/botanix.png +0 -0
- package/src/assets/network/bsc.svg +13 -0
- package/src/assets/pay.png +0 -0
- package/src/assets/tokens/usdc.png +0 -0
- package/src/assets/tokens/usdt.png +0 -0
- package/src/comps/AstraImage.jsx +17 -3
- package/src/comps/AstraModal.jsx +22 -16
- package/src/comps/AstraModalLogo.jsx +9 -9
- package/src/comps/AstraNetwork.jsx +174 -45
- package/src/comps/CheckErc20Button.jsx +1 -1
- package/src/comps/CommonStyle.jsx +4 -0
- package/src/comps/ConnectButton.jsx +16 -33
- package/src/comps/ResultModal.jsx +45 -39
- package/src/comps/ToLightning.jsx +207 -80
- package/src/comps/ToToken.jsx +278 -217
- package/src/constants/index.js +20 -4
- package/src/hooks/useContract.js +164 -125
- package/src/hooks/useGetMinAndMax.js +48 -0
- package/src/hooks/useLspApi.js +56 -39
- package/src/hooks/useParseInvoice.js +82 -72
- package/src/index.jsx +43 -10
- package/src/main.jsx +36 -5
- package/src/utils/index.js +136 -24
- package/vite.config.js +7 -1
- package/dist/astra-sdk.umd.js +0 -12578
- package/dist/hooks.module-BBZfodGH.js +0 -506
- package/dist/index-BKKAfRrw.js +0 -87520
- package/dist/index-C2MAIRET.js +0 -2929
- package/dist/index-CsRxokSv.js +0 -445
- package/dist/index-DQ6iiHxJ.js +0 -13720
- package/dist/index-SJhlkSif.js +0 -133
- package/dist/w3m-modal-CYJpmgnf.js +0 -267
- package/src/constants/contracts/abi/bridge.js +0 -1281
- package/src/constants/contracts/abi/index.js +0 -3
- package/src/constants/contracts/abi/usdt.js +0 -130
- package/src/constants/contracts/abi/watcher.js +0 -437
- package/src/constants/contracts/index.js +0 -37
package/src/index.jsx
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
import { ConfigProvider, theme } from "antd";
|
|
3
3
|
import { createAppKit } from "@reown/appkit/react";
|
|
4
4
|
import { WagmiProvider } from "wagmi";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
sepolia,
|
|
7
|
+
baseSepolia,
|
|
8
|
+
base,
|
|
9
|
+
bsc,
|
|
10
|
+
botanixTestnet,
|
|
11
|
+
} from "@reown/appkit/networks";
|
|
6
12
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
7
13
|
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
|
|
8
14
|
import AstraDialog from "./comps/AstraModal.jsx";
|
|
@@ -11,13 +17,20 @@ import { themeConfig } from "./theme.js";
|
|
|
11
17
|
import { MODAL_DISPLAY_TYPE } from "./constants/index.js";
|
|
12
18
|
import IconEthNetwork from "./assets/network/eth.png";
|
|
13
19
|
import IconBaseNetwork from "./assets/network/base.png";
|
|
14
|
-
import
|
|
20
|
+
import IconBotanixNetwork from "./assets/network/botanix.png";
|
|
21
|
+
import { useLayoutEffect, useMemo, useRef } from "react";
|
|
22
|
+
|
|
15
23
|
const defaultMetadata = {
|
|
16
24
|
name: "Lnfi",
|
|
17
25
|
description: "Lnfi",
|
|
18
|
-
url: "https://
|
|
26
|
+
url: "https://www.lnfi.network/", // origin must match your domain & subdomain
|
|
19
27
|
icons: ["https://avatars.githubusercontent.com/u/37784886"],
|
|
20
28
|
};
|
|
29
|
+
|
|
30
|
+
const API_URL_MAP = {
|
|
31
|
+
development: "https://devof-astralsp.unift.xyz/",
|
|
32
|
+
production: "https://api.astra-labs.io/",
|
|
33
|
+
};
|
|
21
34
|
// 3. Set the networks
|
|
22
35
|
|
|
23
36
|
let wagmiAdapter = null;
|
|
@@ -26,19 +39,36 @@ export default function AstraProvider({
|
|
|
26
39
|
projectId,
|
|
27
40
|
metadata,
|
|
28
41
|
adapter,
|
|
42
|
+
env = "production",
|
|
43
|
+
apiUrl = "https://api.astra-labs.io/",
|
|
29
44
|
children,
|
|
30
45
|
}) {
|
|
31
|
-
const networks =
|
|
46
|
+
const networks = useMemo(() => {
|
|
47
|
+
return env === "development" ? [sepolia, baseSepolia] : [bsc, base];
|
|
48
|
+
}, [env]);
|
|
49
|
+
// const transports = useMemo(()=>{
|
|
50
|
+
// return env==='development'? {
|
|
51
|
+
// [sepolia.id]: http(`https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
52
|
+
// [baseSepolia.id]: http(`https://base-sepolia.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
53
|
+
// }:{
|
|
54
|
+
// [bsc.id]: http(`https://bnb-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
55
|
+
// [base.id]: http(`https://base-mainnet.g.alchemy.com/v2/${ALCHEMY_KEY}`),
|
|
56
|
+
// }
|
|
57
|
+
// },[env])
|
|
58
|
+
const { setAstrApiUrl } = useStore();
|
|
32
59
|
const queryClient = new QueryClient();
|
|
33
|
-
const appKit = useRef(null)
|
|
60
|
+
const appKit = useRef(null);
|
|
34
61
|
if (!wagmiAdapter) {
|
|
35
62
|
wagmiAdapter = adapter
|
|
36
63
|
? adapter
|
|
37
64
|
: new WagmiAdapter({
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
65
|
+
networks,
|
|
66
|
+
// transports: transports,
|
|
67
|
+
projectId: projectId,
|
|
68
|
+
pollingInterval: 8_000,
|
|
69
|
+
cacheTime: 6_000,
|
|
70
|
+
ssr: false,
|
|
71
|
+
});
|
|
42
72
|
}
|
|
43
73
|
useLayoutEffect(() => {
|
|
44
74
|
if (!appKit.current) {
|
|
@@ -48,6 +78,7 @@ export default function AstraProvider({
|
|
|
48
78
|
chainImages: {
|
|
49
79
|
[sepolia.id]: IconEthNetwork,
|
|
50
80
|
[baseSepolia.id]: IconBaseNetwork,
|
|
81
|
+
[botanixTestnet.id]: IconBotanixNetwork,
|
|
51
82
|
},
|
|
52
83
|
debug: false,
|
|
53
84
|
themeMode: "dark",
|
|
@@ -67,7 +98,9 @@ export default function AstraProvider({
|
|
|
67
98
|
},
|
|
68
99
|
});
|
|
69
100
|
}
|
|
70
|
-
|
|
101
|
+
const finalApiUrl = API_URL_MAP[env] || apiUrl;
|
|
102
|
+
setAstrApiUrl(finalApiUrl);
|
|
103
|
+
}, [apiUrl, env, metadata, networks, projectId, setAstrApiUrl]);
|
|
71
104
|
|
|
72
105
|
return (
|
|
73
106
|
<>
|
package/src/main.jsx
CHANGED
|
@@ -9,17 +9,48 @@ import AstraProvider, {
|
|
|
9
9
|
astraReceive,
|
|
10
10
|
} from "./index.jsx";
|
|
11
11
|
|
|
12
|
+
const projectId = "a9bfbd4c2e362787a57afa3c91acaf90";
|
|
13
|
+
|
|
14
|
+
const env = "development";
|
|
15
|
+
|
|
12
16
|
createRoot(document.getElementById("root")).render(
|
|
13
17
|
<StrictMode>
|
|
14
|
-
<AstraProvider projectId=
|
|
15
|
-
<AstraModal
|
|
18
|
+
<AstraProvider projectId={projectId} env={env}>
|
|
19
|
+
<AstraModal />
|
|
20
|
+
<Button
|
|
21
|
+
onClick={() => {
|
|
22
|
+
astraReceive({
|
|
23
|
+
assetId:
|
|
24
|
+
"f7ac99f2c068f1157c787012f50cb043437505c309c6d8685e135cd8481b1e9d",
|
|
25
|
+
invoice:
|
|
26
|
+
"lnbcrt100u1p5gw8avpp5jnqgevzt4dzq4q2f74nfe2ms5fzmuyzj3svre4zlj0dsxyq0cknsdysf3hxv6fmv9ehxet5f9zr5e3hv93njwtxxf3nqd3cvccnzdfhvvmnsdesxyexvdfsvd3rqdpnxsenwdfsx43nxvpevvmxgwpk8q6k2vfnx43kgwp58qckyvt989jrkctdda6kuap6xycrqvp6cqzzsxqrrssrzjqfs8kgq4q0fel6yxesfkxl6de7j9af4g84437k4ceeuquy2h4ut33a03y23dq7ey95qqqqlgqqqqqqgq2qsp56au86fneqmqf97425g3axgdcgd6ew0m92u45qyv9s4qvl2s44t3s9qxpqysgqkzk2e8psallgx37k7elw0lyglgs2px76xcf6fnv58ajq56yxtztr7p8ux8xtr6km254pqv687awm8lx5m3ezjjgx4savjq338wcj2cqqckrdtt",
|
|
27
|
+
});
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
emvToLightning
|
|
31
|
+
</Button>
|
|
32
|
+
<Button
|
|
33
|
+
onClick={() => {
|
|
34
|
+
astraSend({
|
|
35
|
+
assetId:
|
|
36
|
+
"f7ac99f2c068f1157c787012f50cb043437505c309c6d8685e135cd8481b1e9d",
|
|
37
|
+
amount: 999,
|
|
38
|
+
});
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
lightningToEvm
|
|
42
|
+
</Button>
|
|
43
|
+
</AstraProvider>
|
|
44
|
+
{/* <AstraProvider projectId="92461524d3cfcb3d78b38b5dbd6a6ce3" apiUrl="https://devof-astralsp.unift.xyz/" env="development">
|
|
45
|
+
|
|
46
|
+
<AstraModal />
|
|
16
47
|
<Button
|
|
17
48
|
onClick={() => {
|
|
18
49
|
astraReceive({
|
|
19
50
|
assetId:
|
|
20
51
|
"5bd129d549bd68cad64f2c2db141732a523e4546a49662c390e8c14294aa7e84",
|
|
21
52
|
invoice:
|
|
22
|
-
"
|
|
53
|
+
"lnbcrt10u1pncsl97pp5d36zwsnr8zz4njssl8nzrf3uunjgayx0mtme8w9ahtk5a3lng37qdy0f3hxv6fmv9ehxet5f9zr5dtzvscnywtyx56rjcnyxcuxxctyxc6xvvnrxfjxyvf5xymnxvnpx5erxef5x56rvcf58ymrvvnrxvunqefcvvcngv3ex3skzdm98q6rkctdda6kuap6xycrqwscqzzsxqrrssrzjqg3zz9zaagxqxan9fqzr6k7yvf900uf26m0z7c2g0rf55raupqclpa040f0l30n4s5qqqqlgqqqqqqgq2qsp55qzcz8qgfhke67954whzlna58zlsc9s27g43jm32w7l09yr8n5gs9qxpqysgqx2aceldh9plumffk65j23rhuy6ers24p36uf9r9utc34rl85fw387xhtn6x3te50pvpkq3kyq6n4z55dezuz4u2txgm8cf6hnahdhpcp07k2cw",
|
|
23
54
|
});
|
|
24
55
|
}}
|
|
25
56
|
>
|
|
@@ -30,12 +61,12 @@ createRoot(document.getElementById("root")).render(
|
|
|
30
61
|
astraSend({
|
|
31
62
|
assetId:
|
|
32
63
|
"5bd129d549bd68cad64f2c2db141732a523e4546a49662c390e8c14294aa7e84",
|
|
33
|
-
amount:
|
|
64
|
+
amount: 10,
|
|
34
65
|
});
|
|
35
66
|
}}
|
|
36
67
|
>
|
|
37
68
|
Send
|
|
38
69
|
</Button>
|
|
39
|
-
</AstraProvider>
|
|
70
|
+
</AstraProvider> */}
|
|
40
71
|
</StrictMode>
|
|
41
72
|
);
|
package/src/utils/index.js
CHANGED
|
@@ -1,36 +1,148 @@
|
|
|
1
1
|
import Decimal from "decimal.js";
|
|
2
|
-
|
|
2
|
+
import { BaseError as BaseViemError, stringToHex } from "viem";
|
|
3
|
+
import { sha256 } from "viem/utils";
|
|
4
|
+
import { getAssetPayReq } from "../apis/lspApi";
|
|
5
|
+
/* export const msatsToTprAsset = async (msats, asset_id) => {
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch(
|
|
8
|
+
`https://bridge-oracle.ln.exchange/napi/price/getOne?transactionType=1&subjectAssetId=${asset_id}&paymentAssetId=0000000000000000000000000000000000000000000000000000000000000000`
|
|
9
|
+
);
|
|
10
|
+
const ret = await response.json();
|
|
3
11
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
`https://oracle.ln.exchange/napi/price/getOne?transactionType=1&subjectAssetId=${asset_id}&paymentAssetId=0000000000000000000000000000000000000000000000000000000000000000`,
|
|
7
|
-
);
|
|
8
|
-
const ret = await response.json();
|
|
12
|
+
const coefficient = ret?.ok?.assetRates?.subjectAssetRate?.coefficient;
|
|
13
|
+
const scale = ret?.ok?.assetRates?.subjectAssetRate?.scale;
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
const scale = ret?.ok?.assetRates?.subjectAssetRate?.scale;
|
|
15
|
+
//const BTC_TO_USDT_RATE = new Decimal(coefficient).div(10 ** (scale + 8 + 3)).toNumber();
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
const priceOneUnit = new Decimal(coefficient).div(10 ** scale);
|
|
18
|
+
const satToUSDTValue = new Decimal(msats)
|
|
19
|
+
.div(10 ** (8 + 3))
|
|
20
|
+
.mul(priceOneUnit)
|
|
21
|
+
.toFixed(0);
|
|
14
22
|
|
|
15
|
-
|
|
16
|
-
|
|
23
|
+
return satToUSDTValue;
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(e.message);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
}; */
|
|
17
29
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
export const formatAssetByDecimal = (value, decimal) => {
|
|
31
|
+
return new Decimal(value).div(10 ** decimal).toFixed(decimal);
|
|
32
|
+
};
|
|
33
|
+
export function numberWithCommas(x) {
|
|
34
|
+
if (!x && x != 0) {
|
|
35
|
+
return "0";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var parts = x.toString().split(".");
|
|
39
|
+
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
40
|
+
return parts.join(".");
|
|
41
|
+
}
|
|
42
|
+
export function sleep(time = 1000) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
resolve(true);
|
|
46
|
+
}, time);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
export const getParsedError = (e) => {
|
|
50
|
+
let message = e.message ?? "An unknown error occurred";
|
|
51
|
+
if (e instanceof BaseViemError) {
|
|
52
|
+
if (e.details) {
|
|
53
|
+
message = e.details;
|
|
54
|
+
} else if (e.shortMessage) {
|
|
55
|
+
message = e.shortMessage;
|
|
56
|
+
const cause = e.cause;
|
|
57
|
+
// if its not generic error, append custom error name and its args to message
|
|
58
|
+
if (cause?.data && cause.data?.abiItem?.name !== "Error") {
|
|
59
|
+
const customErrorArgs = cause.data.args?.toString() ?? "";
|
|
60
|
+
message = `${message.replace(
|
|
61
|
+
/reverted\.$/,
|
|
62
|
+
"reverted with following reason:"
|
|
63
|
+
)}\n${cause.data.errorName}(${customErrorArgs})`;
|
|
64
|
+
}
|
|
65
|
+
} else if (e.message) {
|
|
66
|
+
message = e.message;
|
|
67
|
+
} else if (e.name) {
|
|
68
|
+
message = e.name;
|
|
22
69
|
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return message;
|
|
23
73
|
};
|
|
24
74
|
|
|
25
|
-
export const
|
|
26
|
-
|
|
75
|
+
export const toBytes32 = (value) => {
|
|
76
|
+
const inputValue = value.startsWith("0x")
|
|
77
|
+
? value
|
|
78
|
+
: /^[0-9a-fA-F]+$/.test(value)
|
|
79
|
+
? "0x" + value
|
|
80
|
+
: value;
|
|
81
|
+
|
|
82
|
+
const dataToHash = /^0x[0-9a-fA-F]+$/.test(inputValue)
|
|
83
|
+
? inputValue
|
|
84
|
+
: stringToHex(inputValue);
|
|
85
|
+
|
|
86
|
+
const hash = sha256(dataToHash);
|
|
87
|
+
|
|
88
|
+
return hash;
|
|
89
|
+
};
|
|
90
|
+
export const invoiceToAssetInfo = async ({ payReq, assetId }) => {
|
|
91
|
+
const ret = await getAssetPayReq({ payReq: payReq, assetId: assetId });
|
|
92
|
+
const { decimal } = ret.data;
|
|
93
|
+
|
|
94
|
+
const decodedInvoice = window.lightningPayReq.decode(payReq);
|
|
95
|
+
const description = decodedInvoice?.tags.find(
|
|
96
|
+
(tag) => tag.tagName === "description"
|
|
97
|
+
)?.data;
|
|
98
|
+
const extractInfo = extractAssetInfo(description);
|
|
99
|
+
return { amount: extractInfo.amount, assetId: assetId, decimal: decimal };
|
|
100
|
+
};
|
|
101
|
+
export function balanceToFixed(balance, decimals) {
|
|
102
|
+
const fixedBalance = balance
|
|
103
|
+
? new Decimal(balance)
|
|
104
|
+
.div(10 ** decimals)
|
|
105
|
+
.toFixed(decimals, Decimal.ROUND_DOWN)
|
|
106
|
+
.toString()
|
|
107
|
+
: 0;
|
|
108
|
+
return fixedBalance;
|
|
27
109
|
}
|
|
28
|
-
export function
|
|
29
|
-
|
|
30
|
-
|
|
110
|
+
export function extractAssetInfo(inputString) {
|
|
111
|
+
const result = {
|
|
112
|
+
assetID: null,
|
|
113
|
+
amount: null,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (!inputString) {
|
|
117
|
+
return result; // Handle empty/null input
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// --- Extract assetID ---
|
|
121
|
+
// Regex looks for "assetID:" followed by capturing non-semicolon characters
|
|
122
|
+
const assetIDMatch = inputString.match(/assetID:([^;]+)/);
|
|
123
|
+
if (assetIDMatch && assetIDMatch[1]) {
|
|
124
|
+
// Get the captured value (group 1)
|
|
125
|
+
let value = assetIDMatch[1].trim();
|
|
126
|
+
// Remove potential trailing colon
|
|
127
|
+
if (value.endsWith(":")) {
|
|
128
|
+
value = value.slice(0, -1);
|
|
31
129
|
}
|
|
130
|
+
result.assetID = value;
|
|
131
|
+
}
|
|
32
132
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
133
|
+
// --- Extract amount ---
|
|
134
|
+
// Regex looks for "amount:" followed by capturing non-semicolon characters
|
|
135
|
+
const amountMatch = inputString.match(/amount:([^;]+)/);
|
|
136
|
+
if (amountMatch && amountMatch[1]) {
|
|
137
|
+
// Get the captured value (group 1)
|
|
138
|
+
let value = amountMatch[1].trim();
|
|
139
|
+
// Remove potential trailing colon
|
|
140
|
+
if (value.endsWith(":")) {
|
|
141
|
+
value = value.slice(0, -1);
|
|
142
|
+
}
|
|
143
|
+
result.amount = value;
|
|
144
|
+
// Optional number conversion can be done here
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return result;
|
|
148
|
+
}
|
package/vite.config.js
CHANGED
|
@@ -9,10 +9,15 @@ export default defineConfig({
|
|
|
9
9
|
entry: 'src/index.jsx',
|
|
10
10
|
name: 'astra-sdk',
|
|
11
11
|
fileName: (format) => `astra-sdk.${format}.js`,
|
|
12
|
+
formats: ['es']
|
|
12
13
|
},
|
|
13
14
|
rollupOptions: {
|
|
14
15
|
external: ['react', 'react-dom', 'antd', 'ahooks', 'axios', 'decimal.js', '@ant-design/icons'],
|
|
15
16
|
output: {
|
|
17
|
+
exports: "named",
|
|
18
|
+
format: 'esm',
|
|
19
|
+
preserveModules: false,
|
|
20
|
+
inlineDynamicImports: false,
|
|
16
21
|
globals: {
|
|
17
22
|
react: 'React',
|
|
18
23
|
'react-dom': 'ReactDOM',
|
|
@@ -21,7 +26,8 @@ export default defineConfig({
|
|
|
21
26
|
'decimal.js': 'Decimal',
|
|
22
27
|
ahooks: 'ahooks',
|
|
23
28
|
axios: 'axios',
|
|
24
|
-
},
|
|
29
|
+
},
|
|
30
|
+
|
|
25
31
|
},
|
|
26
32
|
},
|
|
27
33
|
},
|