@matchain/matchid-sdk-react 0.1.56-alpha.6 → 0.1.56-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.
- package/example/package.json +1 -2
- package/example/src/pages/Wallet/index.tsx +90 -88
- package/example/yarn.lock +2251 -27
- package/package.json +7 -4
- package/dist/api.d.mts +0 -6
- package/dist/api.d.ts +0 -6
- package/dist/api.js +0 -1721
- package/dist/api.js.map +0 -1
- package/dist/api.mjs +0 -23
- package/dist/api.mjs.map +0 -1
- package/dist/assets/lottie.d.mts +0 -1
- package/dist/assets/lottie.d.ts +0 -1
- package/dist/assets/lottie.js +0 -68
- package/dist/assets/lottie.js.map +0 -1
- package/dist/assets/lottie.mjs +0 -22
- package/dist/assets/lottie.mjs.map +0 -1
- package/dist/chains.d.mts +0 -2
- package/dist/chains.d.ts +0 -2
- package/dist/chains.js +0 -94
- package/dist/chains.js.map +0 -1
- package/dist/chains.mjs +0 -11
- package/dist/chains.mjs.map +0 -1
- package/dist/chunk-3CR66BEX.mjs +0 -19
- package/dist/chunk-3CR66BEX.mjs.map +0 -1
- package/dist/chunk-GD7URBBZ.mjs +0 -1399
- package/dist/chunk-GD7URBBZ.mjs.map +0 -1
- package/dist/chunk-HBOS3RBL.mjs +0 -19
- package/dist/chunk-HBOS3RBL.mjs.map +0 -1
- package/dist/chunk-IZOOVZAD.mjs +0 -145
- package/dist/chunk-IZOOVZAD.mjs.map +0 -1
- package/dist/chunk-J5LGTIGS.mjs +0 -10
- package/dist/chunk-J5LGTIGS.mjs.map +0 -1
- package/dist/chunk-JX73EY6V.mjs +0 -67
- package/dist/chunk-JX73EY6V.mjs.map +0 -1
- package/dist/chunk-KFB23MLQ.mjs +0 -7666
- package/dist/chunk-KFB23MLQ.mjs.map +0 -1
- package/dist/chunk-NYE6DBEZ.mjs +0 -97
- package/dist/chunk-NYE6DBEZ.mjs.map +0 -1
- package/dist/chunk-UA6XHZHX.mjs +0 -17
- package/dist/chunk-UA6XHZHX.mjs.map +0 -1
- package/dist/chunk-XM6CYEXN.mjs +0 -53
- package/dist/chunk-XM6CYEXN.mjs.map +0 -1
- package/dist/components.d.mts +0 -6
- package/dist/components.d.ts +0 -6
- package/dist/components.js +0 -6494
- package/dist/components.js.map +0 -1
- package/dist/components.mjs +0 -57
- package/dist/components.mjs.map +0 -1
- package/dist/hooks.d.mts +0 -13
- package/dist/hooks.d.ts +0 -13
- package/dist/hooks.js +0 -3612
- package/dist/hooks.js.map +0 -1
- package/dist/hooks.mjs +0 -41
- package/dist/hooks.mjs.map +0 -1
- package/dist/icon.d.mts +0 -5
- package/dist/icon.d.ts +0 -5
- package/dist/icon.js +0 -1414
- package/dist/icon.js.map +0 -1
- package/dist/icon.mjs +0 -112
- package/dist/icon.mjs.map +0 -1
- package/dist/index-B50DU_xT.d.mts +0 -83
- package/dist/index-B50DU_xT.d.ts +0 -83
- package/dist/index-BcuSCgol.d.ts +0 -111
- package/dist/index-BlMLqmS2.d.mts +0 -3341
- package/dist/index-C1Nyy5zx.d.ts +0 -3341
- package/dist/index-CBcBTQyU.d.mts +0 -66
- package/dist/index-CD0dACxf.d.mts +0 -111
- package/dist/index-CER00guz.d.mts +0 -132
- package/dist/index-CHgaOUiW.d.mts +0 -52590
- package/dist/index-CHgaOUiW.d.ts +0 -52590
- package/dist/index-CjekOYJl.d.mts +0 -38
- package/dist/index-DN-jrh8-.d.ts +0 -213
- package/dist/index-DdN22cwf.d.ts +0 -38
- package/dist/index-DkIIQLbh.d.ts +0 -92
- package/dist/index-DlaCsN95.d.ts +0 -66
- package/dist/index-lh6qBAf_.d.mts +0 -92
- package/dist/index-o0WW1c5O.d.ts +0 -132
- package/dist/index-xThRnNN3.d.mts +0 -213
- package/dist/index.css +0 -2131
- package/dist/index.d.mts +0 -789
- package/dist/index.d.ts +0 -789
- package/dist/index.js +0 -9206
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -45
- package/dist/index.mjs.map +0 -1
- package/dist/request-B0CyrGFT.d.mts +0 -15
- package/dist/request-B0CyrGFT.d.ts +0 -15
- package/dist/types-CheN9vHJ.d.mts +0 -428
- package/dist/types-CheN9vHJ.d.ts +0 -428
- package/dist/types.d.mts +0 -3
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -44
- package/dist/types.js.map +0 -1
- package/dist/types.mjs +0 -11
- package/dist/types.mjs.map +0 -1
- package/dist/ui.d.mts +0 -7
- package/dist/ui.d.ts +0 -7
- package/dist/ui.js +0 -1682
- package/dist/ui.js.map +0 -1
- package/dist/ui.mjs +0 -47
- package/dist/ui.mjs.map +0 -1
- package/dist/utils.d.mts +0 -28
- package/dist/utils.d.ts +0 -28
- package/dist/utils.js +0 -192
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -34
- package/dist/utils.mjs.map +0 -1
- package/example/package-lock.json +0 -2965
package/example/package.json
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@matchain/matchid-sdk-react": "../dist",
|
|
30
|
-
"@zerodev/webauthn-key": "5.3.3",
|
|
31
30
|
"crypto": "^1.0.1",
|
|
32
31
|
"crypto-js": "^4.2.0",
|
|
33
32
|
"eruda": "^3.4.1"
|
|
@@ -41,4 +40,4 @@
|
|
|
41
40
|
"tailwindcss": "^3.4.14",
|
|
42
41
|
"vite": "^5.4.10"
|
|
43
42
|
}
|
|
44
|
-
}
|
|
43
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {useUserInfo, useWallet} from "@matchain/matchid-sdk-react/hooks"
|
|
2
|
-
import {Input, Button} from "@matchain/matchid-sdk-react/components"
|
|
3
|
-
import React, {useEffect, useMemo, useState} from "react";
|
|
1
|
+
import { useUserInfo, useWallet } from "@matchain/matchid-sdk-react/hooks"
|
|
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,
|
|
@@ -10,10 +10,12 @@ import {
|
|
|
10
10
|
Transport,
|
|
11
11
|
HttpTransportConfig, http, TransactionSerializable
|
|
12
12
|
} from "viem";
|
|
13
|
-
import {useQuery} from "@tanstack/react-query";
|
|
13
|
+
import { useQuery } from "@tanstack/react-query";
|
|
14
14
|
import {
|
|
15
15
|
mainnet,
|
|
16
16
|
arbitrum,
|
|
17
|
+
matchain,
|
|
18
|
+
matchainTestnet,
|
|
17
19
|
arbitrumGoerli,
|
|
18
20
|
arbitrumNova,
|
|
19
21
|
arbitrumSepolia,
|
|
@@ -33,7 +35,7 @@ import {
|
|
|
33
35
|
polygonAmoy,
|
|
34
36
|
zkSync,
|
|
35
37
|
} from 'viem/chains';
|
|
36
|
-
import {
|
|
38
|
+
import { MatchMain, MatchTest } from "@matchain/matchid-sdk-react/chains";
|
|
37
39
|
import useLocalStore from "@/store/useLocalStore";
|
|
38
40
|
import ButtonGroup from "@/components/ButtonGroup";
|
|
39
41
|
import Erc20Abi from "@/abi/erc20.json";
|
|
@@ -42,14 +44,14 @@ import AssetListModal from "@/pages/Wallet/components/AssetListModal";
|
|
|
42
44
|
import ImportTokenListModal from "@/pages/Wallet/components/ImportTokenListModal";
|
|
43
45
|
import WalletChainListModal from "@/pages/Wallet/components/WalletChainListModal";
|
|
44
46
|
import MatchWallet from "@/pages/Wallet/components/MatchWallet";
|
|
45
|
-
import {ethers} from "ethers";
|
|
47
|
+
import { ethers } from "ethers";
|
|
46
48
|
|
|
47
49
|
const chainList = [
|
|
48
50
|
mainnet,
|
|
49
51
|
bsc,
|
|
50
52
|
bscTestnet,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
matchain,
|
|
54
|
+
matchainTestnet,
|
|
53
55
|
arbitrum,
|
|
54
56
|
arbitrumGoerli,
|
|
55
57
|
arbitrumNova,
|
|
@@ -70,16 +72,16 @@ const chainList = [
|
|
|
70
72
|
]
|
|
71
73
|
|
|
72
74
|
export default function Wallet() {
|
|
73
|
-
const [modal, setModal] = useState<'chainList' | 'assetList' | 'importTokenList' | 'walletChainList' | ''
|
|
75
|
+
const [modal, setModal] = useState<'chainList' | 'assetList' | 'importTokenList' | 'walletChainList' | ''>('')
|
|
74
76
|
|
|
75
|
-
const {initChainId, setInitChainId} = useLocalStore()
|
|
76
|
-
const {overview} = useUserInfo()
|
|
77
|
+
const { initChainId, setInitChainId } = useLocalStore()
|
|
78
|
+
const { overview } = useUserInfo()
|
|
77
79
|
|
|
78
80
|
const [message, setMessage] = useState('hello')
|
|
79
81
|
const [toAddress, setToAddress] = useState('')
|
|
80
82
|
const [toAmount, setToAmount] = useState('0.000001')
|
|
81
83
|
const [data, setToData] = useState('0x')
|
|
82
|
-
const {address, evmAccount, createWalletClient, walletReady} = useWallet()
|
|
84
|
+
const { address, evmAccount, createWalletClient, walletReady } = useWallet()
|
|
83
85
|
const chain = chainList.find((chain) => chain.id === initChainId)
|
|
84
86
|
|
|
85
87
|
const walletClient = createWalletClient({
|
|
@@ -108,7 +110,7 @@ export default function Wallet() {
|
|
|
108
110
|
queryKey: ['balance', address],
|
|
109
111
|
refetchInterval: 15_000,
|
|
110
112
|
queryFn: async () => {
|
|
111
|
-
return await publicClient.getBalance({address: address as `0x${string}`})
|
|
113
|
+
return await publicClient.getBalance({ address: address as `0x${string}` })
|
|
112
114
|
}
|
|
113
115
|
})
|
|
114
116
|
//to eth
|
|
@@ -125,7 +127,7 @@ export default function Wallet() {
|
|
|
125
127
|
useEffect(() => {
|
|
126
128
|
gasPriceQuery.refetch()
|
|
127
129
|
balanceQuery.refetch()
|
|
128
|
-
}, [chain,address]);
|
|
130
|
+
}, [chain, address]);
|
|
129
131
|
|
|
130
132
|
const onSign = async () => {
|
|
131
133
|
if (!walletClient) return;
|
|
@@ -149,7 +151,7 @@ export default function Wallet() {
|
|
|
149
151
|
const request = await walletClient.prepareTransactionRequest(transaction)
|
|
150
152
|
const res = await evmAccount.signTransaction!(request as TransactionSerializable)
|
|
151
153
|
const tx = ethers.utils.parseTransaction(res);
|
|
152
|
-
console.log('tx',tx)
|
|
154
|
+
console.log('tx', tx)
|
|
153
155
|
setTransactionSign(res)
|
|
154
156
|
} catch (e) {
|
|
155
157
|
console.error(e)
|
|
@@ -178,16 +180,16 @@ export default function Wallet() {
|
|
|
178
180
|
|
|
179
181
|
<ButtonGroup title={"QueryList"}>
|
|
180
182
|
<button className={`bg-gray-300 p-1 rounded`}
|
|
181
|
-
|
|
183
|
+
onClick={() => setModal('chainList')}>ChainList
|
|
182
184
|
</button>
|
|
183
185
|
<button className={`bg-gray-300 p-1 rounded`}
|
|
184
|
-
|
|
186
|
+
onClick={() => setModal('assetList')}>AssetList
|
|
185
187
|
</button>
|
|
186
188
|
<button className={`bg-gray-300 p-1 rounded`}
|
|
187
|
-
|
|
189
|
+
onClick={() => setModal('importTokenList')}>ImportTokenList
|
|
188
190
|
</button>
|
|
189
191
|
<button className={`bg-gray-300 p-1 rounded`}
|
|
190
|
-
|
|
192
|
+
onClick={() => setModal('walletChainList')}>WalletChainList
|
|
191
193
|
</button>
|
|
192
194
|
{/*<button className={`bg-gray-300 p-1 rounded`}*/}
|
|
193
195
|
{/* onClick={exportWallet}>Export*/}
|
|
@@ -208,7 +210,7 @@ export default function Wallet() {
|
|
|
208
210
|
</ButtonGroup>
|
|
209
211
|
<ButtonGroup title={"Signature Message"}>
|
|
210
212
|
<input className="border px-[8px]" type={'text'} placeholder={'message'} value={message}
|
|
211
|
-
|
|
213
|
+
onChange={(e) => setMessage(e.target.value)} />
|
|
212
214
|
<Button onClick={onSign} size={"sm"} disabled={!walletReady}>Sign message</Button>
|
|
213
215
|
</ButtonGroup>
|
|
214
216
|
<ButtonGroup title={"Signature Result"}>
|
|
@@ -224,17 +226,17 @@ export default function Wallet() {
|
|
|
224
226
|
<div>
|
|
225
227
|
To Address:
|
|
226
228
|
<input className="border" type={'text'} placeholder={'to address'} value={toAddress}
|
|
227
|
-
|
|
229
|
+
onChange={(e) => setToAddress(e.target.value)} />
|
|
228
230
|
</div>
|
|
229
231
|
<div>
|
|
230
232
|
Amount:
|
|
231
233
|
<input className="border" type={'text'} placeholder={'amount'} value={toAmount}
|
|
232
|
-
|
|
234
|
+
onChange={(e) => setToAmount(e.target.value)} />
|
|
233
235
|
</div>
|
|
234
236
|
<div>
|
|
235
237
|
Data:
|
|
236
238
|
<input className="border" type={'text'} placeholder={'data'} value={data}
|
|
237
|
-
|
|
239
|
+
onChange={(e) => setToData(e.target.value)} />
|
|
238
240
|
</div>
|
|
239
241
|
<ButtonGroup>
|
|
240
242
|
<Button onClick={onSignTransaction} size={"sm"} disabled={!walletReady}>Sign</Button>
|
|
@@ -247,20 +249,20 @@ export default function Wallet() {
|
|
|
247
249
|
<div className={`flex-1 flex-wrap break-all`}>{hash || '-'}</div>
|
|
248
250
|
</ButtonGroup>
|
|
249
251
|
|
|
250
|
-
{modal == 'chainList' && <ChainListModal isOpen onClose={() => setModal('')}/>}
|
|
251
|
-
{modal == 'walletChainList' && <WalletChainListModal isOpen onClose={() => setModal('')}/>}
|
|
252
|
-
{modal == 'assetList' && <AssetListModal isOpen onClose={() => setModal('')}/>}
|
|
253
|
-
{modal == 'importTokenList' && <ImportTokenListModal isOpen onClose={() => setModal('')}/>}
|
|
252
|
+
{modal == 'chainList' && <ChainListModal isOpen onClose={() => setModal('')} />}
|
|
253
|
+
{modal == 'walletChainList' && <WalletChainListModal isOpen onClose={() => setModal('')} />}
|
|
254
|
+
{modal == 'assetList' && <AssetListModal isOpen onClose={() => setModal('')} />}
|
|
255
|
+
{modal == 'importTokenList' && <ImportTokenListModal isOpen onClose={() => setModal('')} />}
|
|
254
256
|
|
|
255
|
-
<ERC20/>
|
|
256
|
-
<MatchWallet/>
|
|
257
|
+
<ERC20 />
|
|
258
|
+
<MatchWallet />
|
|
257
259
|
</div>
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
function ERC20() {
|
|
261
|
-
const {initChainId, erc20Address, setErc20Address} = useLocalStore()
|
|
263
|
+
const { initChainId, erc20Address, setErc20Address } = useLocalStore()
|
|
262
264
|
|
|
263
|
-
const {address, evmAccount, createWalletClient, walletReady} = useWallet()
|
|
265
|
+
const { address, evmAccount, createWalletClient, walletReady } = useWallet()
|
|
264
266
|
|
|
265
267
|
const chain = chainList.find((chain) => chain.id === initChainId)
|
|
266
268
|
const publicClient = createPublicClient({
|
|
@@ -278,7 +280,7 @@ function ERC20() {
|
|
|
278
280
|
args: []
|
|
279
281
|
}) as number
|
|
280
282
|
},
|
|
281
|
-
enabled
|
|
283
|
+
enabled: !!erc20Address
|
|
282
284
|
})
|
|
283
285
|
|
|
284
286
|
const symbolQuery = useQuery({
|
|
@@ -291,7 +293,7 @@ function ERC20() {
|
|
|
291
293
|
args: []
|
|
292
294
|
}) as string
|
|
293
295
|
},
|
|
294
|
-
enabled
|
|
296
|
+
enabled: !!erc20Address
|
|
295
297
|
})
|
|
296
298
|
|
|
297
299
|
const balanceQuery = useQuery({
|
|
@@ -299,58 +301,58 @@ function ERC20() {
|
|
|
299
301
|
refetchInterval: 15_000,
|
|
300
302
|
queryFn: async () => {
|
|
301
303
|
return await publicClient.readContract({
|
|
302
|
-
abi:Erc20Abi,
|
|
303
|
-
address:erc20Address as `0x${string}`,
|
|
304
|
-
functionName:'balanceOf',
|
|
305
|
-
args:[address]
|
|
304
|
+
abi: Erc20Abi,
|
|
305
|
+
address: erc20Address as `0x${string}`,
|
|
306
|
+
functionName: 'balanceOf',
|
|
307
|
+
args: [address]
|
|
306
308
|
}) as bigint
|
|
307
309
|
},
|
|
308
|
-
enabled
|
|
310
|
+
enabled: !!erc20Address && !!address
|
|
309
311
|
})
|
|
310
312
|
|
|
311
|
-
const balanceUnit = useMemo(()=>{
|
|
312
|
-
if(!decimalsQuery.data) return ''
|
|
313
|
-
if(!balanceQuery.data) return ''
|
|
313
|
+
const balanceUnit = useMemo(() => {
|
|
314
|
+
if (!decimalsQuery.data) return ''
|
|
315
|
+
if (!balanceQuery.data) return ''
|
|
314
316
|
|
|
315
|
-
return formatUnits(balanceQuery.data,decimalsQuery.data)
|
|
316
|
-
},[balanceQuery.data,decimalsQuery.data])
|
|
317
|
+
return formatUnits(balanceQuery.data, decimalsQuery.data)
|
|
318
|
+
}, [balanceQuery.data, decimalsQuery.data])
|
|
317
319
|
|
|
318
320
|
// console.log(balanceQuery,symbolQuery,decimalsQuery)
|
|
319
321
|
|
|
320
|
-
function Transfer(){
|
|
322
|
+
function Transfer() {
|
|
321
323
|
const [to, setTo] = useState(address)
|
|
322
324
|
const [hash, setHash] = useState('')
|
|
323
325
|
const [amount, setAmount] = useState('0.0001')
|
|
324
|
-
const [loading,setLoading] = useState(false)
|
|
325
|
-
const onSend = async()=>{
|
|
326
|
-
try{
|
|
326
|
+
const [loading, setLoading] = useState(false)
|
|
327
|
+
const onSend = async () => {
|
|
328
|
+
try {
|
|
327
329
|
setLoading(true)
|
|
328
|
-
if(!walletReady) throw new Error('wallet not ready')
|
|
329
|
-
if(!evmAccount) throw new Error('account not ready')
|
|
330
|
-
if(!erc20Address) throw new Error('erc20Address not ready')
|
|
331
|
-
if(!to) throw new Error('to not ready')
|
|
332
|
-
if(!amount) throw new Error('amount not ready')
|
|
330
|
+
if (!walletReady) throw new Error('wallet not ready')
|
|
331
|
+
if (!evmAccount) throw new Error('account not ready')
|
|
332
|
+
if (!erc20Address) throw new Error('erc20Address not ready')
|
|
333
|
+
if (!to) throw new Error('to not ready')
|
|
334
|
+
if (!amount) throw new Error('amount not ready')
|
|
333
335
|
|
|
334
336
|
const walletClient = createWalletClient({
|
|
335
|
-
chain:chain,
|
|
336
|
-
transport:http(),
|
|
337
|
+
chain: chain,
|
|
338
|
+
transport: http(),
|
|
337
339
|
})
|
|
338
|
-
if(walletClient){
|
|
340
|
+
if (walletClient) {
|
|
339
341
|
|
|
340
342
|
const hash = await walletClient?.writeContract({
|
|
341
|
-
address:erc20Address as `0x${string}`,
|
|
342
|
-
abi:Erc20Abi as any,
|
|
343
|
-
functionName:'transfer',
|
|
344
|
-
args:[to,parseUnits(amount,decimalsQuery.data||18)],
|
|
343
|
+
address: erc20Address as `0x${string}`,
|
|
344
|
+
abi: Erc20Abi as any,
|
|
345
|
+
functionName: 'transfer',
|
|
346
|
+
args: [to, parseUnits(amount, decimalsQuery.data || 18)],
|
|
345
347
|
})
|
|
346
348
|
setHash(hash)
|
|
347
349
|
}
|
|
348
350
|
|
|
349
351
|
|
|
350
|
-
}catch(error:any){
|
|
352
|
+
} catch (error: any) {
|
|
351
353
|
console.error(error)
|
|
352
354
|
alert(error.message)
|
|
353
|
-
}finally {
|
|
355
|
+
} finally {
|
|
354
356
|
setLoading(false)
|
|
355
357
|
}
|
|
356
358
|
}
|
|
@@ -360,57 +362,57 @@ function ERC20() {
|
|
|
360
362
|
<div className={`flex-1 flex-wrap break-all`}>
|
|
361
363
|
To Address:
|
|
362
364
|
<input className="border px-[8px]" type={'text'} placeholder={'address'} value={to}
|
|
363
|
-
|
|
365
|
+
onChange={(e) => setTo(e.target.value)} />
|
|
364
366
|
</div>
|
|
365
367
|
<div className={`flex-1 flex-wrap break-all`}>
|
|
366
368
|
Amount:
|
|
367
369
|
<input className="border px-[8px]" type={'text'} placeholder={'amount'} value={amount}
|
|
368
|
-
|
|
370
|
+
onChange={(e) => setAmount(e.target.value)} />
|
|
369
371
|
</div>
|
|
370
372
|
|
|
371
373
|
</ButtonGroup>
|
|
372
374
|
|
|
373
375
|
<ButtonGroup title={"Transaction"}>
|
|
374
|
-
<Button size={"sm"} loading={loading} onClick={onSend} disabled={!to
|
|
376
|
+
<Button size={"sm"} loading={loading} onClick={onSend} disabled={!to || !amount || !walletReady}>Send</Button>
|
|
375
377
|
<div className={`flex-1 flex-wrap break-all`}>{hash}</div>
|
|
376
378
|
</ButtonGroup>
|
|
377
379
|
</>
|
|
378
380
|
}
|
|
379
381
|
|
|
380
|
-
function Approve(){
|
|
382
|
+
function Approve() {
|
|
381
383
|
const [to, setTo] = useState(address)
|
|
382
384
|
const [hash, setHash] = useState('')
|
|
383
385
|
const [amount, setAmount] = useState('0.0001')
|
|
384
|
-
const [loading,setLoading] = useState(false)
|
|
385
|
-
const onSend = async()=>{
|
|
386
|
-
try{
|
|
386
|
+
const [loading, setLoading] = useState(false)
|
|
387
|
+
const onSend = async () => {
|
|
388
|
+
try {
|
|
387
389
|
setLoading(true)
|
|
388
|
-
if(!walletReady) throw new Error('wallet not ready')
|
|
389
|
-
if(!evmAccount) throw new Error('account not ready')
|
|
390
|
-
if(!erc20Address) throw new Error('erc20Address not ready')
|
|
391
|
-
if(!to) throw new Error('to not ready')
|
|
392
|
-
if(!amount) throw new Error('amount not ready')
|
|
390
|
+
if (!walletReady) throw new Error('wallet not ready')
|
|
391
|
+
if (!evmAccount) throw new Error('account not ready')
|
|
392
|
+
if (!erc20Address) throw new Error('erc20Address not ready')
|
|
393
|
+
if (!to) throw new Error('to not ready')
|
|
394
|
+
if (!amount) throw new Error('amount not ready')
|
|
393
395
|
|
|
394
396
|
const walletClient = createWalletClient({
|
|
395
|
-
chain:chain,
|
|
396
|
-
transport:http(),
|
|
397
|
+
chain: chain,
|
|
398
|
+
transport: http(),
|
|
397
399
|
})
|
|
398
|
-
if(walletClient){
|
|
400
|
+
if (walletClient) {
|
|
399
401
|
|
|
400
402
|
const hash = await walletClient?.writeContract({
|
|
401
|
-
address:erc20Address as `0x${string}`,
|
|
402
|
-
abi:Erc20Abi as any,
|
|
403
|
-
functionName:'approve',
|
|
404
|
-
args:[to,parseUnits(amount,decimalsQuery.data||18)],
|
|
403
|
+
address: erc20Address as `0x${string}`,
|
|
404
|
+
abi: Erc20Abi as any,
|
|
405
|
+
functionName: 'approve',
|
|
406
|
+
args: [to, parseUnits(amount, decimalsQuery.data || 18)],
|
|
405
407
|
})
|
|
406
408
|
setHash(hash)
|
|
407
409
|
}
|
|
408
410
|
|
|
409
411
|
|
|
410
|
-
}catch(error:any){
|
|
412
|
+
} catch (error: any) {
|
|
411
413
|
console.error(error)
|
|
412
414
|
alert(error.message)
|
|
413
|
-
}finally {
|
|
415
|
+
} finally {
|
|
414
416
|
setLoading(false)
|
|
415
417
|
}
|
|
416
418
|
}
|
|
@@ -420,18 +422,18 @@ function ERC20() {
|
|
|
420
422
|
<div className={`flex-1 flex-wrap break-all`}>
|
|
421
423
|
To Address:
|
|
422
424
|
<input className="border px-[8px]" type={'text'} placeholder={'address'} value={to}
|
|
423
|
-
|
|
425
|
+
onChange={(e) => setTo(e.target.value)} />
|
|
424
426
|
</div>
|
|
425
427
|
<div className={`flex-1 flex-wrap break-all`}>
|
|
426
428
|
Amount:
|
|
427
429
|
<input className="border px-[8px]" type={'text'} placeholder={'amount'} value={amount}
|
|
428
|
-
|
|
430
|
+
onChange={(e) => setAmount(e.target.value)} />
|
|
429
431
|
</div>
|
|
430
432
|
|
|
431
433
|
</ButtonGroup>
|
|
432
434
|
|
|
433
435
|
<ButtonGroup title={"Transaction"}>
|
|
434
|
-
<Button size={"sm"} loading={loading} onClick={onSend} disabled={!to
|
|
436
|
+
<Button size={"sm"} loading={loading} onClick={onSend} disabled={!to || !amount || !walletReady}>Send</Button>
|
|
435
437
|
<div className={`flex-1 flex-wrap break-all`}>{hash}</div>
|
|
436
438
|
</ButtonGroup>
|
|
437
439
|
</>
|
|
@@ -441,7 +443,7 @@ function ERC20() {
|
|
|
441
443
|
<ButtonGroup title={"ERC20"}></ButtonGroup>
|
|
442
444
|
<ButtonGroup title={"Contract Address"}>
|
|
443
445
|
<input className="border px-[8px]" type={'text'} placeholder={'contract'} value={erc20Address}
|
|
444
|
-
|
|
446
|
+
onChange={(e) => setErc20Address(e.target.value)} />
|
|
445
447
|
</ButtonGroup>
|
|
446
448
|
<ButtonGroup title={"Info"}>
|
|
447
449
|
<div className={`flex-1 flex-wrap break-all`}>Symbol:{symbolQuery.data}</div>
|
|
@@ -451,7 +453,7 @@ function ERC20() {
|
|
|
451
453
|
<div className={`flex-1 flex-wrap break-all`}>{balanceQuery.data?.toString()}</div>
|
|
452
454
|
<div className={`flex-1 flex-wrap break-all`}>{balanceUnit} {symbolQuery.data}</div>
|
|
453
455
|
</ButtonGroup>
|
|
454
|
-
<Transfer/>
|
|
455
|
-
<Approve/>
|
|
456
|
+
<Transfer />
|
|
457
|
+
<Approve />
|
|
456
458
|
</div>
|
|
457
459
|
}
|