@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.
@@ -2,11 +2,11 @@ import {
2
2
  bind_exports,
3
3
  poh_exports,
4
4
  user_exports
5
- } from "../../chunk-PV5YB7PG.mjs";
5
+ } from "../../chunk-AZCOCC5H.mjs";
6
6
  import {
7
7
  isSuccess,
8
8
  wallet_exports
9
- } from "../../chunk-IKLQAPKE.mjs";
9
+ } from "../../chunk-ZHBFW26I.mjs";
10
10
  import "../../chunk-UA6XHZHX.mjs";
11
11
  import "../../chunk-FB5MHLWX.mjs";
12
12
  import "../../chunk-5JHHHLG4.mjs";
@@ -1432,39 +1432,15 @@ function TokenSend({
1432
1432
  const [sending, setSending] = (0, import_react23.useState)(false);
1433
1433
  const [txError, setTxError] = (0, import_react23.useState)("");
1434
1434
  const transaction = (0, import_react23.useMemo)(() => {
1435
- if (!amount || !address) {
1435
+ const reg = /^0x[a-fA-F0-9]{40}$/;
1436
+ if (!amount || !address || !reg.test(address)) {
1436
1437
  return;
1437
1438
  }
1438
- const abi = [
1439
- {
1440
- "constant": false,
1441
- "inputs": [
1442
- {
1443
- "name": "_to",
1444
- "type": "address"
1445
- },
1446
- {
1447
- "name": "_value",
1448
- "type": "uint256"
1449
- }
1450
- ],
1451
- "name": "transfer",
1452
- "outputs": [
1453
- {
1454
- "name": "",
1455
- "type": "bool"
1456
- }
1457
- ],
1458
- "payable": false,
1459
- "stateMutability": "nonpayable",
1460
- "type": "function"
1461
- }
1462
- ];
1463
1439
  const viemChain = (0, import_viem2.defineChain)(chain);
1464
1440
  const to = isNative ? address : token.address;
1465
1441
  const value = isNative ? (0, import_viem2.parseUnits)(amount, parseInt(token?.decimals || "18")) : BigInt(0);
1466
1442
  const data = isNative ? "0x" : (0, import_viem2.encodeFunctionData)({
1467
- abi,
1443
+ abi: import_viem2.erc20Abi,
1468
1444
  functionName: "transfer",
1469
1445
  args: [address, (0, import_viem2.parseUnits)(amount, parseInt(token?.decimals || "18"))]
1470
1446
  });
@@ -2533,15 +2509,41 @@ function useMatchChain() {
2533
2509
  // src/hooks/useMatchWallet.tsx
2534
2510
  var import_react_qrcode = require("react-qrcode");
2535
2511
  var import_react38 = require("react");
2536
- var import_react_query6 = require("@tanstack/react-query");
2537
- var import_viem10 = require("viem");
2512
+ var import_react_query7 = require("@tanstack/react-query");
2513
+ var import_viem11 = require("viem");
2538
2514
  var import_react_intl21 = require("react-intl");
2539
2515
 
2540
2516
  // src/components/ImportToken/index.tsx
2541
2517
  var import_react37 = require("react");
2542
2518
  var import_react_intl20 = require("react-intl");
2543
- var import_react_query5 = require("@tanstack/react-query");
2519
+ var import_react_query6 = require("@tanstack/react-query");
2520
+ var import_viem10 = require("viem");
2521
+
2522
+ // src/hooks/useIsContract.ts
2544
2523
  var import_viem9 = require("viem");
2524
+ var import_react_query5 = require("@tanstack/react-query");
2525
+ function useIsContract({
2526
+ address,
2527
+ chain,
2528
+ enabled
2529
+ }) {
2530
+ return (0, import_react_query5.useQuery)({
2531
+ queryKey: ["is_contract", chain?.id, address],
2532
+ queryFn: async () => {
2533
+ if (!chain) return false;
2534
+ if (!address) return false;
2535
+ const publicClient = (0, import_viem9.createPublicClient)({
2536
+ chain,
2537
+ transport: (0, import_viem9.http)()
2538
+ });
2539
+ const res = await publicClient.getCode({ address });
2540
+ return res !== null && res !== void 0;
2541
+ },
2542
+ enabled
2543
+ });
2544
+ }
2545
+
2546
+ // src/components/ImportToken/index.tsx
2545
2547
  var import_jsx_runtime93 = require("react/jsx-runtime");
2546
2548
  function ImportToken({ close }) {
2547
2549
  const [status, setStatus] = (0, import_react37.useState)("");
@@ -2550,19 +2552,19 @@ function ImportToken({ close }) {
2550
2552
  const [symbol, setSymbol] = (0, import_react37.useState)("");
2551
2553
  const [decimals, setDecimals] = (0, import_react37.useState)("");
2552
2554
  const [error, setError] = (0, import_react37.useState)({});
2553
- const { publicClient, chainId } = useMatchChain();
2555
+ const { publicClient, chainId, chain } = useMatchChain();
2554
2556
  const getContractInfo = async () => {
2555
2557
  if (!publicClient) return;
2556
2558
  const calls = [
2557
2559
  {
2558
2560
  address,
2559
- abi: import_viem9.erc20Abi,
2561
+ abi: import_viem10.erc20Abi,
2560
2562
  functionName: "symbol",
2561
2563
  args: []
2562
2564
  },
2563
2565
  {
2564
2566
  address,
2565
- abi: import_viem9.erc20Abi,
2567
+ abi: import_viem10.erc20Abi,
2566
2568
  functionName: "decimals",
2567
2569
  args: []
2568
2570
  }
@@ -2604,7 +2606,7 @@ function ImportToken({ close }) {
2604
2606
  }, [address, publicClient]);
2605
2607
  const [loading, setLoading] = (0, import_react37.useState)(false);
2606
2608
  const toast = useToast();
2607
- const queryClient2 = (0, import_react_query5.useQueryClient)();
2609
+ const queryClient2 = (0, import_react_query6.useQueryClient)();
2608
2610
  const onImport = async () => {
2609
2611
  setLoading(true);
2610
2612
  try {
@@ -2646,7 +2648,12 @@ function ImportToken({ close }) {
2646
2648
  }
2647
2649
  return true;
2648
2650
  }, [error, address, symbol, decimals]);
2649
- console.log("status", status);
2651
+ const isContractQuery = useIsContract({
2652
+ //@ts-ignore
2653
+ chain: (0, import_viem10.defineChain)(chain),
2654
+ address,
2655
+ enabled: canImport
2656
+ });
2650
2657
  if (status == "success" || status == "fail") {
2651
2658
  return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: `matchid-import-token-result matchid-flex`, children: [
2652
2659
  /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: `matchid-import-token-result-box matchid-flex`, children: [
@@ -2660,7 +2667,7 @@ function ImportToken({ close }) {
2660
2667
  /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: "matchid-import-token-form", children: [
2661
2668
  /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(Field, { label: intl.formatMessage({
2662
2669
  id: "tokenSmartContract"
2663
- }), error: error.address, children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
2670
+ }), error: error.address ? error.address : isContractQuery.isFetched && !isContractQuery.isLoading && !isContractQuery.data && canImport ? "Address isn't a contract address" : "", children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
2664
2671
  Input,
2665
2672
  {
2666
2673
  placeholder: intl.formatMessage({
@@ -2704,8 +2711,8 @@ function ImportToken({ close }) {
2704
2711
  size: "lg",
2705
2712
  onClick: onImport,
2706
2713
  block: true,
2707
- loading,
2708
- disabled: !canImport,
2714
+ loading: loading || isContractQuery.isLoading,
2715
+ disabled: !canImport || !isContractQuery.data,
2709
2716
  highlight: true,
2710
2717
  children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_react_intl20.FormattedMessage, { id: "import" })
2711
2718
  }
@@ -2827,13 +2834,13 @@ function useMatchWalletRecords() {
2827
2834
  for (const contract of contractUnique) {
2828
2835
  calls.push({
2829
2836
  address: contract,
2830
- abi: import_viem10.erc20Abi,
2837
+ abi: import_viem11.erc20Abi,
2831
2838
  functionName: "symbol",
2832
2839
  args: []
2833
2840
  });
2834
2841
  calls.push({
2835
2842
  address: contract,
2836
- abi: import_viem10.erc20Abi,
2843
+ abi: import_viem11.erc20Abi,
2837
2844
  functionName: "decimals",
2838
2845
  args: []
2839
2846
  });
@@ -2985,7 +2992,7 @@ function useMatchWalletAssetList({
2985
2992
  name: chain?.nativeCurrency.name,
2986
2993
  balance: 0
2987
2994
  };
2988
- const nativeBalanceQuery = (0, import_react_query6.useQuery)({
2995
+ const nativeBalanceQuery = (0, import_react_query7.useQuery)({
2989
2996
  queryKey: ["nativeBalance", nativeToken?.chain_id],
2990
2997
  queryFn: async () => {
2991
2998
  if (!nativeToken || !publicClient) return null;
@@ -3005,13 +3012,13 @@ function useMatchWalletAssetList({
3005
3012
  // Retry up to 3 times if failed
3006
3013
  });
3007
3014
  const erc20Tokens = (0, import_react38.useMemo)(() => list.filter((asset) => asset.address !== NATIVE_TOKEN_ADDRESS), [list]);
3008
- const erc20BalanceQuery = (0, import_react_query6.useQuery)({
3015
+ const erc20BalanceQuery = (0, import_react_query7.useQuery)({
3009
3016
  queryKey: ["erc20Balances", erc20Tokens.map((token) => token.address)],
3010
3017
  queryFn: async () => {
3011
3018
  if (!erc20Tokens.length || !publicClient) return [];
3012
3019
  const calls = erc20Tokens.map((token) => ({
3013
3020
  address: token.address,
3014
- abi: import_viem10.erc20Abi,
3021
+ abi: import_viem11.erc20Abi,
3015
3022
  functionName: "balanceOf",
3016
3023
  args: [address]
3017
3024
  }));
@@ -3039,13 +3046,14 @@ function useMatchWalletAssetList({
3039
3046
  let balanceValue = "0";
3040
3047
  let balance = 0;
3041
3048
  const decimals = typeof asset.decimals === "string" ? parseInt(asset.decimals) : asset.decimals;
3042
- if (asset.address === NATIVE_TOKEN_ADDRESS) {
3049
+ const assetAddress = asset.address.toLowerCase();
3050
+ if (assetAddress === NATIVE_TOKEN_ADDRESS) {
3043
3051
  balanceValue = nativeBalanceQuery.data?.toString() || "0";
3044
- balance = nativeBalanceQuery.data ? Number((0, import_viem10.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
3052
+ balance = nativeBalanceQuery.data ? Number((0, import_viem11.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
3045
3053
  } else {
3046
- const index = erc20Tokens.findIndex((t) => t.address === asset.address);
3054
+ const index = erc20Tokens.findIndex((t) => t.address.toLowerCase() === assetAddress);
3047
3055
  if (index !== -1 && erc20Balances[index] && erc20Balances[index].status === "success") {
3048
- balance = Number((0, import_viem10.formatUnits)(erc20Balances[index].result, decimals));
3056
+ balance = Number((0, import_viem11.formatUnits)(erc20Balances[index].result, decimals));
3049
3057
  balanceValue = erc20Balances[index].result?.toString() || "0";
3050
3058
  }
3051
3059
  }
@@ -3079,8 +3087,8 @@ function useMatchWalletAssetList({
3079
3087
 
3080
3088
  // src/hooks/useReceipt.tsx
3081
3089
  var import_react39 = require("react");
3082
- var import_react_query7 = require("@tanstack/react-query");
3083
- var import_viem11 = require("viem");
3090
+ var import_react_query8 = require("@tanstack/react-query");
3091
+ var import_viem12 = require("viem");
3084
3092
  var CACHE_TTL = 86400 * 30 * 1e3;
3085
3093
  var MAX_CACHE_SIZE = 500;
3086
3094
  var STORAGE_KEY = "match_receipt_logs";
@@ -3188,7 +3196,7 @@ function useReceipt2({
3188
3196
  const cache = useReceiptCache();
3189
3197
  const chain = list?.find((item) => item.id === chainId);
3190
3198
  const [shouldRefetch, setShouldRefetch] = (0, import_react39.useState)(true);
3191
- const query = (0, import_react_query7.useQuery)({
3199
+ const query = (0, import_react_query8.useQuery)({
3192
3200
  queryKey: ["match-tx-receipt", hash, chain],
3193
3201
  queryFn: async () => {
3194
3202
  if (!chain || !hash) return false;
@@ -3197,9 +3205,9 @@ function useReceipt2({
3197
3205
  return cache.get(cacheKey);
3198
3206
  }
3199
3207
  try {
3200
- const publicClient = (0, import_viem11.createPublicClient)({
3201
- chain: (0, import_viem11.defineChain)(chain),
3202
- transport: (0, import_viem11.http)()
3208
+ const publicClient = (0, import_viem12.createPublicClient)({
3209
+ chain: (0, import_viem12.defineChain)(chain),
3210
+ transport: (0, import_viem12.http)()
3203
3211
  });
3204
3212
  const receipt = await publicClient.getTransactionReceipt({ hash });
3205
3213
  if (!receipt) {
@@ -3223,8 +3231,8 @@ function useReceipt2({
3223
3231
 
3224
3232
  // src/hooks/useTransaction.tsx
3225
3233
  var import_react40 = require("react");
3226
- var import_react_query8 = require("@tanstack/react-query");
3227
- var import_viem12 = require("viem");
3234
+ var import_react_query9 = require("@tanstack/react-query");
3235
+ var import_viem13 = require("viem");
3228
3236
  var CACHE_TTL2 = 86400 * 30 * 1e3;
3229
3237
  var MAX_CACHE_SIZE2 = 500;
3230
3238
  var STORAGE_KEY2 = "match_transaction_logs";
@@ -3332,7 +3340,7 @@ function useTransaction({
3332
3340
  const cache = useTransactionCache();
3333
3341
  const chain = list?.find((item) => item.id === chainId);
3334
3342
  const [shouldRefetch, setShouldRefetch] = (0, import_react40.useState)(true);
3335
- const query = (0, import_react_query8.useQuery)({
3343
+ const query = (0, import_react_query9.useQuery)({
3336
3344
  queryKey: ["match-tx-transaction", hash, chain],
3337
3345
  queryFn: async () => {
3338
3346
  if (!chain || !hash) return false;
@@ -3341,9 +3349,9 @@ function useTransaction({
3341
3349
  return cache.get(cacheKey);
3342
3350
  }
3343
3351
  try {
3344
- const publicClient = (0, import_viem12.createPublicClient)({
3345
- chain: (0, import_viem12.defineChain)(chain),
3346
- transport: (0, import_viem12.http)()
3352
+ const publicClient = (0, import_viem13.createPublicClient)({
3353
+ chain: (0, import_viem13.defineChain)(chain),
3354
+ transport: (0, import_viem13.http)()
3347
3355
  });
3348
3356
  const transaction = await publicClient.getTransaction({ hash });
3349
3357
  if (!transaction) {