@matchain/matchid-sdk-react 0.1.48-alpha.1 → 0.1.48-alpha.2
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.
- package/dist/{chunk-AFZSANRV.mjs → chunk-6HRRPZPM.mjs} +2 -2
- package/dist/{chunk-A477SJHT.mjs → chunk-D6IUBR7S.mjs} +300 -152
- package/dist/chunk-D6IUBR7S.mjs.map +1 -0
- package/dist/components/index.js +137 -130
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/hooks/api/index.js +27 -20
- package/dist/hooks/api/index.js.map +1 -1
- package/dist/hooks/api/index.mjs +2 -2
- package/dist/hooks/index.d.mts +2 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +163 -15
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +3 -1
- package/dist/{index-DO5x10pN.d.mts → index-BHVMQGZj.d.mts} +9 -2
- package/dist/{index-Pssz41An.d.ts → index-DgAnNnit.d.ts} +9 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +243 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-A477SJHT.mjs.map +0 -1
- /package/dist/{chunk-AFZSANRV.mjs.map → chunk-6HRRPZPM.mjs.map} +0 -0
package/dist/hooks/api/index.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
bind_exports,
|
|
3
3
|
poh_exports,
|
|
4
4
|
user_exports
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-6HRRPZPM.mjs";
|
|
6
6
|
import {
|
|
7
7
|
isSuccess,
|
|
8
8
|
wallet_exports
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-D6IUBR7S.mjs";
|
|
10
10
|
import "../../chunk-UA6XHZHX.mjs";
|
|
11
11
|
import "../../chunk-LNSJ3ZXG.mjs";
|
|
12
12
|
import "../../chunk-A5D3NKTK.mjs";
|
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { c as useCopyClipboard,
|
|
1
|
+
export { c as useCopyClipboard, j as useLayout, f as useMatchChain, a as useMatchEvents, g as useMatchWallet, d as useModal, h as useReceipt, e as useToast, u as useUserInfo, b as useWallet } from '../index-BHVMQGZj.mjs';
|
|
2
2
|
import '../types-DQq17lf4.mjs';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'viem';
|
|
5
5
|
import '../mpc-CTbBWHld.mjs';
|
|
6
6
|
import 'viem/types/misc';
|
|
7
7
|
import 'abitype';
|
|
8
|
+
import '@tanstack/react-query';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { c as useCopyClipboard,
|
|
1
|
+
export { c as useCopyClipboard, j as useLayout, f as useMatchChain, a as useMatchEvents, g as useMatchWallet, d as useModal, h as useReceipt, e as useToast, u as useUserInfo, b as useWallet } from '../index-DgAnNnit.js';
|
|
2
2
|
import '../types-DQq17lf4.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'viem';
|
|
5
5
|
import '../mpc-CTbBWHld.js';
|
|
6
6
|
import 'viem/types/misc';
|
|
7
7
|
import 'abitype';
|
|
8
|
+
import '@tanstack/react-query';
|
package/dist/hooks/index.js
CHANGED
|
@@ -36,6 +36,7 @@ __export(hooks_exports, {
|
|
|
36
36
|
useMatchEvents: () => useMatchEvents,
|
|
37
37
|
useMatchWallet: () => useMatchWallet,
|
|
38
38
|
useModal: () => useModal,
|
|
39
|
+
useReceipt: () => useReceipt,
|
|
39
40
|
useToast: () => useToast,
|
|
40
41
|
useUserInfo: () => useUserInfo,
|
|
41
42
|
useWallet: () => useWallet2
|
|
@@ -291,7 +292,7 @@ var persistedState = (0, import_middleware.persist)(
|
|
|
291
292
|
setTheme: (theme) => set({ theme }),
|
|
292
293
|
setEndpoints: (endpoints) => set({ endpoints }),
|
|
293
294
|
address: "",
|
|
294
|
-
setAddress: (
|
|
295
|
+
setAddress: (address2) => set({ address: address2 }),
|
|
295
296
|
locale: "en",
|
|
296
297
|
setLocale: (locale) => set({ locale }),
|
|
297
298
|
wallet: {
|
|
@@ -925,7 +926,7 @@ function useUserInfo() {
|
|
|
925
926
|
logout: logoutStore,
|
|
926
927
|
setOverview,
|
|
927
928
|
overview,
|
|
928
|
-
address,
|
|
929
|
+
address: address2,
|
|
929
930
|
endpoints,
|
|
930
931
|
locale,
|
|
931
932
|
refreshOverview
|
|
@@ -1153,7 +1154,7 @@ function useUserInfo() {
|
|
|
1153
1154
|
token,
|
|
1154
1155
|
mid,
|
|
1155
1156
|
did,
|
|
1156
|
-
address,
|
|
1157
|
+
address: address2,
|
|
1157
1158
|
isLogin,
|
|
1158
1159
|
logout,
|
|
1159
1160
|
getLoginEmailCode,
|
|
@@ -1195,7 +1196,7 @@ var import_react30 = require("react");
|
|
|
1195
1196
|
var import_viem4 = require("viem");
|
|
1196
1197
|
var AppClientId2 = "react-sdk-" + getVersion();
|
|
1197
1198
|
function useWallet2() {
|
|
1198
|
-
const { address, wallet: walletConfig } = useLocalStore_default();
|
|
1199
|
+
const { address: address2, wallet: walletConfig } = useLocalStore_default();
|
|
1199
1200
|
const { walletReady } = useStore_default();
|
|
1200
1201
|
const { open: openHashPanel } = useHashPanelStore();
|
|
1201
1202
|
const isRecovered = async () => {
|
|
@@ -1243,8 +1244,8 @@ function useWallet2() {
|
|
|
1243
1244
|
}
|
|
1244
1245
|
};
|
|
1245
1246
|
const evmAccount = (0, import_react30.useMemo)(() => {
|
|
1246
|
-
return
|
|
1247
|
-
address,
|
|
1247
|
+
return address2 ? (0, import_accounts.toAccount)({
|
|
1248
|
+
address: address2,
|
|
1248
1249
|
async signMessage({ message }) {
|
|
1249
1250
|
return await signMessage2({
|
|
1250
1251
|
message,
|
|
@@ -1275,7 +1276,7 @@ function useWallet2() {
|
|
|
1275
1276
|
return "0x";
|
|
1276
1277
|
}
|
|
1277
1278
|
}) : void 0;
|
|
1278
|
-
}, [
|
|
1279
|
+
}, [address2]);
|
|
1279
1280
|
(0, import_react30.useEffect)(() => {
|
|
1280
1281
|
matchlog_default.log("qwe-evmAccount", evmAccount);
|
|
1281
1282
|
}, [evmAccount]);
|
|
@@ -1368,7 +1369,7 @@ function useWallet2() {
|
|
|
1368
1369
|
});
|
|
1369
1370
|
};
|
|
1370
1371
|
const writeContract = async (parameters2) => {
|
|
1371
|
-
const { abi, address:
|
|
1372
|
+
const { abi, address: address3, args, dataSuffix, functionName, ...request3 } = parameters2;
|
|
1372
1373
|
const data = (0, import_viem2.encodeFunctionData)({
|
|
1373
1374
|
abi,
|
|
1374
1375
|
args,
|
|
@@ -1376,7 +1377,7 @@ function useWallet2() {
|
|
|
1376
1377
|
});
|
|
1377
1378
|
return await sendTransaction({
|
|
1378
1379
|
data: `${data}${dataSuffix ? dataSuffix.replace("0x", "") : ""}`,
|
|
1379
|
-
to:
|
|
1380
|
+
to: address3,
|
|
1380
1381
|
...request3
|
|
1381
1382
|
});
|
|
1382
1383
|
};
|
|
@@ -1390,7 +1391,7 @@ function useWallet2() {
|
|
|
1390
1391
|
return {
|
|
1391
1392
|
walletReady,
|
|
1392
1393
|
evmAccount,
|
|
1393
|
-
address,
|
|
1394
|
+
address: address2,
|
|
1394
1395
|
signMessage: signMessage2,
|
|
1395
1396
|
signTransaction,
|
|
1396
1397
|
isRecovered,
|
|
@@ -1512,19 +1513,20 @@ function useMatchChain() {
|
|
|
1512
1513
|
|
|
1513
1514
|
// src/hooks/useMatchWallet.tsx
|
|
1514
1515
|
var import_react_qrcode = require("react-qrcode");
|
|
1516
|
+
var import_react33 = require("react");
|
|
1515
1517
|
var import_jsx_runtime82 = require("react/jsx-runtime");
|
|
1516
1518
|
function useMatchWallet() {
|
|
1517
1519
|
const modal = useModal();
|
|
1518
|
-
const { address } = useWallet2();
|
|
1520
|
+
const { address: address2 } = useWallet2();
|
|
1519
1521
|
const chain = useMatchChain();
|
|
1520
1522
|
const [copied, setCopied] = useCopyClipboard();
|
|
1521
1523
|
const toast = useToast();
|
|
1522
1524
|
const onCopy = () => {
|
|
1523
|
-
setCopied(
|
|
1525
|
+
setCopied(address2);
|
|
1524
1526
|
toast.success("Copied!");
|
|
1525
1527
|
};
|
|
1526
1528
|
const showReceiveModal = () => {
|
|
1527
|
-
const chainLink = chain.explorerLink("address/" +
|
|
1529
|
+
const chainLink = chain.explorerLink("address/" + address2);
|
|
1528
1530
|
const ReceiveModal = () => {
|
|
1529
1531
|
return /* @__PURE__ */ (0, import_jsx_runtime82.jsxs)("div", { className: `matchid-receive-modal`, children: [
|
|
1530
1532
|
/* @__PURE__ */ (0, import_jsx_runtime82.jsxs)("div", { className: "matchid-receive-container", children: [
|
|
@@ -1534,7 +1536,7 @@ function useMatchWallet() {
|
|
|
1534
1536
|
{
|
|
1535
1537
|
margin: "0",
|
|
1536
1538
|
className: `matchid-qr-code`,
|
|
1537
|
-
value:
|
|
1539
|
+
value: address2
|
|
1538
1540
|
}
|
|
1539
1541
|
) }),
|
|
1540
1542
|
/* @__PURE__ */ (0, import_jsx_runtime82.jsx)(
|
|
@@ -1543,7 +1545,7 @@ function useMatchWallet() {
|
|
|
1543
1545
|
href: chainLink,
|
|
1544
1546
|
target: "_blank",
|
|
1545
1547
|
className: `matchid-receive-link`,
|
|
1546
|
-
children:
|
|
1548
|
+
children: address2
|
|
1547
1549
|
}
|
|
1548
1550
|
)
|
|
1549
1551
|
] }),
|
|
@@ -1559,6 +1561,151 @@ function useMatchWallet() {
|
|
|
1559
1561
|
showReceiveModal
|
|
1560
1562
|
};
|
|
1561
1563
|
}
|
|
1564
|
+
|
|
1565
|
+
// src/hooks/useReceipt.tsx
|
|
1566
|
+
var import_react34 = require("react");
|
|
1567
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
1568
|
+
var import_viem5 = require("viem");
|
|
1569
|
+
var CACHE_TTL = 86400 * 30 * 1e3;
|
|
1570
|
+
var MAX_CACHE_SIZE = 500;
|
|
1571
|
+
var STORAGE_KEY = "match_receipt_logs";
|
|
1572
|
+
function useReceiptCache() {
|
|
1573
|
+
const [cache, setCache] = (0, import_react34.useState)(/* @__PURE__ */ new Map());
|
|
1574
|
+
const isLocalStorageAvailable = (() => {
|
|
1575
|
+
try {
|
|
1576
|
+
const testKey = "__test__";
|
|
1577
|
+
localStorage.setItem(testKey, "1");
|
|
1578
|
+
localStorage.removeItem(testKey);
|
|
1579
|
+
return true;
|
|
1580
|
+
} catch (e) {
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
})();
|
|
1584
|
+
(0, import_react34.useEffect)(() => {
|
|
1585
|
+
if (isLocalStorageAvailable) {
|
|
1586
|
+
try {
|
|
1587
|
+
const storedData = localStorage.getItem(STORAGE_KEY);
|
|
1588
|
+
if (storedData) {
|
|
1589
|
+
try {
|
|
1590
|
+
const parsed = JSON.parse(storedData);
|
|
1591
|
+
const now = Date.now();
|
|
1592
|
+
const validEntries = Object.entries(parsed).filter(([_, entry]) => typeof entry === "object" && entry !== null && "timestamp" in entry && now - entry.timestamp <= CACHE_TTL).map(([key, entry]) => [key, entry]);
|
|
1593
|
+
setCache(new Map(validEntries));
|
|
1594
|
+
} catch (e) {
|
|
1595
|
+
console.error("Failed to parse cache from localStorage:", e);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
} catch (e) {
|
|
1599
|
+
console.error("Failed to load cache from localStorage:", e);
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}, []);
|
|
1603
|
+
const updateLocalStorage = (0, import_react34.useCallback)((updatedCache) => {
|
|
1604
|
+
if (isLocalStorageAvailable) {
|
|
1605
|
+
try {
|
|
1606
|
+
const storedData = localStorage.getItem(STORAGE_KEY);
|
|
1607
|
+
let parsed = {};
|
|
1608
|
+
if (storedData) {
|
|
1609
|
+
parsed = JSON.parse(storedData);
|
|
1610
|
+
}
|
|
1611
|
+
updatedCache.forEach((entry, key) => {
|
|
1612
|
+
parsed[key] = entry;
|
|
1613
|
+
});
|
|
1614
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(parsed));
|
|
1615
|
+
} catch (e) {
|
|
1616
|
+
console.error("Failed to update localStorage:", e);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}, []);
|
|
1620
|
+
const set = (0, import_react34.useCallback)((key, value) => {
|
|
1621
|
+
const now = Date.now();
|
|
1622
|
+
const newCache = new Map(cache);
|
|
1623
|
+
newCache.forEach((entry, k) => {
|
|
1624
|
+
if (now - entry.timestamp > CACHE_TTL) {
|
|
1625
|
+
newCache.delete(k);
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
if (newCache.size >= MAX_CACHE_SIZE) {
|
|
1629
|
+
const firstKey = newCache.keys().next().value;
|
|
1630
|
+
if (firstKey !== void 0) {
|
|
1631
|
+
newCache.delete(firstKey);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
newCache.set(key, { value, timestamp: now });
|
|
1635
|
+
setCache(newCache);
|
|
1636
|
+
updateLocalStorage(newCache);
|
|
1637
|
+
}, [cache, updateLocalStorage]);
|
|
1638
|
+
const get = (0, import_react34.useCallback)((key) => {
|
|
1639
|
+
const entry = cache.get(key);
|
|
1640
|
+
if (entry) {
|
|
1641
|
+
if (Date.now() - entry.timestamp > CACHE_TTL) {
|
|
1642
|
+
const newCache = new Map(cache);
|
|
1643
|
+
newCache.delete(key);
|
|
1644
|
+
setCache(newCache);
|
|
1645
|
+
updateLocalStorage(newCache);
|
|
1646
|
+
return void 0;
|
|
1647
|
+
}
|
|
1648
|
+
return entry.value;
|
|
1649
|
+
}
|
|
1650
|
+
return void 0;
|
|
1651
|
+
}, [cache, updateLocalStorage]);
|
|
1652
|
+
const del = (0, import_react34.useCallback)((key) => {
|
|
1653
|
+
if (cache.has(key)) {
|
|
1654
|
+
const newCache = new Map(cache);
|
|
1655
|
+
newCache.delete(key);
|
|
1656
|
+
setCache(newCache);
|
|
1657
|
+
updateLocalStorage(newCache);
|
|
1658
|
+
}
|
|
1659
|
+
}, [cache, updateLocalStorage]);
|
|
1660
|
+
const clear = (0, import_react34.useCallback)(() => {
|
|
1661
|
+
setCache(/* @__PURE__ */ new Map());
|
|
1662
|
+
if (isLocalStorageAvailable) {
|
|
1663
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
1664
|
+
}
|
|
1665
|
+
}, [isLocalStorageAvailable]);
|
|
1666
|
+
return { set, get, del, clear };
|
|
1667
|
+
}
|
|
1668
|
+
function useReceipt({
|
|
1669
|
+
chainId,
|
|
1670
|
+
hash
|
|
1671
|
+
}) {
|
|
1672
|
+
const { list } = useMatchChain();
|
|
1673
|
+
const cache = useReceiptCache();
|
|
1674
|
+
const chain = list?.find((item) => item.id === chainId);
|
|
1675
|
+
const [shouldRefetch, setShouldRefetch] = (0, import_react34.useState)(true);
|
|
1676
|
+
const query = (0, import_react_query5.useQuery)({
|
|
1677
|
+
queryKey: ["match-tx-receipt", hash, chain],
|
|
1678
|
+
queryFn: async () => {
|
|
1679
|
+
if (!chain || !hash) return false;
|
|
1680
|
+
const cacheKey = `${chain.id}-${hash}`;
|
|
1681
|
+
if (cache.get(cacheKey)) {
|
|
1682
|
+
return cache.get(cacheKey);
|
|
1683
|
+
}
|
|
1684
|
+
try {
|
|
1685
|
+
const publicClient = (0, import_viem5.createPublicClient)({
|
|
1686
|
+
//@ts-ignore
|
|
1687
|
+
chain: (0, import_viem5.defineChain)(chain),
|
|
1688
|
+
transport: (0, import_viem5.http)()
|
|
1689
|
+
});
|
|
1690
|
+
const receipt = await publicClient.getTransaction({ hash });
|
|
1691
|
+
if (!receipt) {
|
|
1692
|
+
return false;
|
|
1693
|
+
}
|
|
1694
|
+
cache.set(cacheKey, receipt);
|
|
1695
|
+
return receipt;
|
|
1696
|
+
} catch (e) {
|
|
1697
|
+
return false;
|
|
1698
|
+
}
|
|
1699
|
+
},
|
|
1700
|
+
refetchInterval: shouldRefetch ? 1e4 : false
|
|
1701
|
+
});
|
|
1702
|
+
(0, import_react34.useEffect)(() => {
|
|
1703
|
+
if (query.data) {
|
|
1704
|
+
setShouldRefetch(false);
|
|
1705
|
+
}
|
|
1706
|
+
}, [query.data]);
|
|
1707
|
+
return query;
|
|
1708
|
+
}
|
|
1562
1709
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1563
1710
|
0 && (module.exports = {
|
|
1564
1711
|
useCopyClipboard,
|
|
@@ -1567,6 +1714,7 @@ function useMatchWallet() {
|
|
|
1567
1714
|
useMatchEvents,
|
|
1568
1715
|
useMatchWallet,
|
|
1569
1716
|
useModal,
|
|
1717
|
+
useReceipt,
|
|
1570
1718
|
useToast,
|
|
1571
1719
|
useUserInfo,
|
|
1572
1720
|
useWallet
|