@matchain/matchid-sdk-react 0.1.42-alpha.1 → 0.1.42-alpha.10
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/assets/icon/index.d.mts +1 -1
- package/dist/assets/icon/index.d.ts +1 -1
- package/dist/{chunk-U5KWO2YJ.mjs → chunk-N53ZMW5C.mjs} +2 -2
- package/dist/chunk-SQIJR7RA.mjs +29 -0
- package/dist/chunk-SQIJR7RA.mjs.map +1 -0
- package/dist/chunk-YG4MNAUD.mjs +4662 -0
- package/dist/chunk-YG4MNAUD.mjs.map +1 -0
- package/dist/components/index.d.mts +3 -2
- package/dist/components/index.d.ts +3 -2
- package/dist/components/index.js +676 -453
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -1
- package/dist/hooks/api/index.d.mts +2 -2
- package/dist/hooks/api/index.d.ts +2 -2
- package/dist/hooks/api/index.js +120 -76
- package/dist/hooks/api/index.js.map +1 -1
- package/dist/hooks/api/index.mjs +3 -2
- package/dist/hooks/index.d.mts +5 -2
- package/dist/hooks/index.d.ts +5 -2
- package/dist/hooks/index.js +328 -145
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +2 -1
- package/dist/index-BxS06a5O.d.ts +50 -0
- package/dist/{index-Dq9Swg8r.d.ts → index-Ca9nh_8s.d.ts} +1 -1
- package/dist/{index-COlsBC-b.d.mts → index-CmH9iRLd.d.mts} +25 -12
- package/dist/{index-C3KZYrtu.d.mts → index-DFZpfAfc.d.mts} +1 -1
- package/dist/index-DKMrpRJC.d.ts +137 -0
- package/dist/{index-fS75Swm8.d.ts → index-DY_ReBra.d.ts} +25 -12
- package/dist/index-q5XDobUF.d.mts +50 -0
- package/dist/index-sOVSnYF4.d.mts +137 -0
- package/dist/index.css +84 -4
- package/dist/index.d.mts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +1100 -614
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -2
- package/dist/mpc-CTbBWHld.d.mts +20 -0
- package/dist/mpc-CTbBWHld.d.ts +20 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +44 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +10 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types-CVwZEgQ0.d.mts +244 -0
- package/dist/types-CVwZEgQ0.d.ts +244 -0
- package/example/package.json +1 -0
- package/example/src/App.tsx +56 -27
- package/example/src/components/ButtonGroup/index.tsx +10 -0
- package/example/src/components/Login/index.tsx +2 -2
- package/example/src/components/RoutePrivate/index.tsx +4 -3
- package/example/src/config/chains/index.ts +2 -0
- package/example/src/config/chains/matchMain.ts +27 -0
- package/example/src/config/chains/matchTest.ts +33 -0
- package/example/src/config/index.ts +6 -2
- package/example/src/pages/User/components/BindListModal.tsx +10 -0
- package/example/src/pages/User/components/PohListModal.tsx +10 -0
- package/example/src/pages/User/components/QueryDisplay.tsx +25 -0
- package/example/src/pages/{User.tsx → User/index.tsx} +55 -84
- package/example/src/pages/Wallet.tsx +133 -44
- package/example/src/store/useLocalStore.ts +45 -0
- package/package.json +7 -2
- package/dist/chunk-SBOIXOAW.mjs +0 -4197
- package/dist/chunk-SBOIXOAW.mjs.map +0 -1
- package/dist/index-BrdP6eg5.d.ts +0 -93
- package/dist/index-D7bNSBwl.d.mts +0 -93
- package/dist/types.d-CLO_WLka.d.mts +0 -176
- package/dist/types.d-CLO_WLka.d.ts +0 -176
- /package/dist/{chunk-U5KWO2YJ.mjs.map → chunk-N53ZMW5C.mjs.map} +0 -0
|
@@ -1,23 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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";
|
|
4
|
+
import {
|
|
5
|
+
createPublicClient,
|
|
6
|
+
formatUnits,
|
|
7
|
+
parseUnits,
|
|
8
|
+
parseGwei,
|
|
9
|
+
Account,
|
|
10
|
+
Transport,
|
|
11
|
+
HttpTransportConfig, http, TransactionSerializable
|
|
12
|
+
} from "viem";
|
|
4
13
|
import {useQuery} from "@tanstack/react-query";
|
|
5
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
mainnet,
|
|
16
|
+
arbitrum,
|
|
17
|
+
arbitrumGoerli,
|
|
18
|
+
arbitrumNova,
|
|
19
|
+
arbitrumSepolia,
|
|
20
|
+
avalanche,
|
|
21
|
+
base,
|
|
22
|
+
baseSepolia,
|
|
23
|
+
baseGoerli,
|
|
24
|
+
bsc,
|
|
25
|
+
bscTestnet,
|
|
26
|
+
goerli,
|
|
27
|
+
linea,
|
|
28
|
+
lineaGoerli,
|
|
29
|
+
lineaSepolia,
|
|
30
|
+
sepolia,
|
|
31
|
+
polygonMumbai,
|
|
32
|
+
polygon,
|
|
33
|
+
polygonAmoy,
|
|
34
|
+
zkSync,
|
|
35
|
+
} from 'viem/chains';
|
|
36
|
+
import {matchMain, matchTest} from "@/config/chains";
|
|
37
|
+
import RoutePrivate from "@/components/RoutePrivate";
|
|
38
|
+
import useLocalStore from "@/store/useLocalStore";
|
|
39
|
+
import ButtonGroup from "@/components/ButtonGroup";
|
|
40
|
+
import type {SerializeTransactionFn} from "viem/utils/transaction/serializeTransaction";
|
|
6
41
|
|
|
7
|
-
const
|
|
42
|
+
const chainList = [
|
|
43
|
+
mainnet,
|
|
44
|
+
bsc,
|
|
45
|
+
bscTestnet,
|
|
46
|
+
matchMain,
|
|
47
|
+
matchTest,
|
|
48
|
+
arbitrum,
|
|
49
|
+
arbitrumGoerli,
|
|
50
|
+
arbitrumNova,
|
|
51
|
+
arbitrumSepolia,
|
|
52
|
+
avalanche,
|
|
53
|
+
base,
|
|
54
|
+
baseSepolia,
|
|
55
|
+
baseGoerli,
|
|
56
|
+
goerli,
|
|
57
|
+
linea,
|
|
58
|
+
lineaGoerli,
|
|
59
|
+
lineaSepolia,
|
|
60
|
+
sepolia,
|
|
61
|
+
polygonMumbai,
|
|
62
|
+
polygon,
|
|
63
|
+
polygonAmoy,
|
|
64
|
+
zkSync,
|
|
65
|
+
]
|
|
8
66
|
|
|
9
67
|
export default function Wallet() {
|
|
68
|
+
|
|
69
|
+
const {initChainId,setInitChainId} = useLocalStore()
|
|
70
|
+
|
|
10
71
|
const [message, setMessage] = useState('hello')
|
|
11
72
|
const [toAddress, setToAddress] = useState('')
|
|
12
73
|
const [toAmount, setToAmount] = useState('0.0001')
|
|
13
74
|
const [data, setToData] = useState('0x')
|
|
14
|
-
const {address, evmAccount} = useWallet()
|
|
15
|
-
const chain =
|
|
75
|
+
const {address, evmAccount, createWalletClient,walletReady} = useWallet()
|
|
76
|
+
const chain = chainList.find((chain) => chain.id === initChainId)
|
|
77
|
+
|
|
16
78
|
const walletClient = createWalletClient({
|
|
17
79
|
chain: chain,
|
|
18
80
|
transport: http(),
|
|
81
|
+
// account:evmAccount
|
|
19
82
|
})
|
|
20
83
|
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (address && !toAddress) {
|
|
86
|
+
setToAddress(address)
|
|
87
|
+
}
|
|
88
|
+
}, [address, toAddress]);
|
|
89
|
+
|
|
21
90
|
|
|
22
91
|
const [hash, setHash] = useState('')
|
|
23
92
|
const [transactionSign, setTransactionSign] = useState('')
|
|
@@ -25,7 +94,7 @@ export default function Wallet() {
|
|
|
25
94
|
|
|
26
95
|
const publicClient = createPublicClient({
|
|
27
96
|
chain: chain,
|
|
28
|
-
transport: http(),
|
|
97
|
+
transport: http() as Transport,
|
|
29
98
|
});
|
|
30
99
|
|
|
31
100
|
const balanceQuery = useQuery({
|
|
@@ -46,7 +115,13 @@ export default function Wallet() {
|
|
|
46
115
|
}
|
|
47
116
|
})
|
|
48
117
|
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
gasPriceQuery.refetch()
|
|
120
|
+
balanceQuery.refetch()
|
|
121
|
+
}, [chain]);
|
|
122
|
+
|
|
49
123
|
const onSign = async () => {
|
|
124
|
+
if (!walletClient) return;
|
|
50
125
|
const res = await walletClient.signMessage({
|
|
51
126
|
message,
|
|
52
127
|
account: evmAccount as Account
|
|
@@ -55,43 +130,62 @@ export default function Wallet() {
|
|
|
55
130
|
}
|
|
56
131
|
|
|
57
132
|
const onSignTransaction = async () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
133
|
+
if (!walletClient||!evmAccount) return
|
|
134
|
+
try {
|
|
135
|
+
|
|
136
|
+
const transaction = {
|
|
137
|
+
to: toAddress as `0x${string}`,
|
|
138
|
+
value: parseUnits(toAmount, 18),
|
|
139
|
+
data: data as `0x${string}`,
|
|
140
|
+
chain: chain
|
|
141
|
+
}
|
|
142
|
+
const request = await walletClient.prepareTransactionRequest(transaction)
|
|
143
|
+
const res = await evmAccount.signTransaction!(request as TransactionSerializable)
|
|
144
|
+
setTransactionSign(res)
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error(e)
|
|
63
147
|
}
|
|
64
|
-
const request = await walletClient.prepareTransactionRequest(transaction)
|
|
65
|
-
const res = await walletClient.signTransaction(request)
|
|
66
|
-
setTransactionSign(res)
|
|
67
148
|
}
|
|
68
149
|
|
|
69
150
|
const onSendTransaction = async () => {
|
|
151
|
+
if (!walletClient) return
|
|
70
152
|
const res = await walletClient.sendTransaction({
|
|
71
|
-
account:evmAccount as Account,
|
|
153
|
+
// account:evmAccount as Account,
|
|
72
154
|
to: toAddress as `0x${string}`,
|
|
73
155
|
value: parseUnits(toAmount, 18),
|
|
74
156
|
data: data as `0x${string}`,
|
|
157
|
+
chain: chain
|
|
75
158
|
})
|
|
76
159
|
setHash(res)
|
|
77
160
|
}
|
|
78
161
|
|
|
79
162
|
|
|
80
163
|
return <div>
|
|
81
|
-
<
|
|
82
|
-
|
|
164
|
+
<ButtonGroup title={"Wallet Ready"}>
|
|
165
|
+
{walletReady ? 'Ready' : 'Not Ready'}
|
|
166
|
+
</ButtonGroup>
|
|
167
|
+
<ButtonGroup title={"CreateWalletClient Chain"}>
|
|
168
|
+
<select value={initChainId} onChange={(e) => setInitChainId(parseInt(e.target.value))}>
|
|
169
|
+
{chainList.map((chain,index) => {
|
|
170
|
+
return <option key={index} value={chain.id}>{chain.name}({chain.id})</option>
|
|
171
|
+
})}
|
|
172
|
+
</select>
|
|
173
|
+
</ButtonGroup>
|
|
174
|
+
<ButtonGroup title={"Ethereum address"}>
|
|
175
|
+
<div className={`flex-1 flex-wrap break-all`}>{address}</div>
|
|
176
|
+
</ButtonGroup>
|
|
177
|
+
<ButtonGroup title={"Signature Message"}>
|
|
178
|
+
<input className="border px-[8px]" type={'text'} placeholder={'message'} value={message}
|
|
179
|
+
onChange={(e) => setMessage(e.target.value)}/>
|
|
180
|
+
<Button onClick={onSign} size={"sm"} disabled={!walletReady}>Sign message</Button>
|
|
181
|
+
</ButtonGroup>
|
|
182
|
+
<ButtonGroup title={"Signature Result"}>
|
|
183
|
+
<div className={`flex-1 flex-wrap break-all`}>{signature||'-'}</div>
|
|
184
|
+
</ButtonGroup>
|
|
185
|
+
|
|
83
186
|
<div className={`text-ellipsis break-words`}>balance:{balanceQuery.data?.toString()} wei/{balanceEth} eth</div>
|
|
84
187
|
<div className={`text-ellipsis break-words`}>gas price:{gasPriceQuery.data?.toString()} wei</div>
|
|
85
|
-
|
|
86
|
-
<input className="border" type={'text'} placeholder={'message'} value={message}
|
|
87
|
-
onChange={(e) => setMessage(e.target.value)}/>
|
|
88
|
-
<button className={`bg-gray-300 p-1 rounded`}
|
|
89
|
-
onClick={onSign}>Sign message
|
|
90
|
-
</button>
|
|
91
|
-
</div>
|
|
92
|
-
<div>
|
|
93
|
-
Signature:{signature}
|
|
94
|
-
</div>
|
|
188
|
+
|
|
95
189
|
<div className="text-bold">
|
|
96
190
|
Send Transaction
|
|
97
191
|
</div>
|
|
@@ -110,21 +204,16 @@ export default function Wallet() {
|
|
|
110
204
|
<input className="border" type={'text'} placeholder={'data'} value={data}
|
|
111
205
|
onChange={(e) => setToData(e.target.value)}/>
|
|
112
206
|
</div>
|
|
113
|
-
<
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
</div>
|
|
124
|
-
<div>
|
|
125
|
-
TxHash:{hash}
|
|
126
|
-
</div>
|
|
127
|
-
|
|
207
|
+
<ButtonGroup>
|
|
208
|
+
<Button onClick={onSignTransaction} size={"sm"} disabled={!walletReady}>Sign</Button>
|
|
209
|
+
<Button onClick={onSendTransaction} size={"sm"} disabled={!walletReady}>Send</Button>
|
|
210
|
+
</ButtonGroup>
|
|
211
|
+
<ButtonGroup title={"TxSignature"}>
|
|
212
|
+
<div className={`flex-1 flex-wrap break-all`}>{transactionSign || '-'}</div>
|
|
213
|
+
</ButtonGroup>
|
|
214
|
+
<ButtonGroup title={"TxHash"}>
|
|
215
|
+
<div className={`flex-1 flex-wrap break-all`}>{hash || '-'}</div>
|
|
216
|
+
</ButtonGroup>
|
|
128
217
|
|
|
129
218
|
</div>
|
|
130
219
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {create} from 'zustand';
|
|
2
|
+
import {devtools, persist} from 'zustand/middleware';
|
|
3
|
+
import {LocaleType} from "@matchain/matchid-sdk-react/types";
|
|
4
|
+
|
|
5
|
+
interface StoreState {
|
|
6
|
+
appid: string
|
|
7
|
+
endpoints: {
|
|
8
|
+
back: string;
|
|
9
|
+
auth: string;
|
|
10
|
+
}
|
|
11
|
+
locale: LocaleType;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
setAppid: (appid: string) => void;
|
|
15
|
+
setEndpoints: (endpoints: StoreState['endpoints']) => void
|
|
16
|
+
setLocale: (locale: LocaleType) => void
|
|
17
|
+
|
|
18
|
+
initChainId: number;
|
|
19
|
+
setInitChainId: (initChainId: number) => void
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const persistedState = persist<StoreState>(
|
|
24
|
+
set => ({
|
|
25
|
+
appid: '',
|
|
26
|
+
endpoints: {
|
|
27
|
+
back: "https://api.matchid.ai/",
|
|
28
|
+
auth: "https://auth.matchid.ai/"
|
|
29
|
+
},
|
|
30
|
+
locale: 'en',
|
|
31
|
+
setAppid: (appid: string) => set({appid: appid}),
|
|
32
|
+
setEndpoints: (endpoints: StoreState['endpoints']) => set({endpoints}),
|
|
33
|
+
setLocale: (locale: LocaleType) => set({locale}),
|
|
34
|
+
|
|
35
|
+
initChainId:1,
|
|
36
|
+
setInitChainId: (initChainId: number) => set({initChainId})
|
|
37
|
+
}),
|
|
38
|
+
{name: 'match-example-local'}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const useLocalStore = create(devtools(persistedState));
|
|
42
|
+
|
|
43
|
+
export const localStore = useLocalStore;
|
|
44
|
+
|
|
45
|
+
export default useLocalStore;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matchain/matchid-sdk-react",
|
|
3
|
-
"version": "0.1.42-alpha.
|
|
3
|
+
"version": "0.1.42-alpha.10",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"import": "./dist/assets/icon/index.mjs",
|
|
29
29
|
"require": "./dist/assets/icon/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./types": {
|
|
32
|
+
"import": "./dist/types/index.mjs",
|
|
33
|
+
"require": "./dist/types/index.js"
|
|
34
|
+
},
|
|
31
35
|
"./index.css": "./dist/index.css"
|
|
32
36
|
},
|
|
33
37
|
"scripts": {
|
|
@@ -81,6 +85,7 @@
|
|
|
81
85
|
"chokidar": "^4.0.3",
|
|
82
86
|
"npm-run-all": "^4.1.5",
|
|
83
87
|
"tsup": "^8.3.5",
|
|
84
|
-
"typescript": "^5.6.3"
|
|
88
|
+
"typescript": "^5.6.3",
|
|
89
|
+
"url-loader": "^4.1.1"
|
|
85
90
|
}
|
|
86
91
|
}
|