@matchain/matchid-sdk-react 0.1.48-alpha.27 → 0.1.48-alpha.29

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.
@@ -2622,7 +2622,7 @@ function useMatchChain() {
2622
2622
  // src/hooks/useMatchWallet.tsx
2623
2623
  var import_react_qrcode = require("react-qrcode");
2624
2624
  var import_react15 = require("react");
2625
- var import_react_query4 = require("@tanstack/react-query");
2625
+ var import_react_query5 = require("@tanstack/react-query");
2626
2626
 
2627
2627
  // src/config/index.tsx
2628
2628
  var EMAIL_INTERVAL = 60;
@@ -2630,7 +2630,7 @@ var EMAIL_CODE_LENGTH = 6;
2630
2630
  var NATIVE_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
2631
2631
 
2632
2632
  // src/hooks/useMatchWallet.tsx
2633
- var import_viem7 = require("viem");
2633
+ var import_viem8 = require("viem");
2634
2634
 
2635
2635
  // src/store/useContractStore.ts
2636
2636
  var import_zustand4 = require("zustand");
@@ -2694,8 +2694,14 @@ var import_react_intl3 = require("react-intl");
2694
2694
  // src/components/ImportToken/index.tsx
2695
2695
  var import_react14 = require("react");
2696
2696
  var import_react_intl2 = require("react-intl");
2697
- var import_react_query3 = require("@tanstack/react-query");
2697
+ var import_react_query4 = require("@tanstack/react-query");
2698
+ var import_viem7 = require("viem");
2699
+
2700
+ // src/hooks/useIsContract.ts
2698
2701
  var import_viem6 = require("viem");
2702
+ var import_react_query3 = require("@tanstack/react-query");
2703
+
2704
+ // src/components/ImportToken/index.tsx
2699
2705
  var import_jsx_runtime67 = require("react/jsx-runtime");
2700
2706
 
2701
2707
  // src/hooks/useMatchWallet.tsx
@@ -2737,13 +2743,13 @@ function useMatchWalletRecords() {
2737
2743
  for (const contract of contractUnique) {
2738
2744
  calls.push({
2739
2745
  address: contract,
2740
- abi: import_viem7.erc20Abi,
2746
+ abi: import_viem8.erc20Abi,
2741
2747
  functionName: "symbol",
2742
2748
  args: []
2743
2749
  });
2744
2750
  calls.push({
2745
2751
  address: contract,
2746
- abi: import_viem7.erc20Abi,
2752
+ abi: import_viem8.erc20Abi,
2747
2753
  functionName: "decimals",
2748
2754
  args: []
2749
2755
  });
@@ -2895,7 +2901,7 @@ function useMatchWalletAssetList({
2895
2901
  name: chain?.nativeCurrency.name,
2896
2902
  balance: 0
2897
2903
  };
2898
- const nativeBalanceQuery = (0, import_react_query4.useQuery)({
2904
+ const nativeBalanceQuery = (0, import_react_query5.useQuery)({
2899
2905
  queryKey: ["nativeBalance", nativeToken?.chain_id],
2900
2906
  queryFn: async () => {
2901
2907
  if (!nativeToken || !publicClient) return null;
@@ -2915,13 +2921,13 @@ function useMatchWalletAssetList({
2915
2921
  // Retry up to 3 times if failed
2916
2922
  });
2917
2923
  const erc20Tokens = (0, import_react15.useMemo)(() => list.filter((asset) => asset.address !== NATIVE_TOKEN_ADDRESS), [list]);
2918
- const erc20BalanceQuery = (0, import_react_query4.useQuery)({
2924
+ const erc20BalanceQuery = (0, import_react_query5.useQuery)({
2919
2925
  queryKey: ["erc20Balances", erc20Tokens.map((token) => token.address)],
2920
2926
  queryFn: async () => {
2921
2927
  if (!erc20Tokens.length || !publicClient) return [];
2922
2928
  const calls = erc20Tokens.map((token) => ({
2923
2929
  address: token.address,
2924
- abi: import_viem7.erc20Abi,
2930
+ abi: import_viem8.erc20Abi,
2925
2931
  functionName: "balanceOf",
2926
2932
  args: [address]
2927
2933
  }));
@@ -2949,13 +2955,14 @@ function useMatchWalletAssetList({
2949
2955
  let balanceValue = "0";
2950
2956
  let balance = 0;
2951
2957
  const decimals = typeof asset.decimals === "string" ? parseInt(asset.decimals) : asset.decimals;
2952
- if (asset.address === NATIVE_TOKEN_ADDRESS) {
2958
+ const assetAddress = asset.address.toLowerCase();
2959
+ if (assetAddress === NATIVE_TOKEN_ADDRESS) {
2953
2960
  balanceValue = nativeBalanceQuery.data?.toString() || "0";
2954
- balance = nativeBalanceQuery.data ? Number((0, import_viem7.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
2961
+ balance = nativeBalanceQuery.data ? Number((0, import_viem8.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
2955
2962
  } else {
2956
- const index = erc20Tokens.findIndex((t) => t.address === asset.address);
2963
+ const index = erc20Tokens.findIndex((t) => t.address.toLowerCase() === assetAddress);
2957
2964
  if (index !== -1 && erc20Balances[index] && erc20Balances[index].status === "success") {
2958
- balance = Number((0, import_viem7.formatUnits)(erc20Balances[index].result, decimals));
2965
+ balance = Number((0, import_viem8.formatUnits)(erc20Balances[index].result, decimals));
2959
2966
  balanceValue = erc20Balances[index].result?.toString() || "0";
2960
2967
  }
2961
2968
  }
@@ -2989,14 +2996,14 @@ function useMatchWalletAssetList({
2989
2996
 
2990
2997
  // src/hooks/useReceipt.tsx
2991
2998
  var import_react16 = require("react");
2992
- var import_react_query5 = require("@tanstack/react-query");
2993
- var import_viem8 = require("viem");
2999
+ var import_react_query6 = require("@tanstack/react-query");
3000
+ var import_viem9 = require("viem");
2994
3001
  var CACHE_TTL = 86400 * 30 * 1e3;
2995
3002
 
2996
3003
  // src/hooks/useTransaction.tsx
2997
3004
  var import_react17 = require("react");
2998
- var import_react_query6 = require("@tanstack/react-query");
2999
- var import_viem9 = require("viem");
3005
+ var import_react_query7 = require("@tanstack/react-query");
3006
+ var import_viem10 = require("viem");
3000
3007
  var CACHE_TTL2 = 86400 * 30 * 1e3;
3001
3008
 
3002
3009
  // src/store/useModalStore.ts
@@ -3103,10 +3110,10 @@ var AppClientId2 = getAppClientId();
3103
3110
  var import_react20 = require("react");
3104
3111
 
3105
3112
  // src/MatchContext.tsx
3106
- var import_react_query7 = require("@tanstack/react-query");
3113
+ var import_react_query8 = require("@tanstack/react-query");
3107
3114
  var import_react_intl5 = require("react-intl");
3108
3115
  var import_jsx_runtime73 = require("react/jsx-runtime");
3109
- var queryClient = new import_react_query7.QueryClient();
3116
+ var queryClient = new import_react_query8.QueryClient();
3110
3117
  var MatchContext = (0, import_react21.createContext)(void 0);
3111
3118
  var useMatch = () => {
3112
3119
  const context = (0, import_react21.useContext)(MatchContext);
@@ -3534,9 +3541,9 @@ var import_react25 = require("react");
3534
3541
  var import_react_intl8 = require("react-intl");
3535
3542
 
3536
3543
  // src/hooks/useAppConfig.ts
3537
- var import_react_query8 = require("@tanstack/react-query");
3544
+ var import_react_query9 = require("@tanstack/react-query");
3538
3545
  function useAppConfig() {
3539
- const query = (0, import_react_query8.useQuery)({
3546
+ const query = (0, import_react_query9.useQuery)({
3540
3547
  queryKey: ["appConfig"],
3541
3548
  queryFn: async () => {
3542
3549
  const res = await getAppConfigApi();
@@ -5288,7 +5295,7 @@ function WalletAsset({
5288
5295
 
5289
5296
  // src/components/TokenSend/index.tsx
5290
5297
  var import_react38 = require("react");
5291
- var import_viem10 = require("viem");
5298
+ var import_viem11 = require("viem");
5292
5299
  var import_react_intl18 = require("react-intl");
5293
5300
  var import_jsx_runtime91 = require("react/jsx-runtime");
5294
5301
  function Input2({
@@ -5331,8 +5338,8 @@ function TokenSend({
5331
5338
  const walletClient = (0, import_react38.useMemo)(() => {
5332
5339
  return createWalletClient2({
5333
5340
  // @ts-ignore
5334
- chain: (0, import_viem10.defineChain)(chain),
5335
- transport: (0, import_viem10.http)()
5341
+ chain: (0, import_viem11.defineChain)(chain),
5342
+ transport: (0, import_viem11.http)()
5336
5343
  });
5337
5344
  }, [chain]);
5338
5345
  const [amount, setAmount] = (0, import_react38.useState)("");
@@ -5341,41 +5348,17 @@ function TokenSend({
5341
5348
  const [sending, setSending] = (0, import_react38.useState)(false);
5342
5349
  const [txError, setTxError] = (0, import_react38.useState)("");
5343
5350
  const transaction = (0, import_react38.useMemo)(() => {
5344
- if (!amount || !address) {
5351
+ const reg = /^0x[a-fA-F0-9]{40}$/;
5352
+ if (!amount || !address || !reg.test(address)) {
5345
5353
  return;
5346
5354
  }
5347
- const abi = [
5348
- {
5349
- "constant": false,
5350
- "inputs": [
5351
- {
5352
- "name": "_to",
5353
- "type": "address"
5354
- },
5355
- {
5356
- "name": "_value",
5357
- "type": "uint256"
5358
- }
5359
- ],
5360
- "name": "transfer",
5361
- "outputs": [
5362
- {
5363
- "name": "",
5364
- "type": "bool"
5365
- }
5366
- ],
5367
- "payable": false,
5368
- "stateMutability": "nonpayable",
5369
- "type": "function"
5370
- }
5371
- ];
5372
- const viemChain = (0, import_viem10.defineChain)(chain);
5355
+ const viemChain = (0, import_viem11.defineChain)(chain);
5373
5356
  const to = isNative ? address : token.address;
5374
- const value = isNative ? (0, import_viem10.parseUnits)(amount, parseInt(token?.decimals || "18")) : BigInt(0);
5375
- const data = isNative ? "0x" : (0, import_viem10.encodeFunctionData)({
5376
- abi,
5357
+ const value = isNative ? (0, import_viem11.parseUnits)(amount, parseInt(token?.decimals || "18")) : BigInt(0);
5358
+ const data = isNative ? "0x" : (0, import_viem11.encodeFunctionData)({
5359
+ abi: import_viem11.erc20Abi,
5377
5360
  functionName: "transfer",
5378
- args: [address, (0, import_viem10.parseUnits)(amount, parseInt(token?.decimals || "18"))]
5361
+ args: [address, (0, import_viem11.parseUnits)(amount, parseInt(token?.decimals || "18"))]
5379
5362
  });
5380
5363
  return {
5381
5364
  to,
@@ -5647,8 +5630,8 @@ function TokenSendList({ close }) {
5647
5630
  // src/components/TransactionList/index.tsx
5648
5631
  var import_react_infinite_scroll_component = __toESM(require("react-infinite-scroll-component"));
5649
5632
  var import_react40 = require("react");
5650
- var import_viem11 = require("viem");
5651
5633
  var import_viem12 = require("viem");
5634
+ var import_viem13 = require("viem");
5652
5635
  var import_react_intl21 = require("react-intl");
5653
5636
  var import_jsx_runtime94 = require("react/jsx-runtime");
5654
5637
  var Item = ({ data }) => {
@@ -5668,32 +5651,35 @@ var Item = ({ data }) => {
5668
5651
  return "unknown";
5669
5652
  }, [data.input]);
5670
5653
  const to = (0, import_react40.useMemo)(() => {
5654
+ if (!isOut) {
5655
+ return data.from;
5656
+ }
5671
5657
  if (transferType == "erc20_transfer") {
5672
- const decodeData = (0, import_viem11.decodeFunctionData)({
5673
- abi: import_viem12.erc20Abi,
5658
+ const decodeData = (0, import_viem12.decodeFunctionData)({
5659
+ abi: import_viem13.erc20Abi,
5674
5660
  data: data.input
5675
5661
  });
5676
5662
  return decodeData.args[0];
5677
5663
  }
5678
5664
  return data.to;
5679
- }, [data.input, transferType, data.to]);
5665
+ }, [data.input, transferType, data.to, isOut]);
5680
5666
  const amount = (0, import_react40.useMemo)(() => {
5681
5667
  if (transferType == "erc20_transfer") {
5682
- const decodeData = (0, import_viem11.decodeFunctionData)({
5683
- abi: import_viem12.erc20Abi,
5668
+ const decodeData = (0, import_viem12.decodeFunctionData)({
5669
+ abi: import_viem13.erc20Abi,
5684
5670
  data: data.input
5685
5671
  });
5686
5672
  const value = decodeData.args[1];
5687
- return (0, import_viem11.formatUnits)(value, contracts[`${chainId}-${data.to.toLowerCase()}`]?.decimals || 18);
5673
+ return (0, import_viem12.formatUnits)(value, contracts[`${chainId}-${data.to.toLowerCase()}`]?.decimals || 18);
5688
5674
  }
5689
5675
  return chainFormatUnits(BigInt(data.value));
5690
5676
  }, [data.input, transferType, data.value, contracts, chainId, data.to]);
5691
5677
  const hashQuery = useHash({
5692
5678
  hash: data.hash,
5693
5679
  //@ts-ignore
5694
- chain: (0, import_viem11.defineChain)(chain),
5680
+ chain: (0, import_viem12.defineChain)(chain),
5695
5681
  refetchInterval: shouldRefetch ? 3e3 : false,
5696
- enabled: shouldRefetch
5682
+ enabled: shouldRefetch && data.source == "local"
5697
5683
  });
5698
5684
  const status = (0, import_react40.useMemo)(() => {
5699
5685
  if (data.source == "matchain") {