@dynamic-labs/ethereum 2.0.0-alpha.20 → 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 +49 -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 +95 -62
- package/src/walletConnect/walletConnect.d.ts +14 -11
- package/src/walletConnect/walletConnect.js +94 -61
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,53 @@
|
|
|
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
|
+
|
|
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)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
* implement barebones signer in PhantomRedirect connector ([#5043](https://github.com/dynamic-labs/DynamicAuth/issues/5043)) ([4d7ff79](https://github.com/dynamic-labs/DynamicAuth/commit/4d7ff79acfe554d651791139b5e1d23ebafe712c))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Bug Fixes
|
|
47
|
+
|
|
48
|
+
* find embedded wallets when no chain is specified ([#5036](https://github.com/dynamic-labs/DynamicAuth/issues/5036)) ([ac50742](https://github.com/dynamic-labs/DynamicAuth/commit/ac50742c6002f48aae7b60c9ec094eb12df8dcca))
|
|
49
|
+
* ignore walletconnect chainChange event when it's the same chain ([#5029](https://github.com/dynamic-labs/DynamicAuth/issues/5029)) ([115311a](https://github.com/dynamic-labs/DynamicAuth/commit/115311a4a64ae35317b8864f93c38203566714fc))
|
|
50
|
+
|
|
2
51
|
## [2.0.0-alpha.20](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.19...v2.0.0-alpha.20) (2024-03-19)
|
|
3
52
|
|
|
4
53
|
|
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,
|
|
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),
|
|
106
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');
|
|
@@ -191,12 +201,17 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
191
201
|
const { name, data } = params.event;
|
|
192
202
|
if (name === 'chainChanged') {
|
|
193
203
|
const chainId = parseIntSafe.parseIntSafe(data);
|
|
204
|
+
if (chainId === this.currentChainId) {
|
|
205
|
+
walletConnectorCore.logger.debug(`ignoring chainChanged event with same chain id as current chain id: ${chainId}`);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
194
208
|
if (chainId === undefined) {
|
|
195
209
|
walletConnectorCore.logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
196
210
|
return;
|
|
197
211
|
}
|
|
198
212
|
this.currentChainId = chainId;
|
|
199
213
|
this.emit('chainChange', { chain: String(chainId) });
|
|
214
|
+
this.hasSwitchedNetwork = true;
|
|
200
215
|
// When a user switches network from their wallet, we need the provider to change network
|
|
201
216
|
// such that any future calls to `getNetwork` will return the correct network
|
|
202
217
|
this.switchNetwork({ networkChainId: chainId });
|
|
@@ -210,18 +225,20 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
210
225
|
const account = data[0].split(':')[2];
|
|
211
226
|
this.setActiveAccount(account);
|
|
212
227
|
}
|
|
213
|
-
}
|
|
214
|
-
WalletConnect.provider.
|
|
228
|
+
};
|
|
229
|
+
WalletConnect.provider.on('session_event', this.sessionEventHandler);
|
|
230
|
+
this.sessionDeleteHandler = () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
215
231
|
this.endSession();
|
|
216
232
|
this.emit('disconnect');
|
|
217
|
-
})
|
|
233
|
+
});
|
|
234
|
+
WalletConnect.provider.on('session_delete', this.sessionDeleteHandler);
|
|
218
235
|
}
|
|
219
236
|
teardownEventListeners() {
|
|
220
237
|
if (!WalletConnect.provider) {
|
|
221
238
|
return;
|
|
222
239
|
}
|
|
223
|
-
WalletConnect.provider.
|
|
224
|
-
WalletConnect.provider.
|
|
240
|
+
WalletConnect.provider.off('session_event', this.sessionEventHandler);
|
|
241
|
+
WalletConnect.provider.off('session_delete', this.sessionDeleteHandler);
|
|
225
242
|
}
|
|
226
243
|
getWalletClient(chainId) {
|
|
227
244
|
if (!WalletConnect.provider) {
|
|
@@ -229,7 +246,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
229
246
|
}
|
|
230
247
|
return viem.createWalletClient({
|
|
231
248
|
account: this.activeAccount ? accounts.toAccount(this.activeAccount) : undefined,
|
|
232
|
-
chain:
|
|
249
|
+
chain: viemUtils.chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
|
|
233
250
|
transport: viem.custom(WalletConnect.provider),
|
|
234
251
|
});
|
|
235
252
|
}
|
|
@@ -239,7 +256,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
239
256
|
if (this.activeAccount) {
|
|
240
257
|
return this.activeAccount;
|
|
241
258
|
}
|
|
242
|
-
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)) {
|
|
243
260
|
walletConnectorCore.logger.debug('No WC2 provider found, re-initializing...');
|
|
244
261
|
yield this.endSession();
|
|
245
262
|
yield this.init();
|
|
@@ -249,13 +266,13 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
249
266
|
// finish setting up the connection URI and making it available
|
|
250
267
|
// on the provider
|
|
251
268
|
yield utils.sleep(1000);
|
|
252
|
-
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)) {
|
|
253
270
|
walletConnectorCore.logger.debug('No WC2 provider found, escaping and throwing error');
|
|
254
271
|
throw new utils.DynamicError('No provider found');
|
|
255
272
|
}
|
|
256
273
|
}
|
|
257
274
|
const metadata = walletBook.getWalletBookWallet(this.walletBook, this.key);
|
|
258
|
-
walletConnectorCore.performPlatformSpecificConnectionMethod(WalletConnect.provider.uri, metadata, {
|
|
275
|
+
walletConnectorCore.performPlatformSpecificConnectionMethod(WalletConnect.provider.signer.uri, metadata, {
|
|
259
276
|
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
260
277
|
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
261
278
|
}, this.deepLinkPreference);
|
|
@@ -268,7 +285,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
268
285
|
const error = new utils.DynamicError('Connection rejected. Please try again.');
|
|
269
286
|
error.code = 'connection_rejected';
|
|
270
287
|
if (WalletConnect.provider) {
|
|
271
|
-
WalletConnect.provider.uri = undefined;
|
|
288
|
+
WalletConnect.provider.signer.uri = undefined;
|
|
272
289
|
// this is needed for mobile to work when using universal links.
|
|
273
290
|
// if the user cancels the connection, we need to re-initialize the provider
|
|
274
291
|
// so that the async work is done ahead of time, before the user tries to connect again,
|
|
@@ -280,13 +297,19 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
280
297
|
// whenever the connection attempt either succeeds or fails
|
|
281
298
|
cleanupListeners();
|
|
282
299
|
};
|
|
283
|
-
const onConnect = (
|
|
300
|
+
const onConnect = () => {
|
|
301
|
+
var _a;
|
|
302
|
+
const session = (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.session;
|
|
284
303
|
if (!session) {
|
|
285
304
|
reject(new utils.DynamicError('No session found'));
|
|
305
|
+
return;
|
|
286
306
|
}
|
|
287
307
|
this.setSession(session);
|
|
288
308
|
this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
289
|
-
|
|
309
|
+
this.getNetwork().then((chainId) => {
|
|
310
|
+
this.currentChainId = chainId;
|
|
311
|
+
resolve(this.activeAccount);
|
|
312
|
+
});
|
|
290
313
|
// We must clean up the onConnect and onFail listeners
|
|
291
314
|
// whenever the connection attempt either succeeds or fails
|
|
292
315
|
cleanupListeners();
|
|
@@ -314,10 +337,12 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
314
337
|
*/
|
|
315
338
|
waitForSignMessage(signMessageFn, messageToSign) {
|
|
316
339
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
317
|
-
const raceConditionPromise = new Promise((resolve) => {
|
|
340
|
+
const raceConditionPromise = new Promise((resolve, reject) => {
|
|
318
341
|
// Create listener for chain change event
|
|
319
342
|
this.on('chainChange', () => resolve({ success: false }));
|
|
320
|
-
signMessageFn(messageToSign)
|
|
343
|
+
signMessageFn(messageToSign)
|
|
344
|
+
.then((result) => resolve({ signedMessage: result, success: true }))
|
|
345
|
+
.catch(reject);
|
|
321
346
|
});
|
|
322
347
|
const signedMessageResult = yield raceConditionPromise;
|
|
323
348
|
if (signedMessageResult.success === false) {
|
|
@@ -336,7 +361,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
336
361
|
metadata,
|
|
337
362
|
mode: 'regular',
|
|
338
363
|
preference: this.deepLinkPreference,
|
|
339
|
-
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,
|
|
340
365
|
});
|
|
341
366
|
if (!deepLink) {
|
|
342
367
|
return;
|
|
@@ -350,10 +375,6 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
350
375
|
if (!this.session) {
|
|
351
376
|
throw new utils.DynamicError('no session');
|
|
352
377
|
}
|
|
353
|
-
const web3Provider = this.getWalletClient();
|
|
354
|
-
if (!web3Provider) {
|
|
355
|
-
throw new utils.DynamicError('No WalletConnect provider found to handle signing');
|
|
356
|
-
}
|
|
357
378
|
const deepLink = this.getDeepLink();
|
|
358
379
|
if (utils.isMobile() && deepLink) {
|
|
359
380
|
window.location.href = deepLink;
|
|
@@ -363,7 +384,8 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
363
384
|
if (!activeAccount) {
|
|
364
385
|
return;
|
|
365
386
|
}
|
|
366
|
-
|
|
387
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
388
|
+
return walletClient.signMessage({
|
|
367
389
|
account: activeAccount,
|
|
368
390
|
message: messageToSign,
|
|
369
391
|
});
|
|
@@ -422,11 +444,17 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
422
444
|
return _super.getNetwork.call(this);
|
|
423
445
|
});
|
|
424
446
|
}
|
|
425
|
-
providerSwitchNetwork({ network,
|
|
447
|
+
providerSwitchNetwork({ network, }) {
|
|
426
448
|
const _super = Object.create(null, {
|
|
427
449
|
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
428
450
|
});
|
|
429
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
|
+
}
|
|
430
458
|
const currentNetworkId = yield this.getNetwork();
|
|
431
459
|
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
432
460
|
return;
|
|
@@ -437,10 +465,14 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
437
465
|
if (!this.supportsNetworkSwitching()) {
|
|
438
466
|
throw new utils.DynamicError('Network switching not supported');
|
|
439
467
|
}
|
|
440
|
-
|
|
441
|
-
|
|
468
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
469
|
+
if (this.isMetaMask()) {
|
|
470
|
+
const deepLink = this.getDeepLink();
|
|
471
|
+
if (deepLink) {
|
|
472
|
+
window.location.href = deepLink;
|
|
473
|
+
}
|
|
442
474
|
}
|
|
443
|
-
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
475
|
+
yield _super.providerSwitchNetwork.call(this, { network, provider: walletClient });
|
|
444
476
|
this.currentChainId = network.chainId;
|
|
445
477
|
this.hasSwitchedNetwork = true;
|
|
446
478
|
this.emit('chainChange', { chain: String(network.chainId) });
|
|
@@ -466,13 +498,14 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
466
498
|
getSupportedNetworks() {
|
|
467
499
|
var _a;
|
|
468
500
|
return _tslib.__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
501
|
yield this.initProvider();
|
|
475
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
|
+
}
|
|
476
509
|
if (!this.session) {
|
|
477
510
|
return [];
|
|
478
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,
|
|
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),
|
|
97
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');
|
|
@@ -182,12 +192,17 @@ class WalletConnect extends EthWalletConnector {
|
|
|
182
192
|
const { name, data } = params.event;
|
|
183
193
|
if (name === 'chainChanged') {
|
|
184
194
|
const chainId = parseIntSafe(data);
|
|
195
|
+
if (chainId === this.currentChainId) {
|
|
196
|
+
logger.debug(`ignoring chainChanged event with same chain id as current chain id: ${chainId}`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
185
199
|
if (chainId === undefined) {
|
|
186
200
|
logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
187
201
|
return;
|
|
188
202
|
}
|
|
189
203
|
this.currentChainId = chainId;
|
|
190
204
|
this.emit('chainChange', { chain: String(chainId) });
|
|
205
|
+
this.hasSwitchedNetwork = true;
|
|
191
206
|
// When a user switches network from their wallet, we need the provider to change network
|
|
192
207
|
// such that any future calls to `getNetwork` will return the correct network
|
|
193
208
|
this.switchNetwork({ networkChainId: chainId });
|
|
@@ -201,18 +216,20 @@ class WalletConnect extends EthWalletConnector {
|
|
|
201
216
|
const account = data[0].split(':')[2];
|
|
202
217
|
this.setActiveAccount(account);
|
|
203
218
|
}
|
|
204
|
-
}
|
|
205
|
-
WalletConnect.provider.
|
|
219
|
+
};
|
|
220
|
+
WalletConnect.provider.on('session_event', this.sessionEventHandler);
|
|
221
|
+
this.sessionDeleteHandler = () => __awaiter(this, void 0, void 0, function* () {
|
|
206
222
|
this.endSession();
|
|
207
223
|
this.emit('disconnect');
|
|
208
|
-
})
|
|
224
|
+
});
|
|
225
|
+
WalletConnect.provider.on('session_delete', this.sessionDeleteHandler);
|
|
209
226
|
}
|
|
210
227
|
teardownEventListeners() {
|
|
211
228
|
if (!WalletConnect.provider) {
|
|
212
229
|
return;
|
|
213
230
|
}
|
|
214
|
-
WalletConnect.provider.
|
|
215
|
-
WalletConnect.provider.
|
|
231
|
+
WalletConnect.provider.off('session_event', this.sessionEventHandler);
|
|
232
|
+
WalletConnect.provider.off('session_delete', this.sessionDeleteHandler);
|
|
216
233
|
}
|
|
217
234
|
getWalletClient(chainId) {
|
|
218
235
|
if (!WalletConnect.provider) {
|
|
@@ -220,7 +237,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
220
237
|
}
|
|
221
238
|
return createWalletClient({
|
|
222
239
|
account: this.activeAccount ? toAccount(this.activeAccount) : undefined,
|
|
223
|
-
chain: chainId ?
|
|
240
|
+
chain: chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
|
|
224
241
|
transport: custom(WalletConnect.provider),
|
|
225
242
|
});
|
|
226
243
|
}
|
|
@@ -230,7 +247,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
230
247
|
if (this.activeAccount) {
|
|
231
248
|
return this.activeAccount;
|
|
232
249
|
}
|
|
233
|
-
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)) {
|
|
234
251
|
logger.debug('No WC2 provider found, re-initializing...');
|
|
235
252
|
yield this.endSession();
|
|
236
253
|
yield this.init();
|
|
@@ -240,13 +257,13 @@ class WalletConnect extends EthWalletConnector {
|
|
|
240
257
|
// finish setting up the connection URI and making it available
|
|
241
258
|
// on the provider
|
|
242
259
|
yield sleep(1000);
|
|
243
|
-
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)) {
|
|
244
261
|
logger.debug('No WC2 provider found, escaping and throwing error');
|
|
245
262
|
throw new DynamicError('No provider found');
|
|
246
263
|
}
|
|
247
264
|
}
|
|
248
265
|
const metadata = getWalletBookWallet(this.walletBook, this.key);
|
|
249
|
-
performPlatformSpecificConnectionMethod(WalletConnect.provider.uri, metadata, {
|
|
266
|
+
performPlatformSpecificConnectionMethod(WalletConnect.provider.signer.uri, metadata, {
|
|
250
267
|
onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
|
|
251
268
|
onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
|
|
252
269
|
}, this.deepLinkPreference);
|
|
@@ -259,7 +276,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
259
276
|
const error = new DynamicError('Connection rejected. Please try again.');
|
|
260
277
|
error.code = 'connection_rejected';
|
|
261
278
|
if (WalletConnect.provider) {
|
|
262
|
-
WalletConnect.provider.uri = undefined;
|
|
279
|
+
WalletConnect.provider.signer.uri = undefined;
|
|
263
280
|
// this is needed for mobile to work when using universal links.
|
|
264
281
|
// if the user cancels the connection, we need to re-initialize the provider
|
|
265
282
|
// so that the async work is done ahead of time, before the user tries to connect again,
|
|
@@ -271,13 +288,19 @@ class WalletConnect extends EthWalletConnector {
|
|
|
271
288
|
// whenever the connection attempt either succeeds or fails
|
|
272
289
|
cleanupListeners();
|
|
273
290
|
};
|
|
274
|
-
const onConnect = (
|
|
291
|
+
const onConnect = () => {
|
|
292
|
+
var _a;
|
|
293
|
+
const session = (_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.session;
|
|
275
294
|
if (!session) {
|
|
276
295
|
reject(new DynamicError('No session found'));
|
|
296
|
+
return;
|
|
277
297
|
}
|
|
278
298
|
this.setSession(session);
|
|
279
299
|
this.setActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
280
|
-
|
|
300
|
+
this.getNetwork().then((chainId) => {
|
|
301
|
+
this.currentChainId = chainId;
|
|
302
|
+
resolve(this.activeAccount);
|
|
303
|
+
});
|
|
281
304
|
// We must clean up the onConnect and onFail listeners
|
|
282
305
|
// whenever the connection attempt either succeeds or fails
|
|
283
306
|
cleanupListeners();
|
|
@@ -305,10 +328,12 @@ class WalletConnect extends EthWalletConnector {
|
|
|
305
328
|
*/
|
|
306
329
|
waitForSignMessage(signMessageFn, messageToSign) {
|
|
307
330
|
return __awaiter(this, void 0, void 0, function* () {
|
|
308
|
-
const raceConditionPromise = new Promise((resolve) => {
|
|
331
|
+
const raceConditionPromise = new Promise((resolve, reject) => {
|
|
309
332
|
// Create listener for chain change event
|
|
310
333
|
this.on('chainChange', () => resolve({ success: false }));
|
|
311
|
-
signMessageFn(messageToSign)
|
|
334
|
+
signMessageFn(messageToSign)
|
|
335
|
+
.then((result) => resolve({ signedMessage: result, success: true }))
|
|
336
|
+
.catch(reject);
|
|
312
337
|
});
|
|
313
338
|
const signedMessageResult = yield raceConditionPromise;
|
|
314
339
|
if (signedMessageResult.success === false) {
|
|
@@ -327,7 +352,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
327
352
|
metadata,
|
|
328
353
|
mode: 'regular',
|
|
329
354
|
preference: this.deepLinkPreference,
|
|
330
|
-
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,
|
|
331
356
|
});
|
|
332
357
|
if (!deepLink) {
|
|
333
358
|
return;
|
|
@@ -341,10 +366,6 @@ class WalletConnect extends EthWalletConnector {
|
|
|
341
366
|
if (!this.session) {
|
|
342
367
|
throw new DynamicError('no session');
|
|
343
368
|
}
|
|
344
|
-
const web3Provider = this.getWalletClient();
|
|
345
|
-
if (!web3Provider) {
|
|
346
|
-
throw new DynamicError('No WalletConnect provider found to handle signing');
|
|
347
|
-
}
|
|
348
369
|
const deepLink = this.getDeepLink();
|
|
349
370
|
if (isMobile() && deepLink) {
|
|
350
371
|
window.location.href = deepLink;
|
|
@@ -354,7 +375,8 @@ class WalletConnect extends EthWalletConnector {
|
|
|
354
375
|
if (!activeAccount) {
|
|
355
376
|
return;
|
|
356
377
|
}
|
|
357
|
-
|
|
378
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
379
|
+
return walletClient.signMessage({
|
|
358
380
|
account: activeAccount,
|
|
359
381
|
message: messageToSign,
|
|
360
382
|
});
|
|
@@ -413,11 +435,17 @@ class WalletConnect extends EthWalletConnector {
|
|
|
413
435
|
return _super.getNetwork.call(this);
|
|
414
436
|
});
|
|
415
437
|
}
|
|
416
|
-
providerSwitchNetwork({ network,
|
|
438
|
+
providerSwitchNetwork({ network, }) {
|
|
417
439
|
const _super = Object.create(null, {
|
|
418
440
|
providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
|
|
419
441
|
});
|
|
420
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
|
+
}
|
|
421
449
|
const currentNetworkId = yield this.getNetwork();
|
|
422
450
|
if (currentNetworkId && currentNetworkId === network.chainId) {
|
|
423
451
|
return;
|
|
@@ -428,10 +456,14 @@ class WalletConnect extends EthWalletConnector {
|
|
|
428
456
|
if (!this.supportsNetworkSwitching()) {
|
|
429
457
|
throw new DynamicError('Network switching not supported');
|
|
430
458
|
}
|
|
431
|
-
|
|
432
|
-
|
|
459
|
+
const walletClient = yield this.getWalletClientFromInitializedProvider();
|
|
460
|
+
if (this.isMetaMask()) {
|
|
461
|
+
const deepLink = this.getDeepLink();
|
|
462
|
+
if (deepLink) {
|
|
463
|
+
window.location.href = deepLink;
|
|
464
|
+
}
|
|
433
465
|
}
|
|
434
|
-
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
466
|
+
yield _super.providerSwitchNetwork.call(this, { network, provider: walletClient });
|
|
435
467
|
this.currentChainId = network.chainId;
|
|
436
468
|
this.hasSwitchedNetwork = true;
|
|
437
469
|
this.emit('chainChange', { chain: String(network.chainId) });
|
|
@@ -457,13 +489,14 @@ class WalletConnect extends EthWalletConnector {
|
|
|
457
489
|
getSupportedNetworks() {
|
|
458
490
|
var _a;
|
|
459
491
|
return __awaiter(this, void 0, void 0, function* () {
|
|
460
|
-
// MM allows you to switch to any network the first time, even if it's not enabled in MM
|
|
461
|
-
// so we should consider all networks as supported if network switching hasn't been triggered yet
|
|
462
|
-
if (this.isMetaMask() && !this.hasSwitchedNetwork) {
|
|
463
|
-
return this.evmNetworks.map((network) => network.chainId.toString());
|
|
464
|
-
}
|
|
465
492
|
yield this.initProvider();
|
|
466
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
|
+
}
|
|
467
500
|
if (!this.session) {
|
|
468
501
|
return [];
|
|
469
502
|
}
|