@ant-design/web3-wagmi 0.0.0-alpha-20260209094036
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 +517 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/esm/chains.d.ts +16 -0
- package/dist/esm/chains.js +83 -0
- package/dist/esm/global.d.ts +3 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/interface.d.ts +26 -0
- package/dist/esm/interface.js +1 -0
- package/dist/esm/utils.d.ts +3 -0
- package/dist/esm/utils.js +8 -0
- package/dist/esm/wagmi-provider/__mocks__/wagmiBaseMock.d.ts +76 -0
- package/dist/esm/wagmi-provider/__mocks__/wagmiBaseMock.js +36 -0
- package/dist/esm/wagmi-provider/config-provider.d.ts +23 -0
- package/dist/esm/wagmi-provider/config-provider.js +243 -0
- package/dist/esm/wagmi-provider/index.d.ts +32 -0
- package/dist/esm/wagmi-provider/index.js +102 -0
- package/dist/esm/wagmi-provider/methods/getNFTMetadata.d.ts +3 -0
- package/dist/esm/wagmi-provider/methods/getNFTMetadata.js +25 -0
- package/dist/esm/wagmi-provider/methods/index.d.ts +1 -0
- package/dist/esm/wagmi-provider/methods/index.js +1 -0
- package/dist/esm/wallets/coinbase-wallet.d.ts +4 -0
- package/dist/esm/wallets/coinbase-wallet.js +19 -0
- package/dist/esm/wallets/eip6963.d.ts +3 -0
- package/dist/esm/wallets/eip6963.js +27 -0
- package/dist/esm/wallets/im-token.d.ts +2 -0
- package/dist/esm/wallets/im-token.js +11 -0
- package/dist/esm/wallets/index.d.ts +10 -0
- package/dist/esm/wallets/index.js +10 -0
- package/dist/esm/wallets/meta-mask.d.ts +2 -0
- package/dist/esm/wallets/meta-mask.js +11 -0
- package/dist/esm/wallets/mobile-wallet.d.ts +2 -0
- package/dist/esm/wallets/mobile-wallet.js +8 -0
- package/dist/esm/wallets/okx-wallet.d.ts +2 -0
- package/dist/esm/wallets/okx-wallet.js +11 -0
- package/dist/esm/wallets/rainbow-wallet.d.ts +2 -0
- package/dist/esm/wallets/rainbow-wallet.js +11 -0
- package/dist/esm/wallets/safeheron.d.ts +2 -0
- package/dist/esm/wallets/safeheron.js +19 -0
- package/dist/esm/wallets/token-pocket.d.ts +2 -0
- package/dist/esm/wallets/token-pocket.js +13 -0
- package/dist/esm/wallets/universal-wallet.d.ts +11 -0
- package/dist/esm/wallets/universal-wallet.js +66 -0
- package/dist/esm/wallets/wallet-connect.d.ts +6 -0
- package/dist/esm/wallets/wallet-connect.js +42 -0
- package/dist/lib/chains.d.ts +16 -0
- package/dist/lib/chains.js +89 -0
- package/dist/lib/global.d.ts +3 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.js +71 -0
- package/dist/lib/interface.d.ts +26 -0
- package/dist/lib/interface.js +5 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +14 -0
- package/dist/lib/wagmi-provider/__mocks__/wagmiBaseMock.d.ts +76 -0
- package/dist/lib/wagmi-provider/__mocks__/wagmiBaseMock.js +42 -0
- package/dist/lib/wagmi-provider/config-provider.d.ts +23 -0
- package/dist/lib/wagmi-provider/config-provider.js +251 -0
- package/dist/lib/wagmi-provider/index.d.ts +32 -0
- package/dist/lib/wagmi-provider/index.js +110 -0
- package/dist/lib/wagmi-provider/methods/getNFTMetadata.d.ts +3 -0
- package/dist/lib/wagmi-provider/methods/getNFTMetadata.js +31 -0
- package/dist/lib/wagmi-provider/methods/index.d.ts +1 -0
- package/dist/lib/wagmi-provider/methods/index.js +16 -0
- package/dist/lib/wallets/coinbase-wallet.d.ts +4 -0
- package/dist/lib/wallets/coinbase-wallet.js +26 -0
- package/dist/lib/wallets/eip6963.d.ts +3 -0
- package/dist/lib/wallets/eip6963.js +34 -0
- package/dist/lib/wallets/im-token.d.ts +2 -0
- package/dist/lib/wallets/im-token.js +18 -0
- package/dist/lib/wallets/index.d.ts +10 -0
- package/dist/lib/wallets/index.js +115 -0
- package/dist/lib/wallets/meta-mask.d.ts +2 -0
- package/dist/lib/wallets/meta-mask.js +18 -0
- package/dist/lib/wallets/mobile-wallet.d.ts +2 -0
- package/dist/lib/wallets/mobile-wallet.js +15 -0
- package/dist/lib/wallets/okx-wallet.d.ts +2 -0
- package/dist/lib/wallets/okx-wallet.js +18 -0
- package/dist/lib/wallets/rainbow-wallet.d.ts +2 -0
- package/dist/lib/wallets/rainbow-wallet.js +18 -0
- package/dist/lib/wallets/safeheron.d.ts +2 -0
- package/dist/lib/wallets/safeheron.js +27 -0
- package/dist/lib/wallets/token-pocket.d.ts +2 -0
- package/dist/lib/wallets/token-pocket.js +20 -0
- package/dist/lib/wallets/universal-wallet.d.ts +11 -0
- package/dist/lib/wallets/universal-wallet.js +73 -0
- package/dist/lib/wallets/wallet-connect.d.ts +6 -0
- package/dist/lib/wallets/wallet-connect.js +49 -0
- package/package.json +73 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AntDesignWeb3ConfigProvider = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _web3Common = require("@ant-design/web3-common");
|
|
9
|
+
var _wagmi = require("wagmi");
|
|
10
|
+
var _actions = require("wagmi/actions");
|
|
11
|
+
var _chains = require("../chains");
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
var _eip = require("../wallets/eip6963");
|
|
14
|
+
var _methods = require("./methods");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
const AntDesignWeb3ConfigProvider = props => {
|
|
18
|
+
const {
|
|
19
|
+
children,
|
|
20
|
+
chainAssets,
|
|
21
|
+
walletFactories,
|
|
22
|
+
ens = true,
|
|
23
|
+
balance,
|
|
24
|
+
locale,
|
|
25
|
+
eip6963,
|
|
26
|
+
wagimConfig,
|
|
27
|
+
useWalletConnectOfficialModal,
|
|
28
|
+
siwe,
|
|
29
|
+
ignoreConfig
|
|
30
|
+
} = props;
|
|
31
|
+
const {
|
|
32
|
+
address,
|
|
33
|
+
isDisconnected,
|
|
34
|
+
chain,
|
|
35
|
+
addresses
|
|
36
|
+
} = (0, _wagmi.useAccount)();
|
|
37
|
+
const config = (0, _wagmi.useConfig)();
|
|
38
|
+
const {
|
|
39
|
+
connectAsync
|
|
40
|
+
} = (0, _wagmi.useConnect)();
|
|
41
|
+
const {
|
|
42
|
+
switchChain
|
|
43
|
+
} = (0, _wagmi.useSwitchChain)();
|
|
44
|
+
const {
|
|
45
|
+
data: balanceData
|
|
46
|
+
} = (0, _wagmi.useBalance)({
|
|
47
|
+
address
|
|
48
|
+
});
|
|
49
|
+
const {
|
|
50
|
+
data: ensName
|
|
51
|
+
} = (0, _wagmi.useEnsName)({
|
|
52
|
+
address
|
|
53
|
+
});
|
|
54
|
+
const {
|
|
55
|
+
data: ensAvatar
|
|
56
|
+
} = (0, _wagmi.useEnsAvatar)({
|
|
57
|
+
name: ensName ?? undefined
|
|
58
|
+
});
|
|
59
|
+
const {
|
|
60
|
+
signMessageAsync
|
|
61
|
+
} = (0, _wagmi.useSignMessage)();
|
|
62
|
+
const [status, setStatus] = _react.default.useState(_web3Common.ConnectStatus.Disconnected);
|
|
63
|
+
_react.default.useEffect(() => {
|
|
64
|
+
setStatus(isDisconnected ? _web3Common.ConnectStatus.Disconnected : _web3Common.ConnectStatus.Connected);
|
|
65
|
+
}, [isDisconnected]);
|
|
66
|
+
const account = address && !isDisconnected ? {
|
|
67
|
+
address,
|
|
68
|
+
name: ensName && ens ? ensName : undefined,
|
|
69
|
+
avatar: ensAvatar ?? undefined,
|
|
70
|
+
addresses,
|
|
71
|
+
status: status
|
|
72
|
+
} : undefined;
|
|
73
|
+
const isConnectorNameMatch = (aName, bName) => {
|
|
74
|
+
// match connector name like okxWallet, Okx Wallet, OKX Wallet
|
|
75
|
+
return aName.replace(/ /g, '').toLowerCase() === bName.replace(/ /g, '').toLowerCase();
|
|
76
|
+
};
|
|
77
|
+
const findConnectorByName = name => {
|
|
78
|
+
const commonConnector = wagimConfig.connectors.find(item => isConnectorNameMatch(item.name, name) && !(0, _utils.isEIP6963Connector)(item));
|
|
79
|
+
if (!eip6963) {
|
|
80
|
+
return commonConnector;
|
|
81
|
+
}
|
|
82
|
+
const eip6963Connector = wagimConfig.connectors.find(item => item.name === name && (0, _utils.isEIP6963Connector)(item));
|
|
83
|
+
return eip6963Connector || commonConnector;
|
|
84
|
+
};
|
|
85
|
+
const wallets = _react.default.useMemo(() => {
|
|
86
|
+
const autoAddEIP6963Wallets = [];
|
|
87
|
+
wagimConfig.connectors.forEach(connector => {
|
|
88
|
+
if ((0, _utils.isEIP6963Connector)(connector)) {
|
|
89
|
+
// check is need auto add eip6963 wallet
|
|
90
|
+
if (typeof eip6963 === 'object' && eip6963?.autoAddInjectedWallets && !walletFactories.find(item => item.connectors.some(aName => isConnectorNameMatch(aName, connector.name)))) {
|
|
91
|
+
// not config wallet and find the wallet in connectors, auto add it
|
|
92
|
+
autoAddEIP6963Wallets.push((0, _eip.EIP6963Wallet)().create([connector], {
|
|
93
|
+
useWalletConnectOfficialModal
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
// Do not need check eip6963 wallet
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const walletFactory = walletFactories.find(factory => factory.connectors.some(aName => isConnectorNameMatch(aName, connector.name)));
|
|
100
|
+
if (!walletFactory?.create) {
|
|
101
|
+
// check user wallets config and console.error for alert
|
|
102
|
+
console.error(`Can not find wallet factory for ${connector.name}, you should config it in WagmiWeb3ConfigProvider 'wallets'.`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Generate Wallet for @ant-design/web3
|
|
107
|
+
const supportWallets = walletFactories.map(factory => {
|
|
108
|
+
const connectors = factory.connectors.map(findConnectorByName).filter(item => !!item);
|
|
109
|
+
if (connectors.length === 0 && !eip6963) {
|
|
110
|
+
// Not config connector for this wallet factory and not use eip6963, ignore it.
|
|
111
|
+
console.error(`Can not find connector for ${factory.connectors.join(',')}, ignore the wallet. Please config connectors or add eip6963 config in WagmiWeb3ConfigProvider.`);
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return factory.create(connectors, {
|
|
115
|
+
useWalletConnectOfficialModal
|
|
116
|
+
});
|
|
117
|
+
}).filter(item => item !== null);
|
|
118
|
+
return [...supportWallets, ...autoAddEIP6963Wallets];
|
|
119
|
+
}, [wagimConfig.connectors, walletFactories, eip6963]);
|
|
120
|
+
const chainList = _react.default.useMemo(() => {
|
|
121
|
+
return wagimConfig.chains.map(item => {
|
|
122
|
+
const c = chainAssets?.find(asset => {
|
|
123
|
+
return asset.id === item.id;
|
|
124
|
+
});
|
|
125
|
+
if (c?.id) {
|
|
126
|
+
return {
|
|
127
|
+
id: c.id,
|
|
128
|
+
name: c.name,
|
|
129
|
+
icon: c.icon
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
console.error(`Can not find chain ${item.id}, you should config it in WagmiWeb3ConfigProvider 'chains'.`);
|
|
133
|
+
return null;
|
|
134
|
+
}).filter(item => item !== null);
|
|
135
|
+
}, [wagimConfig.chains, chainAssets]);
|
|
136
|
+
const chainId = chain?.id || wagimConfig.chains?.[0]?.id;
|
|
137
|
+
const chainName = chain?.name || wagimConfig.chains?.[0]?.name;
|
|
138
|
+
const [currentChain, setCurrentChain] = _react.default.useState(undefined);
|
|
139
|
+
_react.default.useEffect(() => {
|
|
140
|
+
setCurrentChain(prevChain => {
|
|
141
|
+
// not connected any chain, keep current chain
|
|
142
|
+
let newChain = chainAssets?.find(item => item?.id === chainId);
|
|
143
|
+
if (!newChain && chainId) {
|
|
144
|
+
newChain = {
|
|
145
|
+
id: chainId,
|
|
146
|
+
name: chainName
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* v8 ignore next */
|
|
151
|
+
return newChain || prevChain;
|
|
152
|
+
});
|
|
153
|
+
}, [chainAssets, wagimConfig.chains, chainId, chainName]);
|
|
154
|
+
const currency = currentChain?.nativeCurrency;
|
|
155
|
+
const getNFTMetadataFunc = _react.default.useCallback(async ({
|
|
156
|
+
address: contractAddress,
|
|
157
|
+
tokenId
|
|
158
|
+
}) => (0, _methods.getNFTMetadata)(config, contractAddress, tokenId, chain?.id), [chain?.id]);
|
|
159
|
+
const signIn = _react.default.useCallback(async signAddress => {
|
|
160
|
+
const {
|
|
161
|
+
getNonce,
|
|
162
|
+
createMessage,
|
|
163
|
+
verifyMessage
|
|
164
|
+
} = siwe;
|
|
165
|
+
let msg;
|
|
166
|
+
let signature;
|
|
167
|
+
try {
|
|
168
|
+
// get nonce
|
|
169
|
+
const nonce = await getNonce(signAddress);
|
|
170
|
+
msg = createMessage({
|
|
171
|
+
domain: window?.location ? window.location.hostname : '',
|
|
172
|
+
address: signAddress,
|
|
173
|
+
uri: window?.location ? window.location.origin : '',
|
|
174
|
+
nonce,
|
|
175
|
+
// Default config
|
|
176
|
+
version: '1',
|
|
177
|
+
chainId: currentChain?.id ?? _chains.Mainnet.id
|
|
178
|
+
});
|
|
179
|
+
if (signMessageAsync) {
|
|
180
|
+
signature = await signMessageAsync?.({
|
|
181
|
+
message: msg
|
|
182
|
+
});
|
|
183
|
+
await verifyMessage(msg, signature);
|
|
184
|
+
setStatus(_web3Common.ConnectStatus.Signed);
|
|
185
|
+
}
|
|
186
|
+
} catch (error) {
|
|
187
|
+
throw new Error(error.message);
|
|
188
|
+
}
|
|
189
|
+
}, [siwe, currentChain, signMessageAsync]);
|
|
190
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web3Common.Web3ConfigProvider, {
|
|
191
|
+
locale: locale,
|
|
192
|
+
availableChains: chainList,
|
|
193
|
+
chain: currentChain,
|
|
194
|
+
account: account,
|
|
195
|
+
sign: siwe && {
|
|
196
|
+
signIn
|
|
197
|
+
},
|
|
198
|
+
balance: balance ? {
|
|
199
|
+
symbol: balanceData?.symbol,
|
|
200
|
+
value: balanceData?.value,
|
|
201
|
+
decimals: balanceData?.decimals,
|
|
202
|
+
icon: currency?.icon
|
|
203
|
+
} : undefined,
|
|
204
|
+
availableWallets: wallets,
|
|
205
|
+
addressPrefix: "0x",
|
|
206
|
+
connect: async (wallet, options) => {
|
|
207
|
+
let connector = await wallet?.getWagmiConnector?.(options);
|
|
208
|
+
if (!connector && wallet) {
|
|
209
|
+
connector = findConnectorByName(wallet.name);
|
|
210
|
+
}
|
|
211
|
+
if (!connector) {
|
|
212
|
+
throw new Error(`Can not find connector for ${wallet?.name}`);
|
|
213
|
+
}
|
|
214
|
+
const {
|
|
215
|
+
accounts
|
|
216
|
+
} = await connectAsync({
|
|
217
|
+
connector,
|
|
218
|
+
chainId: currentChain?.id
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
address: accounts?.[0],
|
|
222
|
+
addresses: accounts
|
|
223
|
+
};
|
|
224
|
+
},
|
|
225
|
+
disconnect: async () => {
|
|
226
|
+
// await disconnectAsync();
|
|
227
|
+
// TODO@jeasonstudio: wagmi useDisconnect hook 在处理多实例(config)共存时,
|
|
228
|
+
// 存在一些状态处理的 bug,暂时用更低阶 API 代替。
|
|
229
|
+
const {
|
|
230
|
+
connector
|
|
231
|
+
} = (0, _actions.getAccount)(config);
|
|
232
|
+
await (0, _actions.disconnect)(config, {
|
|
233
|
+
connector
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
switchChain: async newChain => {
|
|
237
|
+
if (!chain) {
|
|
238
|
+
// hava not connected any chain
|
|
239
|
+
setCurrentChain(newChain);
|
|
240
|
+
} else {
|
|
241
|
+
switchChain?.({
|
|
242
|
+
chainId: newChain.id
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
getNFTMetadata: getNFTMetadataFunc,
|
|
247
|
+
ignoreConfig: ignoreConfig,
|
|
248
|
+
children: children
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
exports.AntDesignWeb3ConfigProvider = AntDesignWeb3ConfigProvider;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Locale } from '@ant-design/web3-common';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import type { Transport } from 'viem';
|
|
5
|
+
import type { Config, State } from 'wagmi';
|
|
6
|
+
import type { WalletConnectParameters } from 'wagmi/connectors';
|
|
7
|
+
import type { ChainAssetWithWagmiChain, EIP6963Config, SIWEConfig, WalletFactory } from '../interface';
|
|
8
|
+
export interface WalletConnectOptions extends Pick<WalletConnectParameters, 'disableProviderPing' | 'isNewChainsStale' | 'projectId' | 'metadata' | 'relayUrl' | 'storageOptions' | 'qrModalOptions'> {
|
|
9
|
+
useWalletConnectOfficialModal?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface WagmiWeb3ConfigProviderProps {
|
|
12
|
+
config?: Config;
|
|
13
|
+
locale?: Locale;
|
|
14
|
+
wallets?: WalletFactory[];
|
|
15
|
+
chains?: ChainAssetWithWagmiChain[];
|
|
16
|
+
ens?: boolean;
|
|
17
|
+
queryClient?: QueryClient;
|
|
18
|
+
balance?: boolean;
|
|
19
|
+
eip6963?: EIP6963Config;
|
|
20
|
+
initialState?: State;
|
|
21
|
+
reconnectOnMount?: boolean;
|
|
22
|
+
walletConnect?: false | WalletConnectOptions;
|
|
23
|
+
transports?: Record<number, Transport>;
|
|
24
|
+
siwe?: SIWEConfig;
|
|
25
|
+
/**
|
|
26
|
+
* If true, this provider's configuration will be ignored when merging with parent context.
|
|
27
|
+
* This is useful when you have multiple chain providers and want to switch between them
|
|
28
|
+
* without causing page flickering. Only the active provider should not have this flag set.
|
|
29
|
+
*/
|
|
30
|
+
ignoreConfig?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function WagmiWeb3ConfigProvider({ children, config, locale, wallets, chains, ens, queryClient, balance, eip6963, walletConnect, transports, siwe, ignoreConfig, ...restProps }: React.PropsWithChildren<WagmiWeb3ConfigProviderProps>): React.ReactElement;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WagmiWeb3ConfigProvider = WagmiWeb3ConfigProvider;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _reactQuery = require("@tanstack/react-query");
|
|
9
|
+
var _wagmi = require("wagmi");
|
|
10
|
+
var _chains = require("wagmi/chains");
|
|
11
|
+
var _connectors = require("wagmi/connectors");
|
|
12
|
+
var _chains2 = require("../chains");
|
|
13
|
+
var _configProvider = require("./config-provider");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
// Built in popular chains
|
|
17
|
+
|
|
18
|
+
function WagmiWeb3ConfigProvider({
|
|
19
|
+
children,
|
|
20
|
+
config,
|
|
21
|
+
locale,
|
|
22
|
+
wallets = [],
|
|
23
|
+
chains = [],
|
|
24
|
+
ens,
|
|
25
|
+
queryClient,
|
|
26
|
+
balance,
|
|
27
|
+
eip6963,
|
|
28
|
+
walletConnect,
|
|
29
|
+
transports,
|
|
30
|
+
siwe,
|
|
31
|
+
ignoreConfig,
|
|
32
|
+
...restProps
|
|
33
|
+
}) {
|
|
34
|
+
// When user custom config, add Mainnet by default
|
|
35
|
+
// When user not provide config, auto generate config, chains use user provided chains
|
|
36
|
+
const chainAssets = config ? [_chains2.Mainnet, ...chains] : chains?.length ? chains : [_chains2.Mainnet];
|
|
37
|
+
const generateConfigFlag = () => {
|
|
38
|
+
return `${JSON.stringify(walletConnect)}-${chains.map(item => item.id).join(',')}-${wallets.map(item => item.name).join(',')}`;
|
|
39
|
+
};
|
|
40
|
+
const generateConfig = () => {
|
|
41
|
+
// Auto generate config
|
|
42
|
+
const connectors = [];
|
|
43
|
+
// biome-ignore lint/complexity/useOptionalChain: <explanation>
|
|
44
|
+
if (walletConnect && walletConnect.projectId) {
|
|
45
|
+
connectors.push((0, _connectors.walletConnect)({
|
|
46
|
+
...walletConnect,
|
|
47
|
+
showQrModal: walletConnect.useWalletConnectOfficialModal ?? false
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
wallets.forEach(wallet => {
|
|
51
|
+
const connector = wallet.createWagmiConnector?.();
|
|
52
|
+
if (connector) {
|
|
53
|
+
connectors.push(connector);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const autoGenerateConfig = (0, _wagmi.createConfig)({
|
|
57
|
+
chains: chainAssets.map(chain => chain.wagmiChain),
|
|
58
|
+
transports: transports ?? {
|
|
59
|
+
[_chains.mainnet.id]: (0, _wagmi.http)()
|
|
60
|
+
},
|
|
61
|
+
connectors
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
flag: generateConfigFlag(),
|
|
65
|
+
config: autoGenerateConfig
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const [autoConfig, setAutoConfig] = _react.default.useState(() => {
|
|
69
|
+
if (config) {
|
|
70
|
+
return {
|
|
71
|
+
config
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return generateConfig();
|
|
75
|
+
});
|
|
76
|
+
const mergedQueryClient = _react.default.useMemo(() => {
|
|
77
|
+
return queryClient ?? new _reactQuery.QueryClient();
|
|
78
|
+
}, [queryClient]);
|
|
79
|
+
_react.default.useEffect(() => {
|
|
80
|
+
if (config) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const flag = generateConfigFlag();
|
|
84
|
+
if (flag !== autoConfig.flag) {
|
|
85
|
+
// Need recreate wagmi config
|
|
86
|
+
setAutoConfig(generateConfig());
|
|
87
|
+
}
|
|
88
|
+
}, [config, wallets, chains, walletConnect]);
|
|
89
|
+
const wagmiConfig = config || autoConfig.config;
|
|
90
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_wagmi.WagmiProvider, {
|
|
91
|
+
config: wagmiConfig,
|
|
92
|
+
...restProps,
|
|
93
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
|
|
94
|
+
client: mergedQueryClient,
|
|
95
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_configProvider.AntDesignWeb3ConfigProvider, {
|
|
96
|
+
locale: locale,
|
|
97
|
+
siwe: siwe,
|
|
98
|
+
chainAssets: chainAssets,
|
|
99
|
+
walletFactories: wallets,
|
|
100
|
+
ens: ens,
|
|
101
|
+
balance: balance,
|
|
102
|
+
eip6963: eip6963,
|
|
103
|
+
wagimConfig: wagmiConfig,
|
|
104
|
+
useWalletConnectOfficialModal: typeof walletConnect === 'object' && walletConnect?.useWalletConnectOfficialModal,
|
|
105
|
+
ignoreConfig: ignoreConfig,
|
|
106
|
+
children: children
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getNFTMetadata = getNFTMetadata;
|
|
7
|
+
var _web3Common = require("@ant-design/web3-common");
|
|
8
|
+
var _actions = require("wagmi/actions");
|
|
9
|
+
async function getNFTMetadata(config, address, tokenId, chainId) {
|
|
10
|
+
const tokenURI = await (0, _actions.readContract)(config, {
|
|
11
|
+
address: (0, _web3Common.fillAddressWith0x)(address),
|
|
12
|
+
args: [tokenId],
|
|
13
|
+
chainId,
|
|
14
|
+
abi: [{
|
|
15
|
+
name: 'tokenURI',
|
|
16
|
+
inputs: [{
|
|
17
|
+
name: 'tokenId',
|
|
18
|
+
type: 'uint256'
|
|
19
|
+
}],
|
|
20
|
+
outputs: [{
|
|
21
|
+
name: '',
|
|
22
|
+
type: 'string'
|
|
23
|
+
}],
|
|
24
|
+
stateMutability: 'view',
|
|
25
|
+
type: 'function'
|
|
26
|
+
}],
|
|
27
|
+
functionName: 'tokenURI'
|
|
28
|
+
});
|
|
29
|
+
const metaInfo = await (0, _web3Common.requestWeb3Asset)(tokenURI);
|
|
30
|
+
return metaInfo;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getNFTMetadata';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _getNFTMetadata = require("./getNFTMetadata");
|
|
7
|
+
Object.keys(_getNFTMetadata).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _getNFTMetadata[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _getNFTMetadata[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { WalletMetadata } from '@ant-design/web3-common';
|
|
2
|
+
import { type CoinbaseWalletParameters } from 'wagmi/connectors';
|
|
3
|
+
import type { WalletFactory } from '../interface';
|
|
4
|
+
export declare const CoinbaseWallet: (metadata?: Partial<WalletMetadata>, coinbaseConfig?: CoinbaseWalletParameters) => WalletFactory;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CoinbaseWallet = void 0;
|
|
7
|
+
var _web3Assets = require("@ant-design/web3-assets");
|
|
8
|
+
var _connectors = require("wagmi/connectors");
|
|
9
|
+
const CoinbaseWallet = (metadata, coinbaseConfig) => {
|
|
10
|
+
return {
|
|
11
|
+
connectors: ['Coinbase Wallet'],
|
|
12
|
+
create: () => {
|
|
13
|
+
return {
|
|
14
|
+
..._web3Assets.metadata_CoinbaseWallet,
|
|
15
|
+
hasWalletReady: async () => {
|
|
16
|
+
return true;
|
|
17
|
+
},
|
|
18
|
+
...metadata
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
createWagmiConnector: () => {
|
|
22
|
+
return (0, _connectors.coinbaseWallet)(coinbaseConfig);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.CoinbaseWallet = CoinbaseWallet;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EIP6963_CONNECTOR = exports.EIP6963Wallet = void 0;
|
|
7
|
+
const EIP6963_CONNECTOR = exports.EIP6963_CONNECTOR = 'EIP6963';
|
|
8
|
+
|
|
9
|
+
// EIP6963Wallet not export from @ant-design/web3-wagmi, only used in internal
|
|
10
|
+
const EIP6963Wallet = metadata => {
|
|
11
|
+
return {
|
|
12
|
+
connectors: [EIP6963_CONNECTOR],
|
|
13
|
+
create: connectors => {
|
|
14
|
+
const connector = connectors?.[0];
|
|
15
|
+
const metadata_eip6963 = {
|
|
16
|
+
icon: connector?.icon,
|
|
17
|
+
name: connector.name,
|
|
18
|
+
remark: `Wallet ${connector?.name} detected`,
|
|
19
|
+
key: connector?.id
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
...metadata_eip6963,
|
|
23
|
+
hasWalletReady: async () => {
|
|
24
|
+
return !!(await connector?.getProvider());
|
|
25
|
+
},
|
|
26
|
+
hasExtensionInstalled: async () => {
|
|
27
|
+
return !!(await connector?.getProvider());
|
|
28
|
+
},
|
|
29
|
+
...metadata
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.EIP6963Wallet = EIP6963Wallet;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ImToken = void 0;
|
|
7
|
+
var _web3Assets = require("@ant-design/web3-assets");
|
|
8
|
+
var _connectors = require("wagmi/connectors");
|
|
9
|
+
var _universalWallet = require("./universal-wallet");
|
|
10
|
+
const ImToken = metadata => {
|
|
11
|
+
return new _universalWallet.UniversalWallet({
|
|
12
|
+
..._web3Assets.metadata_imToken,
|
|
13
|
+
...metadata
|
|
14
|
+
}, () => (0, _connectors.injected)({
|
|
15
|
+
target: 'imToken'
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
exports.ImToken = ImToken;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './meta-mask';
|
|
2
|
+
export * from './wallet-connect';
|
|
3
|
+
export * from './coinbase-wallet';
|
|
4
|
+
export * from './token-pocket';
|
|
5
|
+
export * from './safeheron';
|
|
6
|
+
export * from './universal-wallet';
|
|
7
|
+
export * from './okx-wallet';
|
|
8
|
+
export * from './im-token';
|
|
9
|
+
export * from './mobile-wallet';
|
|
10
|
+
export * from './rainbow-wallet';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _metaMask = require("./meta-mask");
|
|
7
|
+
Object.keys(_metaMask).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _metaMask[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _metaMask[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _walletConnect = require("./wallet-connect");
|
|
18
|
+
Object.keys(_walletConnect).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _walletConnect[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _walletConnect[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _coinbaseWallet = require("./coinbase-wallet");
|
|
29
|
+
Object.keys(_coinbaseWallet).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _coinbaseWallet[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _coinbaseWallet[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _tokenPocket = require("./token-pocket");
|
|
40
|
+
Object.keys(_tokenPocket).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _tokenPocket[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _tokenPocket[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _safeheron = require("./safeheron");
|
|
51
|
+
Object.keys(_safeheron).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _safeheron[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _safeheron[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _universalWallet = require("./universal-wallet");
|
|
62
|
+
Object.keys(_universalWallet).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _universalWallet[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _universalWallet[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _okxWallet = require("./okx-wallet");
|
|
73
|
+
Object.keys(_okxWallet).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _okxWallet[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _okxWallet[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var _imToken = require("./im-token");
|
|
84
|
+
Object.keys(_imToken).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _imToken[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _imToken[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var _mobileWallet = require("./mobile-wallet");
|
|
95
|
+
Object.keys(_mobileWallet).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _mobileWallet[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _mobileWallet[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
var _rainbowWallet = require("./rainbow-wallet");
|
|
106
|
+
Object.keys(_rainbowWallet).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _rainbowWallet[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _rainbowWallet[key];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|