@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.
Files changed (234) hide show
  1. package/README.md +6 -1
  2. package/api/getTransactions.d.ts +8 -2
  3. package/api/getTransactions.js +23 -3
  4. package/api/getTransactions.mjs +23 -3
  5. package/api/tests/getChains.spec.js +2 -1
  6. package/api/tests/getChains.spec.mjs +2 -1
  7. package/api/tests/getTokens.spec.js +2 -2
  8. package/api/tests/getTokens.spec.mjs +2 -2
  9. package/api/tests/getTransactions.spec.js +79 -69
  10. package/api/tests/getTransactions.spec.mjs +79 -69
  11. package/constants/index.d.ts +1 -1
  12. package/constants/index.js +1 -1
  13. package/constants/index.mjs +1 -1
  14. package/dto/Chain.dto.d.ts +3 -1
  15. package/dto/ConfirmRate.dto.d.ts +1 -0
  16. package/dto/Token.dto.d.ts +7 -2
  17. package/index.js +44 -16
  18. package/index.mjs +14 -16
  19. package/package.json +10 -6
  20. package/reactjs/components/BridgeForm/BridgeForm.d.ts +3 -1
  21. package/reactjs/components/BridgeForm/BridgeForm.js +182 -87
  22. package/reactjs/components/BridgeForm/BridgeForm.mjs +153 -58
  23. package/reactjs/components/BridgeHistory/BridgeHistory.js +73 -26
  24. package/reactjs/components/BridgeHistory/BridgeHistory.mjs +68 -21
  25. package/reactjs/components/Connect/BridgeAccountDisplay.js +2 -5
  26. package/reactjs/components/Connect/BridgeAccountDisplay.mjs +2 -5
  27. package/reactjs/components/Connect/CustomConnectButton.js +2 -5
  28. package/reactjs/components/Connect/CustomConnectButton.mjs +1 -4
  29. package/reactjs/components/Connect/MvxConnectButton.d.ts +2 -4
  30. package/reactjs/components/Connect/MvxConnectButton.js +2 -2
  31. package/reactjs/components/Connect/MvxConnectButton.mjs +2 -2
  32. package/reactjs/components/Connect/SwitchChainButton.js +2 -6
  33. package/reactjs/components/Connect/SwitchChainButton.mjs +1 -5
  34. package/reactjs/components/CopyButton/CopyButton.js +2 -2
  35. package/reactjs/components/CopyButton/CopyButton.mjs +2 -2
  36. package/reactjs/components/DisplayAmount/components/AnimateNumber/AnimateNumber.js +5 -5
  37. package/reactjs/components/Error/Error.d.ts +6 -0
  38. package/reactjs/components/Error/Error.js +67 -0
  39. package/reactjs/components/Error/Error.mjs +66 -0
  40. package/reactjs/components/Error/index.d.ts +1 -0
  41. package/reactjs/components/Error/index.js +5 -0
  42. package/reactjs/components/Error/index.mjs +4 -0
  43. package/reactjs/components/TokenSelector/TokenSelector.d.ts +2 -1
  44. package/reactjs/components/TokenSelector/TokenSelector.js +17 -9
  45. package/reactjs/components/TokenSelector/TokenSelector.mjs +13 -5
  46. package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.d.ts +2 -1
  47. package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.js +7 -3
  48. package/reactjs/components/TokenSelector/components/ChainSelect/ChainSelect.mjs +4 -0
  49. package/reactjs/components/TokenSelector/components/SelectContent.d.ts +2 -1
  50. package/reactjs/components/TokenSelector/components/SelectContent.js +12 -9
  51. package/reactjs/components/TokenSelector/components/SelectContent.mjs +4 -1
  52. package/reactjs/components/TokenSelector/components/TokenIcon.js +3 -3
  53. package/reactjs/components/TokenSelector/components/TokenItem.js +9 -9
  54. package/reactjs/components/TokenSelector/components/TokenItem.mjs +6 -6
  55. package/reactjs/components/base/MxCard/MxCard.js +2 -2
  56. package/reactjs/components/base/MxCircleLoader/MxCircleLoader.d.ts +4 -0
  57. package/reactjs/components/base/MxCircleLoader/MxCircleLoader.js +29 -0
  58. package/reactjs/components/base/MxCircleLoader/MxCircleLoader.mjs +28 -0
  59. package/reactjs/components/base/MxCircleLoader/index.d.ts +1 -0
  60. package/reactjs/components/base/MxCircleLoader/index.js +5 -0
  61. package/reactjs/components/base/MxCircleLoader/index.mjs +4 -0
  62. package/reactjs/components/base/MxLink/MxLink.js +2 -2
  63. package/reactjs/components/base/MxSearch/MxSearch.js +4 -4
  64. package/reactjs/components/base/MxSlideover/MxSlideover.js +4 -4
  65. package/reactjs/components/base/MxTooltip/MxTooltip.js +9 -9
  66. package/reactjs/components/base/MxTooltip/components/TooltipContainer/TooltipContainer.js +2 -2
  67. package/reactjs/components/index.d.ts +1 -0
  68. package/reactjs/components/index.js +2 -0
  69. package/reactjs/components/index.mjs +2 -0
  70. package/reactjs/context/Web3AppProvider.d.ts +3 -1
  71. package/reactjs/context/Web3AppProvider.js +7 -5
  72. package/reactjs/context/Web3AppProvider.mjs +4 -2
  73. package/reactjs/context/useWeb3App.js +2 -2
  74. package/reactjs/hooks/index.js +1 -1
  75. package/reactjs/hooks/index.mjs +1 -1
  76. package/reactjs/hooks/useAccount.js +1 -5
  77. package/reactjs/hooks/useAccount.mjs +1 -5
  78. package/reactjs/hooks/useBalances.d.ts +4 -4
  79. package/reactjs/hooks/useBalances.js +16 -1
  80. package/reactjs/hooks/useBalances.mjs +16 -1
  81. package/reactjs/hooks/useBridgeFormik.js +9 -16
  82. package/reactjs/hooks/useBridgeFormik.mjs +0 -7
  83. package/reactjs/hooks/useDebounce.js +3 -3
  84. package/reactjs/hooks/useFetchBridgeData.d.ts +14 -4
  85. package/reactjs/hooks/useFetchTokens.d.ts +14 -4
  86. package/reactjs/hooks/useFetchTokens.js +9 -9
  87. package/reactjs/hooks/useFetchTokens.mjs +2 -2
  88. package/reactjs/hooks/useFiatData.d.ts +7 -2
  89. package/reactjs/hooks/useFiatData.js +6 -6
  90. package/reactjs/hooks/useFiatData.mjs +1 -1
  91. package/reactjs/hooks/useGetChainId.js +3 -3
  92. package/reactjs/hooks/useGetChainId.mjs +1 -1
  93. package/reactjs/hooks/useResolveTokenChain.js +2 -2
  94. package/reactjs/hooks/useSendTransactions.js +2 -2
  95. package/reactjs/hooks/useSignTransaction.d.ts +93 -67
  96. package/reactjs/hooks/useSignTransaction.js +53 -4
  97. package/reactjs/hooks/useSignTransaction.mjs +53 -4
  98. package/reactjs/hooks/validation/useTestHasEnoughFunds.js +3 -3
  99. package/reactjs/hooks/validation/useTestIsConnected.js +2 -2
  100. package/reactjs/index.js +44 -16
  101. package/reactjs/index.mjs +14 -16
  102. package/reactjs/init/init.d.ts +220 -1
  103. package/reactjs/init/init.js +34 -10
  104. package/reactjs/init/init.mjs +31 -7
  105. package/reactjs/init/tests/init.spec.js +5 -6
  106. package/reactjs/init/tests/init.spec.mjs +5 -6
  107. package/reactjs/queries/index.d.ts +0 -1
  108. package/reactjs/queries/index.js +0 -2
  109. package/reactjs/queries/index.mjs +1 -3
  110. package/reactjs/queries/useGetEvmTokensBalances.query.d.ts +8 -3
  111. package/reactjs/queries/useGetEvmTokensBalances.query.js +15 -18
  112. package/reactjs/queries/useGetEvmTokensBalances.query.mjs +15 -18
  113. package/reactjs/queries/useGetHistory.query.d.ts +9 -1
  114. package/reactjs/queries/useGetHistory.query.js +23 -5
  115. package/reactjs/queries/useGetHistory.query.mjs +23 -5
  116. package/reactjs/queries/useGetMvxTokensBalances.query.d.ts +7 -2
  117. package/reactjs/queries/useGetMvxTokensBalances.query.js +2 -2
  118. package/reactjs/reexports.d.ts +2 -1
  119. package/reactjs/reexports.js +41 -13
  120. package/reactjs/reexports.mjs +11 -13
  121. package/reactjs/utils/getInitialTokens.d.ts +4 -1
  122. package/reactjs/utils/getInitialTokens.js +3 -3
  123. package/reactjs/utils/getInitialTokens.mjs +3 -3
  124. package/style.css +33 -1730
  125. package/types/chainType.d.ts +6 -0
  126. package/types/chainType.js +11 -0
  127. package/types/chainType.mjs +10 -0
  128. package/types/transaction.d.ts +28 -0
  129. package/types/utxo.d.ts +11 -0
  130. package/types/utxo.js +2 -0
  131. package/types/utxo.mjs +1 -0
  132. package/{useBalances-C_69CFoa.mjs → useBalances-Bom1mw1J.mjs} +101 -23
  133. package/{useBalances-C4YhEYxy.js → useBalances-gZTsFZHe.js} +102 -24
  134. package/index-BIVnypNe.mjs +0 -108
  135. package/index-Ben8n3bd.js +0 -58656
  136. package/index-CnKr4rL1.mjs +0 -91
  137. package/index-CnuruJNu.js +0 -329
  138. package/index-DsBh-EBw.js +0 -108
  139. package/index-iN9APQ6x.mjs +0 -58735
  140. package/modules/fiat/components/FiatForm/FiatForm.d.ts +0 -9
  141. package/modules/fiat/components/FiatForm/FiatForm.js +0 -314
  142. package/modules/fiat/components/FiatForm/FiatForm.mjs +0 -313
  143. package/modules/fiat/components/FiatForm/components/AmountInput/AmountInput.d.ts +0 -13
  144. package/modules/fiat/components/FiatForm/components/AmountInput/AmountInput.js +0 -117
  145. package/modules/fiat/components/FiatForm/components/AmountInput/AmountInput.mjs +0 -116
  146. package/modules/fiat/components/FiatForm/components/AmountInput/index.d.ts +0 -1
  147. package/modules/fiat/components/FiatForm/components/AmountInput/index.js +0 -5
  148. package/modules/fiat/components/FiatForm/components/AmountInput/index.mjs +0 -4
  149. package/modules/fiat/components/FiatForm/components/RateReloading/RateReloading.d.ts +0 -7
  150. package/modules/fiat/components/FiatForm/components/RateReloading/RateReloading.js +0 -74
  151. package/modules/fiat/components/FiatForm/components/RateReloading/RateReloading.mjs +0 -73
  152. package/modules/fiat/components/FiatForm/components/TokenSelector/TokenSelector.d.ts +0 -14
  153. package/modules/fiat/components/FiatForm/components/TokenSelector/TokenSelector.js +0 -94
  154. package/modules/fiat/components/FiatForm/components/TokenSelector/TokenSelector.mjs +0 -93
  155. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContainer.d.ts +0 -7
  156. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContainer.js +0 -82
  157. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContainer.mjs +0 -81
  158. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContent.d.ts +0 -7
  159. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContent.js +0 -91
  160. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectContent.mjs +0 -90
  161. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectedOption.d.ts +0 -5
  162. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectedOption.js +0 -30
  163. package/modules/fiat/components/FiatForm/components/TokenSelector/components/SelectedOption.mjs +0 -29
  164. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenIcon.d.ts +0 -8
  165. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenIcon.js +0 -103
  166. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenIcon.mjs +0 -102
  167. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenItem.d.ts +0 -7
  168. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenItem.js +0 -33
  169. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenItem.mjs +0 -32
  170. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenList.d.ts +0 -7
  171. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenList.js +0 -21
  172. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenList.mjs +0 -20
  173. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenSymbol.d.ts +0 -9
  174. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenSymbol.js +0 -26
  175. package/modules/fiat/components/FiatForm/components/TokenSelector/components/TokenSymbol.mjs +0 -25
  176. package/modules/fiat/components/FiatForm/components/TokenSelector/index.d.ts +0 -1
  177. package/modules/fiat/components/FiatForm/components/TokenSelector/index.js +0 -5
  178. package/modules/fiat/components/FiatForm/components/TokenSelector/index.mjs +0 -4
  179. package/modules/fiat/components/FiatForm/index.d.ts +0 -1
  180. package/modules/fiat/components/FiatForm/index.js +0 -5
  181. package/modules/fiat/components/FiatForm/index.mjs +0 -4
  182. package/modules/fiat/components/index.d.ts +0 -1
  183. package/modules/fiat/components/index.js +0 -5
  184. package/modules/fiat/components/index.mjs +0 -4
  185. package/modules/fiat/context/FiatProvider.d.ts +0 -8
  186. package/modules/fiat/context/FiatProvider.js +0 -24
  187. package/modules/fiat/context/FiatProvider.mjs +0 -23
  188. package/modules/fiat/context/queryClient.d.ts +0 -3
  189. package/modules/fiat/context/queryClient.js +0 -12
  190. package/modules/fiat/context/queryClient.mjs +0 -11
  191. package/modules/fiat/context/useFiat.d.ts +0 -1
  192. package/modules/fiat/context/useFiat.js +0 -13
  193. package/modules/fiat/context/useFiat.mjs +0 -12
  194. package/modules/fiat/hooks/index.d.ts +0 -2
  195. package/modules/fiat/hooks/index.js +0 -7
  196. package/modules/fiat/hooks/index.mjs +0 -6
  197. package/modules/fiat/hooks/useFiatData.d.ts +0 -7
  198. package/modules/fiat/hooks/useFiatData.js +0 -75
  199. package/modules/fiat/hooks/useFiatData.mjs +0 -74
  200. package/modules/fiat/hooks/validation/index.d.ts +0 -1
  201. package/modules/fiat/hooks/validation/index.js +0 -5
  202. package/modules/fiat/hooks/validation/index.mjs +0 -4
  203. package/modules/fiat/hooks/validation/useAmountSchema.d.ts +0 -2
  204. package/modules/fiat/hooks/validation/useAmountSchema.js +0 -27
  205. package/modules/fiat/hooks/validation/useAmountSchema.mjs +0 -9
  206. package/modules/fiat/index.d.ts +0 -8
  207. package/modules/fiat/index.js +0 -22
  208. package/modules/fiat/index.mjs +0 -21
  209. package/modules/fiat/init/index.d.ts +0 -2
  210. package/modules/fiat/init/index.js +0 -5
  211. package/modules/fiat/init/index.mjs +0 -4
  212. package/modules/fiat/init/init.d.ts +0 -22
  213. package/modules/fiat/init/init.js +0 -15
  214. package/modules/fiat/init/init.mjs +0 -14
  215. package/modules/fiat/queries/index.d.ts +0 -2
  216. package/modules/fiat/queries/index.js +0 -7
  217. package/modules/fiat/queries/index.mjs +0 -6
  218. package/modules/fiat/queries/useGetRate.mutation.d.ts +0 -6
  219. package/modules/fiat/queries/useGetRate.mutation.js +0 -20
  220. package/modules/fiat/queries/useGetRate.mutation.mjs +0 -19
  221. package/modules/fiat/queries/useGetTokens.query.d.ts +0 -5
  222. package/modules/fiat/queries/useGetTokens.query.js +0 -33
  223. package/modules/fiat/queries/useGetTokens.query.mjs +0 -32
  224. package/react-47kZTyAT.mjs +0 -51
  225. package/react-B_iI3-1z.mjs +0 -3133
  226. package/react-BomcNL1v.js +0 -254
  227. package/react-CqKlu0W0.js +0 -51
  228. package/react-R_xxu7fN.js +0 -3133
  229. package/react-cXurUY4Z.mjs +0 -254
  230. package/reactjs/queries/useGetTokens.query.d.ts +0 -3
  231. package/reactjs/queries/useGetTokens.query.js +0 -34
  232. package/reactjs/queries/useGetTokens.query.mjs +0 -33
  233. package/w3m-modal-Bhg44d6I.js +0 -356
  234. package/w3m-modal-Br2Ec3MM.mjs +0 -356
@@ -0,0 +1,6 @@
1
+ export declare enum ChainType {
2
+ evm = "evm",
3
+ sol = "sol",
4
+ btc = "btc",
5
+ mvx = "mvx"
6
+ }
@@ -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;
@@ -0,0 +1,10 @@
1
+ var ChainType = /* @__PURE__ */ ((ChainType2) => {
2
+ ChainType2["evm"] = "evm";
3
+ ChainType2["sol"] = "sol";
4
+ ChainType2["btc"] = "btc";
5
+ ChainType2["mvx"] = "mvx";
6
+ return ChainType2;
7
+ })(ChainType || {});
8
+ export {
9
+ ChainType
10
+ };
@@ -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}`;
@@ -0,0 +1,11 @@
1
+ export interface Utxo {
2
+ txid: string;
3
+ vout: number;
4
+ value: string;
5
+ height?: number;
6
+ confirmations: number;
7
+ address?: string;
8
+ path?: string;
9
+ lockTime?: number;
10
+ coinbase?: boolean;
11
+ }
package/types/utxo.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
package/types/utxo.mjs ADDED
@@ -0,0 +1 @@
1
+
@@ -1,5 +1,20 @@
1
- import { useCallback } from "react";
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
- tokenIdentifiers.map(async (tokenIdentifier) => {
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
- const balance = await getBalance(config, {
168
- address,
169
- chainId: Number(chainId),
170
- // TODO: fix this using the API support
171
- // omit passing the token for fetching the native currency balance
172
- token: tokenIdentifier.length > 10 ? tokenIdentifier : void 0
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: tokenIdentifier,
176
- balance: balance.value.toString()
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: tokenIdentifier,
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 require$$0 = require("react");
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 fetchBalances = require$$0.useCallback(
161
- async ({
162
- address,
163
- chainId,
164
- tokenIdentifiers
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
- tokenIdentifiers.map(async (tokenIdentifier) => {
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
- const balance = await getBalance(config, {
170
- address,
171
- chainId: Number(chainId),
172
- // TODO: fix this using the API support
173
- // omit passing the token for fetching the native currency balance
174
- token: tokenIdentifier.length > 10 ? tokenIdentifier : void 0
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: tokenIdentifier,
178
- balance: balance.value.toString()
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: tokenIdentifier,
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
@@ -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
- };