@dynamic-labs/ethereum 3.0.0-alpha.9 → 3.0.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 +620 -0
- package/package.json +8 -10
- package/src/coinbase/coinbase.cjs +4 -5
- package/src/coinbase/coinbase.d.ts +2 -2
- package/src/coinbase/coinbase.js +2 -3
- package/src/coinbase/types.d.ts +1 -1
- package/src/ethProviderHelper.cjs +3 -3
- package/src/ethProviderHelper.d.ts +2 -1
- package/src/ethProviderHelper.js +2 -2
- package/src/index.cjs +5 -7
- package/src/index.d.ts +2 -3
- package/src/index.js +1 -4
- package/src/injected/ExodusEvm.d.ts +1 -1
- package/src/injected/FallbackEvmConnector.d.ts +1 -1
- package/src/injected/InjectedWalletBase.cjs +5 -4
- package/src/injected/InjectedWalletBase.d.ts +2 -2
- package/src/injected/InjectedWalletBase.js +4 -3
- package/src/injected/PhantomEvm.cjs +4 -0
- package/src/injected/PhantomEvm.d.ts +2 -1
- package/src/injected/PhantomEvm.js +4 -0
- package/src/injected/UnknownInjected.d.ts +1 -1
- package/src/types.d.ts +1 -0
- package/src/walletConnect/walletConnect.cjs +3 -4
- package/src/walletConnect/walletConnect.d.ts +1 -1
- package/src/walletConnect/walletConnect.js +1 -2
- package/src/EthWalletConnector.cjs +0 -240
- package/src/EthWalletConnector.d.ts +0 -3086
- package/src/EthWalletConnector.js +0 -236
- package/src/utils/findEvmNetwork.cjs +0 -21
- package/src/utils/findEvmNetwork.d.ts +0 -6
- package/src/utils/findEvmNetwork.js +0 -17
- package/src/utils/getNameservice.cjs +0 -46
- package/src/utils/getNameservice.d.ts +0 -6
- package/src/utils/getNameservice.js +0 -42
- package/src/utils/index.d.ts +0 -2
- package/src/utils/isEthWalletConnector/index.d.ts +0 -1
- package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +0 -8
- package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +0 -3
- package/src/utils/isEthWalletConnector/isEthWalletConnector.js +0 -4
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
-
var viem = require('viem');
|
|
8
|
-
var accounts = require('viem/accounts');
|
|
9
|
-
var utils = require('@dynamic-labs/utils');
|
|
10
|
-
var viemUtils = require('@dynamic-labs/viem-utils');
|
|
11
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
12
|
-
var findEvmNetwork = require('./utils/findEvmNetwork.cjs');
|
|
13
|
-
var getNameservice = require('./utils/getNameservice.cjs');
|
|
14
|
-
|
|
15
|
-
class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
16
|
-
getPublicClient() {
|
|
17
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
|
|
20
|
-
if (this.evmNetworks.length === 0) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
const configurations = {
|
|
24
|
-
cosmos: [],
|
|
25
|
-
evm: this.evmNetworks,
|
|
26
|
-
solana: [],
|
|
27
|
-
starknet: undefined,
|
|
28
|
-
};
|
|
29
|
-
if (!this.chainRpcProviders)
|
|
30
|
-
return undefined;
|
|
31
|
-
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
32
|
-
return (_b = this.chainRpcProviders.getEvmProviderByChainId(providers, networkId)) === null || _b === void 0 ? void 0 : _b.provider;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
constructor(props) {
|
|
36
|
-
var _a;
|
|
37
|
-
super(props);
|
|
38
|
-
this.evmNetworkRpcMap = () => this.evmNetworks.reduce((acc, network) => {
|
|
39
|
-
var _a;
|
|
40
|
-
[acc[network.chainId]] = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.length)
|
|
41
|
-
? network.privateCustomerRpcUrls
|
|
42
|
-
: network.rpcUrls;
|
|
43
|
-
return acc;
|
|
44
|
-
}, {});
|
|
45
|
-
this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks);
|
|
46
|
-
this.chainRpcProviders = props.chainRpcProviders;
|
|
47
|
-
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerEvmProviders();
|
|
48
|
-
}
|
|
49
|
-
getNetwork() {
|
|
50
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const provider = this.getWalletClient();
|
|
52
|
-
if (!this.supportsNetworkSwitching || !provider) {
|
|
53
|
-
return Promise.resolve(undefined);
|
|
54
|
-
}
|
|
55
|
-
const chainId = yield utils.retryableFn(provider.getChainId, {
|
|
56
|
-
fallbackValue: utils.FALLBACK_UNDEFINED,
|
|
57
|
-
/**
|
|
58
|
-
* The timeout is set to 1 second because the getChainId method
|
|
59
|
-
* takes around 500ms to resolve on Brave. If the timeout is not set
|
|
60
|
-
* it will use 100ms by default and the method will fail.
|
|
61
|
-
* QNTM-815
|
|
62
|
-
*/
|
|
63
|
-
timeoutMs: 1000,
|
|
64
|
-
});
|
|
65
|
-
this.setActiveChain(viemUtils.chainsMap[chainId]);
|
|
66
|
-
return chainId;
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
getNameService() {
|
|
70
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const [[address], rpcProvider] = yield Promise.all([
|
|
72
|
-
this.getConnectedAccounts(),
|
|
73
|
-
this.getPublicClient(),
|
|
74
|
-
]);
|
|
75
|
-
if (!address || !rpcProvider) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
return getNameservice.getNameservice({ address, rpcProvider });
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
isTestnet() {
|
|
82
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
return (_c = (_b = (_a = (yield this.getPublicClient())) === null || _a === void 0 ? void 0 : _a.chain) === null || _b === void 0 ? void 0 : _b.testnet) !== null && _c !== void 0 ? _c : false;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
parseAddress(address) {
|
|
88
|
-
try {
|
|
89
|
-
// Ensures the address follows the EIP55 format.
|
|
90
|
-
// see: https://eips.ethereum.org/EIPS/eip-55
|
|
91
|
-
return viem.getAddress(address);
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
walletConnectorCore.logger.debug(`Failed to parse EVM address into EIP55 format: error getting checksum, returning default ${address}`, err);
|
|
95
|
-
}
|
|
96
|
-
return address;
|
|
97
|
-
}
|
|
98
|
-
getSigner() {
|
|
99
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
return this.getWalletClient();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
getBalance() {
|
|
104
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
// This is equivalent to getSigner().getAddress() but does not crash
|
|
106
|
-
// if the signer is not available
|
|
107
|
-
const [address] = yield this.getConnectedAccounts();
|
|
108
|
-
if (!address)
|
|
109
|
-
return;
|
|
110
|
-
const client = yield this.getPublicClient();
|
|
111
|
-
const result = yield (client === null || client === void 0 ? void 0 : client.getBalance({
|
|
112
|
-
address: address,
|
|
113
|
-
}));
|
|
114
|
-
if (!result && result !== BigInt(0))
|
|
115
|
-
return;
|
|
116
|
-
return viem.formatEther(result);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
supportsNetworkSwitching() {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
switchNetwork(_a) {
|
|
123
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkName, networkChainId, }) {
|
|
124
|
-
const network = findEvmNetwork.findEvmNetwork({
|
|
125
|
-
chainId: networkChainId,
|
|
126
|
-
name: networkName,
|
|
127
|
-
networks: this.evmNetworks,
|
|
128
|
-
});
|
|
129
|
-
if (!network) {
|
|
130
|
-
throw new utils.DynamicError(`Could not find network mapping for chain ${networkName ? networkName : networkChainId}`);
|
|
131
|
-
}
|
|
132
|
-
if (!this.supportsNetworkSwitching()) {
|
|
133
|
-
throw new utils.DynamicError('Network switching is not supported');
|
|
134
|
-
}
|
|
135
|
-
const provider = this.getWalletClient();
|
|
136
|
-
if (!provider) {
|
|
137
|
-
throw new utils.DynamicError('Provider not found');
|
|
138
|
-
}
|
|
139
|
-
return this.providerSwitchNetwork({ network, provider });
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
getConnectedAccounts() {
|
|
143
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
const provider = this.getWalletClient();
|
|
145
|
-
if (!provider)
|
|
146
|
-
return [];
|
|
147
|
-
const addresses = yield utils.retryableFn(provider.getAddresses, {
|
|
148
|
-
fallbackValue: [],
|
|
149
|
-
timeoutMs: 500,
|
|
150
|
-
});
|
|
151
|
-
if (addresses.length) {
|
|
152
|
-
this.setActiveAccount(addresses[0]);
|
|
153
|
-
}
|
|
154
|
-
return addresses;
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
providerSwitchNetwork(_a) {
|
|
158
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
159
|
-
var _b, _c, _d, _e;
|
|
160
|
-
const { chainId } = network;
|
|
161
|
-
const currentNetworkId = yield this.getNetwork();
|
|
162
|
-
if (currentNetworkId && currentNetworkId === chainId) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
try {
|
|
166
|
-
if (!this.supportsNetworkSwitching()) {
|
|
167
|
-
throw new utils.DynamicError('Network switching is not supported');
|
|
168
|
-
}
|
|
169
|
-
const viemChain = viemUtils.getOrMapViemChain(network);
|
|
170
|
-
yield provider.switchChain(viemChain);
|
|
171
|
-
if (this.key === 'magiceden') {
|
|
172
|
-
const newChainId = yield provider.getChainId();
|
|
173
|
-
this.emit('chainChange', { chain: newChainId.toString() });
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
this.setActiveChain(viemChain);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
181
|
-
if (error.code === 4902 ||
|
|
182
|
-
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Unrecognized chain')) ||
|
|
183
|
-
// https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
|
|
184
|
-
((_d = (_c = error.data) === null || _c === void 0 ? void 0 : _c.orginalError) === null || _d === void 0 ? void 0 : _d.code) === 4902) {
|
|
185
|
-
// error code indicates the chain has not been added yet
|
|
186
|
-
// https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
|
|
187
|
-
return this.providerAddNetwork({ network, provider });
|
|
188
|
-
}
|
|
189
|
-
else if (((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('rejected')) ||
|
|
190
|
-
(typeof error === 'string' && error.includes('rejected'))) {
|
|
191
|
-
throw new utils.DynamicError("User rejected the wallet's request to switch network");
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
providerAddNetwork(_a) {
|
|
200
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
201
|
-
var _b;
|
|
202
|
-
try {
|
|
203
|
-
return yield provider.addChain({ chain: viemUtils.getOrMapViemChain(network) });
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
if (((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('rejected')) ||
|
|
207
|
-
(typeof error === 'string' && error.includes('rejected'))) {
|
|
208
|
-
throw new utils.DynamicError("User rejected the wallet's request to add network");
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
throw error;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
setActiveAccount(account) {
|
|
217
|
-
this.activeAccount = account ? accounts.toAccount(account) : undefined;
|
|
218
|
-
}
|
|
219
|
-
getActiveAccount() {
|
|
220
|
-
return this.activeAccount;
|
|
221
|
-
}
|
|
222
|
-
setActiveChain(chain) {
|
|
223
|
-
this.activeChain = chain;
|
|
224
|
-
}
|
|
225
|
-
getActiveChain() {
|
|
226
|
-
return this.activeChain;
|
|
227
|
-
}
|
|
228
|
-
createUiTransaction(from) {
|
|
229
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
230
|
-
const walletClient = yield this.getWalletClient();
|
|
231
|
-
const publicClient = yield this.getPublicClient();
|
|
232
|
-
if (!publicClient || !walletClient) {
|
|
233
|
-
throw new utils.DynamicError('No public client available');
|
|
234
|
-
}
|
|
235
|
-
return viemUtils.createViemUiTransaction({ from, publicClient, walletClient });
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
exports.EthWalletConnector = EthWalletConnector;
|