@dynamic-labs/ethereum-core 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.
- package/CHANGELOG.md +51 -0
- package/package.json +10 -9
- package/src/connector/EthWalletConnector.cjs +257 -0
- package/src/connector/EthWalletConnector.d.ts +3089 -0
- package/src/connector/EthWalletConnector.js +253 -0
- package/src/connector/index.d.ts +2 -0
- package/src/connector/isEthWalletConnector/index.d.ts +1 -0
- package/src/connector/isEthWalletConnector/isEthWalletConnector.cjs +8 -0
- package/src/connector/isEthWalletConnector/isEthWalletConnector.d.ts +3 -0
- package/src/connector/isEthWalletConnector/isEthWalletConnector.js +4 -0
- package/src/index.cjs +15 -3
- package/src/index.d.ts +2 -0
- package/src/index.js +8 -2
- package/src/rpc/RpcProvidersEthereum/RpcProvidersEthereum.cjs +0 -1
- package/src/rpc/RpcProvidersEthereum/RpcProvidersEthereum.js +0 -1
- package/src/utils/L2ResolverAbi/L2ResolverAbi.cjs +1287 -0
- package/src/utils/L2ResolverAbi/L2ResolverAbi.d.ts +993 -0
- package/src/utils/L2ResolverAbi/L2ResolverAbi.js +1285 -0
- package/src/utils/findEvmNetwork/findEvmNetwork.cjs +21 -0
- package/src/utils/findEvmNetwork/findEvmNetwork.d.ts +6 -0
- package/src/utils/findEvmNetwork/findEvmNetwork.js +17 -0
- package/src/utils/findEvmNetwork/index.d.ts +1 -0
- package/src/utils/getNameservice/getNameservice.cjs +66 -0
- package/src/utils/getNameservice/getNameservice.d.ts +6 -0
- package/src/utils/getNameservice/getNameservice.js +62 -0
- package/src/utils/getNameservice/index.d.ts +1 -0
- package/src/utils/index.d.ts +2 -0
- package/src/utils/validateAddressFormat/index.d.ts +1 -0
- package/src/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.cjs +1 -1
- package/src/utils/viem/ViemRpcUiTransaction/ViemRpcUiTransaction.js +1 -1
- package/src/utils/viem/ViemUiTransaction/ViemUiTransaction.cjs +1 -1
- package/src/utils/viem/ViemUiTransaction/ViemUiTransaction.js +1 -1
- package/src/utils/viem/chainsMap/chainsMap.cjs +3 -3
- package/src/utils/viem/chainsMap/chainsMap.js +2 -2
- package/src/utils/viem/confirmationTransport/confirmationTransport.d.ts +3 -3
- package/src/utils/viem/createAccountWithUiConfirmation/createAccountWithUiConfirmation.d.ts +3 -3
- package/src/utils/viem/createTransportWithUiConfirmation/createTransportWithUiConfirmation.d.ts +3 -3
- package/src/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.cjs +1 -1
- package/src/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.d.ts +4 -4
- package/src/utils/viem/createWalletClientWithUiConfirmation/createWalletClientWithUiConfirmation.js +1 -1
- package/src/utils/viem/estimateL1Fee/opStack/estimateL1Fee.cjs +7 -7
- package/src/utils/viem/getOrMapViemChain/getOrMapViemChain.cjs +3 -3
- package/src/utils/viem/getOrMapViemChain/getOrMapViemChain.js +2 -2
- package/src/utils/viem/index.d.ts +1 -1
- package/src/utils/viem/interceptTransport/interceptTransport.cjs +19 -3
- package/src/utils/viem/interceptTransport/interceptTransport.js +20 -4
- package/src/wallet/EthereumWallet.cjs +67 -0
- package/src/wallet/EthereumWallet.d.ts +18 -0
- package/src/wallet/EthereumWallet.js +63 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isEthereumWallet/index.d.ts +1 -0
- package/src/wallet/isEthereumWallet/isEthereumWallet.cjs +8 -0
- package/src/wallet/isEthereumWallet/isEthereumWallet.d.ts +3 -0
- package/src/wallet/isEthereumWallet/isEthereumWallet.js +4 -0
- package/src/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.cjs +0 -70
- package/src/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.d.ts +0 -19
- package/src/utils/viem/createWalletClientFromWallet/createWalletClientFromWallet.js +0 -46
- package/src/utils/viem/createWalletClientFromWallet/index.d.ts +0 -1
- /package/src/utils/{validateAddressFormat.cjs → validateAddressFormat/validateAddressFormat.cjs} +0 -0
- /package/src/utils/{validateAddressFormat.d.ts → validateAddressFormat/validateAddressFormat.d.ts} +0 -0
- /package/src/utils/{validateAddressFormat.js → validateAddressFormat/validateAddressFormat.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,55 @@
|
|
|
1
1
|
|
|
2
|
+
## [3.0.0-alpha.53](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.52...v3.0.0-alpha.53) (2024-08-29)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* simplify solana wallet signer types (#6748)
|
|
8
|
+
* deprecate getEoaConnector (#6571)
|
|
9
|
+
* limit methods and props returned by wallet.connector (#6540)
|
|
10
|
+
* move generic solana code to solana-core package (#6701)
|
|
11
|
+
* revamp ether v6 interface (#6548)
|
|
12
|
+
* add ethereum wallet specific methods and intercept to sync when needed (#6662)
|
|
13
|
+
* add solana wallet specific methods and intercept to sync when needed (#6608)
|
|
14
|
+
* don't force primary wallet to be connected (#6128)
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add bitcoin wallet specific methods and intercept to sync when needed ([#6663](https://github.com/dynamic-labs/DynamicAuth/issues/6663)) ([ed699b1](https://github.com/dynamic-labs/DynamicAuth/commit/ed699b1f8c264755779ec4840d105f89ade5500e))
|
|
19
|
+
* add ethereum wallet specific methods and intercept to sync when needed ([#6662](https://github.com/dynamic-labs/DynamicAuth/issues/6662)) ([372360e](https://github.com/dynamic-labs/DynamicAuth/commit/372360ed7ca395f88811fc62c94b2b494eb59971))
|
|
20
|
+
* add solana wallet specific methods and intercept to sync when needed ([#6608](https://github.com/dynamic-labs/DynamicAuth/issues/6608)) ([565f610](https://github.com/dynamic-labs/DynamicAuth/commit/565f6100340296c267e9706fd263e9bd3f7d3732))
|
|
21
|
+
* add useSmartWallets hook to manage aa wallets ([#6564](https://github.com/dynamic-labs/DynamicAuth/issues/6564)) ([a243d36](https://github.com/dynamic-labs/DynamicAuth/commit/a243d361ce7c368d0f1afda55f9c1fabefd75ba8))
|
|
22
|
+
* don't force primary wallet to be connected ([#6128](https://github.com/dynamic-labs/DynamicAuth/issues/6128)) ([018a6f6](https://github.com/dynamic-labs/DynamicAuth/commit/018a6f66f8725914ab97ea3e2e1c80626266e503))
|
|
23
|
+
* new prop to enable prompt for linking when account change is detected ([#6713](https://github.com/dynamic-labs/DynamicAuth/issues/6713)) ([b5a6321](https://github.com/dynamic-labs/DynamicAuth/commit/b5a63212ae33fae24401f141d5ca2356b446dcff))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* always sync wagmi client with primary wallet ([#6577](https://github.com/dynamic-labs/DynamicAuth/issues/6577)) ([be22fde](https://github.com/dynamic-labs/DynamicAuth/commit/be22fdea3bb61db79b06ba56cb32da6cd8141b66))
|
|
29
|
+
* cosmos wallet intercepts ([#6720](https://github.com/dynamic-labs/DynamicAuth/issues/6720)) ([cfc9df4](https://github.com/dynamic-labs/DynamicAuth/commit/cfc9df48a8032f7348fec14f77b9e378d2e26a22))
|
|
30
|
+
* magiceden wallet events not working correctly on page refresh ([#6735](https://github.com/dynamic-labs/DynamicAuth/issues/6735)) ([6ed5964](https://github.com/dynamic-labs/DynamicAuth/commit/6ed5964134a2cafd392c19f18eb71e6ca2ce238d))
|
|
31
|
+
* use proxy to intercept solana signer methods ([#6743](https://github.com/dynamic-labs/DynamicAuth/issues/6743)) ([ecbe5ea](https://github.com/dynamic-labs/DynamicAuth/commit/ecbe5ea772592d2c693d8222d85b7642acd151a8))
|
|
32
|
+
* wallet.chain references ([525c1ca](https://github.com/dynamic-labs/DynamicAuth/commit/525c1ca9a8fe6402c06eabe6aebc30e310411d9b))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
* deprecate getEoaConnector ([#6571](https://github.com/dynamic-labs/DynamicAuth/issues/6571)) ([0226ee5](https://github.com/dynamic-labs/DynamicAuth/commit/0226ee5a13f2418607076ee6f2ec0a579b06dd5d))
|
|
36
|
+
* limit methods and props returned by wallet.connector ([#6540](https://github.com/dynamic-labs/DynamicAuth/issues/6540)) ([9c86e35](https://github.com/dynamic-labs/DynamicAuth/commit/9c86e35c72cd40313bfd19254dd6171ee8f62213))
|
|
37
|
+
* move generic solana code to solana-core package ([#6701](https://github.com/dynamic-labs/DynamicAuth/issues/6701)) ([30815f5](https://github.com/dynamic-labs/DynamicAuth/commit/30815f5d46feeefb2413c1b7d30b43d5370ee032))
|
|
38
|
+
* revamp ether v6 interface ([#6548](https://github.com/dynamic-labs/DynamicAuth/issues/6548)) ([f3b2fb8](https://github.com/dynamic-labs/DynamicAuth/commit/f3b2fb8da7de21f9c58e67fa7f5580166195092a))
|
|
39
|
+
* simplify solana wallet signer types ([#6748](https://github.com/dynamic-labs/DynamicAuth/issues/6748)) ([01d1a42](https://github.com/dynamic-labs/DynamicAuth/commit/01d1a42bc916ab329580b741ba60d706bf6c5491))
|
|
40
|
+
|
|
41
|
+
## [3.0.0-alpha.52](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.51...v3.0.0-alpha.52) (2024-08-28)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
* add support for custom keplr chains ([#6635](https://github.com/dynamic-labs/DynamicAuth/issues/6635)) ([f0aa2da](https://github.com/dynamic-labs/DynamicAuth/commit/f0aa2dac2a2b259d145ff52174da7cc6ef963182))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Bug Fixes
|
|
50
|
+
|
|
51
|
+
* better error handling on solana transaction decoding ([#6731](https://github.com/dynamic-labs/DynamicAuth/issues/6731)) ([a71af86](https://github.com/dynamic-labs/DynamicAuth/commit/a71af869395c9b99c04f0cac78a73e1b2b17bafe))
|
|
52
|
+
|
|
2
53
|
## [3.0.0-alpha.51](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.50...v3.0.0-alpha.51) (2024-08-23)
|
|
3
54
|
|
|
4
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.53",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
@@ -25,15 +25,16 @@
|
|
|
25
25
|
},
|
|
26
26
|
"./package.json": "./package.json"
|
|
27
27
|
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.519"
|
|
30
|
+
},
|
|
28
31
|
"peerDependencies": {
|
|
29
32
|
"viem": "^2.7.6",
|
|
30
|
-
"@dynamic-labs/logger": "3.0.0-alpha.
|
|
31
|
-
"@dynamic-labs/rpc-providers": "3.0.0-alpha.
|
|
32
|
-
"@dynamic-labs/
|
|
33
|
-
"@dynamic-labs/
|
|
34
|
-
"@dynamic-labs/
|
|
35
|
-
"@dynamic-labs/wallet-
|
|
36
|
-
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.51",
|
|
37
|
-
"eventemitter3": "5.0.1"
|
|
33
|
+
"@dynamic-labs/logger": "3.0.0-alpha.53",
|
|
34
|
+
"@dynamic-labs/rpc-providers": "3.0.0-alpha.53",
|
|
35
|
+
"@dynamic-labs/types": "3.0.0-alpha.53",
|
|
36
|
+
"@dynamic-labs/utils": "3.0.0-alpha.53",
|
|
37
|
+
"@dynamic-labs/wallet-book": "3.0.0-alpha.53",
|
|
38
|
+
"@dynamic-labs/wallet-connector-core": "3.0.0-alpha.53"
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -0,0 +1,257 @@
|
|
|
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 walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
|
+
require('../utils/logger.cjs');
|
|
12
|
+
require('../utils/viem/estimateL1Fee/opStack/estimateL1Fee.cjs');
|
|
13
|
+
var chainsMap = require('../utils/viem/chainsMap/chainsMap.cjs');
|
|
14
|
+
var createViemUiTransaction = require('../utils/viem/createViemUiTransaction/createViemUiTransaction.cjs');
|
|
15
|
+
var getOrMapViemChain = require('../utils/viem/getOrMapViemChain/getOrMapViemChain.cjs');
|
|
16
|
+
var findEvmNetwork = require('../utils/findEvmNetwork/findEvmNetwork.cjs');
|
|
17
|
+
var getNameservice = require('../utils/getNameservice/getNameservice.cjs');
|
|
18
|
+
var EthereumWallet = require('../wallet/EthereumWallet.cjs');
|
|
19
|
+
|
|
20
|
+
class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
21
|
+
getPublicClient() {
|
|
22
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
|
|
25
|
+
if (this.evmNetworks.length === 0) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
const configurations = {
|
|
29
|
+
cosmos: [],
|
|
30
|
+
evm: this.evmNetworks,
|
|
31
|
+
solana: [],
|
|
32
|
+
starknet: undefined,
|
|
33
|
+
};
|
|
34
|
+
if (!this.chainRpcProviders)
|
|
35
|
+
return undefined;
|
|
36
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
37
|
+
return (_b = this.chainRpcProviders.getEvmProviderByChainId(providers, networkId)) === null || _b === void 0 ? void 0 : _b.provider;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
constructor(props) {
|
|
41
|
+
var _a;
|
|
42
|
+
super(props);
|
|
43
|
+
this.ChainWallet = EthereumWallet.EthereumWallet;
|
|
44
|
+
this.evmNetworkRpcMap = () => this.evmNetworks.reduce((acc, network) => {
|
|
45
|
+
var _a;
|
|
46
|
+
[acc[network.chainId]] = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.length)
|
|
47
|
+
? network.privateCustomerRpcUrls
|
|
48
|
+
: network.rpcUrls;
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks);
|
|
52
|
+
this.chainRpcProviders = props.chainRpcProviders;
|
|
53
|
+
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerEvmProviders();
|
|
54
|
+
}
|
|
55
|
+
getNetwork() {
|
|
56
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const provider = this.getWalletClient();
|
|
58
|
+
if (!this.supportsNetworkSwitching || !provider) {
|
|
59
|
+
return Promise.resolve(undefined);
|
|
60
|
+
}
|
|
61
|
+
const chainId = yield utils.retryableFn(provider.getChainId, {
|
|
62
|
+
fallbackValue: utils.FALLBACK_UNDEFINED,
|
|
63
|
+
/**
|
|
64
|
+
* The timeout is set to 1 second because the getChainId method
|
|
65
|
+
* takes around 500ms to resolve on Brave. If the timeout is not set
|
|
66
|
+
* it will use 100ms by default and the method will fail.
|
|
67
|
+
* QNTM-815
|
|
68
|
+
*/
|
|
69
|
+
timeoutMs: 1000,
|
|
70
|
+
});
|
|
71
|
+
this.setActiveChain(chainsMap.chainsMap[chainId]);
|
|
72
|
+
return chainId;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getNameService(address) {
|
|
76
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const rpcProvider = yield this.getPublicClient();
|
|
78
|
+
if (!rpcProvider) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
return getNameservice.getNameservice({ address, rpcProvider });
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
isTestnet() {
|
|
85
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
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;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
parseAddress(address) {
|
|
91
|
+
try {
|
|
92
|
+
// Ensures the address follows the EIP55 format.
|
|
93
|
+
// see: https://eips.ethereum.org/EIPS/eip-55
|
|
94
|
+
return viem.getAddress(address);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
walletConnectorCore.logger.debug(`Failed to parse EVM address into EIP55 format: error getting checksum, returning default ${address}`, err);
|
|
98
|
+
}
|
|
99
|
+
return address;
|
|
100
|
+
}
|
|
101
|
+
getSigner() {
|
|
102
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
return this.getWalletClient();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
getBalance(address) {
|
|
107
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
const client = yield this.getPublicClient();
|
|
109
|
+
const result = yield (client === null || client === void 0 ? void 0 : client.getBalance({
|
|
110
|
+
address: address,
|
|
111
|
+
}));
|
|
112
|
+
if (!result && result !== BigInt(0))
|
|
113
|
+
return;
|
|
114
|
+
return viem.formatEther(result);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
supportsNetworkSwitching() {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
switchNetwork(_a) {
|
|
121
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkName, networkChainId, }) {
|
|
122
|
+
const network = findEvmNetwork.findEvmNetwork({
|
|
123
|
+
chainId: networkChainId,
|
|
124
|
+
name: networkName,
|
|
125
|
+
networks: this.evmNetworks,
|
|
126
|
+
});
|
|
127
|
+
if (!network) {
|
|
128
|
+
throw new utils.DynamicError(`Could not find network mapping for chain ${networkName ? networkName : networkChainId}`);
|
|
129
|
+
}
|
|
130
|
+
if (!this.supportsNetworkSwitching()) {
|
|
131
|
+
throw new utils.DynamicError('Network switching is not supported');
|
|
132
|
+
}
|
|
133
|
+
const provider = this.getWalletClient();
|
|
134
|
+
if (!provider) {
|
|
135
|
+
throw new utils.DynamicError('Provider not found');
|
|
136
|
+
}
|
|
137
|
+
return this.providerSwitchNetwork({ network, provider });
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
getConnectedAccounts() {
|
|
141
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const provider = this.getWalletClient();
|
|
143
|
+
if (!provider)
|
|
144
|
+
return [];
|
|
145
|
+
const addresses = yield utils.retryableFn(provider.getAddresses, {
|
|
146
|
+
fallbackValue: [],
|
|
147
|
+
timeoutMs: 500,
|
|
148
|
+
});
|
|
149
|
+
if (addresses.length) {
|
|
150
|
+
this.setActiveAccount(addresses[0]);
|
|
151
|
+
}
|
|
152
|
+
return addresses;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
providerSwitchNetwork(_a) {
|
|
156
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
157
|
+
var _b, _c, _d, _e;
|
|
158
|
+
const { chainId } = network;
|
|
159
|
+
const currentNetworkId = yield this.getNetwork();
|
|
160
|
+
if (currentNetworkId && currentNetworkId === chainId) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
if (!this.supportsNetworkSwitching()) {
|
|
165
|
+
throw new utils.DynamicError('Network switching is not supported');
|
|
166
|
+
}
|
|
167
|
+
const viemChain = getOrMapViemChain.getOrMapViemChain(network);
|
|
168
|
+
yield provider.switchChain(viemChain);
|
|
169
|
+
if (this.key === 'magiceden') {
|
|
170
|
+
const newChainId = yield provider.getChainId();
|
|
171
|
+
this.emit('chainChange', { chain: newChainId.toString() });
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
this.setActiveChain(viemChain);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
179
|
+
if (error.code === 4902 ||
|
|
180
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Unrecognized chain')) ||
|
|
181
|
+
// https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
|
|
182
|
+
((_d = (_c = error.data) === null || _c === void 0 ? void 0 : _c.orginalError) === null || _d === void 0 ? void 0 : _d.code) === 4902) {
|
|
183
|
+
// error code indicates the chain has not been added yet
|
|
184
|
+
// https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
|
|
185
|
+
return this.providerAddNetwork({ network, provider });
|
|
186
|
+
}
|
|
187
|
+
else if (((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('rejected')) ||
|
|
188
|
+
(typeof error === 'string' && error.includes('rejected'))) {
|
|
189
|
+
throw new utils.DynamicError("User rejected the wallet's request to switch network");
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
providerAddNetwork(_a) {
|
|
198
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
199
|
+
var _b;
|
|
200
|
+
try {
|
|
201
|
+
return yield provider.addChain({ chain: getOrMapViemChain.getOrMapViemChain(network) });
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
if (((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('rejected')) ||
|
|
205
|
+
(typeof error === 'string' && error.includes('rejected'))) {
|
|
206
|
+
throw new utils.DynamicError("User rejected the wallet's request to add network");
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
setActiveAccount(account) {
|
|
215
|
+
this.activeAccount = account ? accounts.toAccount(account) : undefined;
|
|
216
|
+
}
|
|
217
|
+
getActiveAccount() {
|
|
218
|
+
return this.activeAccount;
|
|
219
|
+
}
|
|
220
|
+
setActiveChain(chain) {
|
|
221
|
+
this.activeChain = chain;
|
|
222
|
+
}
|
|
223
|
+
getActiveChain() {
|
|
224
|
+
return this.activeChain;
|
|
225
|
+
}
|
|
226
|
+
createUiTransaction(from) {
|
|
227
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
yield this.validateActiveWallet(from);
|
|
229
|
+
const walletClient = yield this.getWalletClient();
|
|
230
|
+
const publicClient = yield this.getPublicClient();
|
|
231
|
+
if (!publicClient || !walletClient) {
|
|
232
|
+
throw new utils.DynamicError('No public client available');
|
|
233
|
+
}
|
|
234
|
+
return createViemUiTransaction.createViemUiTransaction({
|
|
235
|
+
from,
|
|
236
|
+
publicClient,
|
|
237
|
+
walletClient,
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
confirmTransactionStatus(txHash) {
|
|
242
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
const publicClient = yield this.getPublicClient();
|
|
244
|
+
if (!publicClient) {
|
|
245
|
+
throw new utils.DynamicError('No public client available');
|
|
246
|
+
}
|
|
247
|
+
// The number of confirmations (blocks that have passed) to wait before resolving.
|
|
248
|
+
const confirmations = 3;
|
|
249
|
+
return publicClient.waitForTransactionReceipt({
|
|
250
|
+
confirmations,
|
|
251
|
+
hash: txHash,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
exports.EthWalletConnector = EthWalletConnector;
|