@matchain/matchid-sdk-react 0.1.48-alpha.7 → 0.1.48-alpha.8

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.
Files changed (50) hide show
  1. package/dist/assets/icon/index.d.mts +1 -1
  2. package/dist/assets/icon/index.d.ts +1 -1
  3. package/dist/{chunk-2CK7JQWH.mjs → chunk-EY6NPX4M.mjs} +240 -41
  4. package/dist/chunk-EY6NPX4M.mjs.map +1 -0
  5. package/dist/{chunk-YXPWZXPT.mjs → chunk-J5U7AXYA.mjs} +2 -2
  6. package/dist/components/index.d.mts +3 -3
  7. package/dist/components/index.d.ts +3 -3
  8. package/dist/components/index.js +3 -2
  9. package/dist/components/index.js.map +1 -1
  10. package/dist/components/index.mjs +1 -1
  11. package/dist/hooks/api/index.d.mts +2 -2
  12. package/dist/hooks/api/index.d.ts +2 -2
  13. package/dist/hooks/api/index.js +33 -2
  14. package/dist/hooks/api/index.js.map +1 -1
  15. package/dist/hooks/api/index.mjs +2 -2
  16. package/dist/hooks/index.d.mts +3 -2
  17. package/dist/hooks/index.d.ts +3 -2
  18. package/dist/hooks/index.js +299 -41
  19. package/dist/hooks/index.js.map +1 -1
  20. package/dist/hooks/index.mjs +1 -1
  21. package/dist/{index-DCeOyAw8.d.ts → index-Bbn2Stvu.d.ts} +2 -2
  22. package/dist/index-Bz53bbI_.d.ts +3268 -0
  23. package/dist/{index-B8DYrhSW.d.mts → index-C-YCr0xJ.d.mts} +12 -4
  24. package/dist/{index-DbG5IjhP.d.mts → index-CB4j_ONH.d.mts} +1 -1
  25. package/dist/{index-B-s1k4Da.d.mts → index-CKyWWkzU.d.mts} +3 -2
  26. package/dist/{index-BZrddrq-.d.mts → index-C_S7k6z2.d.mts} +2 -2
  27. package/dist/{index-BHvCA7F9.d.ts → index-D-uNr-JV.d.ts} +2 -2
  28. package/dist/index-DDV4F9ka.d.mts +3268 -0
  29. package/dist/{index-DG_gyw1q.d.ts → index-DV_mRu4y.d.ts} +3 -2
  30. package/dist/{index-Bzcc-y8m.d.ts → index-DcxdJ0m2.d.ts} +1 -1
  31. package/dist/{index-BvLpvebq.d.mts → index-Dzvj-uGt.d.mts} +2 -2
  32. package/dist/{index-Cwx2p8th.d.ts → index-zRpvDpIK.d.ts} +12 -4
  33. package/dist/index.css +11 -0
  34. package/dist/index.d.mts +8 -7
  35. package/dist/index.d.ts +8 -7
  36. package/dist/index.js +244 -45
  37. package/dist/index.js.map +1 -1
  38. package/dist/index.mjs +2 -2
  39. package/dist/types/index.d.mts +1 -1
  40. package/dist/types/index.d.ts +1 -1
  41. package/dist/{types-CHkU0WHZ.d.mts → types-B4BYNw8B.d.mts} +13 -2
  42. package/dist/{types-CHkU0WHZ.d.ts → types-B4BYNw8B.d.ts} +13 -2
  43. package/dist/ui/index.d.mts +3 -3
  44. package/dist/ui/index.d.ts +3 -3
  45. package/example/src/pages/Wallet/components/MatchWallet.tsx +2 -1
  46. package/package.json +1 -1
  47. package/dist/chunk-2CK7JQWH.mjs.map +0 -1
  48. package/dist/index-DaEFoDv_.d.ts +0 -187
  49. package/dist/index-DktvxNJc.d.mts +0 -187
  50. /package/dist/{chunk-YXPWZXPT.mjs.map → chunk-J5U7AXYA.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React, { CSSProperties } from 'react';
3
- import { r as IconProps$1 } from '../../types-CHkU0WHZ.mjs';
3
+ import { r as IconProps$1 } from '../../types-B4BYNw8B.mjs';
4
4
 
5
5
  declare function BackIcon({ color, size, className, style }: {
6
6
  color?: string;
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React, { CSSProperties } from 'react';
3
- import { r as IconProps$1 } from '../../types-CHkU0WHZ.js';
3
+ import { r as IconProps$1 } from '../../types-B4BYNw8B.js';
4
4
 
5
5
  declare function BackIcon({ color, size, className, style }: {
6
6
  color?: string;
@@ -526,6 +526,13 @@ var getWalletChainListApi = () => {
526
526
  method: "POST"
527
527
  });
528
528
  };
529
+ var getWalletNftListApi = (data) => {
530
+ return request_default({
531
+ url: `/api/v1/wallet/nfts`,
532
+ method: "POST",
533
+ data
534
+ });
535
+ };
529
536
 
530
537
  // src/store/useLocalStore.ts
531
538
  var persistedState = persist(
@@ -1097,6 +1104,7 @@ __export(wallet_exports, {
1097
1104
  useChainListQuery: () => useChainListQuery,
1098
1105
  useImportTokenListQuery: () => useImportTokenListQuery,
1099
1106
  useWalletChainListQuery: () => useWalletChainListQuery,
1107
+ useWalletNftListQuery: () => useWalletNftListQuery,
1100
1108
  userImportTokenApi: () => userImportTokenApi
1101
1109
  });
1102
1110
  import { useQuery } from "@tanstack/react-query";
@@ -1166,9 +1174,32 @@ function useWalletChainListQuery(options) {
1166
1174
  ...options
1167
1175
  });
1168
1176
  }
1177
+ function useWalletNftListQuery({
1178
+ chainId,
1179
+ address: address2,
1180
+ ...options
1181
+ }) {
1182
+ const { isLogin, token } = useUserInfo();
1183
+ return useQuery({
1184
+ queryKey: ["match-wallet-nft-list", token, chainId, address2],
1185
+ queryFn: async () => {
1186
+ const res = await getWalletNftListApi({
1187
+ chain_id: chainId.toString(),
1188
+ address: address2
1189
+ });
1190
+ if (!isSuccess(res)) {
1191
+ return [];
1192
+ }
1193
+ return res.data;
1194
+ },
1195
+ enabled: isLogin,
1196
+ ...options
1197
+ });
1198
+ }
1169
1199
 
1170
1200
  // src/hooks/useMatchChain.tsx
1171
1201
  import { useMemo as useMemo3, useState as useState6 } from "react";
1202
+ import { createPublicClient, http } from "viem";
1172
1203
  import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1173
1204
  function useMatchChain() {
1174
1205
  const chainListQuery = useChainListQuery();
@@ -1228,69 +1259,239 @@ function useMatchChain() {
1228
1259
  content: ChangeNetwork
1229
1260
  });
1230
1261
  };
1262
+ const publicClient = useMemo3(() => {
1263
+ if (!chain) {
1264
+ return null;
1265
+ }
1266
+ return createPublicClient({
1267
+ chain,
1268
+ transport: http()
1269
+ });
1270
+ }, [chain]);
1231
1271
  return {
1232
1272
  list: chainListQuery.data,
1233
1273
  chainId,
1234
1274
  setChainId,
1235
1275
  chain,
1236
1276
  explorerLink,
1237
- showChangeNetwork
1277
+ showChangeNetwork,
1278
+ publicClient
1238
1279
  };
1239
1280
  }
1240
1281
 
1241
1282
  // src/hooks/useMatchWallet.tsx
1242
1283
  import { QRCode } from "react-qrcode";
1243
- import { useEffect as useEffect6, useRef, useState as useState7 } from "react";
1284
+ import { useEffect as useEffect6, useMemo as useMemo4, useRef, useState as useState7 } from "react";
1244
1285
 
1245
1286
  // example/src/config/contract.ts
1246
1287
  var address = "0x4143e29770fd63e24bb1f32d50bf8a590e34de4b";
1247
1288
 
1248
1289
  // src/hooks/useMatchWallet.tsx
1249
1290
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1250
- function useMatchWallet() {
1251
- const modal = useModal();
1252
- const { address: address2 } = useWallet();
1291
+ var ReceiveModal = () => {
1253
1292
  const chain = useMatchChain();
1293
+ const { address: address2 } = useWallet();
1254
1294
  const [copied, setCopied] = useCopyClipboard();
1255
1295
  const toast = useToast();
1256
1296
  const onCopy = () => {
1257
1297
  setCopied(address2);
1258
1298
  toast.success("Copied!");
1259
1299
  };
1300
+ const chainLink = chain.explorerLink("address/" + address2);
1301
+ return /* @__PURE__ */ jsxs5("div", { className: `matchid-receive-modal`, children: [
1302
+ /* @__PURE__ */ jsxs5("div", { className: "matchid-receive-container", children: [
1303
+ /* @__PURE__ */ jsx6("div", { className: `matchid-receive-text`, children: "Receive by scanning the QR code" }),
1304
+ /* @__PURE__ */ jsx6("div", { className: `matchid-qr-container`, children: /* @__PURE__ */ jsx6(
1305
+ QRCode,
1306
+ {
1307
+ margin: "0",
1308
+ className: `matchid-qr-code`,
1309
+ value: address2
1310
+ }
1311
+ ) }),
1312
+ /* @__PURE__ */ jsx6(
1313
+ "a",
1314
+ {
1315
+ href: chainLink,
1316
+ target: "_blank",
1317
+ className: `matchid-receive-link`,
1318
+ children: address2
1319
+ }
1320
+ )
1321
+ ] }),
1322
+ /* @__PURE__ */ jsx6(Button, { size: "lg", onClick: onCopy, block: true, highlight: true, disabled: copied, children: "Copy Address" })
1323
+ ] });
1324
+ };
1325
+ var ImportTokenModal = ({ close }) => {
1326
+ const [address2, setAddress] = useState7("");
1327
+ const [symbol, setSymbol] = useState7("");
1328
+ const [decimals, setDecimals] = useState7("");
1329
+ const [error, setError] = useState7({});
1330
+ const { publicClient, chainId } = useMatchChain();
1331
+ const getContractInfo = async () => {
1332
+ if (!publicClient) return;
1333
+ const erc20Abi = [
1334
+ {
1335
+ name: "decimals",
1336
+ type: "function",
1337
+ stateMutability: "view",
1338
+ inputs: [],
1339
+ outputs: [{ name: "decimals", type: "uint8" }]
1340
+ },
1341
+ {
1342
+ name: "symbol",
1343
+ type: "function",
1344
+ stateMutability: "view",
1345
+ inputs: [],
1346
+ outputs: [{ name: "symbol", type: "string" }]
1347
+ }
1348
+ ];
1349
+ const calls = [
1350
+ {
1351
+ address: address2,
1352
+ abi: erc20Abi,
1353
+ functionName: "symbol",
1354
+ args: []
1355
+ },
1356
+ {
1357
+ address: address2,
1358
+ abi: erc20Abi,
1359
+ functionName: "decimals",
1360
+ args: []
1361
+ }
1362
+ ];
1363
+ try {
1364
+ const results = await publicClient.multicall({ contracts: calls });
1365
+ console.log("results", results);
1366
+ if (!symbol && results[0]?.status == "success") {
1367
+ setSymbol(results[0]?.result);
1368
+ }
1369
+ if (!decimals && results[1]?.status == "success") {
1370
+ setDecimals((results[1]?.result).toString());
1371
+ }
1372
+ } catch (error2) {
1373
+ setError({
1374
+ address: error2.message
1375
+ });
1376
+ }
1377
+ };
1378
+ useEffect6(() => {
1379
+ if (address2.length === 42) {
1380
+ const reg = /^0x[0-9a-fA-F]{40}$/;
1381
+ if (!reg.test(address2)) {
1382
+ setError({
1383
+ ...error,
1384
+ address: "Invalid address"
1385
+ });
1386
+ } else {
1387
+ setError({
1388
+ ...error,
1389
+ address: ""
1390
+ });
1391
+ publicClient && getContractInfo();
1392
+ }
1393
+ }
1394
+ }, [address2, publicClient]);
1395
+ const [loading, setLoading] = useState7(false);
1396
+ const toast = useToast();
1397
+ const onImport = async () => {
1398
+ setLoading(true);
1399
+ try {
1400
+ const res = await userImportTokenApi({
1401
+ chain_id: chainId?.toString() || "",
1402
+ symbol,
1403
+ address: address2,
1404
+ decimals
1405
+ });
1406
+ if (isSuccess(res)) {
1407
+ toast.success("Imported successfully");
1408
+ close();
1409
+ } else {
1410
+ toast.error(res.message);
1411
+ }
1412
+ } catch (error2) {
1413
+ toast.error(error2.message);
1414
+ } finally {
1415
+ setLoading(false);
1416
+ }
1417
+ };
1418
+ const canImport = useMemo4(() => {
1419
+ if (!address2) {
1420
+ return false;
1421
+ }
1422
+ if (!symbol) {
1423
+ return false;
1424
+ }
1425
+ if (decimals.length === 0) {
1426
+ return false;
1427
+ }
1428
+ const reg = /^0x[0-9a-fA-F]{40}$/;
1429
+ if (!reg.test(address2)) {
1430
+ return false;
1431
+ }
1432
+ return true;
1433
+ }, [error, address2, symbol, decimals]);
1434
+ return /* @__PURE__ */ jsxs5("div", { className: `matchid-import-token`, children: [
1435
+ /* @__PURE__ */ jsxs5("div", { className: "matchid-import-token-form", children: [
1436
+ /* @__PURE__ */ jsx6(Field, { label: "Token Smart Contract", error: error.address, children: /* @__PURE__ */ jsx6(
1437
+ Input,
1438
+ {
1439
+ placeholder: "Enter the Token Smart Contract",
1440
+ value: address2,
1441
+ onChange: (e) => setAddress(e.target.value),
1442
+ maxLength: 42
1443
+ }
1444
+ ) }),
1445
+ /* @__PURE__ */ jsx6(Field, { label: "Token Symbol", error: error.symbol, children: /* @__PURE__ */ jsx6(
1446
+ Input,
1447
+ {
1448
+ placeholder: "Enter the Token Symbol",
1449
+ value: symbol,
1450
+ onChange: (e) => setSymbol(e.target.value),
1451
+ maxLength: 16
1452
+ }
1453
+ ) }),
1454
+ /* @__PURE__ */ jsx6(Field, { label: "Decimals", error: error.decimals, children: /* @__PURE__ */ jsx6(
1455
+ Input,
1456
+ {
1457
+ placeholder: "Enter the Decimals",
1458
+ type: "number",
1459
+ value: decimals,
1460
+ onChange: (e) => setDecimals(e.target.value)
1461
+ }
1462
+ ) })
1463
+ ] }),
1464
+ /* @__PURE__ */ jsx6(
1465
+ Button,
1466
+ {
1467
+ size: "lg",
1468
+ onClick: onImport,
1469
+ block: true,
1470
+ loading,
1471
+ disabled: !canImport,
1472
+ highlight: true,
1473
+ children: "Import"
1474
+ }
1475
+ )
1476
+ ] });
1477
+ };
1478
+ function useMatchWallet() {
1479
+ const modal = useModal();
1260
1480
  const showReceiveModal = () => {
1261
- const chainLink = chain.explorerLink("address/" + address2);
1262
- const ReceiveModal = () => {
1263
- return /* @__PURE__ */ jsxs5("div", { className: `matchid-receive-modal`, children: [
1264
- /* @__PURE__ */ jsxs5("div", { className: "matchid-receive-container", children: [
1265
- /* @__PURE__ */ jsx6("div", { className: `matchid-receive-text`, children: "Receive by scanning the QR code" }),
1266
- /* @__PURE__ */ jsx6("div", { className: `matchid-qr-container`, children: /* @__PURE__ */ jsx6(
1267
- QRCode,
1268
- {
1269
- margin: "0",
1270
- className: `matchid-qr-code`,
1271
- value: address2
1272
- }
1273
- ) }),
1274
- /* @__PURE__ */ jsx6(
1275
- "a",
1276
- {
1277
- href: chainLink,
1278
- target: "_blank",
1279
- className: `matchid-receive-link`,
1280
- children: address2
1281
- }
1282
- )
1283
- ] }),
1284
- /* @__PURE__ */ jsx6(Button, { size: "lg", onClick: onCopy, block: true, highlight: true, disabled: copied, children: "Copy Address" })
1285
- ] });
1286
- };
1287
1481
  modal.open({
1288
1482
  title: "Receive",
1289
1483
  content: ReceiveModal
1290
1484
  });
1291
1485
  };
1486
+ const showImportTokenModal = () => {
1487
+ modal.open({
1488
+ title: "Customized Token",
1489
+ content: ImportTokenModal
1490
+ });
1491
+ };
1292
1492
  return {
1293
- showReceiveModal
1493
+ showReceiveModal,
1494
+ showImportTokenModal
1294
1495
  };
1295
1496
  }
1296
1497
  function useMatchWalletRecords({
@@ -1339,7 +1540,7 @@ function useMatchWalletRecords({
1339
1540
  // src/hooks/useReceipt.tsx
1340
1541
  import { useState as useState8, useCallback as useCallback4, useEffect as useEffect7 } from "react";
1341
1542
  import { useQuery as useQuery2 } from "@tanstack/react-query";
1342
- import { createPublicClient, defineChain, http } from "viem";
1543
+ import { createPublicClient as createPublicClient2, defineChain, http as http2 } from "viem";
1343
1544
  var CACHE_TTL = 86400 * 30 * 1e3;
1344
1545
  var MAX_CACHE_SIZE = 500;
1345
1546
  var STORAGE_KEY = "match_receipt_logs";
@@ -1456,10 +1657,9 @@ function useReceipt({
1456
1657
  return cache.get(cacheKey);
1457
1658
  }
1458
1659
  try {
1459
- const publicClient = createPublicClient({
1460
- //@ts-ignore
1660
+ const publicClient = createPublicClient2({
1461
1661
  chain: defineChain(chain),
1462
- transport: http()
1662
+ transport: http2()
1463
1663
  });
1464
1664
  const receipt = await publicClient.getTransactionReceipt({ hash });
1465
1665
  if (!receipt) {
@@ -1484,7 +1684,7 @@ function useReceipt({
1484
1684
  // src/hooks/useTransaction.tsx
1485
1685
  import { useState as useState9, useCallback as useCallback5, useEffect as useEffect8 } from "react";
1486
1686
  import { useQuery as useQuery3 } from "@tanstack/react-query";
1487
- import { createPublicClient as createPublicClient2, defineChain as defineChain2, http as http2 } from "viem";
1687
+ import { createPublicClient as createPublicClient3, defineChain as defineChain2, http as http3 } from "viem";
1488
1688
  var CACHE_TTL2 = 86400 * 30 * 1e3;
1489
1689
  var MAX_CACHE_SIZE2 = 500;
1490
1690
  var STORAGE_KEY2 = "match_transaction_logs";
@@ -1601,10 +1801,9 @@ function useTransaction({
1601
1801
  return cache.get(cacheKey);
1602
1802
  }
1603
1803
  try {
1604
- const publicClient = createPublicClient2({
1605
- //@ts-ignore
1804
+ const publicClient = createPublicClient3({
1606
1805
  chain: defineChain2(chain),
1607
- transport: http2()
1806
+ transport: http3()
1608
1807
  });
1609
1808
  const transaction = await publicClient.getTransaction({ hash });
1610
1809
  if (!transaction) {
@@ -4868,4 +5067,4 @@ export {
4868
5067
  MatchProvider,
4869
5068
  useMatch
4870
5069
  };
4871
- //# sourceMappingURL=chunk-2CK7JQWH.mjs.map
5070
+ //# sourceMappingURL=chunk-EY6NPX4M.mjs.map