@matchain/matchid-sdk-react 0.1.42-alpha.9 → 0.1.44-alpha.0
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-HXXIG4ZO.mjs → chunk-KITTHHSR.mjs} +370 -272
- package/dist/chunk-KITTHHSR.mjs.map +1 -0
- package/dist/{chunk-KU726GST.mjs → chunk-L3G6YN2D.mjs} +2 -2
- package/dist/components/index.d.mts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +306 -232
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +5 -3
- package/dist/hooks/api/index.js +52 -30
- package/dist/hooks/api/index.js.map +1 -1
- package/dist/hooks/api/index.mjs +2 -2
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +87 -53
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +1 -1
- package/dist/{index-sOVSnYF4.d.mts → index-Bluim2ZP.d.mts} +10 -4
- package/dist/{index-DY_ReBra.d.ts → index-CLvQH5gM.d.ts} +9 -2
- package/dist/{index-CmH9iRLd.d.mts → index-DlhAHm_s.d.mts} +9 -2
- package/dist/{index-DKMrpRJC.d.ts → index-EqksEEto.d.ts} +10 -4
- package/dist/index.css +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +408 -313
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/example/src/abi/erc20.json +222 -0
- package/example/src/config/index.ts +1 -0
- package/example/src/pages/Wallet.tsx +135 -9
- package/example/src/store/useLocalStore.ts +7 -1
- package/example/tsconfig.json +1 -0
- package/package.json +1 -1
- package/dist/chunk-HXXIG4ZO.mjs.map +0 -1
- /package/dist/{chunk-KU726GST.mjs.map → chunk-L3G6YN2D.mjs.map} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
} from "./chunk-HYQ3T6WW.mjs";
|
|
4
4
|
import {
|
|
5
5
|
api_exports
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-L3G6YN2D.mjs";
|
|
7
7
|
import {
|
|
8
8
|
MatchProvider,
|
|
9
9
|
components_exports,
|
|
10
10
|
hooks_exports,
|
|
11
11
|
useMatch
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-KITTHHSR.mjs";
|
|
13
13
|
import {
|
|
14
14
|
types_exports
|
|
15
15
|
} from "./chunk-SQIJR7RA.mjs";
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"constant": true,
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"name": "name",
|
|
6
|
+
"outputs": [
|
|
7
|
+
{
|
|
8
|
+
"name": "",
|
|
9
|
+
"type": "string"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"payable": false,
|
|
13
|
+
"stateMutability": "view",
|
|
14
|
+
"type": "function"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"constant": false,
|
|
18
|
+
"inputs": [
|
|
19
|
+
{
|
|
20
|
+
"name": "_spender",
|
|
21
|
+
"type": "address"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "_value",
|
|
25
|
+
"type": "uint256"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"name": "approve",
|
|
29
|
+
"outputs": [
|
|
30
|
+
{
|
|
31
|
+
"name": "",
|
|
32
|
+
"type": "bool"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"payable": false,
|
|
36
|
+
"stateMutability": "nonpayable",
|
|
37
|
+
"type": "function"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"constant": true,
|
|
41
|
+
"inputs": [],
|
|
42
|
+
"name": "totalSupply",
|
|
43
|
+
"outputs": [
|
|
44
|
+
{
|
|
45
|
+
"name": "",
|
|
46
|
+
"type": "uint256"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"payable": false,
|
|
50
|
+
"stateMutability": "view",
|
|
51
|
+
"type": "function"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"constant": false,
|
|
55
|
+
"inputs": [
|
|
56
|
+
{
|
|
57
|
+
"name": "_from",
|
|
58
|
+
"type": "address"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "_to",
|
|
62
|
+
"type": "address"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "_value",
|
|
66
|
+
"type": "uint256"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"name": "transferFrom",
|
|
70
|
+
"outputs": [
|
|
71
|
+
{
|
|
72
|
+
"name": "",
|
|
73
|
+
"type": "bool"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"payable": false,
|
|
77
|
+
"stateMutability": "nonpayable",
|
|
78
|
+
"type": "function"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"constant": true,
|
|
82
|
+
"inputs": [],
|
|
83
|
+
"name": "decimals",
|
|
84
|
+
"outputs": [
|
|
85
|
+
{
|
|
86
|
+
"name": "",
|
|
87
|
+
"type": "uint8"
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"payable": false,
|
|
91
|
+
"stateMutability": "view",
|
|
92
|
+
"type": "function"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"constant": true,
|
|
96
|
+
"inputs": [
|
|
97
|
+
{
|
|
98
|
+
"name": "_owner",
|
|
99
|
+
"type": "address"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"name": "balanceOf",
|
|
103
|
+
"outputs": [
|
|
104
|
+
{
|
|
105
|
+
"name": "balance",
|
|
106
|
+
"type": "uint256"
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"payable": false,
|
|
110
|
+
"stateMutability": "view",
|
|
111
|
+
"type": "function"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"constant": true,
|
|
115
|
+
"inputs": [],
|
|
116
|
+
"name": "symbol",
|
|
117
|
+
"outputs": [
|
|
118
|
+
{
|
|
119
|
+
"name": "",
|
|
120
|
+
"type": "string"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"payable": false,
|
|
124
|
+
"stateMutability": "view",
|
|
125
|
+
"type": "function"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"constant": false,
|
|
129
|
+
"inputs": [
|
|
130
|
+
{
|
|
131
|
+
"name": "_to",
|
|
132
|
+
"type": "address"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "_value",
|
|
136
|
+
"type": "uint256"
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"name": "transfer",
|
|
140
|
+
"outputs": [
|
|
141
|
+
{
|
|
142
|
+
"name": "",
|
|
143
|
+
"type": "bool"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"payable": false,
|
|
147
|
+
"stateMutability": "nonpayable",
|
|
148
|
+
"type": "function"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"constant": true,
|
|
152
|
+
"inputs": [
|
|
153
|
+
{
|
|
154
|
+
"name": "_owner",
|
|
155
|
+
"type": "address"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "_spender",
|
|
159
|
+
"type": "address"
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"name": "allowance",
|
|
163
|
+
"outputs": [
|
|
164
|
+
{
|
|
165
|
+
"name": "",
|
|
166
|
+
"type": "uint256"
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
"payable": false,
|
|
170
|
+
"stateMutability": "view",
|
|
171
|
+
"type": "function"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"payable": true,
|
|
175
|
+
"stateMutability": "payable",
|
|
176
|
+
"type": "fallback"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"anonymous": false,
|
|
180
|
+
"inputs": [
|
|
181
|
+
{
|
|
182
|
+
"indexed": true,
|
|
183
|
+
"name": "owner",
|
|
184
|
+
"type": "address"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"indexed": true,
|
|
188
|
+
"name": "spender",
|
|
189
|
+
"type": "address"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"indexed": false,
|
|
193
|
+
"name": "value",
|
|
194
|
+
"type": "uint256"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"name": "Approval",
|
|
198
|
+
"type": "event"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"anonymous": false,
|
|
202
|
+
"inputs": [
|
|
203
|
+
{
|
|
204
|
+
"indexed": true,
|
|
205
|
+
"name": "from",
|
|
206
|
+
"type": "address"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"indexed": true,
|
|
210
|
+
"name": "to",
|
|
211
|
+
"type": "address"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"indexed": false,
|
|
215
|
+
"name": "value",
|
|
216
|
+
"type": "uint256"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"name": "Transfer",
|
|
220
|
+
"type": "event"
|
|
221
|
+
}
|
|
222
|
+
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {useWallet} from "@matchain/matchid-sdk-react/hooks"
|
|
2
|
-
import {Input,Button} from "@matchain/matchid-sdk-react/components"
|
|
3
|
-
import React, {useEffect, useState} from "react";
|
|
2
|
+
import {Input, Button} from "@matchain/matchid-sdk-react/components"
|
|
3
|
+
import React, {useEffect, useMemo, useState} from "react";
|
|
4
4
|
import {
|
|
5
5
|
createPublicClient,
|
|
6
6
|
formatUnits,
|
|
@@ -34,10 +34,10 @@ import {
|
|
|
34
34
|
zkSync,
|
|
35
35
|
} from 'viem/chains';
|
|
36
36
|
import {matchMain, matchTest} from "@/config/chains";
|
|
37
|
-
import RoutePrivate from "@/components/RoutePrivate";
|
|
38
37
|
import useLocalStore from "@/store/useLocalStore";
|
|
39
38
|
import ButtonGroup from "@/components/ButtonGroup";
|
|
40
|
-
import
|
|
39
|
+
import Erc20Abi from "@/abi/erc20.json";
|
|
40
|
+
import type {Abi} from "abitype";
|
|
41
41
|
|
|
42
42
|
const chainList = [
|
|
43
43
|
mainnet,
|
|
@@ -66,13 +66,13 @@ const chainList = [
|
|
|
66
66
|
|
|
67
67
|
export default function Wallet() {
|
|
68
68
|
|
|
69
|
-
const {initChainId,setInitChainId} = useLocalStore()
|
|
69
|
+
const {initChainId, setInitChainId} = useLocalStore()
|
|
70
70
|
|
|
71
71
|
const [message, setMessage] = useState('hello')
|
|
72
72
|
const [toAddress, setToAddress] = useState('')
|
|
73
73
|
const [toAmount, setToAmount] = useState('0.0001')
|
|
74
74
|
const [data, setToData] = useState('0x')
|
|
75
|
-
const {address, evmAccount, createWalletClient,walletReady} = useWallet()
|
|
75
|
+
const {address, evmAccount, createWalletClient, walletReady} = useWallet()
|
|
76
76
|
const chain = chainList.find((chain) => chain.id === initChainId)
|
|
77
77
|
|
|
78
78
|
const walletClient = createWalletClient({
|
|
@@ -130,7 +130,7 @@ export default function Wallet() {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
const onSignTransaction = async () => {
|
|
133
|
-
if (!walletClient
|
|
133
|
+
if (!walletClient || !evmAccount) return
|
|
134
134
|
try {
|
|
135
135
|
|
|
136
136
|
const transaction = {
|
|
@@ -166,7 +166,7 @@ export default function Wallet() {
|
|
|
166
166
|
</ButtonGroup>
|
|
167
167
|
<ButtonGroup title={"CreateWalletClient Chain"}>
|
|
168
168
|
<select value={initChainId} onChange={(e) => setInitChainId(parseInt(e.target.value))}>
|
|
169
|
-
{chainList.map((chain,index) => {
|
|
169
|
+
{chainList.map((chain, index) => {
|
|
170
170
|
return <option key={index} value={chain.id}>{chain.name}({chain.id})</option>
|
|
171
171
|
})}
|
|
172
172
|
</select>
|
|
@@ -180,7 +180,7 @@ export default function Wallet() {
|
|
|
180
180
|
<Button onClick={onSign} size={"sm"} disabled={!walletReady}>Sign message</Button>
|
|
181
181
|
</ButtonGroup>
|
|
182
182
|
<ButtonGroup title={"Signature Result"}>
|
|
183
|
-
<div className={`flex-1 flex-wrap break-all`}>{signature||'-'}</div>
|
|
183
|
+
<div className={`flex-1 flex-wrap break-all`}>{signature || '-'}</div>
|
|
184
184
|
</ButtonGroup>
|
|
185
185
|
|
|
186
186
|
<div className={`text-ellipsis break-words`}>balance:{balanceQuery.data?.toString()} wei/{balanceEth} eth</div>
|
|
@@ -214,6 +214,132 @@ export default function Wallet() {
|
|
|
214
214
|
<ButtonGroup title={"TxHash"}>
|
|
215
215
|
<div className={`flex-1 flex-wrap break-all`}>{hash || '-'}</div>
|
|
216
216
|
</ButtonGroup>
|
|
217
|
+
<ERC20/>
|
|
218
|
+
</div>
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function ERC20() {
|
|
222
|
+
const {initChainId, erc20Address, setErc20Address} = useLocalStore()
|
|
223
|
+
const [hash, setHash] = useState('')
|
|
224
|
+
const [amount, setAmount] = useState('1')
|
|
225
|
+
const [to, setTo] = useState('')
|
|
226
|
+
const {address, evmAccount, createWalletClient, walletReady} = useWallet()
|
|
227
|
+
const [loading,setLoading] = useState(false)
|
|
228
|
+
const chain = chainList.find((chain) => chain.id === initChainId)
|
|
229
|
+
const publicClient = createPublicClient({
|
|
230
|
+
chain: chain,
|
|
231
|
+
transport: http() as Transport,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const decimalsQuery = useQuery({
|
|
235
|
+
queryKey: ['erc20decimals', erc20Address],
|
|
236
|
+
queryFn: async () => {
|
|
237
|
+
return await publicClient.readContract({
|
|
238
|
+
abi: Erc20Abi,
|
|
239
|
+
address: erc20Address as `0x${string}`,
|
|
240
|
+
functionName: 'decimals',
|
|
241
|
+
args: []
|
|
242
|
+
}) as number
|
|
243
|
+
},
|
|
244
|
+
enabled:!!erc20Address
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
const symbolQuery = useQuery({
|
|
248
|
+
queryKey: ['erc20symbol', erc20Address],
|
|
249
|
+
queryFn: async () => {
|
|
250
|
+
return await publicClient.readContract({
|
|
251
|
+
abi: Erc20Abi,
|
|
252
|
+
address: erc20Address as `0x${string}`,
|
|
253
|
+
functionName: 'symbol',
|
|
254
|
+
args: []
|
|
255
|
+
}) as string
|
|
256
|
+
},
|
|
257
|
+
enabled:!!erc20Address
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
const balanceQuery = useQuery({
|
|
261
|
+
queryKey: ['erc20balance', address],
|
|
262
|
+
refetchInterval: 15_000,
|
|
263
|
+
queryFn: async () => {
|
|
264
|
+
return await publicClient.readContract({
|
|
265
|
+
abi:Erc20Abi,
|
|
266
|
+
address:erc20Address as `0x${string}`,
|
|
267
|
+
functionName:'balanceOf',
|
|
268
|
+
args:[address]
|
|
269
|
+
}) as bigint
|
|
270
|
+
},
|
|
271
|
+
enabled:!!erc20Address&&!!address
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
const balanceUnit = useMemo(()=>{
|
|
275
|
+
if(!decimalsQuery.data) return ''
|
|
276
|
+
if(!balanceQuery.data) return ''
|
|
277
|
+
|
|
278
|
+
return formatUnits(balanceQuery.data,decimalsQuery.data)
|
|
279
|
+
},[balanceQuery.data,decimalsQuery.data])
|
|
280
|
+
|
|
281
|
+
console.log(balanceQuery,symbolQuery,decimalsQuery)
|
|
282
|
+
const onSend = async()=>{
|
|
283
|
+
try{
|
|
284
|
+
setLoading(true)
|
|
285
|
+
if(!walletReady) throw new Error('wallet not ready')
|
|
286
|
+
if(!evmAccount) throw new Error('account not ready')
|
|
287
|
+
if(!erc20Address) throw new Error('erc20Address not ready')
|
|
288
|
+
if(!to) throw new Error('to not ready')
|
|
289
|
+
if(!amount) throw new Error('amount not ready')
|
|
290
|
+
|
|
291
|
+
const walletClient = createWalletClient({
|
|
292
|
+
chain:chain,
|
|
293
|
+
transport:http(),
|
|
294
|
+
})
|
|
295
|
+
if(walletClient){
|
|
296
|
+
|
|
297
|
+
const hash = await walletClient?.writeContract({
|
|
298
|
+
address:erc20Address as `0x${string}`,
|
|
299
|
+
abi:Erc20Abi as any,
|
|
300
|
+
functionName:'transfer',
|
|
301
|
+
args:[to,parseUnits(amount,decimalsQuery.data||18)],
|
|
302
|
+
})
|
|
303
|
+
setHash(hash)
|
|
304
|
+
}
|
|
305
|
+
|
|
217
306
|
|
|
307
|
+
}catch(error:any){
|
|
308
|
+
console.error(error)
|
|
309
|
+
alert(error.message)
|
|
310
|
+
}finally {
|
|
311
|
+
setLoading(false)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return <div>
|
|
315
|
+
<ButtonGroup title={"ERC20"}></ButtonGroup>
|
|
316
|
+
<ButtonGroup title={"Contract Address"}>
|
|
317
|
+
<input className="border px-[8px]" type={'text'} placeholder={'contact'} value={erc20Address}
|
|
318
|
+
onChange={(e) => setErc20Address(e.target.value)}/>
|
|
319
|
+
</ButtonGroup>
|
|
320
|
+
<ButtonGroup title={"Info"}>
|
|
321
|
+
<div className={`flex-1 flex-wrap break-all`}>Symbol:{symbolQuery.data}</div>
|
|
322
|
+
<div className={`flex-1 flex-wrap break-all`}>Decimals:{decimalsQuery.data}</div>
|
|
323
|
+
</ButtonGroup>
|
|
324
|
+
<ButtonGroup title={"Balance"}>
|
|
325
|
+
<div className={`flex-1 flex-wrap break-all`}>{balanceQuery.data?.toString()}</div>
|
|
326
|
+
<div className={`flex-1 flex-wrap break-all`}>{balanceUnit} {symbolQuery.data}</div>
|
|
327
|
+
</ButtonGroup>
|
|
328
|
+
<ButtonGroup title={"Send"}>
|
|
329
|
+
<div className={`flex-1 flex-wrap break-all`}>
|
|
330
|
+
To Address:
|
|
331
|
+
<input className="border px-[8px]" type={'text'} placeholder={'address'} value={to}
|
|
332
|
+
onChange={(e) => setTo(e.target.value)}/>
|
|
333
|
+
</div>
|
|
334
|
+
<div className={`flex-1 flex-wrap break-all`}>
|
|
335
|
+
Amount:
|
|
336
|
+
<input className="border px-[8px]" type={'text'} placeholder={'amount'} value={amount}
|
|
337
|
+
onChange={(e) => setAmount(e.target.value)}/>
|
|
338
|
+
</div>
|
|
339
|
+
<Button size={"sm"} loading={loading} onClick={onSend} disabled={!to||!amount}>Send</Button>
|
|
340
|
+
</ButtonGroup>
|
|
341
|
+
<ButtonGroup title={"Hash"}>
|
|
342
|
+
<div className={`flex-1 flex-wrap break-all`}>{hash}</div>
|
|
343
|
+
</ButtonGroup>
|
|
218
344
|
</div>
|
|
219
345
|
}
|
|
@@ -18,6 +18,9 @@ interface StoreState {
|
|
|
18
18
|
initChainId: number;
|
|
19
19
|
setInitChainId: (initChainId: number) => void
|
|
20
20
|
|
|
21
|
+
erc20Address: string;
|
|
22
|
+
setErc20Address: (erc20Address: string) => void;
|
|
23
|
+
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
const persistedState = persist<StoreState>(
|
|
@@ -33,7 +36,10 @@ const persistedState = persist<StoreState>(
|
|
|
33
36
|
setLocale: (locale: LocaleType) => set({locale}),
|
|
34
37
|
|
|
35
38
|
initChainId:1,
|
|
36
|
-
setInitChainId: (initChainId: number) => set({initChainId})
|
|
39
|
+
setInitChainId: (initChainId: number) => set({initChainId}),
|
|
40
|
+
|
|
41
|
+
erc20Address: '',
|
|
42
|
+
setErc20Address: (erc20Address: string) => set({erc20Address})
|
|
37
43
|
}),
|
|
38
44
|
{name: 'match-example-local'}
|
|
39
45
|
);
|
package/example/tsconfig.json
CHANGED