@ant-design/web3-wagmi 2.9.4 → 2.10.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/CHANGELOG.md +20 -0
- package/dist/esm/interface.d.ts +6 -0
- package/dist/esm/wagmi-provider/__mocks__/wagmiBaseMock.d.ts +73 -0
- package/dist/esm/wagmi-provider/__mocks__/wagmiBaseMock.js +36 -0
- package/dist/esm/wagmi-provider/config-provider.d.ts +2 -1
- package/dist/esm/wagmi-provider/config-provider.js +52 -5
- package/dist/esm/wagmi-provider/index.d.ts +5 -4
- package/dist/esm/wagmi-provider/index.js +2 -0
- package/dist/lib/interface.d.ts +6 -0
- package/dist/lib/wagmi-provider/__mocks__/wagmiBaseMock.d.ts +73 -0
- package/dist/lib/wagmi-provider/__mocks__/wagmiBaseMock.js +42 -0
- package/dist/lib/wagmi-provider/config-provider.d.ts +2 -1
- package/dist/lib/wagmi-provider/config-provider.js +50 -3
- package/dist/lib/wagmi-provider/index.d.ts +5 -4
- package/dist/lib/wagmi-provider/index.js +2 -0
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ant-design/web3-wagmi
|
|
2
2
|
|
|
3
|
+
## 2.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ad278cd: feat: wagmi add siwe config
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 8b857d3: chore: update wagmi version
|
|
12
|
+
- Updated dependencies [ad278cd]
|
|
13
|
+
- Updated dependencies [8b857d3]
|
|
14
|
+
- @ant-design/web3-common@1.16.0
|
|
15
|
+
- @ant-design/web3-assets@1.11.7
|
|
16
|
+
|
|
17
|
+
## 2.9.5
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- @ant-design/web3-assets@1.11.6
|
|
22
|
+
|
|
3
23
|
## 2.9.4
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/esm/interface.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Chain, ConnectOptions, UniversalEIP6963Config, Wallet, WalletMetadata } from '@ant-design/web3-common';
|
|
2
2
|
import type { Chain as WagmiChain } from 'viem';
|
|
3
|
+
import type { CreateSiweMessageParameters } from 'viem/siwe';
|
|
3
4
|
import type { Connector, CreateConnectorFn } from 'wagmi';
|
|
4
5
|
export interface WalletUseInWagmiAdapter extends Wallet {
|
|
5
6
|
getWagmiConnector?: (options?: ConnectOptions) => Promise<Connector | undefined>;
|
|
@@ -18,3 +19,8 @@ export type EIP6963Config = boolean | UniversalEIP6963Config;
|
|
|
18
19
|
export type ChainAssetWithWagmiChain = Chain & {
|
|
19
20
|
wagmiChain?: WagmiChain;
|
|
20
21
|
};
|
|
22
|
+
export interface SIWEConfig {
|
|
23
|
+
getNonce: (address: string, chainId?: number) => Promise<string>;
|
|
24
|
+
createMessage: (args: CreateSiweMessageParameters) => string;
|
|
25
|
+
verifyMessage: (message: string, signature: string) => Promise<boolean>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const wagmiBaseMock: {
|
|
2
|
+
useAccount: () => {
|
|
3
|
+
chain: {
|
|
4
|
+
blockExplorers: {
|
|
5
|
+
readonly default: {
|
|
6
|
+
readonly name: "Etherscan";
|
|
7
|
+
readonly url: "https://etherscan.io";
|
|
8
|
+
readonly apiUrl: "https://api.etherscan.io/api";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
contracts: {
|
|
12
|
+
readonly ensRegistry: {
|
|
13
|
+
readonly address: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
|
|
14
|
+
};
|
|
15
|
+
readonly ensUniversalResolver: {
|
|
16
|
+
readonly address: "0xce01f8eee7E479C928F8919abD53E553a36CeF67";
|
|
17
|
+
readonly blockCreated: 19258213;
|
|
18
|
+
};
|
|
19
|
+
readonly multicall3: {
|
|
20
|
+
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
|
|
21
|
+
readonly blockCreated: 14353601;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
id: 1;
|
|
25
|
+
name: "Ethereum";
|
|
26
|
+
nativeCurrency: {
|
|
27
|
+
readonly name: "Ether";
|
|
28
|
+
readonly symbol: "ETH";
|
|
29
|
+
readonly decimals: 18;
|
|
30
|
+
};
|
|
31
|
+
rpcUrls: {
|
|
32
|
+
readonly default: {
|
|
33
|
+
readonly http: readonly ["https://cloudflare-eth.com"];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
sourceId?: number | undefined;
|
|
37
|
+
testnet?: boolean | undefined;
|
|
38
|
+
custom?: Record<string, unknown> | undefined;
|
|
39
|
+
fees?: import("viem").ChainFees<undefined> | undefined;
|
|
40
|
+
formatters?: undefined;
|
|
41
|
+
serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable<bigint, number>> | undefined;
|
|
42
|
+
};
|
|
43
|
+
address: string;
|
|
44
|
+
connector: {
|
|
45
|
+
name: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
useConfig: () => {};
|
|
49
|
+
useBalance: () => {
|
|
50
|
+
data: {};
|
|
51
|
+
};
|
|
52
|
+
useSwitchChain: () => {
|
|
53
|
+
switchChain: () => void;
|
|
54
|
+
};
|
|
55
|
+
useConnect: () => {
|
|
56
|
+
connectors: {
|
|
57
|
+
name: string;
|
|
58
|
+
}[];
|
|
59
|
+
connectAsync: () => Promise<{}>;
|
|
60
|
+
};
|
|
61
|
+
useDisconnect: () => {
|
|
62
|
+
disconnectAsync: () => void;
|
|
63
|
+
};
|
|
64
|
+
useEnsName: () => {
|
|
65
|
+
data: null;
|
|
66
|
+
};
|
|
67
|
+
useEnsAvatar: () => {
|
|
68
|
+
data: null;
|
|
69
|
+
};
|
|
70
|
+
useSignMessage: () => {
|
|
71
|
+
signMessageAsync: () => Promise<string>;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { mainnet } from 'wagmi/chains';
|
|
2
|
+
const mockConnector = {
|
|
3
|
+
name: 'MetaMask'
|
|
4
|
+
};
|
|
5
|
+
export const wagmiBaseMock = {
|
|
6
|
+
useAccount: () => {
|
|
7
|
+
return {
|
|
8
|
+
chain: mainnet,
|
|
9
|
+
address: '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B',
|
|
10
|
+
connector: mockConnector
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
useConfig: () => ({}),
|
|
14
|
+
useBalance: () => ({
|
|
15
|
+
data: {}
|
|
16
|
+
}),
|
|
17
|
+
useSwitchChain: () => ({
|
|
18
|
+
switchChain: () => {}
|
|
19
|
+
}),
|
|
20
|
+
useConnect: () => ({
|
|
21
|
+
connectors: [mockConnector],
|
|
22
|
+
connectAsync: async () => ({})
|
|
23
|
+
}),
|
|
24
|
+
useDisconnect: () => ({
|
|
25
|
+
disconnectAsync: () => {}
|
|
26
|
+
}),
|
|
27
|
+
useEnsName: () => ({
|
|
28
|
+
data: null
|
|
29
|
+
}),
|
|
30
|
+
useEnsAvatar: () => ({
|
|
31
|
+
data: null
|
|
32
|
+
}),
|
|
33
|
+
useSignMessage: () => ({
|
|
34
|
+
signMessageAsync: async () => 'signMessage'
|
|
35
|
+
})
|
|
36
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type Chain, type Locale } from '@ant-design/web3-common';
|
|
3
3
|
import type { Config as WagmiConfig } from 'wagmi';
|
|
4
|
-
import type { EIP6963Config, WalletFactory } from '../interface';
|
|
4
|
+
import type { EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
|
|
5
5
|
export interface AntDesignWeb3ConfigProviderProps {
|
|
6
6
|
chainAssets: Chain[];
|
|
7
7
|
walletFactories: WalletFactory[];
|
|
@@ -12,5 +12,6 @@ export interface AntDesignWeb3ConfigProviderProps {
|
|
|
12
12
|
eip6963?: EIP6963Config;
|
|
13
13
|
wagimConfig: WagmiConfig;
|
|
14
14
|
useWalletConnectOfficialModal?: boolean;
|
|
15
|
+
siwe?: SIWEConfig;
|
|
15
16
|
}
|
|
16
17
|
export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Web3ConfigProvider } from '@ant-design/web3-common';
|
|
3
|
-
import { useAccount, useBalance, useConfig, useConnect, useEnsAvatar, useEnsName, useSwitchChain } from 'wagmi';
|
|
2
|
+
import { ConnectStatus, Web3ConfigProvider } from '@ant-design/web3-common';
|
|
3
|
+
import { useAccount, useBalance, useConfig, useConnect, useEnsAvatar, useEnsName, useSignMessage, useSwitchChain } from 'wagmi';
|
|
4
4
|
import { disconnect, getAccount } from 'wagmi/actions';
|
|
5
|
+
import { Mainnet } from "../chains";
|
|
5
6
|
import { isEIP6963Connector } from "../utils";
|
|
6
7
|
import { EIP6963Wallet } from "../wallets/eip6963";
|
|
7
8
|
import { getNFTMetadata } from "./methods";
|
|
@@ -16,12 +17,14 @@ export const AntDesignWeb3ConfigProvider = props => {
|
|
|
16
17
|
locale,
|
|
17
18
|
eip6963,
|
|
18
19
|
wagimConfig,
|
|
19
|
-
useWalletConnectOfficialModal
|
|
20
|
+
useWalletConnectOfficialModal,
|
|
21
|
+
siwe
|
|
20
22
|
} = props;
|
|
21
23
|
const {
|
|
22
24
|
address,
|
|
23
25
|
isDisconnected,
|
|
24
|
-
chain
|
|
26
|
+
chain,
|
|
27
|
+
addresses
|
|
25
28
|
} = useAccount();
|
|
26
29
|
const config = useConfig();
|
|
27
30
|
const {
|
|
@@ -45,10 +48,19 @@ export const AntDesignWeb3ConfigProvider = props => {
|
|
|
45
48
|
} = useEnsAvatar({
|
|
46
49
|
name: ensName ?? undefined
|
|
47
50
|
});
|
|
51
|
+
const {
|
|
52
|
+
signMessageAsync
|
|
53
|
+
} = useSignMessage();
|
|
54
|
+
const [status, setStatus] = React.useState(ConnectStatus.Disconnected);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
setStatus(isDisconnected ? ConnectStatus.Disconnected : ConnectStatus.Connected);
|
|
57
|
+
}, [isDisconnected]);
|
|
48
58
|
const account = address && !isDisconnected ? {
|
|
49
59
|
address,
|
|
50
60
|
name: ensName && ens ? ensName : undefined,
|
|
51
|
-
avatar: ensAvatar ?? undefined
|
|
61
|
+
avatar: ensAvatar ?? undefined,
|
|
62
|
+
addresses,
|
|
63
|
+
status: status
|
|
52
64
|
} : undefined;
|
|
53
65
|
const isConnectorNameMatch = (aName, bName) => {
|
|
54
66
|
// match connector name like okxWallet, Okx Wallet, OKX Wallet
|
|
@@ -134,11 +146,46 @@ export const AntDesignWeb3ConfigProvider = props => {
|
|
|
134
146
|
address: contractAddress,
|
|
135
147
|
tokenId
|
|
136
148
|
}) => getNFTMetadata(config, contractAddress, tokenId, chain?.id), [chain?.id]);
|
|
149
|
+
const signIn = React.useCallback(async signAddress => {
|
|
150
|
+
const {
|
|
151
|
+
getNonce,
|
|
152
|
+
createMessage,
|
|
153
|
+
verifyMessage
|
|
154
|
+
} = siwe;
|
|
155
|
+
let msg;
|
|
156
|
+
let signature;
|
|
157
|
+
try {
|
|
158
|
+
// get nonce
|
|
159
|
+
const nonce = await getNonce(signAddress);
|
|
160
|
+
msg = createMessage({
|
|
161
|
+
domain: window?.location ? window.location.hostname : '',
|
|
162
|
+
address: signAddress,
|
|
163
|
+
uri: window?.location ? window.location.origin : '',
|
|
164
|
+
nonce,
|
|
165
|
+
// Default config
|
|
166
|
+
version: '1',
|
|
167
|
+
chainId: currentChain?.id ?? Mainnet.id
|
|
168
|
+
});
|
|
169
|
+
if (signMessageAsync) {
|
|
170
|
+
signature = await signMessageAsync?.({
|
|
171
|
+
message: msg
|
|
172
|
+
});
|
|
173
|
+
console.log('get signature', signature);
|
|
174
|
+
await verifyMessage(msg, signature);
|
|
175
|
+
setStatus(ConnectStatus.Signed);
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw new Error(error.message);
|
|
179
|
+
}
|
|
180
|
+
}, [siwe, currentChain, signMessageAsync]);
|
|
137
181
|
return /*#__PURE__*/_jsx(Web3ConfigProvider, {
|
|
138
182
|
locale: locale,
|
|
139
183
|
availableChains: chainList,
|
|
140
184
|
chain: currentChain,
|
|
141
185
|
account: account,
|
|
186
|
+
sign: siwe && {
|
|
187
|
+
signIn
|
|
188
|
+
},
|
|
142
189
|
balance: balance ? {
|
|
143
190
|
symbol: balanceData?.symbol,
|
|
144
191
|
value: balanceData?.value,
|
|
@@ -4,11 +4,11 @@ import { QueryClient } from '@tanstack/react-query';
|
|
|
4
4
|
import type { Transport } from 'viem';
|
|
5
5
|
import type { Config, State } from 'wagmi';
|
|
6
6
|
import type { WalletConnectParameters } from 'wagmi/connectors';
|
|
7
|
-
import type { ChainAssetWithWagmiChain, EIP6963Config, WalletFactory } from '../interface';
|
|
7
|
+
import type { ChainAssetWithWagmiChain, EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
|
|
8
8
|
export interface WalletConnectOptions extends Pick<WalletConnectParameters, 'disableProviderPing' | 'isNewChainsStale' | 'projectId' | 'metadata' | 'relayUrl' | 'storageOptions' | 'qrModalOptions'> {
|
|
9
9
|
useWalletConnectOfficialModal?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export interface WagmiWeb3ConfigProviderProps {
|
|
12
12
|
config?: Config;
|
|
13
13
|
locale?: Locale;
|
|
14
14
|
wallets?: WalletFactory[];
|
|
@@ -21,5 +21,6 @@ export type WagmiWeb3ConfigProviderProps = {
|
|
|
21
21
|
reconnectOnMount?: boolean;
|
|
22
22
|
walletConnect?: false | WalletConnectOptions;
|
|
23
23
|
transports?: Record<number, Transport>;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
siwe?: SIWEConfig;
|
|
25
|
+
}
|
|
26
|
+
export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, walletConnect, transports, siwe, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
|
|
@@ -19,6 +19,7 @@ export function WagmiWeb3ConfigProvider({
|
|
|
19
19
|
eip6963,
|
|
20
20
|
walletConnect,
|
|
21
21
|
transports,
|
|
22
|
+
siwe,
|
|
22
23
|
...restProps
|
|
23
24
|
}) {
|
|
24
25
|
// When user custom config, add Mainnet by default
|
|
@@ -83,6 +84,7 @@ export function WagmiWeb3ConfigProvider({
|
|
|
83
84
|
client: mergedQueryClient,
|
|
84
85
|
children: /*#__PURE__*/_jsx(AntDesignWeb3ConfigProvider, {
|
|
85
86
|
locale: locale,
|
|
87
|
+
siwe: siwe,
|
|
86
88
|
chainAssets: chainAssets,
|
|
87
89
|
walletFactories: wallets,
|
|
88
90
|
ens: ens,
|
package/dist/lib/interface.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Chain, ConnectOptions, UniversalEIP6963Config, Wallet, WalletMetadata } from '@ant-design/web3-common';
|
|
2
2
|
import type { Chain as WagmiChain } from 'viem';
|
|
3
|
+
import type { CreateSiweMessageParameters } from 'viem/siwe';
|
|
3
4
|
import type { Connector, CreateConnectorFn } from 'wagmi';
|
|
4
5
|
export interface WalletUseInWagmiAdapter extends Wallet {
|
|
5
6
|
getWagmiConnector?: (options?: ConnectOptions) => Promise<Connector | undefined>;
|
|
@@ -18,3 +19,8 @@ export type EIP6963Config = boolean | UniversalEIP6963Config;
|
|
|
18
19
|
export type ChainAssetWithWagmiChain = Chain & {
|
|
19
20
|
wagmiChain?: WagmiChain;
|
|
20
21
|
};
|
|
22
|
+
export interface SIWEConfig {
|
|
23
|
+
getNonce: (address: string, chainId?: number) => Promise<string>;
|
|
24
|
+
createMessage: (args: CreateSiweMessageParameters) => string;
|
|
25
|
+
verifyMessage: (message: string, signature: string) => Promise<boolean>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const wagmiBaseMock: {
|
|
2
|
+
useAccount: () => {
|
|
3
|
+
chain: {
|
|
4
|
+
blockExplorers: {
|
|
5
|
+
readonly default: {
|
|
6
|
+
readonly name: "Etherscan";
|
|
7
|
+
readonly url: "https://etherscan.io";
|
|
8
|
+
readonly apiUrl: "https://api.etherscan.io/api";
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
contracts: {
|
|
12
|
+
readonly ensRegistry: {
|
|
13
|
+
readonly address: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e";
|
|
14
|
+
};
|
|
15
|
+
readonly ensUniversalResolver: {
|
|
16
|
+
readonly address: "0xce01f8eee7E479C928F8919abD53E553a36CeF67";
|
|
17
|
+
readonly blockCreated: 19258213;
|
|
18
|
+
};
|
|
19
|
+
readonly multicall3: {
|
|
20
|
+
readonly address: "0xca11bde05977b3631167028862be2a173976ca11";
|
|
21
|
+
readonly blockCreated: 14353601;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
id: 1;
|
|
25
|
+
name: "Ethereum";
|
|
26
|
+
nativeCurrency: {
|
|
27
|
+
readonly name: "Ether";
|
|
28
|
+
readonly symbol: "ETH";
|
|
29
|
+
readonly decimals: 18;
|
|
30
|
+
};
|
|
31
|
+
rpcUrls: {
|
|
32
|
+
readonly default: {
|
|
33
|
+
readonly http: readonly ["https://cloudflare-eth.com"];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
sourceId?: number | undefined;
|
|
37
|
+
testnet?: boolean | undefined;
|
|
38
|
+
custom?: Record<string, unknown> | undefined;
|
|
39
|
+
fees?: import("viem").ChainFees<undefined> | undefined;
|
|
40
|
+
formatters?: undefined;
|
|
41
|
+
serializers?: import("viem").ChainSerializers<undefined, import("viem").TransactionSerializable<bigint, number>> | undefined;
|
|
42
|
+
};
|
|
43
|
+
address: string;
|
|
44
|
+
connector: {
|
|
45
|
+
name: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
useConfig: () => {};
|
|
49
|
+
useBalance: () => {
|
|
50
|
+
data: {};
|
|
51
|
+
};
|
|
52
|
+
useSwitchChain: () => {
|
|
53
|
+
switchChain: () => void;
|
|
54
|
+
};
|
|
55
|
+
useConnect: () => {
|
|
56
|
+
connectors: {
|
|
57
|
+
name: string;
|
|
58
|
+
}[];
|
|
59
|
+
connectAsync: () => Promise<{}>;
|
|
60
|
+
};
|
|
61
|
+
useDisconnect: () => {
|
|
62
|
+
disconnectAsync: () => void;
|
|
63
|
+
};
|
|
64
|
+
useEnsName: () => {
|
|
65
|
+
data: null;
|
|
66
|
+
};
|
|
67
|
+
useEnsAvatar: () => {
|
|
68
|
+
data: null;
|
|
69
|
+
};
|
|
70
|
+
useSignMessage: () => {
|
|
71
|
+
signMessageAsync: () => Promise<string>;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.wagmiBaseMock = void 0;
|
|
7
|
+
var _chains = require("wagmi/chains");
|
|
8
|
+
const mockConnector = {
|
|
9
|
+
name: 'MetaMask'
|
|
10
|
+
};
|
|
11
|
+
const wagmiBaseMock = exports.wagmiBaseMock = {
|
|
12
|
+
useAccount: () => {
|
|
13
|
+
return {
|
|
14
|
+
chain: _chains.mainnet,
|
|
15
|
+
address: '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B',
|
|
16
|
+
connector: mockConnector
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
useConfig: () => ({}),
|
|
20
|
+
useBalance: () => ({
|
|
21
|
+
data: {}
|
|
22
|
+
}),
|
|
23
|
+
useSwitchChain: () => ({
|
|
24
|
+
switchChain: () => {}
|
|
25
|
+
}),
|
|
26
|
+
useConnect: () => ({
|
|
27
|
+
connectors: [mockConnector],
|
|
28
|
+
connectAsync: async () => ({})
|
|
29
|
+
}),
|
|
30
|
+
useDisconnect: () => ({
|
|
31
|
+
disconnectAsync: () => {}
|
|
32
|
+
}),
|
|
33
|
+
useEnsName: () => ({
|
|
34
|
+
data: null
|
|
35
|
+
}),
|
|
36
|
+
useEnsAvatar: () => ({
|
|
37
|
+
data: null
|
|
38
|
+
}),
|
|
39
|
+
useSignMessage: () => ({
|
|
40
|
+
signMessageAsync: async () => 'signMessage'
|
|
41
|
+
})
|
|
42
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type Chain, type Locale } from '@ant-design/web3-common';
|
|
3
3
|
import type { Config as WagmiConfig } from 'wagmi';
|
|
4
|
-
import type { EIP6963Config, WalletFactory } from '../interface';
|
|
4
|
+
import type { EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
|
|
5
5
|
export interface AntDesignWeb3ConfigProviderProps {
|
|
6
6
|
chainAssets: Chain[];
|
|
7
7
|
walletFactories: WalletFactory[];
|
|
@@ -12,5 +12,6 @@ export interface AntDesignWeb3ConfigProviderProps {
|
|
|
12
12
|
eip6963?: EIP6963Config;
|
|
13
13
|
wagimConfig: WagmiConfig;
|
|
14
14
|
useWalletConnectOfficialModal?: boolean;
|
|
15
|
+
siwe?: SIWEConfig;
|
|
15
16
|
}
|
|
16
17
|
export declare const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderProps>;
|
|
@@ -8,6 +8,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
8
8
|
var _web3Common = require("@ant-design/web3-common");
|
|
9
9
|
var _wagmi = require("wagmi");
|
|
10
10
|
var _actions = require("wagmi/actions");
|
|
11
|
+
var _chains = require("../chains");
|
|
11
12
|
var _utils = require("../utils");
|
|
12
13
|
var _eip = require("../wallets/eip6963");
|
|
13
14
|
var _methods = require("./methods");
|
|
@@ -23,12 +24,14 @@ const AntDesignWeb3ConfigProvider = props => {
|
|
|
23
24
|
locale,
|
|
24
25
|
eip6963,
|
|
25
26
|
wagimConfig,
|
|
26
|
-
useWalletConnectOfficialModal
|
|
27
|
+
useWalletConnectOfficialModal,
|
|
28
|
+
siwe
|
|
27
29
|
} = props;
|
|
28
30
|
const {
|
|
29
31
|
address,
|
|
30
32
|
isDisconnected,
|
|
31
|
-
chain
|
|
33
|
+
chain,
|
|
34
|
+
addresses
|
|
32
35
|
} = (0, _wagmi.useAccount)();
|
|
33
36
|
const config = (0, _wagmi.useConfig)();
|
|
34
37
|
const {
|
|
@@ -52,10 +55,19 @@ const AntDesignWeb3ConfigProvider = props => {
|
|
|
52
55
|
} = (0, _wagmi.useEnsAvatar)({
|
|
53
56
|
name: ensName ?? undefined
|
|
54
57
|
});
|
|
58
|
+
const {
|
|
59
|
+
signMessageAsync
|
|
60
|
+
} = (0, _wagmi.useSignMessage)();
|
|
61
|
+
const [status, setStatus] = _react.default.useState(_web3Common.ConnectStatus.Disconnected);
|
|
62
|
+
_react.default.useEffect(() => {
|
|
63
|
+
setStatus(isDisconnected ? _web3Common.ConnectStatus.Disconnected : _web3Common.ConnectStatus.Connected);
|
|
64
|
+
}, [isDisconnected]);
|
|
55
65
|
const account = address && !isDisconnected ? {
|
|
56
66
|
address,
|
|
57
67
|
name: ensName && ens ? ensName : undefined,
|
|
58
|
-
avatar: ensAvatar ?? undefined
|
|
68
|
+
avatar: ensAvatar ?? undefined,
|
|
69
|
+
addresses,
|
|
70
|
+
status: status
|
|
59
71
|
} : undefined;
|
|
60
72
|
const isConnectorNameMatch = (aName, bName) => {
|
|
61
73
|
// match connector name like okxWallet, Okx Wallet, OKX Wallet
|
|
@@ -141,11 +153,46 @@ const AntDesignWeb3ConfigProvider = props => {
|
|
|
141
153
|
address: contractAddress,
|
|
142
154
|
tokenId
|
|
143
155
|
}) => (0, _methods.getNFTMetadata)(config, contractAddress, tokenId, chain?.id), [chain?.id]);
|
|
156
|
+
const signIn = _react.default.useCallback(async signAddress => {
|
|
157
|
+
const {
|
|
158
|
+
getNonce,
|
|
159
|
+
createMessage,
|
|
160
|
+
verifyMessage
|
|
161
|
+
} = siwe;
|
|
162
|
+
let msg;
|
|
163
|
+
let signature;
|
|
164
|
+
try {
|
|
165
|
+
// get nonce
|
|
166
|
+
const nonce = await getNonce(signAddress);
|
|
167
|
+
msg = createMessage({
|
|
168
|
+
domain: window?.location ? window.location.hostname : '',
|
|
169
|
+
address: signAddress,
|
|
170
|
+
uri: window?.location ? window.location.origin : '',
|
|
171
|
+
nonce,
|
|
172
|
+
// Default config
|
|
173
|
+
version: '1',
|
|
174
|
+
chainId: currentChain?.id ?? _chains.Mainnet.id
|
|
175
|
+
});
|
|
176
|
+
if (signMessageAsync) {
|
|
177
|
+
signature = await signMessageAsync?.({
|
|
178
|
+
message: msg
|
|
179
|
+
});
|
|
180
|
+
console.log('get signature', signature);
|
|
181
|
+
await verifyMessage(msg, signature);
|
|
182
|
+
setStatus(_web3Common.ConnectStatus.Signed);
|
|
183
|
+
}
|
|
184
|
+
} catch (error) {
|
|
185
|
+
throw new Error(error.message);
|
|
186
|
+
}
|
|
187
|
+
}, [siwe, currentChain, signMessageAsync]);
|
|
144
188
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Common.Web3ConfigProvider, {
|
|
145
189
|
locale: locale,
|
|
146
190
|
availableChains: chainList,
|
|
147
191
|
chain: currentChain,
|
|
148
192
|
account: account,
|
|
193
|
+
sign: siwe && {
|
|
194
|
+
signIn
|
|
195
|
+
},
|
|
149
196
|
balance: balance ? {
|
|
150
197
|
symbol: balanceData?.symbol,
|
|
151
198
|
value: balanceData?.value,
|
|
@@ -4,11 +4,11 @@ import { QueryClient } from '@tanstack/react-query';
|
|
|
4
4
|
import type { Transport } from 'viem';
|
|
5
5
|
import type { Config, State } from 'wagmi';
|
|
6
6
|
import type { WalletConnectParameters } from 'wagmi/connectors';
|
|
7
|
-
import type { ChainAssetWithWagmiChain, EIP6963Config, WalletFactory } from '../interface';
|
|
7
|
+
import type { ChainAssetWithWagmiChain, EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
|
|
8
8
|
export interface WalletConnectOptions extends Pick<WalletConnectParameters, 'disableProviderPing' | 'isNewChainsStale' | 'projectId' | 'metadata' | 'relayUrl' | 'storageOptions' | 'qrModalOptions'> {
|
|
9
9
|
useWalletConnectOfficialModal?: boolean;
|
|
10
10
|
}
|
|
11
|
-
export
|
|
11
|
+
export interface WagmiWeb3ConfigProviderProps {
|
|
12
12
|
config?: Config;
|
|
13
13
|
locale?: Locale;
|
|
14
14
|
wallets?: WalletFactory[];
|
|
@@ -21,5 +21,6 @@ export type WagmiWeb3ConfigProviderProps = {
|
|
|
21
21
|
reconnectOnMount?: boolean;
|
|
22
22
|
walletConnect?: false | WalletConnectOptions;
|
|
23
23
|
transports?: Record<number, Transport>;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
siwe?: SIWEConfig;
|
|
25
|
+
}
|
|
26
|
+
export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, walletConnect, transports, siwe, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
|
|
@@ -27,6 +27,7 @@ function WagmiWeb3ConfigProvider({
|
|
|
27
27
|
eip6963,
|
|
28
28
|
walletConnect,
|
|
29
29
|
transports,
|
|
30
|
+
siwe,
|
|
30
31
|
...restProps
|
|
31
32
|
}) {
|
|
32
33
|
// When user custom config, add Mainnet by default
|
|
@@ -91,6 +92,7 @@ function WagmiWeb3ConfigProvider({
|
|
|
91
92
|
client: mergedQueryClient,
|
|
92
93
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
|
|
93
94
|
locale: locale,
|
|
95
|
+
siwe: siwe,
|
|
94
96
|
chainAssets: chainAssets,
|
|
95
97
|
walletFactories: wallets,
|
|
96
98
|
ens: ens,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ant-design/web3-wagmi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -40,21 +40,21 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"debug": "^4.3.5",
|
|
43
|
-
"@ant-design/web3-
|
|
44
|
-
"@ant-design/web3-
|
|
43
|
+
"@ant-design/web3-assets": "1.11.7",
|
|
44
|
+
"@ant-design/web3-common": "1.16.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
+
"@tanstack/react-query": "^5.51.11",
|
|
47
48
|
"@types/debug": "^4.1.12",
|
|
48
49
|
"father": "^4.4.4",
|
|
49
50
|
"typescript": "^5.6.2",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"viem": "^2.21.3"
|
|
51
|
+
"viem": "^2.21.3",
|
|
52
|
+
"wagmi": "^2.14.6"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"wagmi": "^2.12.13",
|
|
56
55
|
"@tanstack/react-query": "^5.51.11",
|
|
57
|
-
"viem": ">=2.0.0"
|
|
56
|
+
"viem": ">=2.0.0",
|
|
57
|
+
"wagmi": "^2.12.13"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"registry": "https://registry.npmjs.org",
|