@wagmi/core 0.4.7 → 0.5.0-prepare-hooks.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/README.md +4 -4
- package/chains/dist/wagmi-core-chains.cjs.dev.js +1 -1
- package/chains/dist/wagmi-core-chains.cjs.prod.js +1 -1
- package/chains/dist/wagmi-core-chains.esm.js +1 -1
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +29 -26
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +29 -26
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +6 -3
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.d.ts +1 -0
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.dev.js +200 -0
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.js +7 -0
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.prod.js +200 -0
- package/connectors/injected/dist/wagmi-core-connectors-injected.esm.js +196 -0
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +21 -22
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +21 -22
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +6 -7
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +31 -29
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +31 -29
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +4 -2
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +23 -24
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +23 -24
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +4 -5
- package/connectors/walletLink/dist/wagmi-core-connectors-walletLink.cjs.d.ts +11 -0
- package/connectors/walletLink/dist/wagmi-core-connectors-walletLink.cjs.js +16 -0
- package/dist/{chains-fd2c546c.esm.js → chains-174cf4b4.esm.js} +3 -3
- package/dist/{chains-f7bb3211.cjs.prod.js → chains-b8e32454.cjs.prod.js} +3 -3
- package/dist/{chains-7e6dc59c.cjs.dev.js → chains-ba6218fb.cjs.dev.js} +3 -3
- package/dist/declarations/src/actions/accounts/fetchSigner.d.ts +3 -3
- package/dist/declarations/src/actions/contracts/index.d.ts +2 -1
- package/dist/declarations/src/actions/contracts/prepareWriteContract.d.ts +37 -0
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +44 -8
- package/dist/declarations/src/actions/ens/fetchEnsAddress.d.ts +2 -1
- package/dist/declarations/src/actions/index.d.ts +2 -2
- package/dist/declarations/src/actions/tokens/fetchToken.d.ts +1 -0
- package/dist/declarations/src/actions/transactions/index.d.ts +2 -1
- package/dist/declarations/src/actions/transactions/prepareSendTransaction.d.ts +36 -0
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +43 -8
- package/dist/declarations/src/client.d.ts +3 -3
- package/dist/declarations/src/connectors/base.d.ts +1 -2
- package/dist/declarations/src/connectors/coinbaseWallet.d.ts +1 -1
- package/dist/declarations/src/connectors/index.d.ts +1 -1
- package/dist/declarations/src/connectors/injected.d.ts +4 -4
- package/dist/declarations/src/connectors/metaMask.d.ts +1 -1
- package/dist/declarations/src/connectors/mock/connector.d.ts +1 -1
- package/dist/declarations/src/connectors/mock/provider.d.ts +3 -3
- package/dist/declarations/src/connectors/walletConnect.d.ts +2 -1
- package/dist/declarations/src/errors.d.ts +10 -3
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/providers/alchemy.d.ts +1 -2
- package/dist/declarations/src/providers/infura.d.ts +1 -2
- package/dist/declarations/src/providers/jsonRpc.d.ts +1 -2
- package/dist/declarations/src/providers/public.d.ts +2 -4
- package/dist/declarations/src/types/index.d.ts +132 -129
- package/dist/declarations/src/utils/configureChains.d.ts +3 -1
- package/dist/declarations/src/utils/getInjectedName.d.ts +2 -1
- package/dist/{client-a05fd511.esm.js → getProvider-048a69c4.esm.js} +380 -13
- package/dist/{client-a6e61429.cjs.prod.js → getProvider-27edfd38.cjs.prod.js} +446 -55
- package/dist/{client-71ece661.cjs.dev.js → getProvider-ec251513.cjs.dev.js} +446 -55
- package/dist/wagmi-core.cjs.dev.js +462 -286
- package/dist/wagmi-core.cjs.prod.js +462 -286
- package/dist/wagmi-core.esm.js +377 -205
- package/package.json +2 -2
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +0 -2
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +0 -2
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +0 -2
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +0 -2
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +0 -2
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +0 -2
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.cjs.dev.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.cjs.prod.js +0 -2
- package/providers/public/dist/wagmi-core-providers-public.esm.js +0 -2
- package/dist/base-797ad073.cjs.prod.js +0 -343
- package/dist/base-90b7f3e4.cjs.dev.js +0 -343
- package/dist/base-b565d5d4.esm.js +0 -316
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var providers = require('@ethersproject/providers');
|
|
6
|
+
var base = require('../../../dist/base-677c6ead.cjs.prod.js');
|
|
7
|
+
var utils = require('ethers/lib/utils');
|
|
8
|
+
require('eventemitter3');
|
|
9
|
+
|
|
10
|
+
const getInjectedName = ethereum => {
|
|
11
|
+
if (!ethereum) return 'Injected';
|
|
12
|
+
if (ethereum.isMetaMask) return 'MetaMask';
|
|
13
|
+
if (ethereum.isCoinbaseWallet) return 'Coinbase Wallet';
|
|
14
|
+
if (ethereum.isFrame) return 'Frame';
|
|
15
|
+
if (ethereum.isTally) return 'Tally';
|
|
16
|
+
return 'Injected';
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const shimKey = 'wagmi.shimDisconnect';
|
|
20
|
+
class InjectedConnector extends base.Connector {
|
|
21
|
+
id = 'injected';
|
|
22
|
+
ready = typeof window != 'undefined' && !!window.ethereum;
|
|
23
|
+
#provider;
|
|
24
|
+
|
|
25
|
+
constructor(config) {
|
|
26
|
+
// TODO(note): Should shimDisconnect be default truthy??
|
|
27
|
+
super({ ...config,
|
|
28
|
+
options: config?.options
|
|
29
|
+
});
|
|
30
|
+
let name = 'Injected';
|
|
31
|
+
if (typeof window !== 'undefined') name = getInjectedName(window.ethereum);
|
|
32
|
+
this.name = name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async connect() {
|
|
36
|
+
try {
|
|
37
|
+
const provider = this.getProvider();
|
|
38
|
+
if (!provider) throw new base.ConnectorNotFoundError();
|
|
39
|
+
|
|
40
|
+
if (provider.on) {
|
|
41
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
42
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
43
|
+
provider.on('disconnect', this.onDisconnect);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const account = await this.getAccount();
|
|
47
|
+
const id = await this.getChainId();
|
|
48
|
+
const unsupported = this.isChainUnsupported(id);
|
|
49
|
+
if (this.options?.shimDisconnect) typeof localStorage !== 'undefined' && localStorage.setItem(shimKey, 'true');
|
|
50
|
+
return {
|
|
51
|
+
account,
|
|
52
|
+
chain: {
|
|
53
|
+
id,
|
|
54
|
+
unsupported
|
|
55
|
+
},
|
|
56
|
+
provider
|
|
57
|
+
};
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error.code === 4001) throw new base.UserRejectedRequestError();
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async disconnect() {
|
|
65
|
+
const provider = this.getProvider();
|
|
66
|
+
if (!provider?.removeListener) return;
|
|
67
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
68
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
69
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
70
|
+
if (this.options?.shimDisconnect) typeof localStorage !== 'undefined' && localStorage.removeItem(shimKey);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getAccount() {
|
|
74
|
+
const provider = this.getProvider();
|
|
75
|
+
if (!provider) throw new base.ConnectorNotFoundError();
|
|
76
|
+
const accounts = await provider.request({
|
|
77
|
+
method: 'eth_requestAccounts'
|
|
78
|
+
}); // return checksum address
|
|
79
|
+
|
|
80
|
+
return utils.getAddress(accounts[0]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getChainId() {
|
|
84
|
+
const provider = this.getProvider();
|
|
85
|
+
if (!provider) throw new base.ConnectorNotFoundError();
|
|
86
|
+
return await provider.request({
|
|
87
|
+
method: 'eth_chainId'
|
|
88
|
+
}).then(base.normalizeChainId);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getProvider() {
|
|
92
|
+
if (typeof window !== 'undefined' && !!window.ethereum) this.#provider = window.ethereum;
|
|
93
|
+
return this.#provider;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getSigner() {
|
|
97
|
+
const provider = this.getProvider();
|
|
98
|
+
const account = await this.getAccount();
|
|
99
|
+
return new providers.Web3Provider(provider).getSigner(account);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async isAuthorized() {
|
|
103
|
+
try {
|
|
104
|
+
if (this.options?.shimDisconnect && typeof localStorage !== 'undefined' && !localStorage.getItem(shimKey)) return false;
|
|
105
|
+
const provider = this.getProvider();
|
|
106
|
+
if (!provider) throw new base.ConnectorNotFoundError();
|
|
107
|
+
const accounts = await provider.request({
|
|
108
|
+
method: 'eth_accounts'
|
|
109
|
+
});
|
|
110
|
+
const account = accounts[0];
|
|
111
|
+
return !!account;
|
|
112
|
+
} catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async switchChain(chainId) {
|
|
118
|
+
const provider = this.getProvider();
|
|
119
|
+
if (!provider) throw new base.ConnectorNotFoundError();
|
|
120
|
+
const id = utils.hexValue(chainId);
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
await provider.request({
|
|
124
|
+
method: 'wallet_switchEthereumChain',
|
|
125
|
+
params: [{
|
|
126
|
+
chainId: id
|
|
127
|
+
}]
|
|
128
|
+
});
|
|
129
|
+
const chains = [...this.chains, ...base.allChains];
|
|
130
|
+
return chains.find(x => x.id === chainId);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
// Indicates chain is not added to MetaMask
|
|
133
|
+
if (error.code === 4902) {
|
|
134
|
+
try {
|
|
135
|
+
const chain = this.chains.find(x => x.id === chainId);
|
|
136
|
+
if (!chain) throw new base.ChainNotConfiguredError();
|
|
137
|
+
await provider.request({
|
|
138
|
+
method: 'wallet_addEthereumChain',
|
|
139
|
+
params: [{
|
|
140
|
+
chainId: id,
|
|
141
|
+
chainName: chain.name,
|
|
142
|
+
nativeCurrency: chain.nativeCurrency,
|
|
143
|
+
rpcUrls: chain.rpcUrls,
|
|
144
|
+
blockExplorerUrls: chain.blockExplorers?.map(x => x.url)
|
|
145
|
+
}]
|
|
146
|
+
});
|
|
147
|
+
} catch (addError) {
|
|
148
|
+
throw new base.AddChainError();
|
|
149
|
+
}
|
|
150
|
+
} else if (error.code === 4001) throw new base.UserRejectedRequestError();else throw new base.SwitchChainError();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async watchAsset({
|
|
155
|
+
address,
|
|
156
|
+
decimals = 18,
|
|
157
|
+
image,
|
|
158
|
+
symbol
|
|
159
|
+
}) {
|
|
160
|
+
const provider = this.getProvider();
|
|
161
|
+
if (!provider) throw new base.ConnectorNotFoundError();
|
|
162
|
+
await provider.request({
|
|
163
|
+
method: 'wallet_watchAsset',
|
|
164
|
+
params: {
|
|
165
|
+
type: 'ERC20',
|
|
166
|
+
options: {
|
|
167
|
+
address,
|
|
168
|
+
decimals,
|
|
169
|
+
image,
|
|
170
|
+
symbol
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
onAccountsChanged = accounts => {
|
|
177
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
178
|
+
account: utils.getAddress(accounts[0])
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
onChainChanged = chainId => {
|
|
182
|
+
const id = base.normalizeChainId(chainId);
|
|
183
|
+
const unsupported = this.isChainUnsupported(id);
|
|
184
|
+
this.emit('change', {
|
|
185
|
+
chain: {
|
|
186
|
+
id,
|
|
187
|
+
unsupported
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
onDisconnect = err => {
|
|
192
|
+
// TODO: this is a hack, probs better way to deal
|
|
193
|
+
if (!err.message.includes('Attempting to connect.')) {
|
|
194
|
+
this.emit('disconnect');
|
|
195
|
+
if (this.options?.shimDisconnect) typeof localStorage !== 'undefined' && localStorage.removeItem(shimKey);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
exports.InjectedConnector = InjectedConnector;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { Web3Provider } from '@ethersproject/providers';
|
|
2
|
+
import { C as Connector, g as ConnectorNotFoundError, U as UserRejectedRequestError, n as normalizeChainId, a as allChains, f as ChainNotConfiguredError, A as AddChainError, S as SwitchChainError } from '../../../dist/base-0de5bfca.esm.js';
|
|
3
|
+
import { getAddress, hexValue } from 'ethers/lib/utils';
|
|
4
|
+
import 'eventemitter3';
|
|
5
|
+
|
|
6
|
+
const getInjectedName = ethereum => {
|
|
7
|
+
if (!ethereum) return 'Injected';
|
|
8
|
+
if (ethereum.isMetaMask) return 'MetaMask';
|
|
9
|
+
if (ethereum.isCoinbaseWallet) return 'Coinbase Wallet';
|
|
10
|
+
if (ethereum.isFrame) return 'Frame';
|
|
11
|
+
if (ethereum.isTally) return 'Tally';
|
|
12
|
+
return 'Injected';
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const shimKey = 'wagmi.shimDisconnect';
|
|
16
|
+
class InjectedConnector extends Connector {
|
|
17
|
+
id = 'injected';
|
|
18
|
+
ready = typeof window != 'undefined' && !!window.ethereum;
|
|
19
|
+
#provider;
|
|
20
|
+
|
|
21
|
+
constructor(config) {
|
|
22
|
+
// TODO(note): Should shimDisconnect be default truthy??
|
|
23
|
+
super({ ...config,
|
|
24
|
+
options: config?.options
|
|
25
|
+
});
|
|
26
|
+
let name = 'Injected';
|
|
27
|
+
if (typeof window !== 'undefined') name = getInjectedName(window.ethereum);
|
|
28
|
+
this.name = name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async connect() {
|
|
32
|
+
try {
|
|
33
|
+
const provider = this.getProvider();
|
|
34
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
35
|
+
|
|
36
|
+
if (provider.on) {
|
|
37
|
+
provider.on('accountsChanged', this.onAccountsChanged);
|
|
38
|
+
provider.on('chainChanged', this.onChainChanged);
|
|
39
|
+
provider.on('disconnect', this.onDisconnect);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const account = await this.getAccount();
|
|
43
|
+
const id = await this.getChainId();
|
|
44
|
+
const unsupported = this.isChainUnsupported(id);
|
|
45
|
+
if (this.options?.shimDisconnect) typeof localStorage !== 'undefined' && localStorage.setItem(shimKey, 'true');
|
|
46
|
+
return {
|
|
47
|
+
account,
|
|
48
|
+
chain: {
|
|
49
|
+
id,
|
|
50
|
+
unsupported
|
|
51
|
+
},
|
|
52
|
+
provider
|
|
53
|
+
};
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (error.code === 4001) throw new UserRejectedRequestError();
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async disconnect() {
|
|
61
|
+
const provider = this.getProvider();
|
|
62
|
+
if (!provider?.removeListener) return;
|
|
63
|
+
provider.removeListener('accountsChanged', this.onAccountsChanged);
|
|
64
|
+
provider.removeListener('chainChanged', this.onChainChanged);
|
|
65
|
+
provider.removeListener('disconnect', this.onDisconnect);
|
|
66
|
+
if (this.options?.shimDisconnect) typeof localStorage !== 'undefined' && localStorage.removeItem(shimKey);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getAccount() {
|
|
70
|
+
const provider = this.getProvider();
|
|
71
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
72
|
+
const accounts = await provider.request({
|
|
73
|
+
method: 'eth_requestAccounts'
|
|
74
|
+
}); // return checksum address
|
|
75
|
+
|
|
76
|
+
return getAddress(accounts[0]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async getChainId() {
|
|
80
|
+
const provider = this.getProvider();
|
|
81
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
82
|
+
return await provider.request({
|
|
83
|
+
method: 'eth_chainId'
|
|
84
|
+
}).then(normalizeChainId);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getProvider() {
|
|
88
|
+
if (typeof window !== 'undefined' && !!window.ethereum) this.#provider = window.ethereum;
|
|
89
|
+
return this.#provider;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async getSigner() {
|
|
93
|
+
const provider = this.getProvider();
|
|
94
|
+
const account = await this.getAccount();
|
|
95
|
+
return new Web3Provider(provider).getSigner(account);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async isAuthorized() {
|
|
99
|
+
try {
|
|
100
|
+
if (this.options?.shimDisconnect && typeof localStorage !== 'undefined' && !localStorage.getItem(shimKey)) return false;
|
|
101
|
+
const provider = this.getProvider();
|
|
102
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
103
|
+
const accounts = await provider.request({
|
|
104
|
+
method: 'eth_accounts'
|
|
105
|
+
});
|
|
106
|
+
const account = accounts[0];
|
|
107
|
+
return !!account;
|
|
108
|
+
} catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async switchChain(chainId) {
|
|
114
|
+
const provider = this.getProvider();
|
|
115
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
116
|
+
const id = hexValue(chainId);
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
await provider.request({
|
|
120
|
+
method: 'wallet_switchEthereumChain',
|
|
121
|
+
params: [{
|
|
122
|
+
chainId: id
|
|
123
|
+
}]
|
|
124
|
+
});
|
|
125
|
+
const chains = [...this.chains, ...allChains];
|
|
126
|
+
return chains.find(x => x.id === chainId);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
// Indicates chain is not added to MetaMask
|
|
129
|
+
if (error.code === 4902) {
|
|
130
|
+
try {
|
|
131
|
+
const chain = this.chains.find(x => x.id === chainId);
|
|
132
|
+
if (!chain) throw new ChainNotConfiguredError();
|
|
133
|
+
await provider.request({
|
|
134
|
+
method: 'wallet_addEthereumChain',
|
|
135
|
+
params: [{
|
|
136
|
+
chainId: id,
|
|
137
|
+
chainName: chain.name,
|
|
138
|
+
nativeCurrency: chain.nativeCurrency,
|
|
139
|
+
rpcUrls: chain.rpcUrls,
|
|
140
|
+
blockExplorerUrls: chain.blockExplorers?.map(x => x.url)
|
|
141
|
+
}]
|
|
142
|
+
});
|
|
143
|
+
} catch (addError) {
|
|
144
|
+
throw new AddChainError();
|
|
145
|
+
}
|
|
146
|
+
} else if (error.code === 4001) throw new UserRejectedRequestError();else throw new SwitchChainError();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async watchAsset({
|
|
151
|
+
address,
|
|
152
|
+
decimals = 18,
|
|
153
|
+
image,
|
|
154
|
+
symbol
|
|
155
|
+
}) {
|
|
156
|
+
const provider = this.getProvider();
|
|
157
|
+
if (!provider) throw new ConnectorNotFoundError();
|
|
158
|
+
await provider.request({
|
|
159
|
+
method: 'wallet_watchAsset',
|
|
160
|
+
params: {
|
|
161
|
+
type: 'ERC20',
|
|
162
|
+
options: {
|
|
163
|
+
address,
|
|
164
|
+
decimals,
|
|
165
|
+
image,
|
|
166
|
+
symbol
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
onAccountsChanged = accounts => {
|
|
173
|
+
if (accounts.length === 0) this.emit('disconnect');else this.emit('change', {
|
|
174
|
+
account: getAddress(accounts[0])
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
onChainChanged = chainId => {
|
|
178
|
+
const id = normalizeChainId(chainId);
|
|
179
|
+
const unsupported = this.isChainUnsupported(id);
|
|
180
|
+
this.emit('change', {
|
|
181
|
+
chain: {
|
|
182
|
+
id,
|
|
183
|
+
unsupported
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
onDisconnect = err => {
|
|
188
|
+
// TODO: this is a hack, probs better way to deal
|
|
189
|
+
if (!err.message.includes('Attempting to connect.')) {
|
|
190
|
+
this.emit('disconnect');
|
|
191
|
+
if (this.options?.shimDisconnect) typeof localStorage !== 'undefined' && localStorage.removeItem(shimKey);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { InjectedConnector };
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var client = require('../../../dist/client-71ece661.cjs.dev.js');
|
|
7
|
-
require('eventemitter3');
|
|
8
|
-
require('../../../dist/chains-7e6dc59c.cjs.dev.js');
|
|
9
|
-
require('../../../dist/rpcs-f1d24f0e.cjs.dev.js');
|
|
5
|
+
var getProvider = require('../../../dist/getProvider-ec251513.cjs.dev.js');
|
|
10
6
|
require('zustand/vanilla');
|
|
11
7
|
require('zustand/middleware');
|
|
12
8
|
require('ethers');
|
|
13
9
|
require('ethers/lib/utils');
|
|
10
|
+
require('eventemitter3');
|
|
11
|
+
require('../../../dist/chains-ba6218fb.cjs.dev.js');
|
|
12
|
+
require('../../../dist/rpcs-f1d24f0e.cjs.dev.js');
|
|
14
13
|
|
|
15
14
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
16
15
|
|
|
@@ -20,7 +19,7 @@ var _getReady = /*#__PURE__*/new WeakSet();
|
|
|
20
19
|
|
|
21
20
|
var _findProvider = /*#__PURE__*/new WeakSet();
|
|
22
21
|
|
|
23
|
-
class MetaMaskConnector extends
|
|
22
|
+
class MetaMaskConnector extends getProvider.InjectedConnector {
|
|
24
23
|
constructor() {
|
|
25
24
|
let {
|
|
26
25
|
chains,
|
|
@@ -37,25 +36,25 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
37
36
|
options
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
getProvider._classPrivateMethodInitSpec(this, _findProvider);
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
getProvider._classPrivateMethodInitSpec(this, _getReady);
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
getProvider._defineProperty(this, "id", 'metaMask');
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
getProvider._defineProperty(this, "ready", typeof window != 'undefined' && !!getProvider._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
getProvider._classPrivateFieldInitSpec(this, _provider, {
|
|
49
48
|
writable: true,
|
|
50
49
|
value: void 0
|
|
51
50
|
});
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
getProvider._classPrivateFieldInitSpec(this, _UNSTABLE_shimOnConnectSelectAccount, {
|
|
54
53
|
writable: true,
|
|
55
54
|
value: void 0
|
|
56
55
|
});
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
getProvider._classPrivateFieldSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
async connect() {
|
|
@@ -67,7 +66,7 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
67
66
|
var _this$options, _getClient$storage, _this$options2, _getClient$storage2;
|
|
68
67
|
|
|
69
68
|
const provider = await this.getProvider();
|
|
70
|
-
if (!provider) throw new
|
|
69
|
+
if (!provider) throw new getProvider.ConnectorNotFoundError();
|
|
71
70
|
|
|
72
71
|
if (provider.on) {
|
|
73
72
|
provider.on('accountsChanged', this.onAccountsChanged);
|
|
@@ -80,7 +79,7 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
80
79
|
}); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
|
|
81
80
|
// `shimDisconnect` is active and account is in disconnected state (flag in storage)
|
|
82
81
|
|
|
83
|
-
if (
|
|
82
|
+
if (getProvider._classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = getProvider.getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(this.shimDisconnectKey))) {
|
|
84
83
|
const accounts = await provider.request({
|
|
85
84
|
method: 'eth_accounts'
|
|
86
85
|
}).catch(() => []);
|
|
@@ -104,7 +103,7 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
104
103
|
unsupported = this.isChainUnsupported(id);
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 =
|
|
106
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getProvider.getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(this.shimDisconnectKey, true);
|
|
108
107
|
return {
|
|
109
108
|
account,
|
|
110
109
|
chain: {
|
|
@@ -114,8 +113,8 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
114
113
|
provider
|
|
115
114
|
};
|
|
116
115
|
} catch (error) {
|
|
117
|
-
if (this.isUserRejectedRequestError(error)) throw new
|
|
118
|
-
if (error.code === -32002) throw new
|
|
116
|
+
if (this.isUserRejectedRequestError(error)) throw new getProvider.UserRejectedRequestError(error);
|
|
117
|
+
if (error.code === -32002) throw new getProvider.ResourceUnavailableError(error);
|
|
119
118
|
throw error;
|
|
120
119
|
}
|
|
121
120
|
}
|
|
@@ -124,10 +123,10 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
124
123
|
if (typeof window !== 'undefined') {
|
|
125
124
|
// TODO: Fallback to `ethereum#initialized` event for async injection
|
|
126
125
|
// https://github.com/MetaMask/detect-provider#synchronous-and-asynchronous-injection=
|
|
127
|
-
|
|
126
|
+
getProvider._classPrivateFieldSet(this, _provider, getProvider._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
return
|
|
129
|
+
return getProvider._classPrivateFieldGet(this, _provider);
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
}
|
|
@@ -144,8 +143,8 @@ function _getReady2(ethereum) {
|
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
function _findProvider2(ethereum) {
|
|
147
|
-
if (ethereum !== null && ethereum !== void 0 && ethereum.providers) return ethereum.providers.find(
|
|
148
|
-
return
|
|
146
|
+
if (ethereum !== null && ethereum !== void 0 && ethereum.providers) return ethereum.providers.find(getProvider._classPrivateMethodGet(this, _getReady, _getReady2));
|
|
147
|
+
return getProvider._classPrivateMethodGet(this, _getReady, _getReady2).call(this, ethereum);
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
exports.MetaMaskConnector = MetaMaskConnector;
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var client = require('../../../dist/client-a6e61429.cjs.prod.js');
|
|
7
|
-
require('eventemitter3');
|
|
8
|
-
require('../../../dist/chains-f7bb3211.cjs.prod.js');
|
|
9
|
-
require('../../../dist/rpcs-1fd0a12f.cjs.prod.js');
|
|
5
|
+
var getProvider = require('../../../dist/getProvider-27edfd38.cjs.prod.js');
|
|
10
6
|
require('zustand/vanilla');
|
|
11
7
|
require('zustand/middleware');
|
|
12
8
|
require('ethers');
|
|
13
9
|
require('ethers/lib/utils');
|
|
10
|
+
require('eventemitter3');
|
|
11
|
+
require('../../../dist/chains-b8e32454.cjs.prod.js');
|
|
12
|
+
require('../../../dist/rpcs-1fd0a12f.cjs.prod.js');
|
|
14
13
|
|
|
15
14
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
16
15
|
|
|
@@ -20,7 +19,7 @@ var _getReady = /*#__PURE__*/new WeakSet();
|
|
|
20
19
|
|
|
21
20
|
var _findProvider = /*#__PURE__*/new WeakSet();
|
|
22
21
|
|
|
23
|
-
class MetaMaskConnector extends
|
|
22
|
+
class MetaMaskConnector extends getProvider.InjectedConnector {
|
|
24
23
|
constructor() {
|
|
25
24
|
let {
|
|
26
25
|
chains,
|
|
@@ -37,25 +36,25 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
37
36
|
options
|
|
38
37
|
});
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
getProvider._classPrivateMethodInitSpec(this, _findProvider);
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
getProvider._classPrivateMethodInitSpec(this, _getReady);
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
getProvider._defineProperty(this, "id", 'metaMask');
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
getProvider._defineProperty(this, "ready", typeof window != 'undefined' && !!getProvider._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
|
|
47
46
|
|
|
48
|
-
|
|
47
|
+
getProvider._classPrivateFieldInitSpec(this, _provider, {
|
|
49
48
|
writable: true,
|
|
50
49
|
value: void 0
|
|
51
50
|
});
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
getProvider._classPrivateFieldInitSpec(this, _UNSTABLE_shimOnConnectSelectAccount, {
|
|
54
53
|
writable: true,
|
|
55
54
|
value: void 0
|
|
56
55
|
});
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
getProvider._classPrivateFieldSet(this, _UNSTABLE_shimOnConnectSelectAccount, options.UNSTABLE_shimOnConnectSelectAccount);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
async connect() {
|
|
@@ -67,7 +66,7 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
67
66
|
var _this$options, _getClient$storage, _this$options2, _getClient$storage2;
|
|
68
67
|
|
|
69
68
|
const provider = await this.getProvider();
|
|
70
|
-
if (!provider) throw new
|
|
69
|
+
if (!provider) throw new getProvider.ConnectorNotFoundError();
|
|
71
70
|
|
|
72
71
|
if (provider.on) {
|
|
73
72
|
provider.on('accountsChanged', this.onAccountsChanged);
|
|
@@ -80,7 +79,7 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
80
79
|
}); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
|
|
81
80
|
// `shimDisconnect` is active and account is in disconnected state (flag in storage)
|
|
82
81
|
|
|
83
|
-
if (
|
|
82
|
+
if (getProvider._classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = getProvider.getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(this.shimDisconnectKey))) {
|
|
84
83
|
const accounts = await provider.request({
|
|
85
84
|
method: 'eth_accounts'
|
|
86
85
|
}).catch(() => []);
|
|
@@ -104,7 +103,7 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
104
103
|
unsupported = this.isChainUnsupported(id);
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 =
|
|
106
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getProvider.getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(this.shimDisconnectKey, true);
|
|
108
107
|
return {
|
|
109
108
|
account,
|
|
110
109
|
chain: {
|
|
@@ -114,8 +113,8 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
114
113
|
provider
|
|
115
114
|
};
|
|
116
115
|
} catch (error) {
|
|
117
|
-
if (this.isUserRejectedRequestError(error)) throw new
|
|
118
|
-
if (error.code === -32002) throw new
|
|
116
|
+
if (this.isUserRejectedRequestError(error)) throw new getProvider.UserRejectedRequestError(error);
|
|
117
|
+
if (error.code === -32002) throw new getProvider.ResourceUnavailableError(error);
|
|
119
118
|
throw error;
|
|
120
119
|
}
|
|
121
120
|
}
|
|
@@ -124,10 +123,10 @@ class MetaMaskConnector extends client.InjectedConnector {
|
|
|
124
123
|
if (typeof window !== 'undefined') {
|
|
125
124
|
// TODO: Fallback to `ethereum#initialized` event for async injection
|
|
126
125
|
// https://github.com/MetaMask/detect-provider#synchronous-and-asynchronous-injection=
|
|
127
|
-
|
|
126
|
+
getProvider._classPrivateFieldSet(this, _provider, getProvider._classPrivateMethodGet(this, _findProvider, _findProvider2).call(this, window.ethereum));
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
return
|
|
129
|
+
return getProvider._classPrivateFieldGet(this, _provider);
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
}
|
|
@@ -144,8 +143,8 @@ function _getReady2(ethereum) {
|
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
function _findProvider2(ethereum) {
|
|
147
|
-
if (ethereum !== null && ethereum !== void 0 && ethereum.providers) return ethereum.providers.find(
|
|
148
|
-
return
|
|
146
|
+
if (ethereum !== null && ethereum !== void 0 && ethereum.providers) return ethereum.providers.find(getProvider._classPrivateMethodGet(this, _getReady, _getReady2));
|
|
147
|
+
return getProvider._classPrivateMethodGet(this, _getReady, _getReady2).call(this, ethereum);
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
exports.MetaMaskConnector = MetaMaskConnector;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { I as InjectedConnector, g as getClient, s as shimDisconnectKey } from '../../../dist/client-a05fd511.esm.js';
|
|
3
|
-
import 'eventemitter3';
|
|
4
|
-
import '../../../dist/chains-fd2c546c.esm.js';
|
|
5
|
-
import '../../../dist/rpcs-b73a8f60.esm.js';
|
|
1
|
+
import { I as InjectedConnector, _ as _classPrivateMethodInitSpec, r as _defineProperty, v as _classPrivateMethodGet, s as _classPrivateFieldInitSpec, u as _classPrivateFieldSet, a as ConnectorNotFoundError, t as _classPrivateFieldGet, g as getClient, U as UserRejectedRequestError, R as ResourceUnavailableError } from '../../../dist/getProvider-048a69c4.esm.js';
|
|
6
2
|
import 'zustand/vanilla';
|
|
7
3
|
import 'zustand/middleware';
|
|
8
4
|
import 'ethers';
|
|
9
5
|
import 'ethers/lib/utils';
|
|
6
|
+
import 'eventemitter3';
|
|
7
|
+
import '../../../dist/chains-174cf4b4.esm.js';
|
|
8
|
+
import '../../../dist/rpcs-b73a8f60.esm.js';
|
|
10
9
|
|
|
11
10
|
var _provider = /*#__PURE__*/new WeakMap();
|
|
12
11
|
|
|
@@ -76,7 +75,7 @@ class MetaMaskConnector extends InjectedConnector {
|
|
|
76
75
|
}); // Attempt to show wallet select prompt with `wallet_requestPermissions` when
|
|
77
76
|
// `shimDisconnect` is active and account is in disconnected state (flag in storage)
|
|
78
77
|
|
|
79
|
-
if (_classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(shimDisconnectKey))) {
|
|
78
|
+
if (_classPrivateFieldGet(this, _UNSTABLE_shimOnConnectSelectAccount) && (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.shimDisconnect && !((_getClient$storage = getClient().storage) !== null && _getClient$storage !== void 0 && _getClient$storage.getItem(this.shimDisconnectKey))) {
|
|
80
79
|
const accounts = await provider.request({
|
|
81
80
|
method: 'eth_accounts'
|
|
82
81
|
}).catch(() => []);
|
|
@@ -100,7 +99,7 @@ class MetaMaskConnector extends InjectedConnector {
|
|
|
100
99
|
unsupported = this.isChainUnsupported(id);
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(shimDisconnectKey, true);
|
|
102
|
+
if ((_this$options2 = this.options) !== null && _this$options2 !== void 0 && _this$options2.shimDisconnect) (_getClient$storage2 = getClient().storage) === null || _getClient$storage2 === void 0 ? void 0 : _getClient$storage2.setItem(this.shimDisconnectKey, true);
|
|
104
103
|
return {
|
|
105
104
|
account,
|
|
106
105
|
chain: {
|