@wagmi/core 0.4.0-test.2 → 0.4.2
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/chains/dist/wagmi-core-chains.cjs.dev.js +2 -2
- package/chains/dist/wagmi-core-chains.cjs.prod.js +2 -2
- package/chains/dist/wagmi-core-chains.esm.js +2 -2
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.dev.js +9 -7
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.cjs.prod.js +9 -7
- package/connectors/coinbaseWallet/dist/wagmi-core-connectors-coinbaseWallet.esm.js +9 -7
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.dev.js +7 -5
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.cjs.prod.js +7 -5
- package/connectors/metaMask/dist/wagmi-core-connectors-metaMask.esm.js +7 -5
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.dev.js +12 -8
- package/connectors/mock/dist/wagmi-core-connectors-mock.cjs.prod.js +12 -8
- package/connectors/mock/dist/wagmi-core-connectors-mock.esm.js +7 -7
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.dev.js +19 -18
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.cjs.prod.js +19 -18
- package/connectors/walletConnect/dist/wagmi-core-connectors-walletConnect.esm.js +19 -18
- package/dist/base-2d484f6c.cjs.prod.js +329 -0
- package/dist/base-e66f9622.esm.js +303 -0
- package/dist/base-e71ae4b2.cjs.dev.js +329 -0
- package/dist/{chains-7e369752.cjs.dev.js → chains-865492ea.cjs.prod.js} +79 -16
- package/dist/{chains-fa406563.esm.js → chains-c389721d.esm.js} +79 -16
- package/dist/{chains-d045862c.cjs.prod.js → chains-d970ee8d.cjs.dev.js} +79 -16
- package/dist/{client-42cf11b7.cjs.dev.js → client-1feb9121.cjs.prod.js} +29 -46
- package/dist/{client-ed3aaa6a.cjs.prod.js → client-53f2119c.cjs.dev.js} +29 -46
- package/dist/{client-60ee0298.esm.js → client-ffba0e25.esm.js} +29 -46
- package/dist/declarations/src/actions/accounts/getAccount.d.ts +31 -2
- package/dist/declarations/src/actions/accounts/getNetwork.d.ts +1 -2
- package/dist/declarations/src/actions/accounts/signTypedData.d.ts +17 -15
- package/dist/declarations/src/actions/accounts/watchAccount.d.ts +9 -1
- package/dist/declarations/src/actions/accounts/watchNetwork.d.ts +8 -1
- package/dist/declarations/src/actions/contracts/index.d.ts +5 -3
- package/dist/declarations/src/actions/contracts/multicall.d.ts +21 -0
- package/dist/declarations/src/actions/contracts/readContract.d.ts +7 -4
- package/dist/declarations/src/actions/contracts/readContracts.d.ts +19 -0
- package/dist/declarations/src/actions/contracts/watchContractEvent.d.ts +3 -3
- package/dist/declarations/src/actions/contracts/watchReadContract.d.ts +2 -3
- package/dist/declarations/src/actions/contracts/watchReadContracts.d.ts +6 -0
- package/dist/declarations/src/actions/contracts/writeContract.d.ts +10 -4
- package/dist/declarations/src/actions/index.d.ts +1 -1
- package/dist/declarations/src/actions/transactions/sendTransaction.d.ts +6 -1
- package/dist/declarations/src/client.d.ts +6 -11
- package/dist/declarations/src/connectors/base.d.ts +4 -3
- package/dist/declarations/src/connectors/mock/connector.d.ts +2 -9
- package/dist/declarations/src/connectors/mock/provider.d.ts +2 -1
- package/dist/declarations/src/connectors/walletConnect.d.ts +5 -4
- package/dist/declarations/src/constants/index.d.ts +2 -1
- package/dist/declarations/src/constants/multicall.d.ts +25 -0
- package/dist/declarations/src/constants/rpcs.d.ts +3 -1
- package/dist/declarations/src/errors.d.ts +27 -5
- package/dist/declarations/src/index.d.ts +5 -5
- package/dist/declarations/src/providers/alchemy.d.ts +2 -2
- package/dist/declarations/src/providers/infura.d.ts +2 -2
- package/dist/declarations/src/providers/jsonRpc.d.ts +2 -2
- package/dist/declarations/src/providers/public.d.ts +2 -2
- package/dist/declarations/src/types/index.d.ts +17 -5
- package/dist/declarations/src/utils/configureChains.d.ts +10 -4
- package/dist/declarations/src/utils/normalizeChainId.d.ts +1 -1
- package/dist/{rpcs-9c4eb960.cjs.dev.js → rpcs-1fd0a12f.cjs.prod.js} +14 -0
- package/dist/{rpcs-7cfbd91c.esm.js → rpcs-b73a8f60.esm.js} +14 -1
- package/dist/{rpcs-b3c52116.cjs.prod.js → rpcs-f1d24f0e.cjs.dev.js} +14 -0
- package/dist/wagmi-core.cjs.dev.js +611 -234
- package/dist/wagmi-core.cjs.prod.js +611 -234
- package/dist/wagmi-core.esm.js +608 -242
- package/package.json +15 -3
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.dev.js +1 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.cjs.prod.js +1 -1
- package/providers/alchemy/dist/wagmi-core-providers-alchemy.esm.js +1 -1
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.dev.js +1 -1
- package/providers/infura/dist/wagmi-core-providers-infura.cjs.prod.js +1 -1
- package/providers/infura/dist/wagmi-core-providers-infura.esm.js +1 -1
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.dev.js +3 -1
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.cjs.prod.js +3 -1
- package/providers/jsonRpc/dist/wagmi-core-providers-jsonRpc.esm.js +3 -1
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.d.ts +0 -1
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.dev.js +0 -200
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.js +0 -7
- package/connectors/injected/dist/wagmi-core-connectors-injected.cjs.prod.js +0 -200
- package/connectors/injected/dist/wagmi-core-connectors-injected.esm.js +0 -196
- package/connectors/walletLink/dist/wagmi-core-connectors-walletLink.cjs.d.ts +0 -11
- package/connectors/walletLink/dist/wagmi-core-connectors-walletLink.cjs.js +0 -16
- package/dist/base-7f682723.cjs.prod.js +0 -623
- package/dist/base-ae774f26.cjs.dev.js +0 -623
- package/dist/base-c546f171.esm.js +0 -603
- package/dist/declarations/src/utils/eventemitter.d.ts +0 -135
|
@@ -1,196 +0,0 @@
|
|
|
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 };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// are you seeing an error that a default export doesn't exist but your source file has a default export?
|
|
2
|
-
// you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
|
|
3
|
-
|
|
4
|
-
// curious why you need to?
|
|
5
|
-
// this file exists so that you can import from the entrypoint normally
|
|
6
|
-
// except that it points to your source file and you don't need to run build constantly
|
|
7
|
-
// which means we need to re-export all of the modules from your source file
|
|
8
|
-
// and since export * doesn't include default exports, we need to read your source file
|
|
9
|
-
// to check for a default export and re-export it if it exists
|
|
10
|
-
// it's not ideal, but it works pretty well ¯\_(ツ)_/¯
|
|
11
|
-
export * from "../../../src/connectors/walletLink";
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// this file might look strange and you might be wondering what it's for
|
|
3
|
-
// it's lets you import your source files by importing this entrypoint
|
|
4
|
-
// as you would import it if it was built with preconstruct build
|
|
5
|
-
// this file is slightly different to some others though
|
|
6
|
-
// it has a require hook which compiles your code with Babel
|
|
7
|
-
// this means that you don't have to set up @babel/register or anything like that
|
|
8
|
-
// but you can still require this module and it'll be compiled
|
|
9
|
-
|
|
10
|
-
// this bit of code imports the require hook and registers it
|
|
11
|
-
let unregister = require("../../../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
|
|
12
|
-
|
|
13
|
-
// this re-exports the source file
|
|
14
|
-
module.exports = require("../../../src/connectors/walletLink.ts");
|
|
15
|
-
|
|
16
|
-
unregister();
|