@dynamic-labs/ethereum 4.0.0-alpha.9 → 4.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 +483 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -9
- package/src/coinbase/coinbase.cjs +1 -3
- package/src/coinbase/coinbase.d.ts +2 -5
- package/src/coinbase/coinbase.js +2 -4
- package/src/coinbase/types.d.ts +2 -2
- package/src/ethProviderHelper.cjs +49 -43
- package/src/ethProviderHelper.d.ts +5 -7
- package/src/ethProviderHelper.js +50 -44
- package/src/index.cjs +14 -3
- package/src/index.d.ts +2 -1
- package/src/index.js +5 -4
- package/src/injected/ExodusEvm.cjs +3 -5
- package/src/injected/ExodusEvm.d.ts +1 -3
- package/src/injected/ExodusEvm.js +3 -5
- package/src/injected/FallbackEvmConnector.cjs +3 -5
- package/src/injected/FallbackEvmConnector.d.ts +1 -3
- package/src/injected/FallbackEvmConnector.js +3 -5
- package/src/injected/InjectedWalletBase.cjs +18 -31
- package/src/injected/InjectedWalletBase.d.ts +4 -10
- package/src/injected/InjectedWalletBase.js +17 -32
- package/src/injected/PhantomEvm.cjs +4 -6
- package/src/injected/PhantomEvm.d.ts +1 -3
- package/src/injected/PhantomEvm.js +4 -6
- package/src/injected/fetchInjectedWalletConnectors.cjs +48 -39
- package/src/injected/fetchInjectedWalletConnectors.js +49 -40
- package/src/injected/index.d.ts +1 -1
- package/src/metaMask/MetaMaskConnector.cjs +376 -0
- package/src/metaMask/MetaMaskConnector.d.ts +52 -0
- package/src/metaMask/MetaMaskConnector.js +372 -0
- package/src/metaMask/utils/createMetaMaskSDKDisplayUriState.cjs +58 -0
- package/src/metaMask/utils/createMetaMaskSDKDisplayUriState.d.ts +14 -0
- package/src/metaMask/utils/createMetaMaskSDKDisplayUriState.js +54 -0
- package/src/metaMask/utils/isPendingWalletRequestPermissionError.cjs +11 -0
- package/src/metaMask/utils/isPendingWalletRequestPermissionError.d.ts +1 -0
- package/src/metaMask/utils/isPendingWalletRequestPermissionError.js +7 -0
- package/src/metaMask/utils/waitForConnection.cjs +10 -0
- package/src/metaMask/utils/waitForConnection.d.ts +2 -0
- package/src/metaMask/utils/waitForConnection.js +6 -0
- package/src/utils/createInjectedConnector/createInjectedConnector.cjs +93 -0
- package/src/utils/createInjectedConnector/createInjectedConnector.d.ts +16 -0
- package/src/utils/createInjectedConnector/createInjectedConnector.js +89 -0
- package/src/utils/createInjectedConnector/index.d.ts +1 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.cjs +30 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.d.ts +3 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js +26 -0
- package/src/utils/getConnectorConstructorForEip6963Wallet/index.d.ts +1 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs +44 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.d.ts +3 -0
- package/src/utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js +40 -0
- package/src/utils/getConnectorConstructorInjectedWallet/index.d.ts +1 -0
- package/src/utils/logger.cjs +10 -0
- package/src/utils/logger.d.ts +2 -0
- package/src/utils/logger.js +6 -0
- package/src/utils/normalizeRpcError/index.d.ts +1 -0
- package/src/utils/normalizeRpcError/normalizeRpcError.cjs +51 -0
- package/src/utils/normalizeRpcError/normalizeRpcError.d.ts +5 -0
- package/src/utils/normalizeRpcError/normalizeRpcError.js +47 -0
- package/src/walletConnect/walletConnect.cjs +175 -204
- package/src/walletConnect/walletConnect.d.ts +7681 -27
- package/src/walletConnect/walletConnect.js +175 -204
- package/src/injected/UnknownInjected.cjs +0 -21
- package/src/injected/UnknownInjected.d.ts +0 -8
- package/src/injected/UnknownInjected.js +0 -17
- package/src/utils/isString.d.ts +0 -1
- package/src/utils/last.d.ts +0 -1
- package/src/utils/parseIntSafe.cjs +0 -23
- package/src/utils/parseIntSafe.d.ts +0 -1
- package/src/utils/parseIntSafe.js +0 -19
|
@@ -1,42 +1,30 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
3
|
import { isMobile } from '@dynamic-labs/utils';
|
|
5
|
-
import {
|
|
4
|
+
import { EthereumWalletConnector } from '@dynamic-labs/ethereum-core';
|
|
6
5
|
import { EthProviderHelper } from '../ethProviderHelper.js';
|
|
7
6
|
import { WalletConnect } from '../walletConnect/walletConnect.js';
|
|
8
7
|
|
|
9
|
-
class InjectedWalletBase extends
|
|
8
|
+
class InjectedWalletBase extends EthereumWalletConnector {
|
|
10
9
|
constructor() {
|
|
11
10
|
super(...arguments);
|
|
12
|
-
this.supportedChains = ['ETH', 'EVM'];
|
|
13
|
-
this.connectedChain = 'EVM';
|
|
14
11
|
this.walletConnectorFallback = false;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
if (!this.
|
|
18
|
-
|
|
19
|
-
// allows the getEthProviderHelper to return undefined if the wallet is not installed
|
|
20
|
-
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
13
|
+
get ethProviderHelper() {
|
|
14
|
+
if (!this._ethProviderHelper) {
|
|
15
|
+
this._ethProviderHelper = new EthProviderHelper(this);
|
|
21
16
|
}
|
|
22
|
-
|
|
23
|
-
this.ethProviderHelper = new EthProviderHelper(this.wallet, this);
|
|
24
|
-
}
|
|
25
|
-
// this.ethProviderHelper is undefined if the wallet is not installed or found in walletbook
|
|
26
|
-
return this.ethProviderHelper;
|
|
17
|
+
return this._ethProviderHelper;
|
|
27
18
|
}
|
|
28
19
|
getMobileOrInstalledWallet() {
|
|
29
|
-
var _a
|
|
30
|
-
if (!this.wallet) {
|
|
31
|
-
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
32
|
-
}
|
|
20
|
+
var _a;
|
|
33
21
|
if (this.isInstalledOnBrowser()) {
|
|
34
22
|
return this;
|
|
35
23
|
}
|
|
36
24
|
// this is to handle the case where the user is in a webview.
|
|
37
25
|
// when the user is in a webview, customers should set the deepLinkPreference prop to universal,
|
|
38
26
|
// in which case this condition will be false, and the SDK will use WalletConnect (if available)
|
|
39
|
-
if (((
|
|
27
|
+
if (((_a = this.metadata) === null || _a === void 0 ? void 0 : _a.inAppBrowserUrl) &&
|
|
40
28
|
this.mobileExperience === 'in-app-browser' &&
|
|
41
29
|
isMobile()) {
|
|
42
30
|
return this;
|
|
@@ -50,33 +38,30 @@ class InjectedWalletBase extends EthWalletConnector {
|
|
|
50
38
|
return new WalletConnect(Object.assign(Object.assign({}, this.constructorProps), { walletName: this.name }));
|
|
51
39
|
}
|
|
52
40
|
findProvider() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return;
|
|
56
|
-
return ethProviderHelper.getInstalledProvider();
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getInstalledProvider();
|
|
57
43
|
}
|
|
58
44
|
setupEventListeners() {
|
|
59
45
|
const provider = this.getWalletClient();
|
|
60
46
|
if (!provider)
|
|
61
47
|
return;
|
|
62
|
-
|
|
63
|
-
if (!ethProviderHelper)
|
|
48
|
+
if (!this.ethProviderHelper)
|
|
64
49
|
return;
|
|
65
|
-
const { tearDownEventListeners } = ethProviderHelper._setupEventListeners(this);
|
|
50
|
+
const { tearDownEventListeners } = this.ethProviderHelper._setupEventListeners(this);
|
|
66
51
|
this.teardownEventListeners = tearDownEventListeners;
|
|
67
52
|
}
|
|
68
53
|
getWalletClient(chainId) {
|
|
69
54
|
var _a;
|
|
70
|
-
return (_a = this.
|
|
55
|
+
return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
|
|
71
56
|
}
|
|
72
57
|
isInstalledOnBrowser() {
|
|
73
58
|
var _a;
|
|
74
|
-
return ((_a = this.
|
|
59
|
+
return ((_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) !== undefined;
|
|
75
60
|
}
|
|
76
61
|
getAddress() {
|
|
77
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
63
|
var _a;
|
|
79
|
-
return (_a = this.
|
|
64
|
+
return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.getAddress();
|
|
80
65
|
});
|
|
81
66
|
}
|
|
82
67
|
connect() {
|
|
@@ -87,7 +72,7 @@ class InjectedWalletBase extends EthWalletConnector {
|
|
|
87
72
|
signMessage(messageToSign) {
|
|
88
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
89
74
|
var _a;
|
|
90
|
-
return (_a = this.
|
|
75
|
+
return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
|
|
91
76
|
});
|
|
92
77
|
}
|
|
93
78
|
proveOwnership(address, messageToSign) {
|
|
@@ -112,4 +97,4 @@ class InjectedWalletBase extends EthWalletConnector {
|
|
|
112
97
|
}
|
|
113
98
|
}
|
|
114
99
|
|
|
115
|
-
export { InjectedWalletBase
|
|
100
|
+
export { InjectedWalletBase };
|
|
@@ -5,15 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
7
|
var utils = require('@dynamic-labs/utils');
|
|
8
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
9
8
|
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
10
9
|
|
|
11
|
-
class PhantomEvm extends InjectedWalletBase {
|
|
12
|
-
constructor(
|
|
13
|
-
super(
|
|
10
|
+
class PhantomEvm extends InjectedWalletBase.InjectedWalletBase {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
14
13
|
this.name = 'Phantom';
|
|
15
14
|
this.overrideKey = 'phantomevm';
|
|
16
|
-
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
17
15
|
}
|
|
18
16
|
getAddress() {
|
|
19
17
|
const _super = Object.create(null, {
|
|
@@ -34,7 +32,7 @@ class PhantomEvm extends InjectedWalletBase {
|
|
|
34
32
|
}
|
|
35
33
|
canGetChainAddress() {
|
|
36
34
|
var _a, _b;
|
|
37
|
-
return Boolean((_b = (_a = this.
|
|
35
|
+
return Boolean((_b = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) === null || _b === void 0 ? void 0 : _b.selectedAddress);
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
38
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import InjectedWalletBase from './InjectedWalletBase';
|
|
1
|
+
import { InjectedWalletBase } from './InjectedWalletBase';
|
|
3
2
|
export declare class PhantomEvm extends InjectedWalletBase {
|
|
4
3
|
name: string;
|
|
5
4
|
overrideKey: string;
|
|
6
|
-
constructor(props: EthWalletConnectorOpts);
|
|
7
5
|
getAddress(): Promise<string | undefined>;
|
|
8
6
|
canGetChainAddress(): boolean;
|
|
9
7
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
3
|
import { isMobile, handleMobileWalletRedirect } from '@dynamic-labs/utils';
|
|
4
|
-
import {
|
|
5
|
-
import InjectedWalletBase from './InjectedWalletBase.js';
|
|
4
|
+
import { InjectedWalletBase } from './InjectedWalletBase.js';
|
|
6
5
|
|
|
7
6
|
class PhantomEvm extends InjectedWalletBase {
|
|
8
|
-
constructor(
|
|
9
|
-
super(
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
10
9
|
this.name = 'Phantom';
|
|
11
10
|
this.overrideKey = 'phantomevm';
|
|
12
|
-
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
13
11
|
}
|
|
14
12
|
getAddress() {
|
|
15
13
|
const _super = Object.create(null, {
|
|
@@ -30,7 +28,7 @@ class PhantomEvm extends InjectedWalletBase {
|
|
|
30
28
|
}
|
|
31
29
|
canGetChainAddress() {
|
|
32
30
|
var _a, _b;
|
|
33
|
-
return Boolean((_b = (_a = this.
|
|
31
|
+
return Boolean((_b = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider()) === null || _b === void 0 ? void 0 : _b.selectedAddress);
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
6
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
-
var
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var getConnectorConstructorForEip6963Wallet = require('../utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.cjs');
|
|
9
|
+
var getConnectorConstructorInjectedWallet = require('../utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.cjs');
|
|
9
10
|
var PhantomEvm = require('./PhantomEvm.cjs');
|
|
10
11
|
var ExodusEvm = require('./ExodusEvm.cjs');
|
|
11
12
|
|
|
@@ -13,53 +14,61 @@ const injectedWalletOverrides = [
|
|
|
13
14
|
PhantomEvm.PhantomEvm,
|
|
14
15
|
ExodusEvm.ExodusEvm,
|
|
15
16
|
];
|
|
16
|
-
const
|
|
17
|
+
const walletsWithCustomConnectors = [
|
|
17
18
|
'phantomevm',
|
|
18
19
|
'coinbase',
|
|
19
20
|
'exodusevm',
|
|
21
|
+
'abstract',
|
|
22
|
+
'metamask',
|
|
23
|
+
'edenonline',
|
|
24
|
+
'intersend',
|
|
20
25
|
];
|
|
26
|
+
let removeEip6963EventsListener;
|
|
27
|
+
// should add eip6963 connector only if not in wallet-book, to avoid adding duplicate connectors
|
|
28
|
+
const shouldAddEip6963Connector = (eip6963ProviderInfo, walletBook) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const { rdns, name } = eip6963ProviderInfo;
|
|
31
|
+
const chain = 'evm';
|
|
32
|
+
const connectorKey = `${utils.sanitizeName(name)}${chain}`;
|
|
33
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', rdns, name, chain, connectorKey);
|
|
34
|
+
const existingWallet = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(([key, wallet]) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
return ((_a = wallet.eip6963Config) === null || _a === void 0 ? void 0 : _a.rdns) === rdns ||
|
|
37
|
+
key === connectorKey ||
|
|
38
|
+
walletsWithCustomConnectors.includes(connectorKey) ||
|
|
39
|
+
(wallet.name === name && ((_b = wallet.injectedConfig) === null || _b === void 0 ? void 0 : _b[0].chain) === chain);
|
|
40
|
+
});
|
|
41
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', existingWallet);
|
|
42
|
+
return !existingWallet;
|
|
43
|
+
};
|
|
44
|
+
const addEip6963Listener = (walletBook) => {
|
|
45
|
+
removeEip6963EventsListener === null || removeEip6963EventsListener === void 0 ? void 0 : removeEip6963EventsListener();
|
|
46
|
+
removeEip6963EventsListener = utils.listenToEip6963Events((event) => {
|
|
47
|
+
if (!shouldAddEip6963Connector(event.detail.info, walletBook)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] listenToEip6963Events', event.detail);
|
|
51
|
+
walletConnectorCore.walletConnectorEvents.emit('providerInjected', {
|
|
52
|
+
injectedConnectorConstructor: getConnectorConstructorForEip6963Wallet.getConnectorConstructorForEip6963Wallet(event.detail),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
21
56
|
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
22
57
|
var _a;
|
|
23
|
-
|
|
58
|
+
addEip6963Listener(walletBook);
|
|
59
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
24
60
|
.filter(([key, wallet]) => {
|
|
25
61
|
var _a;
|
|
26
62
|
return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'evm')) &&
|
|
27
|
-
!
|
|
63
|
+
!walletsWithCustomConnectors.includes(key);
|
|
28
64
|
})
|
|
29
|
-
.map(([key, wallet]) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.name = name;
|
|
37
|
-
this.wallet = wallet;
|
|
38
|
-
this.walletConnectorFallback = walletConnectorFallback;
|
|
39
|
-
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
40
|
-
this.overrideKey = key;
|
|
41
|
-
}
|
|
42
|
-
getAddress() {
|
|
43
|
-
const _super = Object.create(null, {
|
|
44
|
-
getAddress: { get: () => super.getAddress }
|
|
45
|
-
});
|
|
46
|
-
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
var _a;
|
|
48
|
-
if (this.isInstalledOnBrowser()) {
|
|
49
|
-
return _super.getAddress.call(this);
|
|
50
|
-
}
|
|
51
|
-
const inAppBrowserBase = (_a = this.wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
|
|
52
|
-
if (!inAppBrowserBase) {
|
|
53
|
-
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
54
|
-
walletConnectorCore.logger.error(error.message);
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
58
|
-
return undefined;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
});
|
|
65
|
+
.map(([key, wallet]) => getConnectorConstructorInjectedWallet.getConnectorConstructorInjectedWallet(key, wallet));
|
|
66
|
+
const { providers } = utils.Eip6963ProviderSingleton.get();
|
|
67
|
+
const eip6963Connectors = providers
|
|
68
|
+
.filter((provider) => shouldAddEip6963Connector(provider.info, walletBook))
|
|
69
|
+
.map((provider) => getConnectorConstructorForEip6963Wallet.getConnectorConstructorForEip6963Wallet(provider));
|
|
70
|
+
walletConnectorCore.logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] eip6963Connectors', eip6963Connectors);
|
|
71
|
+
return [...walletBookConnectors, ...eip6963Connectors];
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
exports.fetchInjectedWalletConnector = fetchInjectedWalletConnector;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import { logger, walletConnectorEvents } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { Eip6963ProviderSingleton, sanitizeName, listenToEip6963Events } from '@dynamic-labs/utils';
|
|
4
|
+
import { getConnectorConstructorForEip6963Wallet } from '../utils/getConnectorConstructorForEip6963Wallet/getConnectorConstructorForEip6963Wallet.js';
|
|
5
|
+
import { getConnectorConstructorInjectedWallet } from '../utils/getConnectorConstructorInjectedWallet/getConnectorConstructorInjectedWallet.js';
|
|
5
6
|
import { PhantomEvm } from './PhantomEvm.js';
|
|
6
7
|
import { ExodusEvm } from './ExodusEvm.js';
|
|
7
8
|
|
|
@@ -9,53 +10,61 @@ const injectedWalletOverrides = [
|
|
|
9
10
|
PhantomEvm,
|
|
10
11
|
ExodusEvm,
|
|
11
12
|
];
|
|
12
|
-
const
|
|
13
|
+
const walletsWithCustomConnectors = [
|
|
13
14
|
'phantomevm',
|
|
14
15
|
'coinbase',
|
|
15
16
|
'exodusevm',
|
|
17
|
+
'abstract',
|
|
18
|
+
'metamask',
|
|
19
|
+
'edenonline',
|
|
20
|
+
'intersend',
|
|
16
21
|
];
|
|
22
|
+
let removeEip6963EventsListener;
|
|
23
|
+
// should add eip6963 connector only if not in wallet-book, to avoid adding duplicate connectors
|
|
24
|
+
const shouldAddEip6963Connector = (eip6963ProviderInfo, walletBook) => {
|
|
25
|
+
var _a;
|
|
26
|
+
const { rdns, name } = eip6963ProviderInfo;
|
|
27
|
+
const chain = 'evm';
|
|
28
|
+
const connectorKey = `${sanitizeName(name)}${chain}`;
|
|
29
|
+
logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', rdns, name, chain, connectorKey);
|
|
30
|
+
const existingWallet = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {}).find(([key, wallet]) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return ((_a = wallet.eip6963Config) === null || _a === void 0 ? void 0 : _a.rdns) === rdns ||
|
|
33
|
+
key === connectorKey ||
|
|
34
|
+
walletsWithCustomConnectors.includes(connectorKey) ||
|
|
35
|
+
(wallet.name === name && ((_b = wallet.injectedConfig) === null || _b === void 0 ? void 0 : _b[0].chain) === chain);
|
|
36
|
+
});
|
|
37
|
+
logger.logVerboseTroubleshootingMessage('[ETH shouldAddEip6963Connector]', existingWallet);
|
|
38
|
+
return !existingWallet;
|
|
39
|
+
};
|
|
40
|
+
const addEip6963Listener = (walletBook) => {
|
|
41
|
+
removeEip6963EventsListener === null || removeEip6963EventsListener === void 0 ? void 0 : removeEip6963EventsListener();
|
|
42
|
+
removeEip6963EventsListener = listenToEip6963Events((event) => {
|
|
43
|
+
if (!shouldAddEip6963Connector(event.detail.info, walletBook)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] listenToEip6963Events', event.detail);
|
|
47
|
+
walletConnectorEvents.emit('providerInjected', {
|
|
48
|
+
injectedConnectorConstructor: getConnectorConstructorForEip6963Wallet(event.detail),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
17
52
|
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
18
53
|
var _a;
|
|
19
|
-
|
|
54
|
+
addEip6963Listener(walletBook);
|
|
55
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
20
56
|
.filter(([key, wallet]) => {
|
|
21
57
|
var _a;
|
|
22
58
|
return ((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'evm')) &&
|
|
23
|
-
!
|
|
59
|
+
!walletsWithCustomConnectors.includes(key);
|
|
24
60
|
})
|
|
25
|
-
.map(([key, wallet]) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.name = name;
|
|
33
|
-
this.wallet = wallet;
|
|
34
|
-
this.walletConnectorFallback = walletConnectorFallback;
|
|
35
|
-
// this is the key from the wallet book entry so that we don't purely rely on the normalized name
|
|
36
|
-
this.overrideKey = key;
|
|
37
|
-
}
|
|
38
|
-
getAddress() {
|
|
39
|
-
const _super = Object.create(null, {
|
|
40
|
-
getAddress: { get: () => super.getAddress }
|
|
41
|
-
});
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
var _a;
|
|
44
|
-
if (this.isInstalledOnBrowser()) {
|
|
45
|
-
return _super.getAddress.call(this);
|
|
46
|
-
}
|
|
47
|
-
const inAppBrowserBase = (_a = this.wallet.mobile) === null || _a === void 0 ? void 0 : _a.inAppBrowser;
|
|
48
|
-
if (!inAppBrowserBase) {
|
|
49
|
-
const error = new Error(`No inAppBrowserBase found for ${this.name}.`);
|
|
50
|
-
logger.error(error.message);
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
window.location.href = `${inAppBrowserBase}/${window.location.href}`;
|
|
54
|
-
return undefined;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
});
|
|
61
|
+
.map(([key, wallet]) => getConnectorConstructorInjectedWallet(key, wallet));
|
|
62
|
+
const { providers } = Eip6963ProviderSingleton.get();
|
|
63
|
+
const eip6963Connectors = providers
|
|
64
|
+
.filter((provider) => shouldAddEip6963Connector(provider.info, walletBook))
|
|
65
|
+
.map((provider) => getConnectorConstructorForEip6963Wallet(provider));
|
|
66
|
+
logger.logVerboseTroubleshootingMessage('[ETH fetchInjectedWalletConnectors] eip6963Connectors', eip6963Connectors);
|
|
67
|
+
return [...walletBookConnectors, ...eip6963Connectors];
|
|
59
68
|
};
|
|
60
69
|
|
|
61
70
|
export { fetchInjectedWalletConnector, injectedWalletOverrides };
|
package/src/injected/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './PhantomEvm';
|
|
2
2
|
export * from './ExodusEvm';
|
|
3
|
-
export * from './UnknownInjected';
|
|
4
3
|
export * from './FallbackEvmConnector';
|
|
5
4
|
export * from './fetchInjectedWalletConnectors';
|
|
5
|
+
export { InjectedWalletBase as EthereumInjectedConnector } from './InjectedWalletBase';
|