@dynamic-labs/ethereum 1.3.0 → 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,29 @@
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
+
18
+ ### [1.3.1](https://github.com/dynamic-labs/DynamicAuth/compare/v1.3.0...v1.3.1) (2024-03-08)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * pass account and chain to walletClient ([#4865](https://github.com/dynamic-labs/DynamicAuth/issues/4865)) ([#4905](https://github.com/dynamic-labs/DynamicAuth/issues/4905)) ([0f4e79f](https://github.com/dynamic-labs/DynamicAuth/commit/0f4e79ff36f8a3ef63c59bb9f80429cdefbe7307))
24
+ * update btckit network conversion for signpsbt to use correct network ([#4882](https://github.com/dynamic-labs/DynamicAuth/issues/4882)) ([3c14f55](https://github.com/dynamic-labs/DynamicAuth/commit/3c14f55f6e37718a095752d0e04bfbac45fee75c))
25
+ * better auth state handling when logged in with disabled wallets ([#4862](https://github.com/dynamic-labs/DynamicAuth/issues/4862)) ([8cc2a1c](https://github.com/dynamic-labs/DynamicAuth/commit/8cc2a1c4f31cf6acb61d814a3410c5e77da21c50))
26
+
2
27
  ## [1.3.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.2.0...v1.3.0) (2024-03-05)
3
28
 
4
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -28,16 +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.0",
36
- "@dynamic-labs/turnkey": "1.3.0",
37
- "@dynamic-labs/types": "1.3.0",
38
- "@dynamic-labs/utils": "1.3.0",
39
- "@dynamic-labs/wallet-book": "1.3.0",
40
- "@dynamic-labs/wallet-connector-core": "1.3.0",
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",
41
41
  "stream": "0.0.2"
42
42
  },
43
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;
@@ -45,10 +47,10 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
45
47
  return;
46
48
  this.teardownEventListeners = setupResponse.tearDownEventListeners;
47
49
  }
48
- getWalletClient() {
50
+ getWalletClient(chainId) {
49
51
  var _a;
50
52
  if (this.isInstalledOnBrowser()) {
51
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient();
53
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
52
54
  }
53
55
  return viem.createWalletClient({
54
56
  transport: viem.custom(client.getCoinbaseProvider({
@@ -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;
@@ -14,7 +14,7 @@ export declare class Coinbase extends EthWalletConnector {
14
14
  ethProviderHelper: EthProviderHelper | undefined;
15
15
  constructor({ appName, appLogoUrl, evmNetworks, ...props }: CoinbaseOpts);
16
16
  setupEventListeners(): void;
17
- getWalletClient(): {
17
+ getWalletClient(chainId?: string): {
18
18
  account: import("viem").Account | undefined;
19
19
  batch?: {
20
20
  multicall?: boolean | {
@@ -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;
@@ -41,10 +43,10 @@ class Coinbase extends EthWalletConnector {
41
43
  return;
42
44
  this.teardownEventListeners = setupResponse.tearDownEventListeners;
43
45
  }
44
- getWalletClient() {
46
+ getWalletClient(chainId) {
45
47
  var _a;
46
48
  if (this.isInstalledOnBrowser()) {
47
- return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient();
49
+ return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
48
50
  }
49
51
  return createWalletClient({
50
52
  transport: custom(getCoinbaseProvider({
@@ -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 };
@@ -4,8 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _tslib = require('../_virtual/_tslib.cjs');
6
6
  var viem = require('viem');
7
+ var accounts = require('viem/accounts');
7
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
9
  var utils = require('@dynamic-labs/utils');
10
+ var viemUtils = require('@dynamic-labs/viem-utils');
9
11
  var eip6963Provider = require('./eip6963Provider.cjs');
10
12
 
11
13
  class EthProviderHelper {
@@ -75,12 +77,14 @@ class EthProviderHelper {
75
77
  findProvider() {
76
78
  return this.getInstalledProvider();
77
79
  }
78
- findWalletClient() {
80
+ findWalletClient(chainId) {
79
81
  const provider = this.findProvider();
80
82
  if (!provider) {
81
83
  return undefined;
82
84
  }
83
85
  return viem.createWalletClient({
86
+ account: this.account,
87
+ chain: chainId ? viemUtils.chainsMap[chainId] : undefined,
84
88
  transport: viem.custom(provider),
85
89
  });
86
90
  }
@@ -98,6 +102,7 @@ class EthProviderHelper {
98
102
  try {
99
103
  const [lowercaseAddress] = yield client.requestAddresses();
100
104
  const publicAddress = viem.getAddress(lowercaseAddress);
105
+ this.account = accounts.toAccount(publicAddress);
101
106
  return publicAddress;
102
107
  }
103
108
  catch (err) {
@@ -4,6 +4,7 @@ import { WalletSchema } from '@dynamic-labs/wallet-book';
4
4
  import { IEthereum, ProviderFlag } from './types';
5
5
  export declare class EthProviderHelper {
6
6
  private wallet;
7
+ private account;
7
8
  constructor(wallet: WalletSchema);
8
9
  getInstalledProvider(): IEthereum | undefined;
9
10
  getEip6963Config(): {
@@ -27,7 +28,7 @@ export declare class EthProviderHelper {
27
28
  eip6963ProviderLookup(rdns: string): IEthereum | undefined;
28
29
  isInstalledHelper(): boolean;
29
30
  findProvider(): IEthereum | undefined;
30
- findWalletClient(): WalletClient | undefined;
31
+ findWalletClient(chainId?: string): WalletClient | undefined;
31
32
  fetchPublicAddress(): Promise<Hex | undefined>;
32
33
  fetchPublicAddressWithProvider(client: WalletClient): Promise<Hex | undefined>;
33
34
  signMessage(messageToSign: string): Promise<string | undefined>;
@@ -1,7 +1,9 @@
1
1
  import { __awaiter } from '../_virtual/_tslib.js';
2
2
  import { createWalletClient, custom, getAddress } from 'viem';
3
+ import { toAccount } from 'viem/accounts';
3
4
  import { ProviderLookup, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
4
5
  import { getProvidersFromWindow } from '@dynamic-labs/utils';
6
+ import { chainsMap } from '@dynamic-labs/viem-utils';
5
7
  import { Eip6963ProviderSingleton } from './eip6963Provider.js';
6
8
 
7
9
  class EthProviderHelper {
@@ -71,12 +73,14 @@ class EthProviderHelper {
71
73
  findProvider() {
72
74
  return this.getInstalledProvider();
73
75
  }
74
- findWalletClient() {
76
+ findWalletClient(chainId) {
75
77
  const provider = this.findProvider();
76
78
  if (!provider) {
77
79
  return undefined;
78
80
  }
79
81
  return createWalletClient({
82
+ account: this.account,
83
+ chain: chainId ? chainsMap[chainId] : undefined,
80
84
  transport: custom(provider),
81
85
  });
82
86
  }
@@ -94,6 +98,7 @@ class EthProviderHelper {
94
98
  try {
95
99
  const [lowercaseAddress] = yield client.requestAddresses();
96
100
  const publicAddress = getAddress(lowercaseAddress);
101
+ this.account = toAccount(publicAddress);
97
102
  return publicAddress;
98
103
  }
99
104
  catch (err) {
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
  ];
@@ -51,9 +51,9 @@ class InjectedWalletBase extends EthWalletConnector.EthWalletConnector {
51
51
  const { tearDownEventListeners } = ethProviderHelper._setupEventListeners(this);
52
52
  this.teardownEventListeners = tearDownEventListeners;
53
53
  }
54
- getWalletClient() {
54
+ getWalletClient(chainId) {
55
55
  var _a;
56
- return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient();
56
+ return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
57
57
  }
58
58
  isInstalledOnBrowser() {
59
59
  var _a;
@@ -14,7 +14,7 @@ declare abstract class InjectedWalletBase extends EthWalletConnector {
14
14
  getEthProviderHelper(): EthProviderHelper | undefined;
15
15
  getMobileOrInstalledWallet(): InjectedWalletBase;
16
16
  setupEventListeners(): void;
17
- getWalletClient(): WalletClient | undefined;
17
+ getWalletClient(chainId?: string): WalletClient | undefined;
18
18
  isInstalledOnBrowser(): boolean;
19
19
  fetchPublicAddress(): Promise<string | undefined>;
20
20
  connect(): Promise<void>;
@@ -49,9 +49,9 @@ class InjectedWalletBase extends EthWalletConnector {
49
49
  const { tearDownEventListeners } = ethProviderHelper._setupEventListeners(this);
50
50
  this.teardownEventListeners = tearDownEventListeners;
51
51
  }
52
- getWalletClient() {
52
+ getWalletClient(chainId) {
53
53
  var _a;
54
- return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient();
54
+ return (_a = this.getEthProviderHelper()) === null || _a === void 0 ? void 0 : _a.findWalletClient(chainId);
55
55
  }
56
56
  isInstalledOnBrowser() {
57
57
  var _a;
@@ -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 {};