@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.
@@ -12,7 +12,7 @@ import {
12
12
  useTransaction,
13
13
  useUserInfo,
14
14
  useWallet
15
- } from "../chunk-IKLQAPKE.mjs";
15
+ } from "../chunk-ZHBFW26I.mjs";
16
16
  import "../chunk-UA6XHZHX.mjs";
17
17
  import {
18
18
  useLayout_exports
package/dist/index.js CHANGED
@@ -5339,39 +5339,15 @@ function TokenSend({
5339
5339
  const [sending, setSending] = (0, import_react30.useState)(false);
5340
5340
  const [txError, setTxError] = (0, import_react30.useState)("");
5341
5341
  const transaction = (0, import_react30.useMemo)(() => {
5342
- if (!amount || !address) {
5342
+ const reg = /^0x[a-fA-F0-9]{40}$/;
5343
+ if (!amount || !address || !reg.test(address)) {
5343
5344
  return;
5344
5345
  }
5345
- const abi = [
5346
- {
5347
- "constant": false,
5348
- "inputs": [
5349
- {
5350
- "name": "_to",
5351
- "type": "address"
5352
- },
5353
- {
5354
- "name": "_value",
5355
- "type": "uint256"
5356
- }
5357
- ],
5358
- "name": "transfer",
5359
- "outputs": [
5360
- {
5361
- "name": "",
5362
- "type": "bool"
5363
- }
5364
- ],
5365
- "payable": false,
5366
- "stateMutability": "nonpayable",
5367
- "type": "function"
5368
- }
5369
- ];
5370
5346
  const viemChain = (0, import_viem6.defineChain)(chain);
5371
5347
  const to = isNative ? address : token.address;
5372
5348
  const value = isNative ? (0, import_viem6.parseUnits)(amount, parseInt(token?.decimals || "18")) : BigInt(0);
5373
5349
  const data = isNative ? "0x" : (0, import_viem6.encodeFunctionData)({
5374
- abi,
5350
+ abi: import_viem6.erc20Abi,
5375
5351
  functionName: "transfer",
5376
5352
  args: [address, (0, import_viem6.parseUnits)(amount, parseInt(token?.decimals || "18"))]
5377
5353
  });
@@ -5724,6 +5700,9 @@ var Item = ({ data }) => {
5724
5700
  return "unknown";
5725
5701
  }, [data.input]);
5726
5702
  const to = (0, import_react32.useMemo)(() => {
5703
+ if (!isOut) {
5704
+ return data.from;
5705
+ }
5727
5706
  if (transferType == "erc20_transfer") {
5728
5707
  const decodeData = (0, import_viem7.decodeFunctionData)({
5729
5708
  abi: import_viem8.erc20Abi,
@@ -5732,7 +5711,7 @@ var Item = ({ data }) => {
5732
5711
  return decodeData.args[0];
5733
5712
  }
5734
5713
  return data.to;
5735
- }, [data.input, transferType, data.to]);
5714
+ }, [data.input, transferType, data.to, isOut]);
5736
5715
  const amount = (0, import_react32.useMemo)(() => {
5737
5716
  if (transferType == "erc20_transfer") {
5738
5717
  const decodeData = (0, import_viem7.decodeFunctionData)({
@@ -5749,7 +5728,7 @@ var Item = ({ data }) => {
5749
5728
  //@ts-ignore
5750
5729
  chain: (0, import_viem7.defineChain)(chain),
5751
5730
  refetchInterval: shouldRefetch ? 3e3 : false,
5752
- enabled: shouldRefetch
5731
+ enabled: shouldRefetch && data.source == "local"
5753
5732
  });
5754
5733
  const status = (0, import_react32.useMemo)(() => {
5755
5734
  if (data.source == "matchain") {
@@ -5844,15 +5823,41 @@ function TransactionList({
5844
5823
  // src/hooks/useMatchWallet.tsx
5845
5824
  var import_react_qrcode = require("react-qrcode");
5846
5825
  var import_react34 = require("react");
5847
- var import_react_query5 = require("@tanstack/react-query");
5848
- var import_viem10 = require("viem");
5826
+ var import_react_query6 = require("@tanstack/react-query");
5827
+ var import_viem11 = require("viem");
5849
5828
  var import_react_intl19 = require("react-intl");
5850
5829
 
5851
5830
  // src/components/ImportToken/index.tsx
5852
5831
  var import_react33 = require("react");
5853
5832
  var import_react_intl18 = require("react-intl");
5854
- var import_react_query4 = require("@tanstack/react-query");
5833
+ var import_react_query5 = require("@tanstack/react-query");
5834
+ var import_viem10 = require("viem");
5835
+
5836
+ // src/hooks/useIsContract.ts
5855
5837
  var import_viem9 = require("viem");
5838
+ var import_react_query4 = require("@tanstack/react-query");
5839
+ function useIsContract({
5840
+ address,
5841
+ chain,
5842
+ enabled
5843
+ }) {
5844
+ return (0, import_react_query4.useQuery)({
5845
+ queryKey: ["is_contract", chain?.id, address],
5846
+ queryFn: async () => {
5847
+ if (!chain) return false;
5848
+ if (!address) return false;
5849
+ const publicClient = (0, import_viem9.createPublicClient)({
5850
+ chain,
5851
+ transport: (0, import_viem9.http)()
5852
+ });
5853
+ const res = await publicClient.getCode({ address });
5854
+ return res !== null && res !== void 0;
5855
+ },
5856
+ enabled
5857
+ });
5858
+ }
5859
+
5860
+ // src/components/ImportToken/index.tsx
5856
5861
  var import_jsx_runtime89 = require("react/jsx-runtime");
5857
5862
  function ImportToken({ close }) {
5858
5863
  const [status, setStatus] = (0, import_react33.useState)("");
@@ -5861,19 +5866,19 @@ function ImportToken({ close }) {
5861
5866
  const [symbol, setSymbol] = (0, import_react33.useState)("");
5862
5867
  const [decimals, setDecimals] = (0, import_react33.useState)("");
5863
5868
  const [error, setError] = (0, import_react33.useState)({});
5864
- const { publicClient, chainId } = useMatchChain();
5869
+ const { publicClient, chainId, chain } = useMatchChain();
5865
5870
  const getContractInfo = async () => {
5866
5871
  if (!publicClient) return;
5867
5872
  const calls = [
5868
5873
  {
5869
5874
  address,
5870
- abi: import_viem9.erc20Abi,
5875
+ abi: import_viem10.erc20Abi,
5871
5876
  functionName: "symbol",
5872
5877
  args: []
5873
5878
  },
5874
5879
  {
5875
5880
  address,
5876
- abi: import_viem9.erc20Abi,
5881
+ abi: import_viem10.erc20Abi,
5877
5882
  functionName: "decimals",
5878
5883
  args: []
5879
5884
  }
@@ -5915,7 +5920,7 @@ function ImportToken({ close }) {
5915
5920
  }, [address, publicClient]);
5916
5921
  const [loading, setLoading] = (0, import_react33.useState)(false);
5917
5922
  const toast = useToast();
5918
- const queryClient2 = (0, import_react_query4.useQueryClient)();
5923
+ const queryClient2 = (0, import_react_query5.useQueryClient)();
5919
5924
  const onImport = async () => {
5920
5925
  setLoading(true);
5921
5926
  try {
@@ -5957,7 +5962,12 @@ function ImportToken({ close }) {
5957
5962
  }
5958
5963
  return true;
5959
5964
  }, [error, address, symbol, decimals]);
5960
- console.log("status", status);
5965
+ const isContractQuery = useIsContract({
5966
+ //@ts-ignore
5967
+ chain: (0, import_viem10.defineChain)(chain),
5968
+ address,
5969
+ enabled: canImport
5970
+ });
5961
5971
  if (status == "success" || status == "fail") {
5962
5972
  return /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("div", { className: `matchid-import-token-result matchid-flex`, children: [
5963
5973
  /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("div", { className: `matchid-import-token-result-box matchid-flex`, children: [
@@ -5971,7 +5981,7 @@ function ImportToken({ close }) {
5971
5981
  /* @__PURE__ */ (0, import_jsx_runtime89.jsxs)("div", { className: "matchid-import-token-form", children: [
5972
5982
  /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(Field, { label: intl.formatMessage({
5973
5983
  id: "tokenSmartContract"
5974
- }), error: error.address, children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
5984
+ }), 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
5985
  Input,
5976
5986
  {
5977
5987
  placeholder: intl.formatMessage({
@@ -6015,8 +6025,8 @@ function ImportToken({ close }) {
6015
6025
  size: "lg",
6016
6026
  onClick: onImport,
6017
6027
  block: true,
6018
- loading,
6019
- disabled: !canImport,
6028
+ loading: loading || isContractQuery.isLoading,
6029
+ disabled: !canImport || !isContractQuery.data,
6020
6030
  highlight: true,
6021
6031
  children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_react_intl18.FormattedMessage, { id: "import" })
6022
6032
  }
@@ -6138,13 +6148,13 @@ function useMatchWalletRecords() {
6138
6148
  for (const contract of contractUnique) {
6139
6149
  calls.push({
6140
6150
  address: contract,
6141
- abi: import_viem10.erc20Abi,
6151
+ abi: import_viem11.erc20Abi,
6142
6152
  functionName: "symbol",
6143
6153
  args: []
6144
6154
  });
6145
6155
  calls.push({
6146
6156
  address: contract,
6147
- abi: import_viem10.erc20Abi,
6157
+ abi: import_viem11.erc20Abi,
6148
6158
  functionName: "decimals",
6149
6159
  args: []
6150
6160
  });
@@ -6296,7 +6306,7 @@ function useMatchWalletAssetList({
6296
6306
  name: chain?.nativeCurrency.name,
6297
6307
  balance: 0
6298
6308
  };
6299
- const nativeBalanceQuery = (0, import_react_query5.useQuery)({
6309
+ const nativeBalanceQuery = (0, import_react_query6.useQuery)({
6300
6310
  queryKey: ["nativeBalance", nativeToken?.chain_id],
6301
6311
  queryFn: async () => {
6302
6312
  if (!nativeToken || !publicClient) return null;
@@ -6316,13 +6326,13 @@ function useMatchWalletAssetList({
6316
6326
  // Retry up to 3 times if failed
6317
6327
  });
6318
6328
  const erc20Tokens = (0, import_react34.useMemo)(() => list.filter((asset) => asset.address !== NATIVE_TOKEN_ADDRESS), [list]);
6319
- const erc20BalanceQuery = (0, import_react_query5.useQuery)({
6329
+ const erc20BalanceQuery = (0, import_react_query6.useQuery)({
6320
6330
  queryKey: ["erc20Balances", erc20Tokens.map((token) => token.address)],
6321
6331
  queryFn: async () => {
6322
6332
  if (!erc20Tokens.length || !publicClient) return [];
6323
6333
  const calls = erc20Tokens.map((token) => ({
6324
6334
  address: token.address,
6325
- abi: import_viem10.erc20Abi,
6335
+ abi: import_viem11.erc20Abi,
6326
6336
  functionName: "balanceOf",
6327
6337
  args: [address]
6328
6338
  }));
@@ -6350,13 +6360,14 @@ function useMatchWalletAssetList({
6350
6360
  let balanceValue = "0";
6351
6361
  let balance = 0;
6352
6362
  const decimals = typeof asset.decimals === "string" ? parseInt(asset.decimals) : asset.decimals;
6353
- if (asset.address === NATIVE_TOKEN_ADDRESS) {
6363
+ const assetAddress = asset.address.toLowerCase();
6364
+ if (assetAddress === NATIVE_TOKEN_ADDRESS) {
6354
6365
  balanceValue = nativeBalanceQuery.data?.toString() || "0";
6355
- balance = nativeBalanceQuery.data ? Number((0, import_viem10.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
6366
+ balance = nativeBalanceQuery.data ? Number((0, import_viem11.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
6356
6367
  } else {
6357
- const index = erc20Tokens.findIndex((t) => t.address === asset.address);
6368
+ const index = erc20Tokens.findIndex((t) => t.address.toLowerCase() === assetAddress);
6358
6369
  if (index !== -1 && erc20Balances[index] && erc20Balances[index].status === "success") {
6359
- balance = Number((0, import_viem10.formatUnits)(erc20Balances[index].result, decimals));
6370
+ balance = Number((0, import_viem11.formatUnits)(erc20Balances[index].result, decimals));
6360
6371
  balanceValue = erc20Balances[index].result?.toString() || "0";
6361
6372
  }
6362
6373
  }
@@ -6390,8 +6401,8 @@ function useMatchWalletAssetList({
6390
6401
 
6391
6402
  // src/hooks/useReceipt.tsx
6392
6403
  var import_react35 = require("react");
6393
- var import_react_query6 = require("@tanstack/react-query");
6394
- var import_viem11 = require("viem");
6404
+ var import_react_query7 = require("@tanstack/react-query");
6405
+ var import_viem12 = require("viem");
6395
6406
  var CACHE_TTL = 86400 * 30 * 1e3;
6396
6407
  var MAX_CACHE_SIZE = 500;
6397
6408
  var STORAGE_KEY = "match_receipt_logs";
@@ -6499,7 +6510,7 @@ function useReceipt2({
6499
6510
  const cache = useReceiptCache();
6500
6511
  const chain = list?.find((item) => item.id === chainId);
6501
6512
  const [shouldRefetch, setShouldRefetch] = (0, import_react35.useState)(true);
6502
- const query = (0, import_react_query6.useQuery)({
6513
+ const query = (0, import_react_query7.useQuery)({
6503
6514
  queryKey: ["match-tx-receipt", hash, chain],
6504
6515
  queryFn: async () => {
6505
6516
  if (!chain || !hash) return false;
@@ -6508,9 +6519,9 @@ function useReceipt2({
6508
6519
  return cache.get(cacheKey);
6509
6520
  }
6510
6521
  try {
6511
- const publicClient = (0, import_viem11.createPublicClient)({
6512
- chain: (0, import_viem11.defineChain)(chain),
6513
- transport: (0, import_viem11.http)()
6522
+ const publicClient = (0, import_viem12.createPublicClient)({
6523
+ chain: (0, import_viem12.defineChain)(chain),
6524
+ transport: (0, import_viem12.http)()
6514
6525
  });
6515
6526
  const receipt = await publicClient.getTransactionReceipt({ hash });
6516
6527
  if (!receipt) {
@@ -6534,8 +6545,8 @@ function useReceipt2({
6534
6545
 
6535
6546
  // src/hooks/useTransaction.tsx
6536
6547
  var import_react36 = require("react");
6537
- var import_react_query7 = require("@tanstack/react-query");
6538
- var import_viem12 = require("viem");
6548
+ var import_react_query8 = require("@tanstack/react-query");
6549
+ var import_viem13 = require("viem");
6539
6550
  var CACHE_TTL2 = 86400 * 30 * 1e3;
6540
6551
  var MAX_CACHE_SIZE2 = 500;
6541
6552
  var STORAGE_KEY2 = "match_transaction_logs";
@@ -6643,7 +6654,7 @@ function useTransaction({
6643
6654
  const cache = useTransactionCache();
6644
6655
  const chain = list?.find((item) => item.id === chainId);
6645
6656
  const [shouldRefetch, setShouldRefetch] = (0, import_react36.useState)(true);
6646
- const query = (0, import_react_query7.useQuery)({
6657
+ const query = (0, import_react_query8.useQuery)({
6647
6658
  queryKey: ["match-tx-transaction", hash, chain],
6648
6659
  queryFn: async () => {
6649
6660
  if (!chain || !hash) return false;
@@ -6652,9 +6663,9 @@ function useTransaction({
6652
6663
  return cache.get(cacheKey);
6653
6664
  }
6654
6665
  try {
6655
- const publicClient = (0, import_viem12.createPublicClient)({
6656
- chain: (0, import_viem12.defineChain)(chain),
6657
- transport: (0, import_viem12.http)()
6666
+ const publicClient = (0, import_viem13.createPublicClient)({
6667
+ chain: (0, import_viem13.defineChain)(chain),
6668
+ transport: (0, import_viem13.http)()
6658
6669
  });
6659
6670
  const transaction = await publicClient.getTransaction({ hash });
6660
6671
  if (!transaction) {
@@ -7225,7 +7236,7 @@ function useInit({
7225
7236
  }
7226
7237
 
7227
7238
  // src/MatchContext.tsx
7228
- var import_react_query8 = require("@tanstack/react-query");
7239
+ var import_react_query9 = require("@tanstack/react-query");
7229
7240
  var import_react_intl21 = require("react-intl");
7230
7241
 
7231
7242
  // src/i18n/en.json
@@ -7963,7 +7974,7 @@ var messages = {
7963
7974
 
7964
7975
  // src/MatchContext.tsx
7965
7976
  var import_jsx_runtime94 = require("react/jsx-runtime");
7966
- var queryClient = new import_react_query8.QueryClient();
7977
+ var queryClient = new import_react_query9.QueryClient();
7967
7978
  var MatchContext = (0, import_react40.createContext)(void 0);
7968
7979
  var MatchProvider = ({
7969
7980
  children,
@@ -7984,7 +7995,7 @@ var MatchProvider = ({
7984
7995
  useWalletInit({
7985
7996
  config: wallet
7986
7997
  });
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)(
7998
+ 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
7999
  MatchContext.Provider,
7989
8000
  {
7990
8001
  value: {
@@ -8026,10 +8037,10 @@ __export(bind_exports, {
8026
8037
  useBindInfo: () => useBindInfo,
8027
8038
  useBindList: () => useBindList
8028
8039
  });
8029
- var import_react_query9 = require("@tanstack/react-query");
8040
+ var import_react_query10 = require("@tanstack/react-query");
8030
8041
  function useBindList(options) {
8031
8042
  const { isLogin } = useUserInfo();
8032
- return (0, import_react_query9.useQuery)({
8043
+ return (0, import_react_query10.useQuery)({
8033
8044
  queryKey: ["bindList"],
8034
8045
  enabled: isLogin,
8035
8046
  queryFn: async () => {
@@ -8041,7 +8052,7 @@ function useBindList(options) {
8041
8052
  }
8042
8053
  function useBindInfo(options) {
8043
8054
  const { isLogin } = useUserInfo();
8044
- return (0, import_react_query9.useQuery)({
8055
+ return (0, import_react_query10.useQuery)({
8045
8056
  queryKey: ["bindInfo"],
8046
8057
  enabled: isLogin,
8047
8058
  queryFn: async () => {
@@ -8058,10 +8069,10 @@ __export(poh_exports, {
8058
8069
  usePohList: () => usePohList,
8059
8070
  verifyPohApi: () => verifyPohApi
8060
8071
  });
8061
- var import_react_query10 = require("@tanstack/react-query");
8072
+ var import_react_query11 = require("@tanstack/react-query");
8062
8073
  function usePohList(options) {
8063
8074
  const { isLogin } = useUserInfo();
8064
- return (0, import_react_query10.useQuery)({
8075
+ return (0, import_react_query11.useQuery)({
8065
8076
  queryKey: ["pohList"],
8066
8077
  enabled: isLogin,
8067
8078
  queryFn: async () => {
@@ -8087,8 +8098,8 @@ __export(chains_exports, {
8087
8098
  });
8088
8099
 
8089
8100
  // src/config/chains/MatchMain.ts
8090
- var import_viem13 = require("viem");
8091
- var matchMain = /* @__PURE__ */ (0, import_viem13.defineChain)({
8101
+ var import_viem14 = require("viem");
8102
+ var matchMain = /* @__PURE__ */ (0, import_viem14.defineChain)({
8092
8103
  //定义match链
8093
8104
  id: 698,
8094
8105
  name: "Matchain",
@@ -8115,8 +8126,8 @@ var matchMain = /* @__PURE__ */ (0, import_viem13.defineChain)({
8115
8126
  });
8116
8127
 
8117
8128
  // src/config/chains/MatchTest.ts
8118
- var import_viem14 = require("viem");
8119
- var matchTest = /* @__PURE__ */ (0, import_viem14.defineChain)({
8129
+ var import_viem15 = require("viem");
8130
+ var matchTest = /* @__PURE__ */ (0, import_viem15.defineChain)({
8120
8131
  //定义matchTest链
8121
8132
  id: 699,
8122
8133
  name: "MatchTest",