@dynamic-labs/ethereum 0.0.0-exp20240808.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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +49 -0
- package/_virtual/_tslib.js +44 -0
- package/package.json +46 -0
- package/src/EthWalletConnector.cjs +234 -0
- package/src/EthWalletConnector.d.ts +3088 -0
- package/src/EthWalletConnector.js +230 -0
- package/src/coinbase/coinbase.cjs +98 -0
- package/src/coinbase/coinbase.d.ts +22 -0
- package/src/coinbase/coinbase.js +94 -0
- package/src/coinbase/helpers.cjs +38 -0
- package/src/coinbase/helpers.d.ts +3 -0
- package/src/coinbase/helpers.js +34 -0
- package/src/coinbase/index.d.ts +3 -0
- package/src/coinbase/types.d.ts +18 -0
- package/src/constants.cjs +8 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +4 -0
- package/src/ethProviderHelper.cjs +163 -0
- package/src/ethProviderHelper.d.ts +43 -0
- package/src/ethProviderHelper.js +159 -0
- package/src/index.cjs +49 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +35 -0
- package/src/injected/ExodusEvm.cjs +20 -0
- package/src/injected/ExodusEvm.d.ts +8 -0
- package/src/injected/ExodusEvm.js +16 -0
- package/src/injected/FallbackEvmConnector.cjs +22 -0
- package/src/injected/FallbackEvmConnector.d.ts +9 -0
- package/src/injected/FallbackEvmConnector.js +18 -0
- package/src/injected/InjectedWalletBase.cjs +110 -0
- package/src/injected/InjectedWalletBase.d.ts +29 -0
- package/src/injected/InjectedWalletBase.js +108 -0
- package/src/injected/PhantomEvm.cjs +37 -0
- package/src/injected/PhantomEvm.d.ts +8 -0
- package/src/injected/PhantomEvm.js +33 -0
- package/src/injected/UnknownInjected.cjs +21 -0
- package/src/injected/UnknownInjected.d.ts +8 -0
- package/src/injected/UnknownInjected.js +17 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +67 -0
- package/src/injected/fetchInjectedWalletConnectors.d.ts +6 -0
- package/src/injected/fetchInjectedWalletConnectors.js +62 -0
- package/src/injected/index.d.ts +5 -0
- package/src/polyfills.cjs +17 -0
- package/src/polyfills.d.ts +1 -0
- package/src/polyfills.js +15 -0
- package/src/types.d.ts +33 -0
- package/src/utils/findEvmNetwork.cjs +21 -0
- package/src/utils/findEvmNetwork.d.ts +6 -0
- package/src/utils/findEvmNetwork.js +17 -0
- package/src/utils/getNameservice.cjs +46 -0
- package/src/utils/getNameservice.d.ts +6 -0
- package/src/utils/getNameservice.js +42 -0
- package/src/utils/index.d.ts +2 -0
- package/src/utils/isEthWalletConnector/index.d.ts +1 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +8 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +3 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.js +4 -0
- package/src/utils/isString.d.ts +1 -0
- package/src/utils/isUnsupportedProviderError/index.d.ts +1 -0
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +6 -0
- package/src/utils/last.d.ts +1 -0
- package/src/utils/parseIntSafe.cjs +23 -0
- package/src/utils/parseIntSafe.d.ts +1 -0
- package/src/utils/parseIntSafe.js +19 -0
- package/src/wallet/EthereumWallet.cjs +65 -0
- package/src/wallet/EthereumWallet.d.ts +17 -0
- package/src/wallet/EthereumWallet.js +61 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isEthereumWallet.cjs +8 -0
- package/src/wallet/isEthereumWallet.d.ts +3 -0
- package/src/wallet/isEthereumWallet.js +4 -0
- package/src/walletConnect/fetchWalletConnectWallets.cjs +30 -0
- package/src/walletConnect/fetchWalletConnectWallets.d.ts +6 -0
- package/src/walletConnect/fetchWalletConnectWallets.js +25 -0
- package/src/walletConnect/index.d.ts +2 -0
- package/src/walletConnect/walletConnect.cjs +531 -0
- package/src/walletConnect/walletConnect.d.ts +78 -0
- package/src/walletConnect/walletConnect.js +522 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __rest(s, e) {
|
|
22
|
+
var t = {};
|
|
23
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
24
|
+
t[p] = s[p];
|
|
25
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
26
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
27
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
28
|
+
t[p[i]] = s[p[i]];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
34
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
35
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
36
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
37
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
38
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
39
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
44
|
+
var e = new Error(message);
|
|
45
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.__awaiter = __awaiter;
|
|
49
|
+
exports.__rest = __rest;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __rest(s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
30
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
33
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
34
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
35
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
40
|
+
var e = new Error(message);
|
|
41
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { __awaiter, __rest };
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/ethereum",
|
|
3
|
+
"version": "0.0.0-exp20240808.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
7
|
+
"directory": "packages/ethereum"
|
|
8
|
+
},
|
|
9
|
+
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/dynamic-labs/DynamicAuth/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/dynamic-labs/DynamicAuth#readme",
|
|
14
|
+
"author": "Dynamic Labs, Inc.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "./src/index.cjs",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"import": "./src/index.js",
|
|
24
|
+
"require": "./src/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.509",
|
|
30
|
+
"@coinbase/wallet-sdk": "4.0.4",
|
|
31
|
+
"@walletconnect/ethereum-provider": "2.11.2",
|
|
32
|
+
"eventemitter3": "5.0.1",
|
|
33
|
+
"buffer": "6.0.3",
|
|
34
|
+
"@dynamic-labs/embedded-wallet-evm": "0.0.0-exp20240808.0",
|
|
35
|
+
"@dynamic-labs/rpc-provider-ethereum": "0.0.0-exp20240808.0",
|
|
36
|
+
"@dynamic-labs/types": "0.0.0-exp20240808.0",
|
|
37
|
+
"@dynamic-labs/utils": "0.0.0-exp20240808.0",
|
|
38
|
+
"@dynamic-labs/viem-utils": "0.0.0-exp20240808.0",
|
|
39
|
+
"@dynamic-labs/wallet-book": "0.0.0-exp20240808.0",
|
|
40
|
+
"@dynamic-labs/wallet-connector-core": "0.0.0-exp20240808.0",
|
|
41
|
+
"stream": "0.0.2"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"viem": "^2.7.6"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
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
|
+
var EthereumWallet = require('./wallet/EthereumWallet.cjs');
|
|
15
|
+
|
|
16
|
+
class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
17
|
+
getPublicClient() {
|
|
18
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const networkId = (_a = (yield this.getNetwork())) !== null && _a !== void 0 ? _a : 1;
|
|
21
|
+
if (this.evmNetworks.length === 0) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const configurations = {
|
|
25
|
+
cosmos: [],
|
|
26
|
+
evm: this.evmNetworks,
|
|
27
|
+
solana: [],
|
|
28
|
+
starknet: undefined,
|
|
29
|
+
};
|
|
30
|
+
if (!this.chainRpcProviders)
|
|
31
|
+
return undefined;
|
|
32
|
+
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
33
|
+
return (_b = this.chainRpcProviders.getEvmProviderByChainId(providers, networkId)) === null || _b === void 0 ? void 0 : _b.provider;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
constructor(props) {
|
|
37
|
+
var _a;
|
|
38
|
+
super(props);
|
|
39
|
+
this.ChainWallet = EthereumWallet.EthereumWallet;
|
|
40
|
+
this.evmNetworkRpcMap = () => this.evmNetworks.reduce((acc, network) => {
|
|
41
|
+
var _a;
|
|
42
|
+
[acc[network.chainId]] = ((_a = network === null || network === void 0 ? void 0 : network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a.length)
|
|
43
|
+
? network.privateCustomerRpcUrls
|
|
44
|
+
: network.rpcUrls;
|
|
45
|
+
return acc;
|
|
46
|
+
}, {});
|
|
47
|
+
this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks);
|
|
48
|
+
this.chainRpcProviders = props.chainRpcProviders;
|
|
49
|
+
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerEvmProviders();
|
|
50
|
+
}
|
|
51
|
+
getNetwork() {
|
|
52
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const provider = this.getWalletClient();
|
|
54
|
+
if (!this.supportsNetworkSwitching || !provider) {
|
|
55
|
+
return Promise.resolve(undefined);
|
|
56
|
+
}
|
|
57
|
+
const chainId = yield utils.retryableFn(provider.getChainId, {
|
|
58
|
+
fallbackValue: utils.FALLBACK_UNDEFINED,
|
|
59
|
+
/**
|
|
60
|
+
* The timeout is set to 1 second because the getChainId method
|
|
61
|
+
* takes around 500ms to resolve on Brave. If the timeout is not set
|
|
62
|
+
* it will use 100ms by default and the method will fail.
|
|
63
|
+
* QNTM-815
|
|
64
|
+
*/
|
|
65
|
+
timeoutMs: 1000,
|
|
66
|
+
});
|
|
67
|
+
this.setActiveChain(viemUtils.chainsMap[chainId]);
|
|
68
|
+
return chainId;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
getNameService(address) {
|
|
72
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const rpcProvider = yield this.getPublicClient();
|
|
74
|
+
if (!rpcProvider) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return getNameservice.getNameservice({ address, rpcProvider });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
isTestnet() {
|
|
81
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
var _a, _b, _c;
|
|
83
|
+
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;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
parseAddress(address) {
|
|
87
|
+
try {
|
|
88
|
+
// Ensures the address follows the EIP55 format.
|
|
89
|
+
// see: https://eips.ethereum.org/EIPS/eip-55
|
|
90
|
+
return viem.getAddress(address);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
walletConnectorCore.logger.debug(`Failed to parse EVM address into EIP55 format: error getting checksum, returning default ${address}`, err);
|
|
94
|
+
}
|
|
95
|
+
return address;
|
|
96
|
+
}
|
|
97
|
+
getSigner() {
|
|
98
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
return this.getWalletClient();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getBalance(address) {
|
|
103
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const client = yield this.getPublicClient();
|
|
105
|
+
const result = yield (client === null || client === void 0 ? void 0 : client.getBalance({
|
|
106
|
+
address: address,
|
|
107
|
+
}));
|
|
108
|
+
if (!result && result !== BigInt(0))
|
|
109
|
+
return;
|
|
110
|
+
return viem.formatEther(result);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
supportsNetworkSwitching() {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
switchNetwork(_a) {
|
|
117
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkName, networkChainId, }) {
|
|
118
|
+
const network = findEvmNetwork.findEvmNetwork({
|
|
119
|
+
chainId: networkChainId,
|
|
120
|
+
name: networkName,
|
|
121
|
+
networks: this.evmNetworks,
|
|
122
|
+
});
|
|
123
|
+
if (!network) {
|
|
124
|
+
throw new utils.DynamicError(`Could not find network mapping for chain ${networkName ? networkName : networkChainId}`);
|
|
125
|
+
}
|
|
126
|
+
if (!this.supportsNetworkSwitching()) {
|
|
127
|
+
throw new utils.DynamicError('Network switching is not supported');
|
|
128
|
+
}
|
|
129
|
+
const provider = this.getWalletClient();
|
|
130
|
+
if (!provider) {
|
|
131
|
+
throw new utils.DynamicError('Provider not found');
|
|
132
|
+
}
|
|
133
|
+
return this.providerSwitchNetwork({ network, provider });
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
getConnectedAccounts() {
|
|
137
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
const provider = this.getWalletClient();
|
|
139
|
+
if (!provider)
|
|
140
|
+
return [];
|
|
141
|
+
const addresses = yield utils.retryableFn(provider.getAddresses, {
|
|
142
|
+
fallbackValue: [],
|
|
143
|
+
timeoutMs: 500,
|
|
144
|
+
});
|
|
145
|
+
if (addresses.length) {
|
|
146
|
+
this.setActiveAccount(addresses[0]);
|
|
147
|
+
}
|
|
148
|
+
return addresses;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
providerSwitchNetwork(_a) {
|
|
152
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
153
|
+
var _b, _c, _d, _e;
|
|
154
|
+
const { chainId } = network;
|
|
155
|
+
const currentNetworkId = yield this.getNetwork();
|
|
156
|
+
if (currentNetworkId && currentNetworkId === chainId) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
if (!this.supportsNetworkSwitching()) {
|
|
161
|
+
throw new utils.DynamicError('Network switching is not supported');
|
|
162
|
+
}
|
|
163
|
+
const viemChain = viemUtils.getOrMapViemChain(network);
|
|
164
|
+
yield provider.switchChain(viemChain);
|
|
165
|
+
if (this.key === 'magiceden') {
|
|
166
|
+
const newChainId = yield provider.getChainId();
|
|
167
|
+
this.emit('chainChange', { chain: newChainId.toString() });
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.setActiveChain(viemChain);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
175
|
+
if (error.code === 4902 ||
|
|
176
|
+
((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('Unrecognized chain')) ||
|
|
177
|
+
// https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
|
|
178
|
+
((_d = (_c = error.data) === null || _c === void 0 ? void 0 : _c.orginalError) === null || _d === void 0 ? void 0 : _d.code) === 4902) {
|
|
179
|
+
// error code indicates the chain has not been added yet
|
|
180
|
+
// https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
|
|
181
|
+
return this.providerAddNetwork({ network, provider });
|
|
182
|
+
}
|
|
183
|
+
else if (((_e = error.message) === null || _e === void 0 ? void 0 : _e.includes('rejected')) ||
|
|
184
|
+
(typeof error === 'string' && error.includes('rejected'))) {
|
|
185
|
+
throw new utils.DynamicError("User rejected the wallet's request to switch network");
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
providerAddNetwork(_a) {
|
|
194
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ network, provider, }) {
|
|
195
|
+
var _b;
|
|
196
|
+
try {
|
|
197
|
+
return yield provider.addChain({ chain: viemUtils.getOrMapViemChain(network) });
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (((_b = error.message) === null || _b === void 0 ? void 0 : _b.includes('rejected')) ||
|
|
201
|
+
(typeof error === 'string' && error.includes('rejected'))) {
|
|
202
|
+
throw new utils.DynamicError("User rejected the wallet's request to add network");
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
setActiveAccount(account) {
|
|
211
|
+
this.activeAccount = account ? accounts.toAccount(account) : undefined;
|
|
212
|
+
}
|
|
213
|
+
getActiveAccount() {
|
|
214
|
+
return this.activeAccount;
|
|
215
|
+
}
|
|
216
|
+
setActiveChain(chain) {
|
|
217
|
+
this.activeChain = chain;
|
|
218
|
+
}
|
|
219
|
+
getActiveChain() {
|
|
220
|
+
return this.activeChain;
|
|
221
|
+
}
|
|
222
|
+
createUiTransaction(from) {
|
|
223
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
const walletClient = yield this.getWalletClient();
|
|
225
|
+
const publicClient = yield this.getPublicClient();
|
|
226
|
+
if (!publicClient || !walletClient) {
|
|
227
|
+
throw new utils.DynamicError('No public client available');
|
|
228
|
+
}
|
|
229
|
+
return viemUtils.createViemUiTransaction({ from, publicClient, walletClient });
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
exports.EthWalletConnector = EthWalletConnector;
|