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

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.
@@ -1293,7 +1293,7 @@ function useMatchChain() {
1293
1293
  // src/hooks/useMatchWallet.tsx
1294
1294
  import { QRCode } from "react-qrcode";
1295
1295
  import { useEffect as useEffect7, useMemo as useMemo5, useRef, useState as useState8 } from "react";
1296
- import { useQuery as useQuery2 } from "@tanstack/react-query";
1296
+ import { useQuery as useQuery3 } from "@tanstack/react-query";
1297
1297
 
1298
1298
  // src/config/index.tsx
1299
1299
  var EMAIL_INTERVAL = 60;
@@ -1366,7 +1366,33 @@ import { FormattedMessage as FormattedMessage3, useIntl as useIntl3 } from "reac
1366
1366
  import { useEffect as useEffect6, useMemo as useMemo4, useState as useState7 } from "react";
1367
1367
  import { FormattedMessage as FormattedMessage2, useIntl as useIntl2 } from "react-intl";
1368
1368
  import { useQueryClient } from "@tanstack/react-query";
1369
- import { erc20Abi } from "viem";
1369
+ import { defineChain, erc20Abi } from "viem";
1370
+
1371
+ // src/hooks/useIsContract.ts
1372
+ import { createPublicClient as createPublicClient3, http as http3 } from "viem";
1373
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
1374
+ function useIsContract({
1375
+ address,
1376
+ chain,
1377
+ enabled
1378
+ }) {
1379
+ return useQuery2({
1380
+ queryKey: ["is_contract", chain?.id, address],
1381
+ queryFn: async () => {
1382
+ if (!chain) return false;
1383
+ if (!address) return false;
1384
+ const publicClient = createPublicClient3({
1385
+ chain,
1386
+ transport: http3()
1387
+ });
1388
+ const res = await publicClient.getCode({ address });
1389
+ return res !== null && res !== void 0;
1390
+ },
1391
+ enabled
1392
+ });
1393
+ }
1394
+
1395
+ // src/components/ImportToken/index.tsx
1370
1396
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1371
1397
  function ImportToken({ close }) {
1372
1398
  const [status, setStatus] = useState7("");
@@ -1375,7 +1401,7 @@ function ImportToken({ close }) {
1375
1401
  const [symbol, setSymbol] = useState7("");
1376
1402
  const [decimals, setDecimals] = useState7("");
1377
1403
  const [error, setError] = useState7({});
1378
- const { publicClient, chainId } = useMatchChain();
1404
+ const { publicClient, chainId, chain } = useMatchChain();
1379
1405
  const getContractInfo = async () => {
1380
1406
  if (!publicClient) return;
1381
1407
  const calls = [
@@ -1471,7 +1497,12 @@ function ImportToken({ close }) {
1471
1497
  }
1472
1498
  return true;
1473
1499
  }, [error, address, symbol, decimals]);
1474
- console.log("status", status);
1500
+ const isContractQuery = useIsContract({
1501
+ //@ts-ignore
1502
+ chain: defineChain(chain),
1503
+ address,
1504
+ enabled: canImport
1505
+ });
1475
1506
  if (status == "success" || status == "fail") {
1476
1507
  return /* @__PURE__ */ jsxs5("div", { className: `matchid-import-token-result matchid-flex`, children: [
1477
1508
  /* @__PURE__ */ jsxs5("div", { className: `matchid-import-token-result-box matchid-flex`, children: [
@@ -1485,7 +1516,7 @@ function ImportToken({ close }) {
1485
1516
  /* @__PURE__ */ jsxs5("div", { className: "matchid-import-token-form", children: [
1486
1517
  /* @__PURE__ */ jsx6(Field, { label: intl.formatMessage({
1487
1518
  id: "tokenSmartContract"
1488
- }), error: error.address, children: /* @__PURE__ */ jsx6(
1519
+ }), error: error.address ? error.address : isContractQuery.isFetched && !isContractQuery.isLoading && !isContractQuery.data && canImport ? "Address isn't a contract address" : "", children: /* @__PURE__ */ jsx6(
1489
1520
  Input,
1490
1521
  {
1491
1522
  placeholder: intl.formatMessage({
@@ -1529,8 +1560,8 @@ function ImportToken({ close }) {
1529
1560
  size: "lg",
1530
1561
  onClick: onImport,
1531
1562
  block: true,
1532
- loading,
1533
- disabled: !canImport,
1563
+ loading: loading || isContractQuery.isLoading,
1564
+ disabled: !canImport || !isContractQuery.data,
1534
1565
  highlight: true,
1535
1566
  children: /* @__PURE__ */ jsx6(FormattedMessage2, { id: "import" })
1536
1567
  }
@@ -1810,7 +1841,7 @@ function useMatchWalletAssetList({
1810
1841
  name: chain?.nativeCurrency.name,
1811
1842
  balance: 0
1812
1843
  };
1813
- const nativeBalanceQuery = useQuery2({
1844
+ const nativeBalanceQuery = useQuery3({
1814
1845
  queryKey: ["nativeBalance", nativeToken?.chain_id],
1815
1846
  queryFn: async () => {
1816
1847
  if (!nativeToken || !publicClient) return null;
@@ -1830,7 +1861,7 @@ function useMatchWalletAssetList({
1830
1861
  // Retry up to 3 times if failed
1831
1862
  });
1832
1863
  const erc20Tokens = useMemo5(() => list.filter((asset) => asset.address !== NATIVE_TOKEN_ADDRESS), [list]);
1833
- const erc20BalanceQuery = useQuery2({
1864
+ const erc20BalanceQuery = useQuery3({
1834
1865
  queryKey: ["erc20Balances", erc20Tokens.map((token) => token.address)],
1835
1866
  queryFn: async () => {
1836
1867
  if (!erc20Tokens.length || !publicClient) return [];
@@ -1864,11 +1895,12 @@ function useMatchWalletAssetList({
1864
1895
  let balanceValue = "0";
1865
1896
  let balance = 0;
1866
1897
  const decimals = typeof asset.decimals === "string" ? parseInt(asset.decimals) : asset.decimals;
1867
- if (asset.address === NATIVE_TOKEN_ADDRESS) {
1898
+ const assetAddress = asset.address.toLowerCase();
1899
+ if (assetAddress === NATIVE_TOKEN_ADDRESS) {
1868
1900
  balanceValue = nativeBalanceQuery.data?.toString() || "0";
1869
1901
  balance = nativeBalanceQuery.data ? Number(formatUnits2(nativeBalanceQuery.data, decimals)) : 0;
1870
1902
  } else {
1871
- const index = erc20Tokens.findIndex((t) => t.address === asset.address);
1903
+ const index = erc20Tokens.findIndex((t) => t.address.toLowerCase() === assetAddress);
1872
1904
  if (index !== -1 && erc20Balances[index] && erc20Balances[index].status === "success") {
1873
1905
  balance = Number(formatUnits2(erc20Balances[index].result, decimals));
1874
1906
  balanceValue = erc20Balances[index].result?.toString() || "0";
@@ -1904,8 +1936,8 @@ function useMatchWalletAssetList({
1904
1936
 
1905
1937
  // src/hooks/useReceipt.tsx
1906
1938
  import { useState as useState9, useCallback as useCallback4, useEffect as useEffect8 } from "react";
1907
- import { useQuery as useQuery3 } from "@tanstack/react-query";
1908
- import { createPublicClient as createPublicClient3, defineChain, http as http3 } from "viem";
1939
+ import { useQuery as useQuery4 } from "@tanstack/react-query";
1940
+ import { createPublicClient as createPublicClient4, defineChain as defineChain2, http as http4 } from "viem";
1909
1941
  var CACHE_TTL = 86400 * 30 * 1e3;
1910
1942
  var MAX_CACHE_SIZE = 500;
1911
1943
  var STORAGE_KEY = "match_receipt_logs";
@@ -2013,7 +2045,7 @@ function useReceipt({
2013
2045
  const cache = useReceiptCache();
2014
2046
  const chain = list?.find((item) => item.id === chainId);
2015
2047
  const [shouldRefetch, setShouldRefetch] = useState9(true);
2016
- const query = useQuery3({
2048
+ const query = useQuery4({
2017
2049
  queryKey: ["match-tx-receipt", hash, chain],
2018
2050
  queryFn: async () => {
2019
2051
  if (!chain || !hash) return false;
@@ -2022,9 +2054,9 @@ function useReceipt({
2022
2054
  return cache.get(cacheKey);
2023
2055
  }
2024
2056
  try {
2025
- const publicClient = createPublicClient3({
2026
- chain: defineChain(chain),
2027
- transport: http3()
2057
+ const publicClient = createPublicClient4({
2058
+ chain: defineChain2(chain),
2059
+ transport: http4()
2028
2060
  });
2029
2061
  const receipt = await publicClient.getTransactionReceipt({ hash });
2030
2062
  if (!receipt) {
@@ -2048,8 +2080,8 @@ function useReceipt({
2048
2080
 
2049
2081
  // src/hooks/useTransaction.tsx
2050
2082
  import { useState as useState10, useCallback as useCallback5, useEffect as useEffect9 } from "react";
2051
- import { useQuery as useQuery4 } from "@tanstack/react-query";
2052
- import { createPublicClient as createPublicClient4, defineChain as defineChain2, http as http4 } from "viem";
2083
+ import { useQuery as useQuery5 } from "@tanstack/react-query";
2084
+ import { createPublicClient as createPublicClient5, defineChain as defineChain3, http as http5 } from "viem";
2053
2085
  var CACHE_TTL2 = 86400 * 30 * 1e3;
2054
2086
  var MAX_CACHE_SIZE2 = 500;
2055
2087
  var STORAGE_KEY2 = "match_transaction_logs";
@@ -2157,7 +2189,7 @@ function useTransaction({
2157
2189
  const cache = useTransactionCache();
2158
2190
  const chain = list?.find((item) => item.id === chainId);
2159
2191
  const [shouldRefetch, setShouldRefetch] = useState10(true);
2160
- const query = useQuery4({
2192
+ const query = useQuery5({
2161
2193
  queryKey: ["match-tx-transaction", hash, chain],
2162
2194
  queryFn: async () => {
2163
2195
  if (!chain || !hash) return false;
@@ -2166,9 +2198,9 @@ function useTransaction({
2166
2198
  return cache.get(cacheKey);
2167
2199
  }
2168
2200
  try {
2169
- const publicClient = createPublicClient4({
2170
- chain: defineChain2(chain),
2171
- transport: http4()
2201
+ const publicClient = createPublicClient5({
2202
+ chain: defineChain3(chain),
2203
+ transport: http5()
2172
2204
  });
2173
2205
  const transaction = await publicClient.getTransaction({ hash });
2174
2206
  if (!transaction) {
@@ -4024,9 +4056,9 @@ import { useMemo as useMemo9, useState as useState15 } from "react";
4024
4056
  import { FormattedMessage as FormattedMessage6, useIntl as useIntl7 } from "react-intl";
4025
4057
 
4026
4058
  // src/hooks/useAppConfig.ts
4027
- import { useQuery as useQuery5 } from "@tanstack/react-query";
4059
+ import { useQuery as useQuery6 } from "@tanstack/react-query";
4028
4060
  function useAppConfig() {
4029
- const query = useQuery5({
4061
+ const query = useQuery6({
4030
4062
  queryKey: ["appConfig"],
4031
4063
  queryFn: async () => {
4032
4064
  const res = await getAppConfigApi();
@@ -5825,7 +5857,7 @@ function WalletAsset({
5825
5857
 
5826
5858
  // src/components/TokenSend/index.tsx
5827
5859
  import { useEffect as useEffect24, useMemo as useMemo15, useState as useState26 } from "react";
5828
- import { defineChain as defineChain3, encodeFunctionData as encodeFunctionData2, http as http5, parseUnits as parseUnits2 } from "viem";
5860
+ import { defineChain as defineChain4, encodeFunctionData as encodeFunctionData2, http as http6, parseUnits as parseUnits2 } from "viem";
5829
5861
  import { FormattedMessage as FormattedMessage11, useIntl as useIntl16 } from "react-intl";
5830
5862
  import { jsx as jsx30, jsxs as jsxs20 } from "react/jsx-runtime";
5831
5863
  function Input2({
@@ -5868,8 +5900,8 @@ function TokenSend({
5868
5900
  const walletClient = useMemo15(() => {
5869
5901
  return createWalletClient2({
5870
5902
  // @ts-ignore
5871
- chain: defineChain3(chain),
5872
- transport: http5()
5903
+ chain: defineChain4(chain),
5904
+ transport: http6()
5873
5905
  });
5874
5906
  }, [chain]);
5875
5907
  const [amount, setAmount] = useState26("");
@@ -5906,7 +5938,7 @@ function TokenSend({
5906
5938
  "type": "function"
5907
5939
  }
5908
5940
  ];
5909
- const viemChain = defineChain3(chain);
5941
+ const viemChain = defineChain4(chain);
5910
5942
  const to = isNative ? address : token.address;
5911
5943
  const value = isNative ? parseUnits2(amount, parseInt(token?.decimals || "18")) : BigInt(0);
5912
5944
  const data = isNative ? "0x" : encodeFunctionData2({
@@ -6184,7 +6216,7 @@ function TokenSendList({ close }) {
6184
6216
  // src/components/TransactionList/index.tsx
6185
6217
  import InfiniteScroll from "react-infinite-scroll-component";
6186
6218
  import { useEffect as useEffect25, useMemo as useMemo16, useState as useState28 } from "react";
6187
- import { decodeFunctionData, defineChain as defineChain4, formatUnits as formatUnits3 } from "viem";
6219
+ import { decodeFunctionData, defineChain as defineChain5, formatUnits as formatUnits3 } from "viem";
6188
6220
  import { erc20Abi as erc20Abi3 } from "viem";
6189
6221
  import { FormattedMessage as FormattedMessage14 } from "react-intl";
6190
6222
  import { jsx as jsx33, jsxs as jsxs23 } from "react/jsx-runtime";
@@ -6205,6 +6237,9 @@ var Item = ({ data }) => {
6205
6237
  return "unknown";
6206
6238
  }, [data.input]);
6207
6239
  const to = useMemo16(() => {
6240
+ if (!isOut) {
6241
+ return data.from;
6242
+ }
6208
6243
  if (transferType == "erc20_transfer") {
6209
6244
  const decodeData = decodeFunctionData({
6210
6245
  abi: erc20Abi3,
@@ -6213,7 +6248,7 @@ var Item = ({ data }) => {
6213
6248
  return decodeData.args[0];
6214
6249
  }
6215
6250
  return data.to;
6216
- }, [data.input, transferType, data.to]);
6251
+ }, [data.input, transferType, data.to, isOut]);
6217
6252
  const amount = useMemo16(() => {
6218
6253
  if (transferType == "erc20_transfer") {
6219
6254
  const decodeData = decodeFunctionData({
@@ -6228,9 +6263,9 @@ var Item = ({ data }) => {
6228
6263
  const hashQuery = useHash({
6229
6264
  hash: data.hash,
6230
6265
  //@ts-ignore
6231
- chain: defineChain4(chain),
6266
+ chain: defineChain5(chain),
6232
6267
  refetchInterval: shouldRefetch ? 3e3 : false,
6233
- enabled: shouldRefetch
6268
+ enabled: shouldRefetch && data.source == "local"
6234
6269
  });
6235
6270
  const status = useMemo16(() => {
6236
6271
  if (data.source == "matchain") {
@@ -6368,4 +6403,4 @@ export {
6368
6403
  MatchProvider,
6369
6404
  useMatch
6370
6405
  };
6371
- //# sourceMappingURL=chunk-IKLQAPKE.mjs.map
6406
+ //# sourceMappingURL=chunk-OSIGDX4D.mjs.map