@dynamic-labs/ethereum 3.0.0-alpha.51 → 3.0.0-alpha.53

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