@multiversx/sdk-dapp-liquidity 1.1.0-alpha.2 → 1.1.0-alpha.21
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 +6 -1
- package/api/getTransactions.d.ts +8 -2
- package/api/getTransactions.js +23 -3
- package/api/getTransactions.mjs +23 -3
- package/api/tests/getChains.spec.js +2 -1
- package/api/tests/getChains.spec.mjs +2 -1
- package/api/tests/getTokens.spec.js +2 -2
- package/api/tests/getTokens.spec.mjs +2 -2
- package/api/tests/getTransactions.spec.js +79 -69
- package/api/tests/getTransactions.spec.mjs +79 -69
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/constants/index.mjs +1 -1
- package/dto/Chain.dto.d.ts +3 -1
- package/dto/ConfirmRate.dto.d.ts +1 -0
- package/dto/Token.dto.d.ts +7 -2
- package/index.js +44 -16
- package/index.mjs +14 -16
- package/package.json +10 -6
- package/reactjs/components/BridgeForm/BridgeForm.d.ts +3 -1
- package/reactjs/components/BridgeForm/BridgeForm.js +182 -87
- package/reactjs/components/BridgeForm/BridgeForm.mjs +153 -58
- package/reactjs/components/BridgeHistory/BridgeHistory.js +73 -26
- package/reactjs/components/BridgeHistory/BridgeHistory.mjs +68 -21
- package/reactjs/components/Connect/BridgeAccountDisplay.js +2 -5
- package/reactjs/components/Connect/BridgeAccountDisplay.mjs +2 -5
- package/reactjs/components/Connect/CustomConnectButton.js +2 -5
- package/reactjs/components/Connect/CustomConnectButton.mjs +1 -4
- package/reactjs/components/Connect/MvxConnectButton.d.ts +2 -4
- package/reactjs/components/Connect/MvxConnectButton.js +2 -2
- package/reactjs/components/Connect/MvxConnectButton.mjs +2 -2
- package/reactjs/components/Connect/SwitchChainButton.js +2 -6
- package/reactjs/components/Connect/SwitchChainButton.mjs +1 -5
- package/reactjs/components/CopyButton/CopyButton.js +2 -2
- package/reactjs/components/CopyButton/CopyButton.mjs +2 -2
- package/reactjs/components/DisplayAmount/components/AnimateNumber/AnimateNumber.js +5 -5
- package/reactjs/components/Error/Error.d.ts +6 -0
- package/reactjs/components/Error/Error.js +67 -0
- package/reactjs/components/Error/Error.mjs +66 -0
- package/reactjs/components/Error/index.d.ts +1 -0
- package/reactjs/components/Error/index.js +5 -0
- package/reactjs/components/Error/index.mjs +4 -0
- package/reactjs/components/TokenSelector/TokenSelector.d.ts +2 -1
- package/reactjs/components/TokenSelector/TokenSelector.js +17 -9
- package/reactjs/components/TokenSelector/TokenSelector.mjs +13 -5
- package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.d.ts +2 -1
- package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.js +7 -3
- package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.mjs +4 -0
- package/reactjs/components/TokenSelector/components/SelectContent.d.ts +2 -1
- package/reactjs/components/TokenSelector/components/SelectContent.js +12 -9
- package/reactjs/components/TokenSelector/components/SelectContent.mjs +4 -1
- package/reactjs/components/TokenSelector/components/TokenIcon.js +3 -3
- package/reactjs/components/TokenSelector/components/TokenItem.js +9 -9
- package/reactjs/components/TokenSelector/components/TokenItem.mjs +6 -6
- package/reactjs/components/base/MxCard/MxCard.js +2 -2
- package/reactjs/components/base/MxCircleLoader/MxCircleLoader.d.ts +4 -0
- package/reactjs/components/base/MxCircleLoader/MxCircleLoader.js +29 -0
- package/reactjs/components/base/MxCircleLoader/MxCircleLoader.mjs +28 -0
- package/reactjs/components/base/MxCircleLoader/index.d.ts +1 -0
- package/reactjs/components/base/MxCircleLoader/index.js +5 -0
- package/reactjs/components/base/MxCircleLoader/index.mjs +4 -0
- package/reactjs/components/base/MxLink/MxLink.js +2 -2
- package/reactjs/components/base/MxSearch/MxSearch.js +4 -4
- package/reactjs/components/base/MxSlideover/MxSlideover.js +4 -4
- package/reactjs/components/base/MxTooltip/MxTooltip.js +9 -9
- package/reactjs/components/base/MxTooltip/components/TooltipContainer/TooltipContainer.js +2 -2
- package/reactjs/components/index.d.ts +1 -0
- package/reactjs/components/index.js +2 -0
- package/reactjs/components/index.mjs +2 -0
- package/reactjs/context/Web3AppProvider.d.ts +3 -1
- package/reactjs/context/Web3AppProvider.js +7 -5
- package/reactjs/context/Web3AppProvider.mjs +4 -2
- package/reactjs/context/useWeb3App.js +2 -2
- package/reactjs/hooks/index.js +1 -1
- package/reactjs/hooks/index.mjs +1 -1
- package/reactjs/hooks/useAccount.js +1 -5
- package/reactjs/hooks/useAccount.mjs +1 -5
- package/reactjs/hooks/useBalances.d.ts +4 -4
- package/reactjs/hooks/useBalances.js +16 -1
- package/reactjs/hooks/useBalances.mjs +16 -1
- package/reactjs/hooks/useBridgeFormik.js +9 -16
- package/reactjs/hooks/useBridgeFormik.mjs +0 -7
- package/reactjs/hooks/useDebounce.js +3 -3
- package/reactjs/hooks/useFetchBridgeData.d.ts +14 -4
- package/reactjs/hooks/useFetchTokens.d.ts +14 -4
- package/reactjs/hooks/useFetchTokens.js +9 -9
- package/reactjs/hooks/useFetchTokens.mjs +2 -2
- package/reactjs/hooks/useFiatData.d.ts +7 -2
- package/reactjs/hooks/useFiatData.js +6 -6
- package/reactjs/hooks/useFiatData.mjs +1 -1
- package/reactjs/hooks/useGetChainId.js +3 -3
- package/reactjs/hooks/useGetChainId.mjs +1 -1
- package/reactjs/hooks/useResolveTokenChain.js +2 -2
- package/reactjs/hooks/useSendTransactions.js +2 -2
- package/reactjs/hooks/useSignTransaction.d.ts +93 -67
- package/reactjs/hooks/useSignTransaction.js +53 -4
- package/reactjs/hooks/useSignTransaction.mjs +53 -4
- package/reactjs/hooks/validation/useTestHasEnoughFunds.js +3 -3
- package/reactjs/hooks/validation/useTestIsConnected.js +2 -2
- package/reactjs/index.js +44 -16
- package/reactjs/index.mjs +14 -16
- package/reactjs/init/init.d.ts +220 -1
- package/reactjs/init/init.js +34 -10
- package/reactjs/init/init.mjs +31 -7
- package/reactjs/init/tests/init.spec.js +5 -6
- package/reactjs/init/tests/init.spec.mjs +5 -6
- package/reactjs/queries/index.d.ts +0 -1
- package/reactjs/queries/index.js +0 -2
- package/reactjs/queries/index.mjs +1 -3
- package/reactjs/queries/useGetEvmTokensBalances.query.d.ts +8 -3
- package/reactjs/queries/useGetEvmTokensBalances.query.js +15 -18
- package/reactjs/queries/useGetEvmTokensBalances.query.mjs +15 -18
- package/reactjs/queries/useGetHistory.query.d.ts +9 -1
- package/reactjs/queries/useGetHistory.query.js +23 -5
- package/reactjs/queries/useGetHistory.query.mjs +23 -5
- package/reactjs/queries/useGetMvxTokensBalances.query.d.ts +7 -2
- package/reactjs/queries/useGetMvxTokensBalances.query.js +2 -2
- package/reactjs/reexports.d.ts +2 -1
- package/reactjs/reexports.js +41 -13
- package/reactjs/reexports.mjs +11 -13
- package/reactjs/utils/getInitialTokens.d.ts +4 -1
- package/reactjs/utils/getInitialTokens.js +3 -3
- package/reactjs/utils/getInitialTokens.mjs +3 -3
- package/style.css +33 -1730
- package/types/chainType.d.ts +6 -0
- package/types/chainType.js +11 -0
- package/types/chainType.mjs +10 -0
- package/types/transaction.d.ts +28 -0
- package/types/utxo.d.ts +11 -0
- package/types/utxo.js +2 -0
- package/types/utxo.mjs +1 -0
- package/{useBalances-C_69CFoa.mjs → useBalances-Bom1mw1J.mjs} +101 -23
- package/{useBalances-C4YhEYxy.js → useBalances-gZTsFZHe.js} +102 -24
- package/index-BIVnypNe.mjs +0 -108
- package/index-Ben8n3bd.js +0 -58656
- package/index-CnKr4rL1.mjs +0 -91
- package/index-CnuruJNu.js +0 -329
- package/index-DsBh-EBw.js +0 -108
- package/index-iN9APQ6x.mjs +0 -58735
- package/modules/fiat/components/FiatForm/FiatForm.d.ts +0 -9
- package/modules/fiat/components/FiatForm/FiatForm.js +0 -314
- package/modules/fiat/components/FiatForm/FiatForm.mjs +0 -313
- package/modules/fiat/components/FiatForm/components/AmountInput/AmountInput.d.ts +0 -13
- package/modules/fiat/components/FiatForm/components/AmountInput/AmountInput.js +0 -117
- package/modules/fiat/components/FiatForm/components/AmountInput/AmountInput.mjs +0 -116
- package/modules/fiat/components/FiatForm/components/AmountInput/index.d.ts +0 -1
- package/modules/fiat/components/FiatForm/components/AmountInput/index.js +0 -5
- package/modules/fiat/components/FiatForm/components/AmountInput/index.mjs +0 -4
- package/modules/fiat/components/FiatForm/components/RateReloading/RateReloading.d.ts +0 -7
- package/modules/fiat/components/FiatForm/components/RateReloading/RateReloading.js +0 -74
- package/modules/fiat/components/FiatForm/components/RateReloading/RateReloading.mjs +0 -73
- package/modules/fiat/components/FiatForm/components/TokenSelector/TokenSelector.d.ts +0 -14
- package/modules/fiat/components/FiatForm/components/TokenSelector/TokenSelector.js +0 -94
- package/modules/fiat/components/FiatForm/components/TokenSelector/TokenSelector.mjs +0 -93
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContainer.d.ts +0 -7
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContainer.js +0 -82
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContainer.mjs +0 -81
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContent.d.ts +0 -7
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContent.js +0 -91
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContent.mjs +0 -90
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectedOption.d.ts +0 -5
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectedOption.js +0 -30
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectedOption.mjs +0 -29
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenIcon.d.ts +0 -8
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenIcon.js +0 -103
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenIcon.mjs +0 -102
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenItem.d.ts +0 -7
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenItem.js +0 -33
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenItem.mjs +0 -32
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenList.d.ts +0 -7
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenList.js +0 -21
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenList.mjs +0 -20
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenSymbol.d.ts +0 -9
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenSymbol.js +0 -26
- package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenSymbol.mjs +0 -25
- package/modules/fiat/components/FiatForm/components/TokenSelector/index.d.ts +0 -1
- package/modules/fiat/components/FiatForm/components/TokenSelector/index.js +0 -5
- package/modules/fiat/components/FiatForm/components/TokenSelector/index.mjs +0 -4
- package/modules/fiat/components/FiatForm/index.d.ts +0 -1
- package/modules/fiat/components/FiatForm/index.js +0 -5
- package/modules/fiat/components/FiatForm/index.mjs +0 -4
- package/modules/fiat/components/index.d.ts +0 -1
- package/modules/fiat/components/index.js +0 -5
- package/modules/fiat/components/index.mjs +0 -4
- package/modules/fiat/context/FiatProvider.d.ts +0 -8
- package/modules/fiat/context/FiatProvider.js +0 -24
- package/modules/fiat/context/FiatProvider.mjs +0 -23
- package/modules/fiat/context/queryClient.d.ts +0 -3
- package/modules/fiat/context/queryClient.js +0 -12
- package/modules/fiat/context/queryClient.mjs +0 -11
- package/modules/fiat/context/useFiat.d.ts +0 -1
- package/modules/fiat/context/useFiat.js +0 -13
- package/modules/fiat/context/useFiat.mjs +0 -12
- package/modules/fiat/hooks/index.d.ts +0 -2
- package/modules/fiat/hooks/index.js +0 -7
- package/modules/fiat/hooks/index.mjs +0 -6
- package/modules/fiat/hooks/useFiatData.d.ts +0 -7
- package/modules/fiat/hooks/useFiatData.js +0 -75
- package/modules/fiat/hooks/useFiatData.mjs +0 -74
- package/modules/fiat/hooks/validation/index.d.ts +0 -1
- package/modules/fiat/hooks/validation/index.js +0 -5
- package/modules/fiat/hooks/validation/index.mjs +0 -4
- package/modules/fiat/hooks/validation/useAmountSchema.d.ts +0 -2
- package/modules/fiat/hooks/validation/useAmountSchema.js +0 -27
- package/modules/fiat/hooks/validation/useAmountSchema.mjs +0 -9
- package/modules/fiat/index.d.ts +0 -8
- package/modules/fiat/index.js +0 -22
- package/modules/fiat/index.mjs +0 -21
- package/modules/fiat/init/index.d.ts +0 -2
- package/modules/fiat/init/index.js +0 -5
- package/modules/fiat/init/index.mjs +0 -4
- package/modules/fiat/init/init.d.ts +0 -22
- package/modules/fiat/init/init.js +0 -15
- package/modules/fiat/init/init.mjs +0 -14
- package/modules/fiat/queries/index.d.ts +0 -2
- package/modules/fiat/queries/index.js +0 -7
- package/modules/fiat/queries/index.mjs +0 -6
- package/modules/fiat/queries/useGetRate.mutation.d.ts +0 -6
- package/modules/fiat/queries/useGetRate.mutation.js +0 -20
- package/modules/fiat/queries/useGetRate.mutation.mjs +0 -19
- package/modules/fiat/queries/useGetTokens.query.d.ts +0 -5
- package/modules/fiat/queries/useGetTokens.query.js +0 -33
- package/modules/fiat/queries/useGetTokens.query.mjs +0 -32
- package/react-47kZTyAT.mjs +0 -51
- package/react-B_iI3-1z.mjs +0 -3133
- package/react-BomcNL1v.js +0 -254
- package/react-CqKlu0W0.js +0 -51
- package/react-R_xxu7fN.js +0 -3133
- package/react-cXurUY4Z.mjs +0 -254
- package/reactjs/queries/useGetTokens.query.d.ts +0 -3
- package/reactjs/queries/useGetTokens.query.js +0 -34
- package/reactjs/queries/useGetTokens.query.mjs +0 -33
- package/w3m-modal-Bhg44d6I.js +0 -356
- package/w3m-modal-Br2Ec3MM.mjs +0 -356
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
var ChainType = /* @__PURE__ */ ((ChainType2) => {
|
|
5
|
+
ChainType2["evm"] = "evm";
|
|
6
|
+
ChainType2["sol"] = "sol";
|
|
7
|
+
ChainType2["btc"] = "btc";
|
|
8
|
+
ChainType2["mvx"] = "mvx";
|
|
9
|
+
return ChainType2;
|
|
10
|
+
})(ChainType || {});
|
|
11
|
+
exports.ChainType = ChainType;
|
package/types/transaction.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { TransactionBase, Transaction as ViemTransaction } from 'viem/types/transaction';
|
|
2
2
|
|
|
3
|
+
export type ServerTransactionInstruction = {
|
|
4
|
+
keys: [
|
|
5
|
+
{
|
|
6
|
+
pubkey: string;
|
|
7
|
+
isSigner: boolean;
|
|
8
|
+
isWritable: boolean;
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
pubkey: string;
|
|
12
|
+
isSigner: boolean;
|
|
13
|
+
isWritable: boolean;
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
programId: string;
|
|
17
|
+
data: ArrayBuffer;
|
|
18
|
+
};
|
|
3
19
|
export type ServerTransaction = {
|
|
4
20
|
to: `0x${string}`;
|
|
5
21
|
data: `0x${string}`;
|
|
@@ -7,6 +23,18 @@ export type ServerTransaction = {
|
|
|
7
23
|
value: bigint;
|
|
8
24
|
account: string;
|
|
9
25
|
txHash: string;
|
|
26
|
+
signatures?: string[];
|
|
27
|
+
feePayer?: string;
|
|
28
|
+
instructions?: ServerTransactionInstruction[];
|
|
29
|
+
bitcoinParams?: {
|
|
30
|
+
psbt: string;
|
|
31
|
+
signInputs: {
|
|
32
|
+
address: string;
|
|
33
|
+
index: number;
|
|
34
|
+
sighashTypes: number[];
|
|
35
|
+
}[];
|
|
36
|
+
broadcast: boolean;
|
|
37
|
+
};
|
|
10
38
|
};
|
|
11
39
|
export type TransactionType = TransactionBase & {
|
|
12
40
|
account: `0x${string}`;
|
package/types/utxo.d.ts
ADDED
package/types/utxo.js
ADDED
package/types/utxo.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useAppKitAccount } from "@reown/appkit/react";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import { useMemo, useCallback } from "react";
|
|
5
|
+
import { getApiURL } from "./helpers/getApiURL.mjs";
|
|
6
|
+
import { useGetChainId } from "./reactjs/hooks/useGetChainId.mjs";
|
|
7
|
+
import { ChainType } from "./types/chainType.mjs";
|
|
2
8
|
import { useWeb3App } from "./reactjs/context/useWeb3App.mjs";
|
|
9
|
+
import "@tanstack/react-query";
|
|
10
|
+
import { useGetChainsQuery } from "./reactjs/queries/useGetChains.query.mjs";
|
|
11
|
+
import "yup";
|
|
12
|
+
import "@multiversx/sdk-dapp-utils/out/helpers/parseAmount";
|
|
13
|
+
import "./bignumber-CKZkoo0g.mjs";
|
|
14
|
+
import "wagmi";
|
|
15
|
+
import "formik";
|
|
16
|
+
import "./reactjs/constants/index.mjs";
|
|
17
|
+
import "@reown/appkit-adapter-solana/react";
|
|
3
18
|
import { weiUnits, ContractFunctionExecutionError, hexToString, trim, formatUnits } from "viem";
|
|
4
19
|
import { multicall as multicall$1, readContract as readContract$1, getBalance as getBalance$1 } from "viem/actions";
|
|
5
20
|
function getAction(client, actionFn, name) {
|
|
@@ -155,41 +170,104 @@ async function getTokenBalance(config, parameters) {
|
|
|
155
170
|
}
|
|
156
171
|
const useBalances = () => {
|
|
157
172
|
const { config } = useWeb3App();
|
|
173
|
+
const { address, isConnected } = useAppKitAccount();
|
|
174
|
+
const chainId = useGetChainId();
|
|
175
|
+
const { data: chains } = useGetChainsQuery();
|
|
176
|
+
const activeChain = useMemo(() => {
|
|
177
|
+
return chains == null ? void 0 : chains.find(
|
|
178
|
+
(chain) => chain.chainId.toString() === (chainId == null ? void 0 : chainId.toString())
|
|
179
|
+
);
|
|
180
|
+
}, [chainId, chains]);
|
|
181
|
+
const chainsMap = useMemo(() => {
|
|
182
|
+
return (chains ?? []).reduce(
|
|
183
|
+
(acc, chain) => {
|
|
184
|
+
acc[chain.chainId.toString()] = chain;
|
|
185
|
+
return acc;
|
|
186
|
+
},
|
|
187
|
+
{}
|
|
188
|
+
);
|
|
189
|
+
}, [chains]);
|
|
190
|
+
const getSolBalance = async (rpcUrl, addr) => {
|
|
191
|
+
const connection = new Connection(rpcUrl);
|
|
192
|
+
const publicKey = new PublicKey(addr);
|
|
193
|
+
const balance = await connection.getBalance(publicKey);
|
|
194
|
+
return BigInt(balance.toString());
|
|
195
|
+
};
|
|
196
|
+
const getBtcBalance = async () => {
|
|
197
|
+
const url = `${getApiURL()}/user/balance/${address}`;
|
|
198
|
+
try {
|
|
199
|
+
const { data } = await axios.get(url);
|
|
200
|
+
return BigInt(data.balance);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
throw new Error(`Error fetching BTC balance: ${error}`);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
158
205
|
const fetchBalances = useCallback(
|
|
159
|
-
async ({
|
|
160
|
-
address,
|
|
161
|
-
chainId,
|
|
162
|
-
tokenIdentifiers
|
|
163
|
-
}) => {
|
|
206
|
+
async ({ tokens }) => {
|
|
164
207
|
return await Promise.all(
|
|
165
|
-
|
|
208
|
+
tokens.map(async (token) => {
|
|
209
|
+
var _a;
|
|
210
|
+
if (!isConnected || !address || !token.chainId) {
|
|
211
|
+
return {
|
|
212
|
+
tokenId: token.address,
|
|
213
|
+
balance: "0"
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const chainType = (_a = chainsMap[token.chainId]) == null ? void 0 : _a.chainType;
|
|
217
|
+
console.log("chainType", {
|
|
218
|
+
chainType
|
|
219
|
+
});
|
|
166
220
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
221
|
+
let balance = BigInt(0);
|
|
222
|
+
switch (chainType) {
|
|
223
|
+
case ChainType.evm:
|
|
224
|
+
if ((activeChain == null ? void 0 : activeChain.chainType) !== ChainType.evm) {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
balance = (await getBalance(config, {
|
|
228
|
+
address,
|
|
229
|
+
chainId: Number(token.chainId),
|
|
230
|
+
// omit passing the token for fetching the native currency balance
|
|
231
|
+
token: token.isNative ? void 0 : token.address
|
|
232
|
+
})).value;
|
|
233
|
+
break;
|
|
234
|
+
case ChainType.sol:
|
|
235
|
+
if ((activeChain == null ? void 0 : activeChain.chainType) !== ChainType.sol) {
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
if (!(activeChain == null ? void 0 : activeChain.rpc)) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`RPC URL not found for chain ID: ${token.chainId}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
balance = await getSolBalance(activeChain == null ? void 0 : activeChain.rpc, address);
|
|
244
|
+
break;
|
|
245
|
+
case ChainType.btc:
|
|
246
|
+
if ((activeChain == null ? void 0 : activeChain.chainType) !== ChainType.btc) {
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
balance = await getBtcBalance();
|
|
250
|
+
break;
|
|
251
|
+
case ChainType.mvx:
|
|
252
|
+
break;
|
|
253
|
+
default:
|
|
254
|
+
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
255
|
+
}
|
|
174
256
|
return {
|
|
175
|
-
tokenId:
|
|
176
|
-
balance: balance.
|
|
257
|
+
tokenId: token.address,
|
|
258
|
+
balance: balance == null ? void 0 : balance.toString()
|
|
177
259
|
};
|
|
178
260
|
} catch (error) {
|
|
179
|
-
console.warn(
|
|
180
|
-
"Error fetching balance for: ",
|
|
181
|
-
tokenIdentifier,
|
|
182
|
-
error
|
|
183
|
-
);
|
|
261
|
+
console.warn("Error fetching balance for: ", token.address, error);
|
|
184
262
|
return {
|
|
185
|
-
tokenId:
|
|
263
|
+
tokenId: token.address,
|
|
186
264
|
balance: "0"
|
|
187
265
|
};
|
|
188
266
|
}
|
|
189
267
|
})
|
|
190
268
|
);
|
|
191
269
|
},
|
|
192
|
-
[config]
|
|
270
|
+
[config, isConnected, address, activeChain == null ? void 0 : activeChain.rpc]
|
|
193
271
|
);
|
|
194
272
|
return {
|
|
195
273
|
fetchBalances
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
const
|
|
3
|
+
const react = require("@reown/appkit/react");
|
|
4
|
+
const web3_js = require("@solana/web3.js");
|
|
5
|
+
const axios = require("axios");
|
|
6
|
+
const React = require("react");
|
|
7
|
+
const helpers_getApiURL = require("./helpers/getApiURL.js");
|
|
8
|
+
const reactjs_hooks_useGetChainId = require("./reactjs/hooks/useGetChainId.js");
|
|
9
|
+
const types_chainType = require("./types/chainType.js");
|
|
4
10
|
const reactjs_context_useWeb3App = require("./reactjs/context/useWeb3App.js");
|
|
11
|
+
require("@tanstack/react-query");
|
|
12
|
+
const reactjs_queries_useGetChains_query = require("./reactjs/queries/useGetChains.query.js");
|
|
13
|
+
require("yup");
|
|
14
|
+
require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount");
|
|
15
|
+
require("./bignumber-B8vjg9qn.js");
|
|
16
|
+
require("wagmi");
|
|
17
|
+
require("formik");
|
|
18
|
+
require("./reactjs/constants/index.js");
|
|
19
|
+
require("@reown/appkit-adapter-solana/react");
|
|
5
20
|
const viem = require("viem");
|
|
6
21
|
const actions = require("viem/actions");
|
|
7
22
|
function getAction(client, actionFn, name) {
|
|
@@ -157,41 +172,104 @@ async function getTokenBalance(config, parameters) {
|
|
|
157
172
|
}
|
|
158
173
|
const useBalances = () => {
|
|
159
174
|
const { config } = reactjs_context_useWeb3App.useWeb3App();
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
175
|
+
const { address, isConnected } = react.useAppKitAccount();
|
|
176
|
+
const chainId = reactjs_hooks_useGetChainId.useGetChainId();
|
|
177
|
+
const { data: chains } = reactjs_queries_useGetChains_query.useGetChainsQuery();
|
|
178
|
+
const activeChain = React.useMemo(() => {
|
|
179
|
+
return chains == null ? void 0 : chains.find(
|
|
180
|
+
(chain) => chain.chainId.toString() === (chainId == null ? void 0 : chainId.toString())
|
|
181
|
+
);
|
|
182
|
+
}, [chainId, chains]);
|
|
183
|
+
const chainsMap = React.useMemo(() => {
|
|
184
|
+
return (chains ?? []).reduce(
|
|
185
|
+
(acc, chain) => {
|
|
186
|
+
acc[chain.chainId.toString()] = chain;
|
|
187
|
+
return acc;
|
|
188
|
+
},
|
|
189
|
+
{}
|
|
190
|
+
);
|
|
191
|
+
}, [chains]);
|
|
192
|
+
const getSolBalance = async (rpcUrl, addr) => {
|
|
193
|
+
const connection = new web3_js.Connection(rpcUrl);
|
|
194
|
+
const publicKey = new web3_js.PublicKey(addr);
|
|
195
|
+
const balance = await connection.getBalance(publicKey);
|
|
196
|
+
return BigInt(balance.toString());
|
|
197
|
+
};
|
|
198
|
+
const getBtcBalance = async () => {
|
|
199
|
+
const url = `${helpers_getApiURL.getApiURL()}/user/balance/${address}`;
|
|
200
|
+
try {
|
|
201
|
+
const { data } = await axios.get(url);
|
|
202
|
+
return BigInt(data.balance);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw new Error(`Error fetching BTC balance: ${error}`);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const fetchBalances = React.useCallback(
|
|
208
|
+
async ({ tokens }) => {
|
|
166
209
|
return await Promise.all(
|
|
167
|
-
|
|
210
|
+
tokens.map(async (token) => {
|
|
211
|
+
var _a;
|
|
212
|
+
if (!isConnected || !address || !token.chainId) {
|
|
213
|
+
return {
|
|
214
|
+
tokenId: token.address,
|
|
215
|
+
balance: "0"
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
const chainType = (_a = chainsMap[token.chainId]) == null ? void 0 : _a.chainType;
|
|
219
|
+
console.log("chainType", {
|
|
220
|
+
chainType
|
|
221
|
+
});
|
|
168
222
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
223
|
+
let balance = BigInt(0);
|
|
224
|
+
switch (chainType) {
|
|
225
|
+
case types_chainType.ChainType.evm:
|
|
226
|
+
if ((activeChain == null ? void 0 : activeChain.chainType) !== types_chainType.ChainType.evm) {
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
balance = (await getBalance(config, {
|
|
230
|
+
address,
|
|
231
|
+
chainId: Number(token.chainId),
|
|
232
|
+
// omit passing the token for fetching the native currency balance
|
|
233
|
+
token: token.isNative ? void 0 : token.address
|
|
234
|
+
})).value;
|
|
235
|
+
break;
|
|
236
|
+
case types_chainType.ChainType.sol:
|
|
237
|
+
if ((activeChain == null ? void 0 : activeChain.chainType) !== types_chainType.ChainType.sol) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
if (!(activeChain == null ? void 0 : activeChain.rpc)) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`RPC URL not found for chain ID: ${token.chainId}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
balance = await getSolBalance(activeChain == null ? void 0 : activeChain.rpc, address);
|
|
246
|
+
break;
|
|
247
|
+
case types_chainType.ChainType.btc:
|
|
248
|
+
if ((activeChain == null ? void 0 : activeChain.chainType) !== types_chainType.ChainType.btc) {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
balance = await getBtcBalance();
|
|
252
|
+
break;
|
|
253
|
+
case types_chainType.ChainType.mvx:
|
|
254
|
+
break;
|
|
255
|
+
default:
|
|
256
|
+
throw new Error(`Unsupported chain type: ${chainType}`);
|
|
257
|
+
}
|
|
176
258
|
return {
|
|
177
|
-
tokenId:
|
|
178
|
-
balance: balance.
|
|
259
|
+
tokenId: token.address,
|
|
260
|
+
balance: balance == null ? void 0 : balance.toString()
|
|
179
261
|
};
|
|
180
262
|
} catch (error) {
|
|
181
|
-
console.warn(
|
|
182
|
-
"Error fetching balance for: ",
|
|
183
|
-
tokenIdentifier,
|
|
184
|
-
error
|
|
185
|
-
);
|
|
263
|
+
console.warn("Error fetching balance for: ", token.address, error);
|
|
186
264
|
return {
|
|
187
|
-
tokenId:
|
|
265
|
+
tokenId: token.address,
|
|
188
266
|
balance: "0"
|
|
189
267
|
};
|
|
190
268
|
}
|
|
191
269
|
})
|
|
192
270
|
);
|
|
193
271
|
},
|
|
194
|
-
[config]
|
|
272
|
+
[config, isConnected, address, activeChain == null ? void 0 : activeChain.rpc]
|
|
195
273
|
);
|
|
196
274
|
return {
|
|
197
275
|
fetchBalances
|
package/index-BIVnypNe.mjs
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useSyncExternalStore } from "react";
|
|
2
|
-
import { ay as ProviderUtil } from "./index-iN9APQ6x.mjs";
|
|
3
|
-
import { u as useSnapshot } from "./react-cXurUY4Z.mjs";
|
|
4
|
-
let modal = void 0;
|
|
5
|
-
function getAppKit(appKit) {
|
|
6
|
-
if (appKit) {
|
|
7
|
-
modal = appKit;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function useAppKitProvider(chainNamespace) {
|
|
11
|
-
const { providers, providerIds } = useSnapshot(ProviderUtil.state);
|
|
12
|
-
const walletProvider = providers[chainNamespace];
|
|
13
|
-
const walletProviderType = providerIds[chainNamespace];
|
|
14
|
-
return {
|
|
15
|
-
walletProvider,
|
|
16
|
-
walletProviderType
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function useAppKitTheme() {
|
|
20
|
-
if (!modal) {
|
|
21
|
-
throw new Error('Please call "createAppKit" before using "useAppKitTheme" hook');
|
|
22
|
-
}
|
|
23
|
-
function setThemeMode(themeMode2) {
|
|
24
|
-
if (themeMode2) {
|
|
25
|
-
modal == null ? void 0 : modal.setThemeMode(themeMode2);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function setThemeVariables(themeVariables2) {
|
|
29
|
-
if (themeVariables2) {
|
|
30
|
-
modal == null ? void 0 : modal.setThemeVariables(themeVariables2);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const [themeMode, setInternalThemeMode] = useState(modal.getThemeMode());
|
|
34
|
-
const [themeVariables, setInternalThemeVariables] = useState(modal.getThemeVariables());
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
const unsubscribe = modal == null ? void 0 : modal.subscribeTheme((state) => {
|
|
37
|
-
setInternalThemeMode(state.themeMode);
|
|
38
|
-
setInternalThemeVariables(state.themeVariables);
|
|
39
|
-
});
|
|
40
|
-
return () => {
|
|
41
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
42
|
-
};
|
|
43
|
-
}, []);
|
|
44
|
-
return {
|
|
45
|
-
themeMode,
|
|
46
|
-
themeVariables,
|
|
47
|
-
setThemeMode,
|
|
48
|
-
setThemeVariables
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function useAppKit() {
|
|
52
|
-
if (!modal) {
|
|
53
|
-
throw new Error('Please call "createAppKit" before using "useAppKit" hook');
|
|
54
|
-
}
|
|
55
|
-
async function open(options) {
|
|
56
|
-
await (modal == null ? void 0 : modal.open(options));
|
|
57
|
-
}
|
|
58
|
-
async function close() {
|
|
59
|
-
await (modal == null ? void 0 : modal.close());
|
|
60
|
-
}
|
|
61
|
-
return { open, close };
|
|
62
|
-
}
|
|
63
|
-
function useWalletInfo() {
|
|
64
|
-
if (!modal) {
|
|
65
|
-
throw new Error('Please call "createAppKit" before using "useWalletInfo" hook');
|
|
66
|
-
}
|
|
67
|
-
const walletInfo = useSyncExternalStore(modal.subscribeWalletInfo, modal.getWalletInfo, modal.getWalletInfo);
|
|
68
|
-
return { walletInfo };
|
|
69
|
-
}
|
|
70
|
-
function useAppKitState() {
|
|
71
|
-
if (!modal) {
|
|
72
|
-
throw new Error('Please call "createAppKit" before using "useAppKitState" hook');
|
|
73
|
-
}
|
|
74
|
-
const [state, setState] = useState(modal.getState());
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
const unsubscribe = modal == null ? void 0 : modal.subscribeState((newState) => {
|
|
77
|
-
setState({ ...newState });
|
|
78
|
-
});
|
|
79
|
-
return () => {
|
|
80
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
81
|
-
};
|
|
82
|
-
}, []);
|
|
83
|
-
return state;
|
|
84
|
-
}
|
|
85
|
-
function useAppKitEvents() {
|
|
86
|
-
if (!modal) {
|
|
87
|
-
throw new Error('Please call "createAppKit" before using "useAppKitEvents" hook');
|
|
88
|
-
}
|
|
89
|
-
const [event, setEvents] = useState(modal.getEvent());
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
const unsubscribe = modal == null ? void 0 : modal.subscribeEvents((newEvent) => {
|
|
92
|
-
setEvents({ ...newEvent });
|
|
93
|
-
});
|
|
94
|
-
return () => {
|
|
95
|
-
unsubscribe == null ? void 0 : unsubscribe();
|
|
96
|
-
};
|
|
97
|
-
}, []);
|
|
98
|
-
return event;
|
|
99
|
-
}
|
|
100
|
-
export {
|
|
101
|
-
useAppKitEvents as a,
|
|
102
|
-
useAppKitState as b,
|
|
103
|
-
useAppKitTheme as c,
|
|
104
|
-
useWalletInfo as d,
|
|
105
|
-
useAppKitProvider as e,
|
|
106
|
-
getAppKit as g,
|
|
107
|
-
useAppKit as u
|
|
108
|
-
};
|