@dynamic-labs/ethereum 2.0.0-alpha.21 → 2.0.0-alpha.22
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 +36 -0
- package/package.json +9 -9
- package/src/injected/Zerion.cjs +38 -0
- package/src/injected/Zerion.d.ts +23 -0
- package/src/injected/Zerion.js +34 -0
- package/src/injected/fetchInjectedWalletConnectors.cjs +3 -0
- package/src/injected/fetchInjectedWalletConnectors.js +3 -0
- package/src/walletConnect/index.d.ts +1 -1
- package/src/walletConnect/walletConnect.cjs +83 -59
- package/src/walletConnect/walletConnect.d.ts +14 -11
- package/src/walletConnect/walletConnect.js +82 -58
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
|
|
2
|
+
## [2.0.0-alpha.22](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.21...v2.0.0-alpha.22) (2024-03-27)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* remove isFullyConnected (#5066)
|
|
8
|
+
* remove and deprecated exported methods (#5065)
|
|
9
|
+
* remove emailOnly provider
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add method property to track which phantom connector function was called ([#5044](https://github.com/dynamic-labs/DynamicAuth/issues/5044)) ([f820cd4](https://github.com/dynamic-labs/DynamicAuth/commit/f820cd4c7e047fd5181115b4d388e54df682e5c8))
|
|
14
|
+
* add signAndSendTransaction to phantom redirect connector ([#5054](https://github.com/dynamic-labs/DynamicAuth/issues/5054)) ([694a300](https://github.com/dynamic-labs/DynamicAuth/commit/694a3003c8765098878a5c95174be5eba4509fc2))
|
|
15
|
+
* implement remaining signer methods on phantom redirect connector ([#5060](https://github.com/dynamic-labs/DynamicAuth/issues/5060)) ([29db446](https://github.com/dynamic-labs/DynamicAuth/commit/29db4464de6eea11c92a8080fed1eb3e7588b2b8))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* add recommended wallet tags to the WalletSimpleSignIn component ([#5041](https://github.com/dynamic-labs/DynamicAuth/issues/5041)) ([aefde4d](https://github.com/dynamic-labs/DynamicAuth/commit/aefde4d927427c131dce4402eb3c705527c64e8f))
|
|
21
|
+
* display invalid phone number error ([#5103](https://github.com/dynamic-labs/DynamicAuth/issues/5103)) ([842c0ba](https://github.com/dynamic-labs/DynamicAuth/commit/842c0ba3cfe1120c166f12410efbc346d8e30ed0))
|
|
22
|
+
* ensure the user field modals uses the base widget context ([#5105](https://github.com/dynamic-labs/DynamicAuth/issues/5105)) ([aa2a545](https://github.com/dynamic-labs/DynamicAuth/commit/aa2a545bdbf6f38f4131ccdde61142389dbf5480))
|
|
23
|
+
* force aspect ratio for social icon pfps ([#5072](https://github.com/dynamic-labs/DynamicAuth/issues/5072)) ([6f611a7](https://github.com/dynamic-labs/DynamicAuth/commit/6f611a7cbe41d66796449b28af919bc93a7bae42))
|
|
24
|
+
* handle too many email verifications error ([#5051](https://github.com/dynamic-labs/DynamicAuth/issues/5051)) ([7af96df](https://github.com/dynamic-labs/DynamicAuth/commit/7af96dfb85cdc68577fdb8cc880e2fd09bcff5af))
|
|
25
|
+
* hardcode zerion provider and update walletbook to prevent showing up as metamask when not installed ([#5071](https://github.com/dynamic-labs/DynamicAuth/issues/5071)) ([3ab6c37](https://github.com/dynamic-labs/DynamicAuth/commit/3ab6c3772efe2c2e3259ca7a9dbb92e924314029))
|
|
26
|
+
* issue where ethereum is tree shaken ([#5028](https://github.com/dynamic-labs/DynamicAuth/issues/5028)) ([fda542d](https://github.com/dynamic-labs/DynamicAuth/commit/fda542db2b65a437004fe809a0ea9f90fde47b13))
|
|
27
|
+
* not clearing the loading when creating an embedded wallet ([323086f](https://github.com/dynamic-labs/DynamicAuth/commit/323086f673fb8a2108b8262181511987d0bc1d09))
|
|
28
|
+
* solflare double connection on page refresh ([#5083](https://github.com/dynamic-labs/DynamicAuth/issues/5083)) ([ef76005](https://github.com/dynamic-labs/DynamicAuth/commit/ef7600564b646cf45396287a0d6b6f1420473b04))
|
|
29
|
+
* swap out findProvider for getSigner on solflare ([#5057](https://github.com/dynamic-labs/DynamicAuth/issues/5057)) ([b78827f](https://github.com/dynamic-labs/DynamicAuth/commit/b78827f8fd87a594114908d890f58b8771123383))
|
|
30
|
+
* validate user session whenever user is connected/authenticated ([#5082](https://github.com/dynamic-labs/DynamicAuth/issues/5082)) ([432faa0](https://github.com/dynamic-labs/DynamicAuth/commit/432faa0a69b43cb7324a252a2450db3cbd3b4b12))
|
|
31
|
+
* walletconnect improvements and fixes ([#5085](https://github.com/dynamic-labs/DynamicAuth/issues/5085)) ([bb42566](https://github.com/dynamic-labs/DynamicAuth/commit/bb425666aef5071b7827ef0aa167a328493f1ae7))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
* remove and deprecated exported methods ([#5065](https://github.com/dynamic-labs/DynamicAuth/issues/5065)) ([63af7ea](https://github.com/dynamic-labs/DynamicAuth/commit/63af7ea691b2112032de332f2b3558ac6260a38d))
|
|
35
|
+
* remove emailOnly provider ([60a30bc](https://github.com/dynamic-labs/DynamicAuth/commit/60a30bc2f242de19d9c6167279fc44b7f9395ac8))
|
|
36
|
+
* remove isFullyConnected ([#5066](https://github.com/dynamic-labs/DynamicAuth/issues/5066)) ([0a662d9](https://github.com/dynamic-labs/DynamicAuth/commit/0a662d9eda19045f13c21ad1b5238ca11594fde5))
|
|
37
|
+
|
|
2
38
|
## [2.0.0-alpha.21](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.20...v2.0.0-alpha.21) (2024-03-20)
|
|
3
39
|
|
|
4
40
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.22",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@coinbase/wallet-sdk": "3.9.2",
|
|
30
|
-
"@walletconnect/
|
|
30
|
+
"@walletconnect/ethereum-provider": "2.11.2",
|
|
31
31
|
"eventemitter3": "5.0.1",
|
|
32
32
|
"buffer": "6.0.3",
|
|
33
|
-
"@dynamic-labs/rpc-provider-ethereum": "2.0.0-alpha.
|
|
34
|
-
"@dynamic-labs/turnkey": "2.0.0-alpha.
|
|
35
|
-
"@dynamic-labs/types": "2.0.0-alpha.
|
|
36
|
-
"@dynamic-labs/utils": "2.0.0-alpha.
|
|
37
|
-
"@dynamic-labs/viem-utils": "2.0.0-alpha.
|
|
38
|
-
"@dynamic-labs/wallet-book": "2.0.0-alpha.
|
|
39
|
-
"@dynamic-labs/wallet-connector-core": "2.0.0-alpha.
|
|
33
|
+
"@dynamic-labs/rpc-provider-ethereum": "2.0.0-alpha.22",
|
|
34
|
+
"@dynamic-labs/turnkey": "2.0.0-alpha.22",
|
|
35
|
+
"@dynamic-labs/types": "2.0.0-alpha.22",
|
|
36
|
+
"@dynamic-labs/utils": "2.0.0-alpha.22",
|
|
37
|
+
"@dynamic-labs/viem-utils": "2.0.0-alpha.22",
|
|
38
|
+
"@dynamic-labs/wallet-book": "2.0.0-alpha.22",
|
|
39
|
+
"@dynamic-labs/wallet-connector-core": "2.0.0-alpha.22",
|
|
40
40
|
"stream": "0.0.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
6
|
+
|
|
7
|
+
// on desktop, we use EIP-6963 to connect to the wallet so the injectedConfig
|
|
8
|
+
// is not needed.
|
|
9
|
+
const zerionWalletBookConfig = {
|
|
10
|
+
eip6963Config: {
|
|
11
|
+
rdns: 'io.zerion.wallet',
|
|
12
|
+
},
|
|
13
|
+
filterFromWalletConnect: true,
|
|
14
|
+
injectedConfig: [
|
|
15
|
+
{
|
|
16
|
+
chain: 'evm',
|
|
17
|
+
// adds isMetaMask flag to the wallet connector so that the window provider works
|
|
18
|
+
// in the zerion in-app browser.
|
|
19
|
+
extensionLocators: [{ flag: 'isMetaMask', value: true }],
|
|
20
|
+
windowLocations: ['zerionWallet', 'zerionwallet.ethereum'],
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
name: 'Zerion',
|
|
24
|
+
};
|
|
25
|
+
class Zerion extends InjectedWalletBase {
|
|
26
|
+
constructor(props) {
|
|
27
|
+
super(props);
|
|
28
|
+
this.name = 'Zerion';
|
|
29
|
+
this.overrideKey = 'zerion';
|
|
30
|
+
this.wallet = zerionWalletBookConfig;
|
|
31
|
+
}
|
|
32
|
+
isInstalledOnBrowser() {
|
|
33
|
+
var _a;
|
|
34
|
+
return Boolean(window.zerionWallet || ((_a = window.zerionwallet) === null || _a === void 0 ? void 0 : _a.ethereum));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.Zerion = Zerion;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EthWalletConnectorOpts } from '../EthWalletConnector';
|
|
2
|
+
import InjectedWalletBase from './InjectedWalletBase';
|
|
3
|
+
export declare class Zerion extends InjectedWalletBase {
|
|
4
|
+
name: string;
|
|
5
|
+
overrideKey: string;
|
|
6
|
+
wallet: {
|
|
7
|
+
eip6963Config: {
|
|
8
|
+
rdns: string;
|
|
9
|
+
};
|
|
10
|
+
filterFromWalletConnect: boolean;
|
|
11
|
+
injectedConfig: {
|
|
12
|
+
chain: string;
|
|
13
|
+
extensionLocators: {
|
|
14
|
+
flag: string;
|
|
15
|
+
value: boolean;
|
|
16
|
+
}[];
|
|
17
|
+
windowLocations: string[];
|
|
18
|
+
}[];
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
21
|
+
constructor(props: EthWalletConnectorOpts);
|
|
22
|
+
isInstalledOnBrowser(): boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import InjectedWalletBase from './InjectedWalletBase.js';
|
|
2
|
+
|
|
3
|
+
// on desktop, we use EIP-6963 to connect to the wallet so the injectedConfig
|
|
4
|
+
// is not needed.
|
|
5
|
+
const zerionWalletBookConfig = {
|
|
6
|
+
eip6963Config: {
|
|
7
|
+
rdns: 'io.zerion.wallet',
|
|
8
|
+
},
|
|
9
|
+
filterFromWalletConnect: true,
|
|
10
|
+
injectedConfig: [
|
|
11
|
+
{
|
|
12
|
+
chain: 'evm',
|
|
13
|
+
// adds isMetaMask flag to the wallet connector so that the window provider works
|
|
14
|
+
// in the zerion in-app browser.
|
|
15
|
+
extensionLocators: [{ flag: 'isMetaMask', value: true }],
|
|
16
|
+
windowLocations: ['zerionWallet', 'zerionwallet.ethereum'],
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
name: 'Zerion',
|
|
20
|
+
};
|
|
21
|
+
class Zerion extends InjectedWalletBase {
|
|
22
|
+
constructor(props) {
|
|
23
|
+
super(props);
|
|
24
|
+
this.name = 'Zerion';
|
|
25
|
+
this.overrideKey = 'zerion';
|
|
26
|
+
this.wallet = zerionWalletBookConfig;
|
|
27
|
+
}
|
|
28
|
+
isInstalledOnBrowser() {
|
|
29
|
+
var _a;
|
|
30
|
+
return Boolean(window.zerionWallet || ((_a = window.zerionwallet) === null || _a === void 0 ? void 0 : _a.ethereum));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { Zerion };
|
|
@@ -5,15 +5,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var InjectedWalletBase = require('./InjectedWalletBase.cjs');
|
|
6
6
|
var PhantomEvm = require('./PhantomEvm.cjs');
|
|
7
7
|
var ExodusEvm = require('./ExodusEvm.cjs');
|
|
8
|
+
var Zerion = require('./Zerion.cjs');
|
|
8
9
|
|
|
9
10
|
const injectedWalletOverrides = [
|
|
10
11
|
PhantomEvm.PhantomEvm,
|
|
11
12
|
ExodusEvm.ExodusEvm,
|
|
13
|
+
Zerion.Zerion,
|
|
12
14
|
];
|
|
13
15
|
const filteredInjectedWalletKeysOverrides = [
|
|
14
16
|
'phantomevm',
|
|
15
17
|
'coinbase',
|
|
16
18
|
'exodusevm',
|
|
19
|
+
'zerion',
|
|
17
20
|
];
|
|
18
21
|
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
19
22
|
var _a;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import InjectedWalletBase from './InjectedWalletBase.js';
|
|
2
2
|
import { PhantomEvm } from './PhantomEvm.js';
|
|
3
3
|
import { ExodusEvm } from './ExodusEvm.js';
|
|
4
|
+
import { Zerion } from './Zerion.js';
|
|
4
5
|
|
|
5
6
|
const injectedWalletOverrides = [
|
|
6
7
|
PhantomEvm,
|
|
7
8
|
ExodusEvm,
|
|
9
|
+
Zerion,
|
|
8
10
|
];
|
|
9
11
|
const filteredInjectedWalletKeysOverrides = [
|
|
10
12
|
'phantomevm',
|
|
11
13
|
'coinbase',
|
|
12
14
|
'exodusevm',
|
|
15
|
+
'zerion',
|
|
13
16
|
];
|
|
14
17
|
const fetchInjectedWalletConnector = ({ walletBook, }) => {
|
|
15
18
|
var _a;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { WalletConnect
|
|
1
|
+
export { WalletConnect } from './walletConnect';
|
|
2
2
|
export { fetchWalletConnectWallets } from './fetchWalletConnectWallets';
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
6
|
-
var
|
|
6
|
+
var EthereumProvider = require('@walletconnect/ethereum-provider');
|
|
7
7
|
var EventEmitter = require('eventemitter3');
|
|
8
8
|
var viem = require('viem');
|
|
9
9
|
var accounts = require('viem/accounts');
|
|
10
|
-
var utils = require('@dynamic-labs/utils');
|
|
11
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
12
10
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
12
|
+
var utils = require('@dynamic-labs/utils');
|
|
13
13
|
var viemUtils = require('@dynamic-labs/viem-utils');
|
|
14
14
|
var EthWalletConnector = require('../EthWalletConnector.cjs');
|
|
15
15
|
var parseIntSafe = require('../utils/parseIntSafe.cjs');
|
|
16
16
|
|
|
17
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var EthereumProvider__default = /*#__PURE__*/_interopDefaultLegacy(EthereumProvider);
|
|
20
20
|
var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
21
21
|
|
|
22
22
|
const activeAccountKey = (walletName) => `dynamic-wc2-active-account-${walletName}`;
|
|
@@ -37,6 +37,8 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
37
37
|
// When trying to switch network for MetaMask, the switch promise gets stuck
|
|
38
38
|
// if the switch got trigged once already, so we need to keep track of that
|
|
39
39
|
this._hasSwitchedNetwork = false;
|
|
40
|
+
this.sessionEventHandler = () => { };
|
|
41
|
+
this.sessionDeleteHandler = () => { };
|
|
40
42
|
this.name = opts.walletName;
|
|
41
43
|
this.projectId = opts.projectId;
|
|
42
44
|
this.deepLinkPreference = opts.deepLinkPreference || 'native';
|
|
@@ -58,7 +60,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
58
60
|
const allChains = this.getMappedChains();
|
|
59
61
|
const reorderedChains = this.preferredChains.filter((chain) => allChains.includes(chain));
|
|
60
62
|
const remainingChains = allChains.filter((chain) => !this.preferredChains.includes(chain));
|
|
61
|
-
return [...reorderedChains, ...remainingChains];
|
|
63
|
+
return [...reorderedChains, ...remainingChains].map((chain) => Number(chain.split(':')[1]));
|
|
62
64
|
}
|
|
63
65
|
initConnection() {
|
|
64
66
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -67,43 +69,51 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
67
69
|
throw new utils.DynamicError('No provider found (init connection)');
|
|
68
70
|
}
|
|
69
71
|
// this means there is already a connection in progress, so don't call connect again
|
|
70
|
-
if (provider === null || provider === void 0 ? void 0 : provider.uri) {
|
|
72
|
+
if (provider === null || provider === void 0 ? void 0 : provider.signer.uri) {
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
73
|
-
|
|
74
|
-
eip155: {
|
|
75
|
-
chains: this.getMappedChainsByPreferredOrder(),
|
|
76
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
77
|
-
methods: [
|
|
78
|
-
'eth_chainId',
|
|
79
|
-
'eth_signTypedData',
|
|
80
|
-
'eth_signTransaction',
|
|
81
|
-
'eth_sign',
|
|
82
|
-
'personal_sign',
|
|
83
|
-
'eth_sendTransaction',
|
|
84
|
-
'eth_signTypedData_v4',
|
|
85
|
-
'wallet_switchEthereumChain',
|
|
86
|
-
'wallet_addEthereumChain',
|
|
87
|
-
],
|
|
88
|
-
rpcMap: this.evmNetworkRpcMap(),
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
provider
|
|
92
|
-
.connect({
|
|
93
|
-
optionalNamespaces,
|
|
94
|
-
})
|
|
95
|
-
.catch((e) => {
|
|
75
|
+
provider.connect().catch((e) => {
|
|
96
76
|
walletConnectorCore.logger.error(e);
|
|
97
77
|
ee.emit('walletconnect_connection_failed', e);
|
|
98
78
|
});
|
|
99
79
|
});
|
|
100
80
|
}
|
|
101
|
-
|
|
81
|
+
createProvider() {
|
|
102
82
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
|
|
104
|
-
|
|
83
|
+
return EthereumProvider__default["default"].init({
|
|
84
|
+
events: ['chainChanged', 'accountsChanged'],
|
|
85
|
+
methods: [],
|
|
86
|
+
optionalChains: this.getMappedChainsByPreferredOrder(),
|
|
87
|
+
optionalMethods: [
|
|
88
|
+
'eth_chainId',
|
|
89
|
+
'eth_signTypedData',
|
|
90
|
+
'eth_signTransaction',
|
|
91
|
+
'eth_sign',
|
|
92
|
+
'personal_sign',
|
|
93
|
+
'eth_sendTransaction',
|
|
94
|
+
'eth_signTypedData_v4',
|
|
95
|
+
'wallet_switchEthereumChain',
|
|
96
|
+
'wallet_addEthereumChain',
|
|
97
|
+
],
|
|
105
98
|
projectId: this.projectId,
|
|
99
|
+
rpcMap: this.evmNetworkRpcMap(),
|
|
100
|
+
showQrModal: false,
|
|
106
101
|
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
getWalletClientFromInitializedProvider() {
|
|
105
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const walletConnect = this.createProvider();
|
|
107
|
+
const walletClient = viem.createWalletClient({
|
|
108
|
+
account: this.activeAccount ? accounts.toAccount(this.activeAccount) : undefined,
|
|
109
|
+
transport: viem.custom(yield walletConnect),
|
|
110
|
+
});
|
|
111
|
+
return walletClient;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
createInitProviderPromise() {
|
|
115
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
WalletConnect.provider = yield this.createProvider();
|
|
107
117
|
this.teardownEventListeners();
|
|
108
118
|
this.setupEventListeners();
|
|
109
119
|
});
|
|
@@ -182,7 +192,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
182
192
|
if (!WalletConnect.provider) {
|
|
183
193
|
return;
|
|
184
194
|
}
|
|
185
|
-
|
|
195
|
+
this.sessionEventHandler = ({ params, }) => {
|
|
186
196
|
walletConnectorCore.logger.debug('session_event was called', { params });
|
|
187
197
|
if (!params || !params.event) {
|
|
188
198
|
walletConnectorCore.logger.debug('session_event was called without params or params.event');
|
|
@@ -201,6 +211,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
201
211
|
}
|
|
202
212
|
this.currentChainId = chainId;
|
|
203
213
|
this.emit('chainChange', { chain: String(chainId) });
|
|
214
|
+
this.hasSwitchedNetwork = true;
|
|
204
215
|
// When a user switches network from their wallet, we need the provider to change network
|
|
205
216
|
// such that any future calls to `getNetwork` will return the correct network
|
|
206
217
|
this.switchNetwork({ networkChainId: chainId });
|
|
@@ -214,18 +225,20 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
214
225
|
const account = data[0].split(':')[2];
|
|
215
226
|
this.setActiveAccount(account);
|
|
216
227
|
}
|
|
217
|
-
}
|
|
218
|
-
WalletConnect.provider.
|
|
228
|
+
};
|
|
229
|
+
WalletConnect.provider.on('session_event', this.sessionEventHandler);
|
|
230
|
+
this.sessionDeleteHandler = () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
219
231
|
this.endSession();
|
|
220
232
|
this.emit('disconnect');
|
|
221
|
-
})
|
|
233
|
+
});
|
|
234
|
+
WalletConnect.provider.on('session_delete', this.sessionDeleteHandler);
|
|
222
235
|
}
|
|
223
236
|
teardownEventListeners() {
|
|
224
237
|
if (!WalletConnect.provider) {
|
|
225
238
|
return;
|
|
226
239
|
}
|
|
227
|
-
WalletConnect.provider.
|
|
228
|
-
WalletConnect.provider.
|
|
240
|
+
WalletConnect.provider.off('session_event', this.sessionEventHandler);
|
|
241
|
+
WalletConnect.provider.off('session_delete', this.sessionDeleteHandler);
|
|
229
242
|
}
|
|
230
243
|
getWalletClient(chainId) {
|
|
231
244
|
if (!WalletConnect.provider) {
|
|
@@ -233,7 +246,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
233
246
|
}
|
|
234
247
|
return viem.createWalletClient({
|
|
235
248
|
account: this.activeAccount ? accounts.toAccount(this.activeAccount) : undefined,
|
|
236
|
-
chain:
|
|
249
|
+
chain: viemUtils.chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
|
|
237
250
|
transport: viem.custom(WalletConnect.provider),
|
|
238
251
|
});
|
|
239
252
|
}
|
|
@@ -243,7 +256,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
243
256
|
if (this.activeAccount) {
|
|
244
257
|
return this.activeAccount;
|
|
245
258
|
}
|
|
246
|
-
if (!WalletConnect.provider || !((_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.uri)) {
|
|
259
|
+
if (!WalletConnect.provider || !((_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.signer.uri)) {
|
|
247
260
|
walletConnectorCore.logger.debug('No WC2 provider found, re-initializing...');
|
|
248
261
|
yield this.endSession();
|
|
249
262
|
yield this.init();
|
|
@@ -253,13 +266,13 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
253
266
|
// finish setting up the connection URI and making it available
|
|
254
267
|
// on the provider
|
|
255
268
|
yield utils.sleep(1000);
|
|
256
|
-
if (!WalletConnect.provider || !((_b = WalletConnect.provider) === null || _b === void 0 ? void 0 : _b.uri)) {
|
|
269
|
+
if (!WalletConnect.provider || !((_b = WalletConnect.provider) === null || _b === void 0 ? void 0 : _b.signer.uri)) {
|
|
257
270
|
walletConnectorCore.logger.debug('No WC2 provider found, escaping and throwing error');
|
|
258
271
|
throw new utils.DynamicError('No provider found');
|
|
259
272
|
}
|
|
260
273
|
}
|
|
261
274
|
const metadata = walletBook.getWalletBookWallet(this.walletBook, this.key);
|
|
262
|
-
walletConnectorCore.performPlatformSpecificConnectionMethod(WalletConnect.provider.uri, metadata, {
|
|
275
|
+
walletConnectorCore.performPlatformSpecificConnectionMethod(WalletConnect.provider.signer.uri, metadata, {
|
|
263
276
|
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
264
277
|
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
265
278
|
}, this.deepLinkPreference);
|
|
@@ -272,7 +285,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
272
285
|
const error = new utils.DynamicError('Connection rejected. Please try again.');
|
|
273
286
|
error.code = 'connection_rejected';
|
|
274
287
|
if (WalletConnect.provider) {
|
|
275
|
-
WalletConnect.provider.uri = undefined;
|
|
288
|
+
WalletConnect.provider.signer.uri = undefined;
|
|
276
289
|
// this is needed for mobile to work when using universal links.
|
|
277
290
|
// if the user cancels the connection, we need to re-initialize the provider
|
|
278
291
|
// so that the async work is done ahead of time, before the user tries to connect again,
|
|
@@ -284,9 +297,12 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
284
297
|
// whenever the connection attempt either succeeds or fails
|
|
285
298
|
cleanupListeners();
|
|
286
299
|
};
|
|
287
|
-
const onConnect = (
|
|
300
|
+
const onConnect = () => {
|
|
301
|
+
var _a;
|
|
302
|
+
const session = (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.session;
|
|
288
303
|
if (!session) {
|
|
289
304
|
reject(new utils.DynamicError('No session found'));
|
|
305
|
+
return;
|
|
290
306
|
}
|
|
291
307
|
this.setSession(session);
|
|
292
308
|
this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
@@ -345,7 +361,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
345
361
|
metadata,
|
|
346
362
|
mode: 'regular',
|
|
347
363
|
preference: this.deepLinkPreference,
|
|
348
|
-
uri: (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.uri,
|
|
364
|
+
uri: (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.signer.uri,
|
|
349
365
|
});
|
|
350
366
|
if (!deepLink) {
|
|
351
367
|
return;
|
|
@@ -359,10 +375,6 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
359
375
|
if (!this.session) {
|
|
360
376
|
throw new utils.DynamicError('no session');
|
|
361
377
|
}
|
|
362
|
-
const web3Provider = this.getWalletClient();
|
|
363
|
-
if (!web3Provider) {
|
|
364
|
-
throw new utils.DynamicError('No WalletConnect provider found to handle signing');
|
|
365
|
-
}
|
|
366
378
|
const deepLink = this.getDeepLink();
|
|
367
379
|
if (utils.isMobile() && deepLink) {
|
|
368
380
|
window.location.href = deepLink;
|
|
@@ -372,7 +384,8 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
372
384
|
if (!activeAccount) {
|
|
373
385
|
return;
|
|
374
386
|
}
|
|
375
|
-
|
|
387
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
388
|
+
return walletClient.signMessage({
|
|
376
389
|
account: activeAccount,
|
|
377
390
|
message: messageToSign,
|
|
378
391
|
});
|
|
@@ -431,11 +444,17 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
431
444
|
return _super.getNetwork.call(this);
|
|
432
445
|
});
|
|
433
446
|
}
|
|
434
|
-
providerSwitchNetwork({ network,
|
|
447
|
+
providerSwitchNetwork({ network, }) {
|
|
435
448
|
const _super = Object.create(null, {
|
|
436
449
|
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
437
450
|
});
|
|
438
451
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
452
|
+
const supportedNetworks = yield this.getSupportedNetworks();
|
|
453
|
+
if (!(supportedNetworks === null || supportedNetworks === void 0 ? void 0 : supportedNetworks.includes(network.chainId.toString()))) {
|
|
454
|
+
const error = new utils.DynamicError('Network switching is not available at this time. The user should manually switch network in their wallet');
|
|
455
|
+
error.code = 'network_switching_only_available_in_wallet';
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
439
458
|
const currentNetworkId = yield this.getNetwork();
|
|
440
459
|
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
441
460
|
return;
|
|
@@ -446,10 +465,14 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
446
465
|
if (!this.supportsNetworkSwitching()) {
|
|
447
466
|
throw new utils.DynamicError('Network switching not supported');
|
|
448
467
|
}
|
|
449
|
-
|
|
450
|
-
|
|
468
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
469
|
+
if (this.isMetaMask()) {
|
|
470
|
+
const deepLink = this.getDeepLink();
|
|
471
|
+
if (deepLink) {
|
|
472
|
+
window.location.href = deepLink;
|
|
473
|
+
}
|
|
451
474
|
}
|
|
452
|
-
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
475
|
+
yield _super.providerSwitchNetwork.call(this, { network, provider: walletClient });
|
|
453
476
|
this.currentChainId = network.chainId;
|
|
454
477
|
this.hasSwitchedNetwork = true;
|
|
455
478
|
this.emit('chainChange', { chain: String(network.chainId) });
|
|
@@ -475,13 +498,14 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
475
498
|
getSupportedNetworks() {
|
|
476
499
|
var _a;
|
|
477
500
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
478
|
-
// MM allows you to switch to any network the first time, even if it's not enabled in MM
|
|
479
|
-
// so we should consider all networks as supported if network switching hasn't been triggered yet
|
|
480
|
-
if (this.isMetaMask() && !this.hasSwitchedNetwork) {
|
|
481
|
-
return this.evmNetworks.map((network) => network.chainId.toString());
|
|
482
|
-
}
|
|
483
501
|
yield this.initProvider();
|
|
484
502
|
this.refreshSession();
|
|
503
|
+
if (this.isMetaMask()) {
|
|
504
|
+
if (this.hasSwitchedNetwork) {
|
|
505
|
+
return [String(this.currentChainId)];
|
|
506
|
+
}
|
|
507
|
+
return this.evmNetworks.map((network) => network.chainId.toString());
|
|
508
|
+
}
|
|
485
509
|
if (!this.session) {
|
|
486
510
|
return [];
|
|
487
511
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SessionTypes } from '@walletconnect/types';
|
|
2
|
-
import { Hex
|
|
2
|
+
import { Hex } from 'viem';
|
|
3
|
+
import { Chain, GetAddressOpts, DeepLinkVariant, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
4
|
import { EvmNetwork } from '@dynamic-labs/types';
|
|
4
|
-
import { Chain, DeepLinkVariant, GetAddressOpts, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
|
|
6
6
|
export type WalletConnectOpts = EthWalletConnectorOpts & {
|
|
7
7
|
projectId?: string;
|
|
@@ -29,6 +29,8 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
29
29
|
private getMappedChains;
|
|
30
30
|
private getMappedChainsByPreferredOrder;
|
|
31
31
|
private initConnection;
|
|
32
|
+
private createProvider;
|
|
33
|
+
private getWalletClientFromInitializedProvider;
|
|
32
34
|
private createInitProviderPromise;
|
|
33
35
|
private initProvider;
|
|
34
36
|
private refreshSession;
|
|
@@ -42,6 +44,8 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
42
44
|
private set hasSwitchedNetwork(value);
|
|
43
45
|
private get hasSwitchedNetwork();
|
|
44
46
|
supportsNetworkSwitching(): boolean;
|
|
47
|
+
private sessionEventHandler;
|
|
48
|
+
private sessionDeleteHandler;
|
|
45
49
|
setupEventListeners(): void;
|
|
46
50
|
teardownEventListeners(): void;
|
|
47
51
|
getWalletClient(chainId?: string): {
|
|
@@ -53,7 +57,7 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
53
57
|
} | undefined;
|
|
54
58
|
} | undefined;
|
|
55
59
|
cacheTime: number;
|
|
56
|
-
chain: import("viem").Chain
|
|
60
|
+
chain: import("viem").Chain;
|
|
57
61
|
key: string;
|
|
58
62
|
name: string;
|
|
59
63
|
pollingInterval: number;
|
|
@@ -62,20 +66,20 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
62
66
|
type: string;
|
|
63
67
|
uid: string;
|
|
64
68
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
65
|
-
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi, import("viem").Chain
|
|
69
|
+
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi, import("viem").Chain, import("viem").JsonRpcAccount | undefined, chainOverride>) => Promise<`0x${string}`>;
|
|
66
70
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
67
71
|
getChainId: () => Promise<number>;
|
|
68
72
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
69
|
-
prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends import("viem").Chain | undefined = undefined, TAccountOverride extends `0x${string}` | import("viem").Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain
|
|
73
|
+
prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends import("viem").Chain | undefined = undefined, TAccountOverride extends `0x${string}` | import("viem").Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride, TAccountOverride, TParameterType>) => Promise<import("viem").PrepareTransactionRequestReturnType<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride, TAccountOverride, TParameterType>>;
|
|
70
74
|
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
71
75
|
requestPermissions: (args: {
|
|
72
76
|
[x: string]: Record<string, any>;
|
|
73
77
|
eth_accounts: Record<string, any>;
|
|
74
78
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
75
79
|
sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
76
|
-
sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain
|
|
80
|
+
sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride_1>) => Promise<`0x${string}`>;
|
|
77
81
|
signMessage: (args: import("viem").SignMessageParameters<import("viem").JsonRpcAccount | undefined>) => Promise<`0x${string}`>;
|
|
78
|
-
signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain
|
|
82
|
+
signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
79
83
|
signTypedData: <const TTypedData extends {
|
|
80
84
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
81
85
|
[x: `string[${string}]`]: undefined;
|
|
@@ -286,7 +290,7 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
286
290
|
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, import("viem").JsonRpcAccount | undefined>) => Promise<`0x${string}`>;
|
|
287
291
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
288
292
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
289
|
-
writeContract: <const abi_1 extends import("viem").Abi | readonly unknown[], functionName extends import("viem").ContractFunctionName<abi_1, "nonpayable" | "payable">, args extends import("viem").ContractFunctionArgs<abi_1, "pure" | "view", functionName>, TChainOverride_3 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_1, functionName, args, import("viem").Chain
|
|
293
|
+
writeContract: <const abi_1 extends import("viem").Abi | readonly unknown[], functionName extends import("viem").ContractFunctionName<abi_1, "nonpayable" | "payable">, args extends import("viem").ContractFunctionArgs<abi_1, "pure" | "view", functionName>, TChainOverride_3 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<abi_1, functionName, args, import("viem").Chain, import("viem").JsonRpcAccount | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
290
294
|
extend: <const client extends {
|
|
291
295
|
[x: string]: unknown;
|
|
292
296
|
account?: undefined;
|
|
@@ -300,7 +304,7 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
300
304
|
transport?: undefined;
|
|
301
305
|
type?: undefined;
|
|
302
306
|
uid?: undefined;
|
|
303
|
-
} & Partial<Pick<import("viem").PublicActions<import("viem").CustomTransport, import("viem").Chain
|
|
307
|
+
} & Partial<Pick<import("viem").PublicActions<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount | undefined>, "getChainId" | "prepareTransactionRequest" | "sendRawTransaction" | "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "readContract" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount | undefined>>) => client) => import("viem").Client<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount | undefined>>;
|
|
304
308
|
} | undefined;
|
|
305
309
|
getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
|
|
306
310
|
/**
|
|
@@ -323,9 +327,8 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
323
327
|
private setSession;
|
|
324
328
|
endSession(): Promise<void>;
|
|
325
329
|
getNetwork(): Promise<number | undefined>;
|
|
326
|
-
providerSwitchNetwork({ network,
|
|
330
|
+
providerSwitchNetwork({ network, }: {
|
|
327
331
|
network: EvmNetwork;
|
|
328
|
-
provider: WalletClient;
|
|
329
332
|
}): Promise<void>;
|
|
330
333
|
getConnectedAccounts(): Promise<string[]>;
|
|
331
334
|
private isMetaMask;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
2
|
-
import
|
|
2
|
+
import EthereumProvider from '@walletconnect/ethereum-provider';
|
|
3
3
|
import EventEmitter from 'eventemitter3';
|
|
4
4
|
import { createWalletClient, custom } from 'viem';
|
|
5
5
|
import { toAccount } from 'viem/accounts';
|
|
6
|
-
import { DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
|
|
7
|
-
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
8
6
|
import { logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
|
|
7
|
+
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
8
|
+
import { DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
|
|
9
9
|
import { chainsMap } from '@dynamic-labs/viem-utils';
|
|
10
10
|
import { EthWalletConnector } from '../EthWalletConnector.js';
|
|
11
11
|
import { parseIntSafe } from '../utils/parseIntSafe.js';
|
|
@@ -28,6 +28,8 @@ class WalletConnect extends EthWalletConnector {
|
|
|
28
28
|
// When trying to switch network for MetaMask, the switch promise gets stuck
|
|
29
29
|
// if the switch got trigged once already, so we need to keep track of that
|
|
30
30
|
this._hasSwitchedNetwork = false;
|
|
31
|
+
this.sessionEventHandler = () => { };
|
|
32
|
+
this.sessionDeleteHandler = () => { };
|
|
31
33
|
this.name = opts.walletName;
|
|
32
34
|
this.projectId = opts.projectId;
|
|
33
35
|
this.deepLinkPreference = opts.deepLinkPreference || 'native';
|
|
@@ -49,7 +51,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
49
51
|
const allChains = this.getMappedChains();
|
|
50
52
|
const reorderedChains = this.preferredChains.filter((chain) => allChains.includes(chain));
|
|
51
53
|
const remainingChains = allChains.filter((chain) => !this.preferredChains.includes(chain));
|
|
52
|
-
return [...reorderedChains, ...remainingChains];
|
|
54
|
+
return [...reorderedChains, ...remainingChains].map((chain) => Number(chain.split(':')[1]));
|
|
53
55
|
}
|
|
54
56
|
initConnection() {
|
|
55
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -58,43 +60,51 @@ class WalletConnect extends EthWalletConnector {
|
|
|
58
60
|
throw new DynamicError('No provider found (init connection)');
|
|
59
61
|
}
|
|
60
62
|
// this means there is already a connection in progress, so don't call connect again
|
|
61
|
-
if (provider === null || provider === void 0 ? void 0 : provider.uri) {
|
|
63
|
+
if (provider === null || provider === void 0 ? void 0 : provider.signer.uri) {
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
64
|
-
|
|
65
|
-
eip155: {
|
|
66
|
-
chains: this.getMappedChainsByPreferredOrder(),
|
|
67
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
68
|
-
methods: [
|
|
69
|
-
'eth_chainId',
|
|
70
|
-
'eth_signTypedData',
|
|
71
|
-
'eth_signTransaction',
|
|
72
|
-
'eth_sign',
|
|
73
|
-
'personal_sign',
|
|
74
|
-
'eth_sendTransaction',
|
|
75
|
-
'eth_signTypedData_v4',
|
|
76
|
-
'wallet_switchEthereumChain',
|
|
77
|
-
'wallet_addEthereumChain',
|
|
78
|
-
],
|
|
79
|
-
rpcMap: this.evmNetworkRpcMap(),
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
provider
|
|
83
|
-
.connect({
|
|
84
|
-
optionalNamespaces,
|
|
85
|
-
})
|
|
86
|
-
.catch((e) => {
|
|
66
|
+
provider.connect().catch((e) => {
|
|
87
67
|
logger.error(e);
|
|
88
68
|
ee.emit('walletconnect_connection_failed', e);
|
|
89
69
|
});
|
|
90
70
|
});
|
|
91
71
|
}
|
|
92
|
-
|
|
72
|
+
createProvider() {
|
|
93
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
return EthereumProvider.init({
|
|
75
|
+
events: ['chainChanged', 'accountsChanged'],
|
|
76
|
+
methods: [],
|
|
77
|
+
optionalChains: this.getMappedChainsByPreferredOrder(),
|
|
78
|
+
optionalMethods: [
|
|
79
|
+
'eth_chainId',
|
|
80
|
+
'eth_signTypedData',
|
|
81
|
+
'eth_signTransaction',
|
|
82
|
+
'eth_sign',
|
|
83
|
+
'personal_sign',
|
|
84
|
+
'eth_sendTransaction',
|
|
85
|
+
'eth_signTypedData_v4',
|
|
86
|
+
'wallet_switchEthereumChain',
|
|
87
|
+
'wallet_addEthereumChain',
|
|
88
|
+
],
|
|
96
89
|
projectId: this.projectId,
|
|
90
|
+
rpcMap: this.evmNetworkRpcMap(),
|
|
91
|
+
showQrModal: false,
|
|
97
92
|
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
getWalletClientFromInitializedProvider() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const walletConnect = this.createProvider();
|
|
98
|
+
const walletClient = createWalletClient({
|
|
99
|
+
account: this.activeAccount ? toAccount(this.activeAccount) : undefined,
|
|
100
|
+
transport: custom(yield walletConnect),
|
|
101
|
+
});
|
|
102
|
+
return walletClient;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
createInitProviderPromise() {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
WalletConnect.provider = yield this.createProvider();
|
|
98
108
|
this.teardownEventListeners();
|
|
99
109
|
this.setupEventListeners();
|
|
100
110
|
});
|
|
@@ -173,7 +183,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
173
183
|
if (!WalletConnect.provider) {
|
|
174
184
|
return;
|
|
175
185
|
}
|
|
176
|
-
|
|
186
|
+
this.sessionEventHandler = ({ params, }) => {
|
|
177
187
|
logger.debug('session_event was called', { params });
|
|
178
188
|
if (!params || !params.event) {
|
|
179
189
|
logger.debug('session_event was called without params or params.event');
|
|
@@ -192,6 +202,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
192
202
|
}
|
|
193
203
|
this.currentChainId = chainId;
|
|
194
204
|
this.emit('chainChange', { chain: String(chainId) });
|
|
205
|
+
this.hasSwitchedNetwork = true;
|
|
195
206
|
// When a user switches network from their wallet, we need the provider to change network
|
|
196
207
|
// such that any future calls to `getNetwork` will return the correct network
|
|
197
208
|
this.switchNetwork({ networkChainId: chainId });
|
|
@@ -205,18 +216,20 @@ class WalletConnect extends EthWalletConnector {
|
|
|
205
216
|
const account = data[0].split(':')[2];
|
|
206
217
|
this.setActiveAccount(account);
|
|
207
218
|
}
|
|
208
|
-
}
|
|
209
|
-
WalletConnect.provider.
|
|
219
|
+
};
|
|
220
|
+
WalletConnect.provider.on('session_event', this.sessionEventHandler);
|
|
221
|
+
this.sessionDeleteHandler = () => __awaiter(this, void 0, void 0, function* () {
|
|
210
222
|
this.endSession();
|
|
211
223
|
this.emit('disconnect');
|
|
212
|
-
})
|
|
224
|
+
});
|
|
225
|
+
WalletConnect.provider.on('session_delete', this.sessionDeleteHandler);
|
|
213
226
|
}
|
|
214
227
|
teardownEventListeners() {
|
|
215
228
|
if (!WalletConnect.provider) {
|
|
216
229
|
return;
|
|
217
230
|
}
|
|
218
|
-
WalletConnect.provider.
|
|
219
|
-
WalletConnect.provider.
|
|
231
|
+
WalletConnect.provider.off('session_event', this.sessionEventHandler);
|
|
232
|
+
WalletConnect.provider.off('session_delete', this.sessionDeleteHandler);
|
|
220
233
|
}
|
|
221
234
|
getWalletClient(chainId) {
|
|
222
235
|
if (!WalletConnect.provider) {
|
|
@@ -224,7 +237,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
224
237
|
}
|
|
225
238
|
return createWalletClient({
|
|
226
239
|
account: this.activeAccount ? toAccount(this.activeAccount) : undefined,
|
|
227
|
-
chain: chainId ?
|
|
240
|
+
chain: chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
|
|
228
241
|
transport: custom(WalletConnect.provider),
|
|
229
242
|
});
|
|
230
243
|
}
|
|
@@ -234,7 +247,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
234
247
|
if (this.activeAccount) {
|
|
235
248
|
return this.activeAccount;
|
|
236
249
|
}
|
|
237
|
-
if (!WalletConnect.provider || !((_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.uri)) {
|
|
250
|
+
if (!WalletConnect.provider || !((_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.signer.uri)) {
|
|
238
251
|
logger.debug('No WC2 provider found, re-initializing...');
|
|
239
252
|
yield this.endSession();
|
|
240
253
|
yield this.init();
|
|
@@ -244,13 +257,13 @@ class WalletConnect extends EthWalletConnector {
|
|
|
244
257
|
// finish setting up the connection URI and making it available
|
|
245
258
|
// on the provider
|
|
246
259
|
yield sleep(1000);
|
|
247
|
-
if (!WalletConnect.provider || !((_b = WalletConnect.provider) === null || _b === void 0 ? void 0 : _b.uri)) {
|
|
260
|
+
if (!WalletConnect.provider || !((_b = WalletConnect.provider) === null || _b === void 0 ? void 0 : _b.signer.uri)) {
|
|
248
261
|
logger.debug('No WC2 provider found, escaping and throwing error');
|
|
249
262
|
throw new DynamicError('No provider found');
|
|
250
263
|
}
|
|
251
264
|
}
|
|
252
265
|
const metadata = getWalletBookWallet(this.walletBook, this.key);
|
|
253
|
-
performPlatformSpecificConnectionMethod(WalletConnect.provider.uri, metadata, {
|
|
266
|
+
performPlatformSpecificConnectionMethod(WalletConnect.provider.signer.uri, metadata, {
|
|
254
267
|
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
255
268
|
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
256
269
|
}, this.deepLinkPreference);
|
|
@@ -263,7 +276,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
263
276
|
const error = new DynamicError('Connection rejected. Please try again.');
|
|
264
277
|
error.code = 'connection_rejected';
|
|
265
278
|
if (WalletConnect.provider) {
|
|
266
|
-
WalletConnect.provider.uri = undefined;
|
|
279
|
+
WalletConnect.provider.signer.uri = undefined;
|
|
267
280
|
// this is needed for mobile to work when using universal links.
|
|
268
281
|
// if the user cancels the connection, we need to re-initialize the provider
|
|
269
282
|
// so that the async work is done ahead of time, before the user tries to connect again,
|
|
@@ -275,9 +288,12 @@ class WalletConnect extends EthWalletConnector {
|
|
|
275
288
|
// whenever the connection attempt either succeeds or fails
|
|
276
289
|
cleanupListeners();
|
|
277
290
|
};
|
|
278
|
-
const onConnect = (
|
|
291
|
+
const onConnect = () => {
|
|
292
|
+
var _a;
|
|
293
|
+
const session = (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.session;
|
|
279
294
|
if (!session) {
|
|
280
295
|
reject(new DynamicError('No session found'));
|
|
296
|
+
return;
|
|
281
297
|
}
|
|
282
298
|
this.setSession(session);
|
|
283
299
|
this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
@@ -336,7 +352,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
336
352
|
metadata,
|
|
337
353
|
mode: 'regular',
|
|
338
354
|
preference: this.deepLinkPreference,
|
|
339
|
-
uri: (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.uri,
|
|
355
|
+
uri: (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.signer.uri,
|
|
340
356
|
});
|
|
341
357
|
if (!deepLink) {
|
|
342
358
|
return;
|
|
@@ -350,10 +366,6 @@ class WalletConnect extends EthWalletConnector {
|
|
|
350
366
|
if (!this.session) {
|
|
351
367
|
throw new DynamicError('no session');
|
|
352
368
|
}
|
|
353
|
-
const web3Provider = this.getWalletClient();
|
|
354
|
-
if (!web3Provider) {
|
|
355
|
-
throw new DynamicError('No WalletConnect provider found to handle signing');
|
|
356
|
-
}
|
|
357
369
|
const deepLink = this.getDeepLink();
|
|
358
370
|
if (isMobile() && deepLink) {
|
|
359
371
|
window.location.href = deepLink;
|
|
@@ -363,7 +375,8 @@ class WalletConnect extends EthWalletConnector {
|
|
|
363
375
|
if (!activeAccount) {
|
|
364
376
|
return;
|
|
365
377
|
}
|
|
366
|
-
|
|
378
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
379
|
+
return walletClient.signMessage({
|
|
367
380
|
account: activeAccount,
|
|
368
381
|
message: messageToSign,
|
|
369
382
|
});
|
|
@@ -422,11 +435,17 @@ class WalletConnect extends EthWalletConnector {
|
|
|
422
435
|
return _super.getNetwork.call(this);
|
|
423
436
|
});
|
|
424
437
|
}
|
|
425
|
-
providerSwitchNetwork({ network,
|
|
438
|
+
providerSwitchNetwork({ network, }) {
|
|
426
439
|
const _super = Object.create(null, {
|
|
427
440
|
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
428
441
|
});
|
|
429
442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
443
|
+
const supportedNetworks = yield this.getSupportedNetworks();
|
|
444
|
+
if (!(supportedNetworks === null || supportedNetworks === void 0 ? void 0 : supportedNetworks.includes(network.chainId.toString()))) {
|
|
445
|
+
const error = new DynamicError('Network switching is not available at this time. The user should manually switch network in their wallet');
|
|
446
|
+
error.code = 'network_switching_only_available_in_wallet';
|
|
447
|
+
throw error;
|
|
448
|
+
}
|
|
430
449
|
const currentNetworkId = yield this.getNetwork();
|
|
431
450
|
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
432
451
|
return;
|
|
@@ -437,10 +456,14 @@ class WalletConnect extends EthWalletConnector {
|
|
|
437
456
|
if (!this.supportsNetworkSwitching()) {
|
|
438
457
|
throw new DynamicError('Network switching not supported');
|
|
439
458
|
}
|
|
440
|
-
|
|
441
|
-
|
|
459
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
460
|
+
if (this.isMetaMask()) {
|
|
461
|
+
const deepLink = this.getDeepLink();
|
|
462
|
+
if (deepLink) {
|
|
463
|
+
window.location.href = deepLink;
|
|
464
|
+
}
|
|
442
465
|
}
|
|
443
|
-
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
466
|
+
yield _super.providerSwitchNetwork.call(this, { network, provider: walletClient });
|
|
444
467
|
this.currentChainId = network.chainId;
|
|
445
468
|
this.hasSwitchedNetwork = true;
|
|
446
469
|
this.emit('chainChange', { chain: String(network.chainId) });
|
|
@@ -466,13 +489,14 @@ class WalletConnect extends EthWalletConnector {
|
|
|
466
489
|
getSupportedNetworks() {
|
|
467
490
|
var _a;
|
|
468
491
|
return __awaiter(this, void 0, void 0, function* () {
|
|
469
|
-
// MM allows you to switch to any network the first time, even if it's not enabled in MM
|
|
470
|
-
// so we should consider all networks as supported if network switching hasn't been triggered yet
|
|
471
|
-
if (this.isMetaMask() && !this.hasSwitchedNetwork) {
|
|
472
|
-
return this.evmNetworks.map((network) => network.chainId.toString());
|
|
473
|
-
}
|
|
474
492
|
yield this.initProvider();
|
|
475
493
|
this.refreshSession();
|
|
494
|
+
if (this.isMetaMask()) {
|
|
495
|
+
if (this.hasSwitchedNetwork) {
|
|
496
|
+
return [String(this.currentChainId)];
|
|
497
|
+
}
|
|
498
|
+
return this.evmNetworks.map((network) => network.chainId.toString());
|
|
499
|
+
}
|
|
476
500
|
if (!this.session) {
|
|
477
501
|
return [];
|
|
478
502
|
}
|