@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.
- package/dist/{chunk-2MJFQXBZ.mjs → chunk-OSIGDX4D.mjs} +72 -37
- package/dist/chunk-OSIGDX4D.mjs.map +1 -0
- package/dist/{chunk-PWUDQPH3.mjs → chunk-UGKYENZK.mjs} +2 -2
- package/dist/components/index.js +48 -38
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -1
- package/dist/hooks/api/index.js +20 -14
- package/dist/hooks/api/index.js.map +1 -1
- package/dist/hooks/api/index.mjs +2 -2
- package/dist/hooks/index.js +64 -32
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.js +84 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-2MJFQXBZ.mjs.map +0 -1
- /package/dist/{chunk-PWUDQPH3.mjs.map → chunk-UGKYENZK.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-UGKYENZK.mjs";
|
|
6
6
|
import {
|
|
7
7
|
isSuccess,
|
|
8
8
|
wallet_exports
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-OSIGDX4D.mjs";
|
|
10
10
|
import "../../chunk-UA6XHZHX.mjs";
|
|
11
11
|
import "../../chunk-FB5MHLWX.mjs";
|
|
12
12
|
import "../../chunk-5JHHHLG4.mjs";
|
package/dist/hooks/index.js
CHANGED
|
@@ -2533,15 +2533,41 @@ function useMatchChain() {
|
|
|
2533
2533
|
// src/hooks/useMatchWallet.tsx
|
|
2534
2534
|
var import_react_qrcode = require("react-qrcode");
|
|
2535
2535
|
var import_react38 = require("react");
|
|
2536
|
-
var
|
|
2537
|
-
var
|
|
2536
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
2537
|
+
var import_viem11 = require("viem");
|
|
2538
2538
|
var import_react_intl21 = require("react-intl");
|
|
2539
2539
|
|
|
2540
2540
|
// src/components/ImportToken/index.tsx
|
|
2541
2541
|
var import_react37 = require("react");
|
|
2542
2542
|
var import_react_intl20 = require("react-intl");
|
|
2543
|
-
var
|
|
2543
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
2544
|
+
var import_viem10 = require("viem");
|
|
2545
|
+
|
|
2546
|
+
// src/hooks/useIsContract.ts
|
|
2544
2547
|
var import_viem9 = require("viem");
|
|
2548
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
2549
|
+
function useIsContract({
|
|
2550
|
+
address,
|
|
2551
|
+
chain,
|
|
2552
|
+
enabled
|
|
2553
|
+
}) {
|
|
2554
|
+
return (0, import_react_query5.useQuery)({
|
|
2555
|
+
queryKey: ["is_contract", chain?.id, address],
|
|
2556
|
+
queryFn: async () => {
|
|
2557
|
+
if (!chain) return false;
|
|
2558
|
+
if (!address) return false;
|
|
2559
|
+
const publicClient = (0, import_viem9.createPublicClient)({
|
|
2560
|
+
chain,
|
|
2561
|
+
transport: (0, import_viem9.http)()
|
|
2562
|
+
});
|
|
2563
|
+
const res = await publicClient.getCode({ address });
|
|
2564
|
+
return res !== null && res !== void 0;
|
|
2565
|
+
},
|
|
2566
|
+
enabled
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// src/components/ImportToken/index.tsx
|
|
2545
2571
|
var import_jsx_runtime93 = require("react/jsx-runtime");
|
|
2546
2572
|
function ImportToken({ close }) {
|
|
2547
2573
|
const [status, setStatus] = (0, import_react37.useState)("");
|
|
@@ -2550,19 +2576,19 @@ function ImportToken({ close }) {
|
|
|
2550
2576
|
const [symbol, setSymbol] = (0, import_react37.useState)("");
|
|
2551
2577
|
const [decimals, setDecimals] = (0, import_react37.useState)("");
|
|
2552
2578
|
const [error, setError] = (0, import_react37.useState)({});
|
|
2553
|
-
const { publicClient, chainId } = useMatchChain();
|
|
2579
|
+
const { publicClient, chainId, chain } = useMatchChain();
|
|
2554
2580
|
const getContractInfo = async () => {
|
|
2555
2581
|
if (!publicClient) return;
|
|
2556
2582
|
const calls = [
|
|
2557
2583
|
{
|
|
2558
2584
|
address,
|
|
2559
|
-
abi:
|
|
2585
|
+
abi: import_viem10.erc20Abi,
|
|
2560
2586
|
functionName: "symbol",
|
|
2561
2587
|
args: []
|
|
2562
2588
|
},
|
|
2563
2589
|
{
|
|
2564
2590
|
address,
|
|
2565
|
-
abi:
|
|
2591
|
+
abi: import_viem10.erc20Abi,
|
|
2566
2592
|
functionName: "decimals",
|
|
2567
2593
|
args: []
|
|
2568
2594
|
}
|
|
@@ -2604,7 +2630,7 @@ function ImportToken({ close }) {
|
|
|
2604
2630
|
}, [address, publicClient]);
|
|
2605
2631
|
const [loading, setLoading] = (0, import_react37.useState)(false);
|
|
2606
2632
|
const toast = useToast();
|
|
2607
|
-
const queryClient2 = (0,
|
|
2633
|
+
const queryClient2 = (0, import_react_query6.useQueryClient)();
|
|
2608
2634
|
const onImport = async () => {
|
|
2609
2635
|
setLoading(true);
|
|
2610
2636
|
try {
|
|
@@ -2646,7 +2672,12 @@ function ImportToken({ close }) {
|
|
|
2646
2672
|
}
|
|
2647
2673
|
return true;
|
|
2648
2674
|
}, [error, address, symbol, decimals]);
|
|
2649
|
-
|
|
2675
|
+
const isContractQuery = useIsContract({
|
|
2676
|
+
//@ts-ignore
|
|
2677
|
+
chain: (0, import_viem10.defineChain)(chain),
|
|
2678
|
+
address,
|
|
2679
|
+
enabled: canImport
|
|
2680
|
+
});
|
|
2650
2681
|
if (status == "success" || status == "fail") {
|
|
2651
2682
|
return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: `matchid-import-token-result matchid-flex`, children: [
|
|
2652
2683
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: `matchid-import-token-result-box matchid-flex`, children: [
|
|
@@ -2660,7 +2691,7 @@ function ImportToken({ close }) {
|
|
|
2660
2691
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: "matchid-import-token-form", children: [
|
|
2661
2692
|
/* @__PURE__ */ (0, import_jsx_runtime93.jsx)(Field, { label: intl.formatMessage({
|
|
2662
2693
|
id: "tokenSmartContract"
|
|
2663
|
-
}), error: error.address, children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
|
|
2694
|
+
}), error: error.address ? error.address : isContractQuery.isFetched && !isContractQuery.isLoading && !isContractQuery.data && canImport ? "Address isn't a contract address" : "", children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
|
|
2664
2695
|
Input,
|
|
2665
2696
|
{
|
|
2666
2697
|
placeholder: intl.formatMessage({
|
|
@@ -2704,8 +2735,8 @@ function ImportToken({ close }) {
|
|
|
2704
2735
|
size: "lg",
|
|
2705
2736
|
onClick: onImport,
|
|
2706
2737
|
block: true,
|
|
2707
|
-
loading,
|
|
2708
|
-
disabled: !canImport,
|
|
2738
|
+
loading: loading || isContractQuery.isLoading,
|
|
2739
|
+
disabled: !canImport || !isContractQuery.data,
|
|
2709
2740
|
highlight: true,
|
|
2710
2741
|
children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_react_intl20.FormattedMessage, { id: "import" })
|
|
2711
2742
|
}
|
|
@@ -2827,13 +2858,13 @@ function useMatchWalletRecords() {
|
|
|
2827
2858
|
for (const contract of contractUnique) {
|
|
2828
2859
|
calls.push({
|
|
2829
2860
|
address: contract,
|
|
2830
|
-
abi:
|
|
2861
|
+
abi: import_viem11.erc20Abi,
|
|
2831
2862
|
functionName: "symbol",
|
|
2832
2863
|
args: []
|
|
2833
2864
|
});
|
|
2834
2865
|
calls.push({
|
|
2835
2866
|
address: contract,
|
|
2836
|
-
abi:
|
|
2867
|
+
abi: import_viem11.erc20Abi,
|
|
2837
2868
|
functionName: "decimals",
|
|
2838
2869
|
args: []
|
|
2839
2870
|
});
|
|
@@ -2985,7 +3016,7 @@ function useMatchWalletAssetList({
|
|
|
2985
3016
|
name: chain?.nativeCurrency.name,
|
|
2986
3017
|
balance: 0
|
|
2987
3018
|
};
|
|
2988
|
-
const nativeBalanceQuery = (0,
|
|
3019
|
+
const nativeBalanceQuery = (0, import_react_query7.useQuery)({
|
|
2989
3020
|
queryKey: ["nativeBalance", nativeToken?.chain_id],
|
|
2990
3021
|
queryFn: async () => {
|
|
2991
3022
|
if (!nativeToken || !publicClient) return null;
|
|
@@ -3005,13 +3036,13 @@ function useMatchWalletAssetList({
|
|
|
3005
3036
|
// Retry up to 3 times if failed
|
|
3006
3037
|
});
|
|
3007
3038
|
const erc20Tokens = (0, import_react38.useMemo)(() => list.filter((asset) => asset.address !== NATIVE_TOKEN_ADDRESS), [list]);
|
|
3008
|
-
const erc20BalanceQuery = (0,
|
|
3039
|
+
const erc20BalanceQuery = (0, import_react_query7.useQuery)({
|
|
3009
3040
|
queryKey: ["erc20Balances", erc20Tokens.map((token) => token.address)],
|
|
3010
3041
|
queryFn: async () => {
|
|
3011
3042
|
if (!erc20Tokens.length || !publicClient) return [];
|
|
3012
3043
|
const calls = erc20Tokens.map((token) => ({
|
|
3013
3044
|
address: token.address,
|
|
3014
|
-
abi:
|
|
3045
|
+
abi: import_viem11.erc20Abi,
|
|
3015
3046
|
functionName: "balanceOf",
|
|
3016
3047
|
args: [address]
|
|
3017
3048
|
}));
|
|
@@ -3039,13 +3070,14 @@ function useMatchWalletAssetList({
|
|
|
3039
3070
|
let balanceValue = "0";
|
|
3040
3071
|
let balance = 0;
|
|
3041
3072
|
const decimals = typeof asset.decimals === "string" ? parseInt(asset.decimals) : asset.decimals;
|
|
3042
|
-
|
|
3073
|
+
const assetAddress = asset.address.toLowerCase();
|
|
3074
|
+
if (assetAddress === NATIVE_TOKEN_ADDRESS) {
|
|
3043
3075
|
balanceValue = nativeBalanceQuery.data?.toString() || "0";
|
|
3044
|
-
balance = nativeBalanceQuery.data ? Number((0,
|
|
3076
|
+
balance = nativeBalanceQuery.data ? Number((0, import_viem11.formatUnits)(nativeBalanceQuery.data, decimals)) : 0;
|
|
3045
3077
|
} else {
|
|
3046
|
-
const index = erc20Tokens.findIndex((t) => t.address ===
|
|
3078
|
+
const index = erc20Tokens.findIndex((t) => t.address.toLowerCase() === assetAddress);
|
|
3047
3079
|
if (index !== -1 && erc20Balances[index] && erc20Balances[index].status === "success") {
|
|
3048
|
-
balance = Number((0,
|
|
3080
|
+
balance = Number((0, import_viem11.formatUnits)(erc20Balances[index].result, decimals));
|
|
3049
3081
|
balanceValue = erc20Balances[index].result?.toString() || "0";
|
|
3050
3082
|
}
|
|
3051
3083
|
}
|
|
@@ -3079,8 +3111,8 @@ function useMatchWalletAssetList({
|
|
|
3079
3111
|
|
|
3080
3112
|
// src/hooks/useReceipt.tsx
|
|
3081
3113
|
var import_react39 = require("react");
|
|
3082
|
-
var
|
|
3083
|
-
var
|
|
3114
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
3115
|
+
var import_viem12 = require("viem");
|
|
3084
3116
|
var CACHE_TTL = 86400 * 30 * 1e3;
|
|
3085
3117
|
var MAX_CACHE_SIZE = 500;
|
|
3086
3118
|
var STORAGE_KEY = "match_receipt_logs";
|
|
@@ -3188,7 +3220,7 @@ function useReceipt2({
|
|
|
3188
3220
|
const cache = useReceiptCache();
|
|
3189
3221
|
const chain = list?.find((item) => item.id === chainId);
|
|
3190
3222
|
const [shouldRefetch, setShouldRefetch] = (0, import_react39.useState)(true);
|
|
3191
|
-
const query = (0,
|
|
3223
|
+
const query = (0, import_react_query8.useQuery)({
|
|
3192
3224
|
queryKey: ["match-tx-receipt", hash, chain],
|
|
3193
3225
|
queryFn: async () => {
|
|
3194
3226
|
if (!chain || !hash) return false;
|
|
@@ -3197,9 +3229,9 @@ function useReceipt2({
|
|
|
3197
3229
|
return cache.get(cacheKey);
|
|
3198
3230
|
}
|
|
3199
3231
|
try {
|
|
3200
|
-
const publicClient = (0,
|
|
3201
|
-
chain: (0,
|
|
3202
|
-
transport: (0,
|
|
3232
|
+
const publicClient = (0, import_viem12.createPublicClient)({
|
|
3233
|
+
chain: (0, import_viem12.defineChain)(chain),
|
|
3234
|
+
transport: (0, import_viem12.http)()
|
|
3203
3235
|
});
|
|
3204
3236
|
const receipt = await publicClient.getTransactionReceipt({ hash });
|
|
3205
3237
|
if (!receipt) {
|
|
@@ -3223,8 +3255,8 @@ function useReceipt2({
|
|
|
3223
3255
|
|
|
3224
3256
|
// src/hooks/useTransaction.tsx
|
|
3225
3257
|
var import_react40 = require("react");
|
|
3226
|
-
var
|
|
3227
|
-
var
|
|
3258
|
+
var import_react_query9 = require("@tanstack/react-query");
|
|
3259
|
+
var import_viem13 = require("viem");
|
|
3228
3260
|
var CACHE_TTL2 = 86400 * 30 * 1e3;
|
|
3229
3261
|
var MAX_CACHE_SIZE2 = 500;
|
|
3230
3262
|
var STORAGE_KEY2 = "match_transaction_logs";
|
|
@@ -3332,7 +3364,7 @@ function useTransaction({
|
|
|
3332
3364
|
const cache = useTransactionCache();
|
|
3333
3365
|
const chain = list?.find((item) => item.id === chainId);
|
|
3334
3366
|
const [shouldRefetch, setShouldRefetch] = (0, import_react40.useState)(true);
|
|
3335
|
-
const query = (0,
|
|
3367
|
+
const query = (0, import_react_query9.useQuery)({
|
|
3336
3368
|
queryKey: ["match-tx-transaction", hash, chain],
|
|
3337
3369
|
queryFn: async () => {
|
|
3338
3370
|
if (!chain || !hash) return false;
|
|
@@ -3341,9 +3373,9 @@ function useTransaction({
|
|
|
3341
3373
|
return cache.get(cacheKey);
|
|
3342
3374
|
}
|
|
3343
3375
|
try {
|
|
3344
|
-
const publicClient = (0,
|
|
3345
|
-
chain: (0,
|
|
3346
|
-
transport: (0,
|
|
3376
|
+
const publicClient = (0, import_viem13.createPublicClient)({
|
|
3377
|
+
chain: (0, import_viem13.defineChain)(chain),
|
|
3378
|
+
transport: (0, import_viem13.http)()
|
|
3347
3379
|
});
|
|
3348
3380
|
const transaction = await publicClient.getTransaction({ hash });
|
|
3349
3381
|
if (!transaction) {
|