@matchain/matchid-sdk-react 0.1.48-alpha.26 → 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.
@@ -12,7 +12,7 @@ import {
12
12
  useTransaction,
13
13
  useUserInfo,
14
14
  useWallet
15
- } from "../chunk-2MJFQXBZ.mjs";
15
+ } from "../chunk-OSIGDX4D.mjs";
16
16
  import "../chunk-UA6XHZHX.mjs";
17
17
  import {
18
18
  useLayout_exports
package/dist/index.js CHANGED
@@ -5724,6 +5724,9 @@ var Item = ({ data }) => {
5724
5724
  return "unknown";
5725
5725
  }, [data.input]);
5726
5726
  const to = (0, import_react32.useMemo)(() => {
5727
+ if (!isOut) {
5728
+ return data.from;
5729
+ }
5727
5730
  if (transferType == "erc20_transfer") {
5728
5731
  const decodeData = (0, import_viem7.decodeFunctionData)({
5729
5732
  abi: import_viem8.erc20Abi,
@@ -5732,7 +5735,7 @@ var Item = ({ data }) => {
5732
5735
  return decodeData.args[0];
5733
5736
  }
5734
5737
  return data.to;
5735
- }, [data.input, transferType, data.to]);
5738
+ }, [data.input, transferType, data.to, isOut]);
5736
5739
  const amount = (0, import_react32.useMemo)(() => {
5737
5740
  if (transferType == "erc20_transfer") {
5738
5741
  const decodeData = (0, import_viem7.decodeFunctionData)({
@@ -5740,7 +5743,7 @@ var Item = ({ data }) => {
5740
5743
  data: data.input
5741
5744
  });
5742
5745
  const value = decodeData.args[1];
5743
- return (0, import_viem7.formatUnits)(value, contracts[`${chainId}-${data.to}`]?.decimals || 18);
5746
+ return (0, import_viem7.formatUnits)(value, contracts[`${chainId}-${data.to.toLowerCase()}`]?.decimals || 18);
5744
5747
  }
5745
5748
  return chainFormatUnits(BigInt(data.value));
5746
5749
  }, [data.input, transferType, data.value, contracts, chainId, data.to]);
@@ -5749,7 +5752,7 @@ var Item = ({ data }) => {
5749
5752
  //@ts-ignore
5750
5753
  chain: (0, import_viem7.defineChain)(chain),
5751
5754
  refetchInterval: shouldRefetch ? 3e3 : false,
5752
- enabled: shouldRefetch
5755
+ enabled: shouldRefetch && data.source == "local"
5753
5756
  });
5754
5757
  const status = (0, import_react32.useMemo)(() => {
5755
5758
  if (data.source == "matchain") {
@@ -5785,8 +5788,8 @@ var Item = ({ data }) => {
5785
5788
  }, [status, data.hash]);
5786
5789
  const symbol = (0, import_react32.useMemo)(() => {
5787
5790
  if (transferType == "erc20_transfer") {
5788
- const contract = contracts[`${chainId}-${data.to}`];
5789
- return contracts?.symbol || contracts?.name || "unknown";
5791
+ const contract = contracts[`${chainId}-${data.to.toLowerCase()}`];
5792
+ return contract?.symbol || contract?.name || "unknown";
5790
5793
  }
5791
5794
  return chain?.nativeCurrency.symbol || chain?.nativeCurrency.name;
5792
5795
  }, [transferType, chain, contracts, chainId, data.to]);
@@ -5844,15 +5847,41 @@ function TransactionList({
5844
5847
  // src/hooks/useMatchWallet.tsx
5845
5848
  var import_react_qrcode = require("react-qrcode");
5846
5849
  var import_react34 = require("react");
5847
- var import_react_query5 = require("@tanstack/react-query");
5848
- var import_viem10 = require("viem");
5850
+ var import_react_query6 = require("@tanstack/react-query");
5851
+ var import_viem11 = require("viem");
5849
5852
  var import_react_intl19 = require("react-intl");
5850
5853
 
5851
5854
  // src/components/ImportToken/index.tsx
5852
5855
  var import_react33 = require("react");
5853
5856
  var import_react_intl18 = require("react-intl");
5854
- var import_react_query4 = require("@tanstack/react-query");
5857
+ var import_react_query5 = require("@tanstack/react-query");
5858
+ var import_viem10 = require("viem");
5859
+
5860
+ // src/hooks/useIsContract.ts
5855
5861
  var import_viem9 = require("viem");
5862
+ var import_react_query4 = require("@tanstack/react-query");
5863
+ function useIsContract({
5864
+ address,
5865
+ chain,
5866
+ enabled
5867
+ }) {
5868
+ return (0, import_react_query4.useQuery)({
5869
+ queryKey: ["is_contract", chain?.id, address],
5870
+ queryFn: async () => {
5871
+ if (!chain) return false;
5872
+ if (!address) return false;
5873
+ const publicClient = (0, import_viem9.createPublicClient)({
5874
+ chain,
5875
+ transport: (0, import_viem9.http)()
5876
+ });
5877
+ const res = await publicClient.getCode({ address });
5878
+ return res !== null && res !== void 0;
5879
+ },
5880
+ enabled
5881
+ });
5882
+ }
5883
+
5884
+ // src/components/ImportToken/index.tsx
5856
5885
  var import_jsx_runtime89 = require("react/jsx-runtime");
5857
5886
  function ImportToken({ close }) {
5858
5887
  const [status, setStatus] = (0, import_react33.useState)("");
@@ -5861,19 +5890,19 @@ function ImportToken({ close }) {
5861
5890
  const [symbol, setSymbol] = (0, import_react33.useState)("");
5862
5891
  const [decimals, setDecimals] = (0, import_react33.useState)("");
5863
5892
  const [error, setError] = (0, import_react33.useState)({});
5864
- const { publicClient, chainId } = useMatchChain();
5893
+ const { publicClient, chainId, chain } = useMatchChain();
5865
5894
  const getContractInfo = async () => {
5866
5895
  if (!publicClient) return;
5867
5896
  const calls = [
5868
5897
  {
5869
5898
  address,
5870
- abi: import_viem9.erc20Abi,
5899
+ abi: import_viem10.erc20Abi,
5871
5900
  functionName: "symbol",
5872
5901
  args: []
5873
5902
  },
5874
5903
  {
5875
5904
  address,
5876
- abi: import_viem9.erc20Abi,
5905
+ abi: import_viem10.erc20Abi,
5877
5906
  functionName: "decimals",
5878
5907
  args: []
5879
5908
  }
@@ -5915,7 +5944,7 @@ function ImportToken({ close }) {
5915
5944
  }, [address, publicClient]);
5916
5945
  const [loading, setLoading] = (0, import_react33.useState)(false);
5917
5946
  const toast = useToast();
5918
- const queryClient2 = (0, import_react_query4.useQueryClient)();
5947
+ const queryClient2 = (0, import_react_query5.useQueryClient)();
5919
5948
  const onImport = async () => {
5920
5949
  setLoading(true);
5921
5950
  try {
@@ -5957,7 +5986,12 @@ function ImportToken({ close }) {
5957
5986
  }
5958
5987
  return true;
5959
5988
  }, [error, address, symbol, decimals]);
5960
- console.log("status", status);
5989
+ const isContractQuery = useIsContract({
5990
+ //@ts-ignore
5991
+ chain: (0, import_viem10.defineChain)(chain),
5992
+ address,
5993
+ enabled: canImport
5994
+ });
5961
5995
  if (status == "success" || status == "fail") {
5962
5996
  return /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("div", { className: `matchid-import-token-result matchid-flex`, children: [
5963
5997
  /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("div", { className: `matchid-import-token-result-box matchid-flex`, children: [
@@ -5971,7 +6005,7 @@ function ImportToken({ close }) {
5971
6005
  /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("div", { className: "matchid-import-token-form", children: [
5972
6006
  /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(Field, { label: intl.formatMessage({
5973
6007
  id: "tokenSmartContract"
5974
- }), error: error.address, children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
6008
+ }), error: error.address ? error.address : isContractQuery.isFetched && !isContractQuery.isLoading && !isContractQuery.data && canImport ? "Address isn't a contract address" : "", children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
5975
6009
  Input,
5976
6010
  {
5977
6011
  placeholder: intl.formatMessage({
@@ -6015,8 +6049,8 @@ function ImportToken({ close }) {
6015
6049
  size: "lg",
6016
6050
  onClick: onImport,
6017
6051
  block: true,
6018
- loading,
6019
- disabled: !canImport,
6052
+ loading: loading || isContractQuery.isLoading,
6053
+ disabled: !canImport || !isContractQuery.data,
6020
6054
  highlight: true,
6021
6055
  children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_react_intl18.FormattedMessage, { id: "import" })
6022
6056
  }
@@ -6138,13 +6172,13 @@ function useMatchWalletRecords() {
6138
6172
  for (const contract of contractUnique) {
6139
6173
  calls.push({
6140
6174
  address: contract,
6141
- abi: import_viem10.erc20Abi,
6175
+ abi: import_viem11.erc20Abi,
6142
6176
  functionName: "symbol",
6143
6177
  args: []
6144
6178
  });
6145
6179
  calls.push({
6146
6180
  address: contract,
6147
- abi: import_viem10.erc20Abi,
6181
+ abi: import_viem11.erc20Abi,
6148
6182
  functionName: "decimals",
6149
6183
  args: []
6150
6184
  });
@@ -6296,7 +6330,7 @@ function useMatchWalletAssetList({
6296
6330
  name: chain?.nativeCurrency.name,
6297
6331
  balance: 0
6298
6332
  };
6299
- const nativeBalanceQuery = (0, import_react_query5.useQuery)({
6333
+ const nativeBalanceQuery = (0, import_react_query6.useQuery)({
6300
6334
  queryKey: ["nativeBalance", nativeToken?.chain_id],
6301
6335
  queryFn: async () => {
6302
6336
  if (!nativeToken || !publicClient) return null;
@@ -6316,13 +6350,13 @@ function useMatchWalletAssetList({
6316
6350
  // Retry up to 3 times if failed
6317
6351
  });
6318
6352
  const erc20Tokens = (0, import_react34.useMemo)(() => list.filter((asset) => asset.address !== NATIVE_TOKEN_ADDRESS), [list]);
6319
- const erc20BalanceQuery = (0, import_react_query5.useQuery)({
6353
+ const erc20BalanceQuery = (0, import_react_query6.useQuery)({
6320
6354
  queryKey: ["erc20Balances", erc20Tokens.map((token) => token.address)],
6321
6355
  queryFn: async () => {
6322
6356
  if (!erc20Tokens.length || !publicClient) return [];
6323
6357
  const calls = erc20Tokens.map((token) => ({
6324
6358
  address: token.address,
6325
- abi: import_viem10.erc20Abi,
6359
+ abi: import_viem11.erc20Abi,
6326
6360
  functionName: "balanceOf",
6327
6361
  args: [address]
6328
6362
  }));
@@ -6350,13 +6384,14 @@ function useMatchWalletAssetList({
6350
6384
  let balanceValue = "0";
6351
6385
  let balance = 0;
6352
6386
  const decimals = typeof asset.decimals === "string" ? parseInt(asset.decimals) : asset.decimals;
6353
- if (asset.address === NATIVE_TOKEN_ADDRESS) {
6387
+ const assetAddress = asset.address.toLowerCase();
6388
+ if (assetAddress === NATIVE_TOKEN_ADDRESS) {
6354
6389
  balanceValue = nativeBalanceQuery.data?.toString() || "0";
6355
- balance = nativeBalanceQuery.data ? Number((0, import_viem10.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
6390
+ balance = nativeBalanceQuery.data ? Number((0, import_viem11.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
6356
6391
  } else {
6357
- const index = erc20Tokens.findIndex((t) => t.address === asset.address);
6392
+ const index = erc20Tokens.findIndex((t) => t.address.toLowerCase() === assetAddress);
6358
6393
  if (index !== -1 && erc20Balances[index] && erc20Balances[index].status === "success") {
6359
- balance = Number((0, import_viem10.formatUnits)(erc20Balances[index].result, decimals));
6394
+ balance = Number((0, import_viem11.formatUnits)(erc20Balances[index].result, decimals));
6360
6395
  balanceValue = erc20Balances[index].result?.toString() || "0";
6361
6396
  }
6362
6397
  }
@@ -6390,8 +6425,8 @@ function useMatchWalletAssetList({
6390
6425
 
6391
6426
  // src/hooks/useReceipt.tsx
6392
6427
  var import_react35 = require("react");
6393
- var import_react_query6 = require("@tanstack/react-query");
6394
- var import_viem11 = require("viem");
6428
+ var import_react_query7 = require("@tanstack/react-query");
6429
+ var import_viem12 = require("viem");
6395
6430
  var CACHE_TTL = 86400 * 30 * 1e3;
6396
6431
  var MAX_CACHE_SIZE = 500;
6397
6432
  var STORAGE_KEY = "match_receipt_logs";
@@ -6499,7 +6534,7 @@ function useReceipt2({
6499
6534
  const cache = useReceiptCache();
6500
6535
  const chain = list?.find((item) => item.id === chainId);
6501
6536
  const [shouldRefetch, setShouldRefetch] = (0, import_react35.useState)(true);
6502
- const query = (0, import_react_query6.useQuery)({
6537
+ const query = (0, import_react_query7.useQuery)({
6503
6538
  queryKey: ["match-tx-receipt", hash, chain],
6504
6539
  queryFn: async () => {
6505
6540
  if (!chain || !hash) return false;
@@ -6508,9 +6543,9 @@ function useReceipt2({
6508
6543
  return cache.get(cacheKey);
6509
6544
  }
6510
6545
  try {
6511
- const publicClient = (0, import_viem11.createPublicClient)({
6512
- chain: (0, import_viem11.defineChain)(chain),
6513
- transport: (0, import_viem11.http)()
6546
+ const publicClient = (0, import_viem12.createPublicClient)({
6547
+ chain: (0, import_viem12.defineChain)(chain),
6548
+ transport: (0, import_viem12.http)()
6514
6549
  });
6515
6550
  const receipt = await publicClient.getTransactionReceipt({ hash });
6516
6551
  if (!receipt) {
@@ -6534,8 +6569,8 @@ function useReceipt2({
6534
6569
 
6535
6570
  // src/hooks/useTransaction.tsx
6536
6571
  var import_react36 = require("react");
6537
- var import_react_query7 = require("@tanstack/react-query");
6538
- var import_viem12 = require("viem");
6572
+ var import_react_query8 = require("@tanstack/react-query");
6573
+ var import_viem13 = require("viem");
6539
6574
  var CACHE_TTL2 = 86400 * 30 * 1e3;
6540
6575
  var MAX_CACHE_SIZE2 = 500;
6541
6576
  var STORAGE_KEY2 = "match_transaction_logs";
@@ -6643,7 +6678,7 @@ function useTransaction({
6643
6678
  const cache = useTransactionCache();
6644
6679
  const chain = list?.find((item) => item.id === chainId);
6645
6680
  const [shouldRefetch, setShouldRefetch] = (0, import_react36.useState)(true);
6646
- const query = (0, import_react_query7.useQuery)({
6681
+ const query = (0, import_react_query8.useQuery)({
6647
6682
  queryKey: ["match-tx-transaction", hash, chain],
6648
6683
  queryFn: async () => {
6649
6684
  if (!chain || !hash) return false;
@@ -6652,9 +6687,9 @@ function useTransaction({
6652
6687
  return cache.get(cacheKey);
6653
6688
  }
6654
6689
  try {
6655
- const publicClient = (0, import_viem12.createPublicClient)({
6656
- chain: (0, import_viem12.defineChain)(chain),
6657
- transport: (0, import_viem12.http)()
6690
+ const publicClient = (0, import_viem13.createPublicClient)({
6691
+ chain: (0, import_viem13.defineChain)(chain),
6692
+ transport: (0, import_viem13.http)()
6658
6693
  });
6659
6694
  const transaction = await publicClient.getTransaction({ hash });
6660
6695
  if (!transaction) {
@@ -7225,7 +7260,7 @@ function useInit({
7225
7260
  }
7226
7261
 
7227
7262
  // src/MatchContext.tsx
7228
- var import_react_query8 = require("@tanstack/react-query");
7263
+ var import_react_query9 = require("@tanstack/react-query");
7229
7264
  var import_react_intl21 = require("react-intl");
7230
7265
 
7231
7266
  // src/i18n/en.json
@@ -7963,7 +7998,7 @@ var messages = {
7963
7998
 
7964
7999
  // src/MatchContext.tsx
7965
8000
  var import_jsx_runtime94 = require("react/jsx-runtime");
7966
- var queryClient = new import_react_query8.QueryClient();
8001
+ var queryClient = new import_react_query9.QueryClient();
7967
8002
  var MatchContext = (0, import_react40.createContext)(void 0);
7968
8003
  var MatchProvider = ({
7969
8004
  children,
@@ -7984,7 +8019,7 @@ var MatchProvider = ({
7984
8019
  useWalletInit({
7985
8020
  config: wallet
7986
8021
  });
7987
- return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_intl21.IntlProvider, { locale: realLocale, messages: messages[realLocale], children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_query8.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
8022
+ return /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_intl21.IntlProvider, { locale: realLocale, messages: messages[realLocale], children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_react_query9.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
7988
8023
  MatchContext.Provider,
7989
8024
  {
7990
8025
  value: {
@@ -8026,10 +8061,10 @@ __export(bind_exports, {
8026
8061
  useBindInfo: () => useBindInfo,
8027
8062
  useBindList: () => useBindList
8028
8063
  });
8029
- var import_react_query9 = require("@tanstack/react-query");
8064
+ var import_react_query10 = require("@tanstack/react-query");
8030
8065
  function useBindList(options) {
8031
8066
  const { isLogin } = useUserInfo();
8032
- return (0, import_react_query9.useQuery)({
8067
+ return (0, import_react_query10.useQuery)({
8033
8068
  queryKey: ["bindList"],
8034
8069
  enabled: isLogin,
8035
8070
  queryFn: async () => {
@@ -8041,7 +8076,7 @@ function useBindList(options) {
8041
8076
  }
8042
8077
  function useBindInfo(options) {
8043
8078
  const { isLogin } = useUserInfo();
8044
- return (0, import_react_query9.useQuery)({
8079
+ return (0, import_react_query10.useQuery)({
8045
8080
  queryKey: ["bindInfo"],
8046
8081
  enabled: isLogin,
8047
8082
  queryFn: async () => {
@@ -8058,10 +8093,10 @@ __export(poh_exports, {
8058
8093
  usePohList: () => usePohList,
8059
8094
  verifyPohApi: () => verifyPohApi
8060
8095
  });
8061
- var import_react_query10 = require("@tanstack/react-query");
8096
+ var import_react_query11 = require("@tanstack/react-query");
8062
8097
  function usePohList(options) {
8063
8098
  const { isLogin } = useUserInfo();
8064
- return (0, import_react_query10.useQuery)({
8099
+ return (0, import_react_query11.useQuery)({
8065
8100
  queryKey: ["pohList"],
8066
8101
  enabled: isLogin,
8067
8102
  queryFn: async () => {
@@ -8087,8 +8122,8 @@ __export(chains_exports, {
8087
8122
  });
8088
8123
 
8089
8124
  // src/config/chains/MatchMain.ts
8090
- var import_viem13 = require("viem");
8091
- var matchMain = /* @__PURE__ */ (0, import_viem13.defineChain)({
8125
+ var import_viem14 = require("viem");
8126
+ var matchMain = /* @__PURE__ */ (0, import_viem14.defineChain)({
8092
8127
  //定义match链
8093
8128
  id: 698,
8094
8129
  name: "Matchain",
@@ -8115,8 +8150,8 @@ var matchMain = /* @__PURE__ */ (0, import_viem13.defineChain)({
8115
8150
  });
8116
8151
 
8117
8152
  // src/config/chains/MatchTest.ts
8118
- var import_viem14 = require("viem");
8119
- var matchTest = /* @__PURE__ */ (0, import_viem14.defineChain)({
8153
+ var import_viem15 = require("viem");
8154
+ var matchTest = /* @__PURE__ */ (0, import_viem15.defineChain)({
8120
8155
  //定义matchTest链
8121
8156
  id: 699,
8122
8157
  name: "MatchTest",