@dynamic-labs/ethereum 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ## [1.4.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.3.1...v1.4.0) (2024-03-21)
3
+
4
+
5
+ ### Features
6
+
7
+ * add sign-in with farcaster ([#5059](https://github.com/dynamic-labs/DynamicAuth/issues/5059)) ([83245aa](https://github.com/dynamic-labs/DynamicAuth/commit/83245aa9f973ca349abcbaccf5d150b4a31beb0e)), closes [#4947](https://github.com/dynamic-labs/DynamicAuth/issues/4947)
8
+ * add prop to hide embedded wallet transaction UIs ([#4928](https://github.com/dynamic-labs/DynamicAuth/issues/4928)) ([b0ad954](https://github.com/dynamic-labs/DynamicAuth/commit/b0ad95494ebf991e61f09a23999c3526498f2db9)), closes [#4924](https://github.com/dynamic-labs/DynamicAuth/issues/4924)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * multiple wallet improvements
14
+ * multiple ui/ux improvements
15
+ * miscellaneous copy and localization updates
16
+ * add missing css variables for DynamicConnectButton
17
+
2
18
  ### [1.3.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.3.0...v1.3.1) (2024-03-08)
3
19
 
4
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -28,17 +28,16 @@
28
28
  "dependencies": {
29
29
  "@coinbase/wallet-sdk": "3.9.2",
30
30
  "@walletconnect/client": "1.8.0",
31
- "@walletconnect/ethereum-provider": "1.8.0",
32
- "@walletconnect/universal-provider": "2.10.6",
31
+ "@walletconnect/ethereum-provider": "2.11.2",
33
32
  "eventemitter3": "5.0.1",
34
33
  "buffer": "6.0.3",
35
- "@dynamic-labs/rpc-providers": "1.3.1",
36
- "@dynamic-labs/turnkey": "1.3.1",
37
- "@dynamic-labs/types": "1.3.1",
38
- "@dynamic-labs/utils": "1.3.1",
39
- "@dynamic-labs/viem-utils": "1.3.1",
40
- "@dynamic-labs/wallet-book": "1.3.1",
41
- "@dynamic-labs/wallet-connector-core": "1.3.1",
34
+ "@dynamic-labs/rpc-providers": "1.4.0",
35
+ "@dynamic-labs/turnkey": "1.4.0",
36
+ "@dynamic-labs/types": "1.4.0",
37
+ "@dynamic-labs/utils": "1.4.0",
38
+ "@dynamic-labs/viem-utils": "1.4.0",
39
+ "@dynamic-labs/wallet-book": "1.4.0",
40
+ "@dynamic-labs/wallet-connector-core": "1.4.0",
42
41
  "stream": "0.0.2"
43
42
  },
44
43
  "peerDependencies": {
@@ -5,15 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _tslib = require('../../_virtual/_tslib.cjs');
6
6
  var viem = require('viem');
7
7
  var walletBook = require('@dynamic-labs/wallet-book');
8
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
9
  require('../polyfills.cjs');
9
10
  require('@dynamic-labs/turnkey');
10
11
  require('@dynamic-labs/utils');
11
12
  var ethProviderHelper = require('../ethProviderHelper.cjs');
12
13
  var EthWalletConnector = require('../EthWalletConnector.cjs');
13
14
  require('../walletConnect/walletConnectV2.cjs');
14
- require('@walletconnect/ethereum-provider');
15
- require('@dynamic-labs/wallet-connector-core');
16
- require('@walletconnect/client');
17
15
  var client = require('./client/client.cjs');
18
16
 
19
17
  class Coinbase extends EthWalletConnector.EthWalletConnector {
@@ -36,6 +34,10 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
36
34
  }
37
35
  setupEventListeners() {
38
36
  var _a, _b, _c;
37
+ if (!this.isInstalledOnBrowser()) {
38
+ this.setupCoinbaseProviderEventListeners();
39
+ return;
40
+ }
39
41
  const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
40
42
  if (!provider) {
41
43
  return;
@@ -85,6 +87,23 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
85
87
  client.killCoinbaseSession();
86
88
  });
87
89
  }
90
+ setupCoinbaseProviderEventListeners() {
91
+ const provider = client.getCoinbaseProvider({
92
+ opts: this.coinbaseProviderOpts,
93
+ });
94
+ if (!provider) {
95
+ return;
96
+ }
97
+ const { handleAccountChange, handleChainChange, handleDisconnect } = walletConnectorCore.eventListenerHandlers(this);
98
+ provider.on('accountsChanged', handleAccountChange);
99
+ provider.on('chainChanged', handleChainChange);
100
+ provider.on('disconnect', handleDisconnect);
101
+ this.teardownEventListeners = () => {
102
+ provider.removeListener('accountsChanged', handleAccountChange);
103
+ provider.removeListener('chainChanged', handleChainChange);
104
+ provider.removeListener('disconnect', handleDisconnect);
105
+ };
106
+ }
88
107
  }
89
108
 
90
109
  exports.Coinbase = Coinbase;
@@ -533,5 +533,6 @@ export declare class Coinbase extends EthWalletConnector {
533
533
  fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
534
534
  signMessage(messageToSign: string): Promise<string | undefined>;
535
535
  endSession(): Promise<void>;
536
+ private setupCoinbaseProviderEventListeners;
536
537
  }
537
538
  export {};
@@ -1,15 +1,13 @@
1
1
  import { __rest, __awaiter } from '../../_virtual/_tslib.js';
2
2
  import { createWalletClient, custom } from 'viem';
3
3
  import { findWalletBookWallet } from '@dynamic-labs/wallet-book';
4
+ import { eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
4
5
  import '../polyfills.js';
5
6
  import '@dynamic-labs/turnkey';
6
7
  import '@dynamic-labs/utils';
7
8
  import { EthProviderHelper } from '../ethProviderHelper.js';
8
9
  import { EthWalletConnector } from '../EthWalletConnector.js';
9
10
  import '../walletConnect/walletConnectV2.js';
10
- import '@walletconnect/ethereum-provider';
11
- import '@dynamic-labs/wallet-connector-core';
12
- import '@walletconnect/client';
13
11
  import { getCoinbaseProvider, fetchPublicAddress, signMessage, killCoinbaseSession } from './client/client.js';
14
12
 
15
13
  class Coinbase extends EthWalletConnector {
@@ -32,6 +30,10 @@ class Coinbase extends EthWalletConnector {
32
30
  }
33
31
  setupEventListeners() {
34
32
  var _a, _b, _c;
33
+ if (!this.isInstalledOnBrowser()) {
34
+ this.setupCoinbaseProviderEventListeners();
35
+ return;
36
+ }
35
37
  const provider = (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findProvider();
36
38
  if (!provider) {
37
39
  return;
@@ -81,6 +83,23 @@ class Coinbase extends EthWalletConnector {
81
83
  killCoinbaseSession();
82
84
  });
83
85
  }
86
+ setupCoinbaseProviderEventListeners() {
87
+ const provider = getCoinbaseProvider({
88
+ opts: this.coinbaseProviderOpts,
89
+ });
90
+ if (!provider) {
91
+ return;
92
+ }
93
+ const { handleAccountChange, handleChainChange, handleDisconnect } = eventListenerHandlers(this);
94
+ provider.on('accountsChanged', handleAccountChange);
95
+ provider.on('chainChanged', handleChainChange);
96
+ provider.on('disconnect', handleDisconnect);
97
+ this.teardownEventListeners = () => {
98
+ provider.removeListener('accountsChanged', handleAccountChange);
99
+ provider.removeListener('chainChanged', handleChainChange);
100
+ provider.removeListener('disconnect', handleDisconnect);
101
+ };
102
+ }
84
103
  }
85
104
 
86
105
  export { Coinbase };
package/src/index.cjs CHANGED
@@ -9,23 +9,17 @@ var ExodusEvm = require('./injected/ExodusEvm.cjs');
9
9
  var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
10
10
  require('./walletConnect/walletConnectV2.cjs');
11
11
  require('../_virtual/_tslib.cjs');
12
- require('@walletconnect/ethereum-provider');
13
- require('viem');
14
- require('@dynamic-labs/wallet-connector-core');
15
- require('@dynamic-labs/wallet-book');
16
- require('@dynamic-labs/utils');
17
12
  var EthWalletConnector = require('./EthWalletConnector.cjs');
18
- var constants = require('./constants.cjs');
19
- require('@walletconnect/client');
20
13
  var fetchWalletConnectWallets = require('./walletConnect/fetchWalletConnectWallets.cjs');
21
14
  var coinbase = require('./coinbase/coinbase.cjs');
22
15
  var ethProviderHelper = require('./ethProviderHelper.cjs');
16
+ var constants = require('./constants.cjs');
23
17
 
24
18
  const EthereumWalletConnectors = (props) => [
25
19
  ...fetchInjectedWalletConnectors.injectedWalletOverrides,
26
20
  ...fetchInjectedWalletConnectors.fetchInjectedWalletConnector(props),
27
21
  ...fetchWalletConnectWallets.fetchWalletConnectWallets(props),
28
- ...turnkey.TurnkeyWalletConnectors(props),
22
+ ...turnkey.TurnkeyEVMWalletConnectors(props),
29
23
  coinbase.Coinbase,
30
24
  fetchWalletConnectWallets.getWalletConnectConnector(props),
31
25
  ];
@@ -35,6 +29,6 @@ exports.ExodusEvm = ExodusEvm.ExodusEvm;
35
29
  exports.fetchInjectedWalletConnector = fetchInjectedWalletConnectors.fetchInjectedWalletConnector;
36
30
  exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOverrides;
37
31
  exports.EthWalletConnector = EthWalletConnector.EthWalletConnector;
38
- exports.INFURA_ID = constants.INFURA_ID;
39
32
  exports.EthProviderHelper = ethProviderHelper.EthProviderHelper;
33
+ exports.INFURA_ID = constants.INFURA_ID;
40
34
  exports.EthereumWalletConnectors = EthereumWalletConnectors;
package/src/index.js CHANGED
@@ -1,28 +1,22 @@
1
1
  import './polyfills.js';
2
- import { TurnkeyWalletConnectors } from '@dynamic-labs/turnkey';
2
+ import { TurnkeyEVMWalletConnectors } from '@dynamic-labs/turnkey';
3
3
  export { PhantomEvm } from './injected/PhantomEvm.js';
4
4
  export { ExodusEvm } from './injected/ExodusEvm.js';
5
5
  import { injectedWalletOverrides, fetchInjectedWalletConnector } from './injected/fetchInjectedWalletConnectors.js';
6
6
  export { fetchInjectedWalletConnector, injectedWalletOverrides } from './injected/fetchInjectedWalletConnectors.js';
7
7
  import './walletConnect/walletConnectV2.js';
8
8
  import '../_virtual/_tslib.js';
9
- import '@walletconnect/ethereum-provider';
10
- import 'viem';
11
- import '@dynamic-labs/wallet-connector-core';
12
- import '@dynamic-labs/wallet-book';
13
- import '@dynamic-labs/utils';
14
9
  export { EthWalletConnector } from './EthWalletConnector.js';
15
- export { INFURA_ID } from './constants.js';
16
- import '@walletconnect/client';
17
10
  import { fetchWalletConnectWallets, getWalletConnectConnector } from './walletConnect/fetchWalletConnectWallets.js';
18
11
  import { Coinbase } from './coinbase/coinbase.js';
19
12
  export { EthProviderHelper } from './ethProviderHelper.js';
13
+ export { INFURA_ID } from './constants.js';
20
14
 
21
15
  const EthereumWalletConnectors = (props) => [
22
16
  ...injectedWalletOverrides,
23
17
  ...fetchInjectedWalletConnector(props),
24
18
  ...fetchWalletConnectWallets(props),
25
- ...TurnkeyWalletConnectors(props),
19
+ ...TurnkeyEVMWalletConnectors(props),
26
20
  Coinbase,
27
21
  getWalletConnectConnector(props),
28
22
  ];
@@ -3,153 +3,19 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../../_virtual/_tslib.cjs');
6
- var WalletConnectProvider = require('@walletconnect/ethereum-provider');
7
- var viem = require('viem');
8
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
- var walletBook = require('@dynamic-labs/wallet-book');
10
- var utils = require('@dynamic-labs/utils');
11
6
  var EthWalletConnector = require('../EthWalletConnector.cjs');
12
- var constants = require('../constants.cjs');
13
- var client = require('./client/client.cjs');
14
-
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var WalletConnectProvider__default = /*#__PURE__*/_interopDefaultLegacy(WalletConnectProvider);
18
7
 
19
8
  class WalletConnect extends EthWalletConnector.EthWalletConnector {
20
9
  constructor(_a) {
21
- var { walletConnectV1Bridge, walletName } = _a, props = _tslib.__rest(_a, ["walletConnectV1Bridge", "walletName"]);
10
+ var { walletName } = _a, props = _tslib.__rest(_a, ["walletName"]);
22
11
  super(props);
23
12
  this.supportedChains = ['EVM', 'ETH'];
24
13
  this.connectedChain = 'EVM';
25
14
  this.bridge = 'https://bridge.walletconnect.org';
26
- this.canConnectViaQrCode = true;
27
- this.isWalletConnect = true;
28
- this.switchNetworkOnlyFromWallet = false;
29
15
  this.name = walletName;
30
- if (walletConnectV1Bridge) {
31
- this.bridge = walletConnectV1Bridge;
32
- }
33
- this.deepLinkPreference = props.deepLinkPreference || 'native';
34
- }
35
- getClient() {
36
- if (this.client) {
37
- return this.client;
38
- }
39
- this.client = client.initClient(this.key, this.bridge, this.clientOptions);
40
- return this.client;
41
- }
42
- supportsNetworkSwitching() {
43
- if (this.connectedChain === 'EVM') {
44
- return true;
45
- }
46
- else {
47
- const client = this.getClient();
48
- return Boolean(client === null || client === void 0 ? void 0 : client.chainId);
49
- }
50
- }
51
- setupEventListeners() {
52
- client.setupWalletConnectEventListeners(this, this.getClient());
53
- }
54
- teardownEventListeners() {
55
- client.teardownWalletConnectEventListeners(this.getClient());
56
16
  }
57
17
  getWalletClient() {
58
- const client = this.getClient();
59
- return client
60
- ? viem.createWalletClient({
61
- transport: viem.custom(new WalletConnectProvider__default["default"]({
62
- connector: client,
63
- infuraId: constants.INFURA_ID,
64
- rpc: this.evmNetworkRpcMap(),
65
- })),
66
- })
67
- : undefined;
68
- }
69
- fetchPublicAddress(opts) {
70
- return _tslib.__awaiter(this, void 0, void 0, function* () {
71
- return client.fetchWalletConnectEVMPublicAddress(walletBook.getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference, Object.assign(Object.assign({}, opts), { onConnect: (payload) => {
72
- var _a, _b;
73
- (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
74
- this.connectedChain = payload.params[0].chainId ? 'EVM' : 'SOL';
75
- if ((_b = payload.params[0].accounts) === null || _b === void 0 ? void 0 : _b.length) {
76
- this.emit('accountChange', {
77
- accounts: payload.params[0].accounts,
78
- });
79
- }
80
- } }));
81
- });
82
- }
83
- getDeepLink() {
84
- var _a;
85
- const wallet = walletBook.getWalletBookWallet(this.walletBook, this.key);
86
- if (!utils.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
87
- return undefined;
88
- }
89
- return walletConnectorCore.getDeepLink({
90
- metadata: wallet,
91
- mode: 'regular',
92
- preference: this.deepLinkPreference,
93
- uri: this.getClient().uri,
94
- });
95
- }
96
- signMessage(messageToSign) {
97
- return _tslib.__awaiter(this, void 0, void 0, function* () {
98
- return client.signWalletConnectPersonalMessage(messageToSign, walletBook.getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference,
99
- // don't call getPublicClient until we really need to
100
- () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.getPublicClient(); }));
101
- });
102
- }
103
- endSession() {
104
- return _tslib.__awaiter(this, void 0, void 0, function* () {
105
- client.killWalletConnectSession(this.getClient());
106
- });
107
- }
108
- providerSwitchNetwork({ network, provider, }) {
109
- const _super = Object.create(null, {
110
- providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
111
- });
112
- return _tslib.__awaiter(this, void 0, void 0, function* () {
113
- const client = this.getClient();
114
- const currentNetworkId = yield this.getNetwork();
115
- if (currentNetworkId && currentNetworkId === network.chainId) {
116
- return;
117
- }
118
- if (this.switchNetworkOnlyFromWallet !== undefined &&
119
- this.switchNetworkOnlyFromWallet) {
120
- throw new utils.DynamicError('Network switching is only supported through the wallet');
121
- }
122
- if (!this.supportsNetworkSwitching()) {
123
- throw new utils.DynamicError('Network switching not supported');
124
- }
125
- if (!client) {
126
- throw new utils.DynamicError('Client not found');
127
- }
128
- if (utils.isMobile()) {
129
- const deepLink = walletConnectorCore.getDeepLink({
130
- metadata: walletBook.getWalletBookWallet(this.walletBook, this.key),
131
- mode: 'regular',
132
- preference: this.deepLinkPreference,
133
- uri: client.uri,
134
- });
135
- window.location.href = deepLink;
136
- }
137
- return _super.providerSwitchNetwork.call(this, { network, provider });
138
- });
139
- }
140
- getConnectedAccounts() {
141
- return _tslib.__awaiter(this, void 0, void 0, function* () {
142
- const client = this.getClient();
143
- if (!client.connected)
144
- return [];
145
- return client.accounts;
146
- });
147
- }
148
- getSession() {
149
- var _a;
150
- return _tslib.__awaiter(this, void 0, void 0, function* () {
151
- return (_a = this.client) === null || _a === void 0 ? void 0 : _a.session;
152
- });
18
+ return undefined;
153
19
  }
154
20
  }
155
21
 
@@ -1,52 +1,13 @@
1
- import Client from '@walletconnect/client';
2
- import { Hex, WalletClient } from 'viem';
3
- import { Chain, FetchPublicAddressOpts, DeepLinkVariant } from '@dynamic-labs/wallet-connector-core';
4
- import { EvmNetwork } from '@dynamic-labs/types';
1
+ import { Chain } from '@dynamic-labs/wallet-connector-core';
5
2
  import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
6
- type ConnectorSession = {
7
- connected: boolean;
8
- accounts: string[];
9
- chainId: number;
10
- bridge: string;
11
- key: string;
12
- clientId: string;
13
- clientMeta: any;
14
- peerId: string;
15
- peerMeta: any;
16
- handshakeId: number;
17
- handshakeTopic: string;
18
- };
19
3
  export type WalletConnectOpts = EthWalletConnectorOpts & {
20
- walletConnectV1Bridge: string;
21
4
  walletName: string;
22
- deepLinkPreference?: DeepLinkVariant;
23
5
  };
24
6
  export declare class WalletConnect extends EthWalletConnector {
25
7
  supportedChains: Chain[];
26
8
  connectedChain: Chain;
27
9
  name: string;
28
10
  bridge: string;
29
- canConnectViaQrCode: boolean;
30
- isWalletConnect: boolean;
31
- switchNetworkOnlyFromWallet: boolean;
32
- private deepLinkPreference;
33
- client?: Client;
34
- clientOptions?: any;
35
- constructor({ walletConnectV1Bridge, walletName, ...props }: WalletConnectOpts);
36
- getClient(): Client;
37
- supportsNetworkSwitching(): boolean;
38
- setupEventListeners(): void;
39
- teardownEventListeners(): void;
40
- getWalletClient(): WalletClient | undefined;
41
- fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
42
- getDeepLink(): string | undefined;
43
- signMessage(messageToSign: string): Promise<string | undefined>;
44
- endSession(): Promise<void>;
45
- providerSwitchNetwork({ network, provider, }: {
46
- network: EvmNetwork;
47
- provider: WalletClient;
48
- }): Promise<void>;
49
- getConnectedAccounts(): Promise<Hex[]>;
50
- getSession(): Promise<ConnectorSession | undefined>;
11
+ constructor({ walletName, ...props }: WalletConnectOpts);
12
+ getWalletClient(): undefined;
51
13
  }
52
- export {};
@@ -1,147 +1,17 @@
1
- import { __rest, __awaiter } from '../../_virtual/_tslib.js';
2
- import WalletConnectProvider from '@walletconnect/ethereum-provider';
3
- import { createWalletClient, custom } from 'viem';
4
- import { getDeepLink } from '@dynamic-labs/wallet-connector-core';
5
- import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
6
- import { isMobile, DynamicError } from '@dynamic-labs/utils';
1
+ import { __rest } from '../../_virtual/_tslib.js';
7
2
  import { EthWalletConnector } from '../EthWalletConnector.js';
8
- import { INFURA_ID } from '../constants.js';
9
- import { initClient, setupWalletConnectEventListeners, teardownWalletConnectEventListeners, fetchWalletConnectEVMPublicAddress, signWalletConnectPersonalMessage, killWalletConnectSession } from './client/client.js';
10
3
 
11
4
  class WalletConnect extends EthWalletConnector {
12
5
  constructor(_a) {
13
- var { walletConnectV1Bridge, walletName } = _a, props = __rest(_a, ["walletConnectV1Bridge", "walletName"]);
6
+ var { walletName } = _a, props = __rest(_a, ["walletName"]);
14
7
  super(props);
15
8
  this.supportedChains = ['EVM', 'ETH'];
16
9
  this.connectedChain = 'EVM';
17
10
  this.bridge = 'https://bridge.walletconnect.org';
18
- this.canConnectViaQrCode = true;
19
- this.isWalletConnect = true;
20
- this.switchNetworkOnlyFromWallet = false;
21
11
  this.name = walletName;
22
- if (walletConnectV1Bridge) {
23
- this.bridge = walletConnectV1Bridge;
24
- }
25
- this.deepLinkPreference = props.deepLinkPreference || 'native';
26
- }
27
- getClient() {
28
- if (this.client) {
29
- return this.client;
30
- }
31
- this.client = initClient(this.key, this.bridge, this.clientOptions);
32
- return this.client;
33
- }
34
- supportsNetworkSwitching() {
35
- if (this.connectedChain === 'EVM') {
36
- return true;
37
- }
38
- else {
39
- const client = this.getClient();
40
- return Boolean(client === null || client === void 0 ? void 0 : client.chainId);
41
- }
42
- }
43
- setupEventListeners() {
44
- setupWalletConnectEventListeners(this, this.getClient());
45
- }
46
- teardownEventListeners() {
47
- teardownWalletConnectEventListeners(this.getClient());
48
12
  }
49
13
  getWalletClient() {
50
- const client = this.getClient();
51
- return client
52
- ? createWalletClient({
53
- transport: custom(new WalletConnectProvider({
54
- connector: client,
55
- infuraId: INFURA_ID,
56
- rpc: this.evmNetworkRpcMap(),
57
- })),
58
- })
59
- : undefined;
60
- }
61
- fetchPublicAddress(opts) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- return fetchWalletConnectEVMPublicAddress(getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference, Object.assign(Object.assign({}, opts), { onConnect: (payload) => {
64
- var _a, _b;
65
- (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
66
- this.connectedChain = payload.params[0].chainId ? 'EVM' : 'SOL';
67
- if ((_b = payload.params[0].accounts) === null || _b === void 0 ? void 0 : _b.length) {
68
- this.emit('accountChange', {
69
- accounts: payload.params[0].accounts,
70
- });
71
- }
72
- } }));
73
- });
74
- }
75
- getDeepLink() {
76
- var _a;
77
- const wallet = getWalletBookWallet(this.walletBook, this.key);
78
- if (!isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
79
- return undefined;
80
- }
81
- return getDeepLink({
82
- metadata: wallet,
83
- mode: 'regular',
84
- preference: this.deepLinkPreference,
85
- uri: this.getClient().uri,
86
- });
87
- }
88
- signMessage(messageToSign) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- return signWalletConnectPersonalMessage(messageToSign, getWalletBookWallet(this.walletBook, this.key), this.getClient(), this.deepLinkPreference,
91
- // don't call getPublicClient until we really need to
92
- () => __awaiter(this, void 0, void 0, function* () { return this.getPublicClient(); }));
93
- });
94
- }
95
- endSession() {
96
- return __awaiter(this, void 0, void 0, function* () {
97
- killWalletConnectSession(this.getClient());
98
- });
99
- }
100
- providerSwitchNetwork({ network, provider, }) {
101
- const _super = Object.create(null, {
102
- providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
103
- });
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const client = this.getClient();
106
- const currentNetworkId = yield this.getNetwork();
107
- if (currentNetworkId && currentNetworkId === network.chainId) {
108
- return;
109
- }
110
- if (this.switchNetworkOnlyFromWallet !== undefined &&
111
- this.switchNetworkOnlyFromWallet) {
112
- throw new DynamicError('Network switching is only supported through the wallet');
113
- }
114
- if (!this.supportsNetworkSwitching()) {
115
- throw new DynamicError('Network switching not supported');
116
- }
117
- if (!client) {
118
- throw new DynamicError('Client not found');
119
- }
120
- if (isMobile()) {
121
- const deepLink = getDeepLink({
122
- metadata: getWalletBookWallet(this.walletBook, this.key),
123
- mode: 'regular',
124
- preference: this.deepLinkPreference,
125
- uri: client.uri,
126
- });
127
- window.location.href = deepLink;
128
- }
129
- return _super.providerSwitchNetwork.call(this, { network, provider });
130
- });
131
- }
132
- getConnectedAccounts() {
133
- return __awaiter(this, void 0, void 0, function* () {
134
- const client = this.getClient();
135
- if (!client.connected)
136
- return [];
137
- return client.accounts;
138
- });
139
- }
140
- getSession() {
141
- var _a;
142
- return __awaiter(this, void 0, void 0, function* () {
143
- return (_a = this.client) === null || _a === void 0 ? void 0 : _a.session;
144
- });
14
+ return undefined;
145
15
  }
146
16
  }
147
17