@dynamic-labs/ethereum 0.17.0-RC.9 → 0.17.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.
@@ -22,6 +22,7 @@ import { UnknownInjectedWallet } from './UnknownInjectedWallet.js';
22
22
  export { UnknownInjectedWallet } from './UnknownInjectedWallet.js';
23
23
  import { Zerion } from './Zerion.js';
24
24
  export { Zerion } from './Zerion.js';
25
+ import { Superb } from './Superb.js';
25
26
 
26
27
  const injectedWallets = [
27
28
  BloctoInjected,
@@ -36,6 +37,7 @@ const injectedWallets = [
36
37
  Trust,
37
38
  UnknownInjectedWallet,
38
39
  Zerion,
40
+ Superb,
39
41
  ];
40
42
 
41
43
  export { injectedWallets };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var _ = require('buffer/');
4
+
5
+ /* eslint-disable */
6
+ /**
7
+ * @walletconnect/client and @walletconnect/qrcode-modal use `global` and `Buffer`, respectively.
8
+ * This issue is captured here: https://github.com/WalletConnect/walletconnect-monorepo/issues/341
9
+ * Here are some GH issues of others facing the same problem:
10
+ * * https://github.com/WalletConnect/walletconnect-monorepo/issues/734
11
+ * * https://github.com/WalletConnect/walletconnect-monorepo/issues/748
12
+ */
13
+ if (typeof window !== 'undefined') {
14
+ window.global = globalThis;
15
+ Object.assign(window, { Buffer: _.Buffer });
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { Buffer } from 'buffer/index.js';
2
+
3
+ /* eslint-disable */
4
+ /**
5
+ * @walletconnect/client and @walletconnect/qrcode-modal use `global` and `Buffer`, respectively.
6
+ * This issue is captured here: https://github.com/WalletConnect/walletconnect-monorepo/issues/341
7
+ * Here are some GH issues of others facing the same problem:
8
+ * * https://github.com/WalletConnect/walletconnect-monorepo/issues/734
9
+ * * https://github.com/WalletConnect/walletconnect-monorepo/issues/748
10
+ */
11
+ if (typeof window !== 'undefined') {
12
+ window.global = globalThis;
13
+ Object.assign(window, { Buffer });
14
+ }
package/src/types.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { ProviderCondition } from '@dynamic-labs/wallet-connector-core';
2
2
  declare global {
3
+ interface IWindowPhantom {
4
+ ethereum: IEthereum;
5
+ }
3
6
  interface Window {
4
7
  ethereum?: IEthereum;
5
- phantom?: {
6
- ethereum: IEthereum;
7
- };
8
+ phantom?: IWindowPhantom;
8
9
  zerionWallet?: IEthereum;
10
+ superb?: IEthereum;
9
11
  }
10
12
  }
11
13
  export type IEthereum = {
@@ -16,5 +18,5 @@ export type IEthereum = {
16
18
  method: T;
17
19
  } | object) => Promise<T extends 'eth_requestAccounts' ? [string] : object>;
18
20
  };
19
- export type ProviderFlag = 'isDawn' | 'isBraveWallet' | 'isCoinbaseWallet' | 'isFrame' | 'isGamestop' | 'isMetaMask' | 'isExodus' | 'isOpera' | 'isBlocto' | 'isTrustWallet' | 'isZerion' | 'isPhantom';
21
+ export type ProviderFlag = 'isDawn' | 'isBraveWallet' | 'isCoinbaseWallet' | 'isFrame' | 'isGamestop' | 'isMetaMask' | 'isExodus' | 'isOpera' | 'isBlocto' | 'isTrustWallet' | 'isZerion' | 'isPhantom' | 'isSuperb';
20
22
  export type EthProviderCondition = ProviderCondition<ProviderFlag>;
@@ -72,26 +72,6 @@ const killWalletConnectSession = (client) => _tslib.__awaiter(void 0, void 0, vo
72
72
  walletConnectorCore.logger.debug(e);
73
73
  }
74
74
  });
75
- const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
76
- var _a, _b, _c, _d;
77
- if (!utils.isMobile()) {
78
- const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
79
- if (removeWCUri)
80
- return origin || '';
81
- return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
82
- }
83
- // deeplinks for ios require special treatment
84
- // see: https://docs.walletconnect.com/mobile-linking#for-ios
85
- else if (utils.isIOS()) {
86
- const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
87
- if (removeWCUri)
88
- return origin || '';
89
- return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
90
- }
91
- // on android, the deeplink is simply the uri
92
- // see: https://docs.walletconnect.com/mobile-linking#for-android
93
- return uri;
94
- };
95
75
  const createSession = (client) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
96
76
  return new Promise((resolve, reject) => {
97
77
  client.on('connect', (error, payload) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
@@ -104,19 +84,6 @@ const createSession = (client) => _tslib.__awaiter(void 0, void 0, void 0, funct
104
84
  });
105
85
  });
106
86
  });
107
- const useDeepLink = (metadata, wcClient, opts) => {
108
- var _a, _b, _c;
109
- const deepLink = getDeepLink(wcClient.uri, metadata);
110
- if (utils.isMobile()) {
111
- window.location.href = deepLink;
112
- }
113
- else {
114
- if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
115
- (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
116
- }
117
- (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
118
- }
119
- };
120
87
  const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
121
88
  var _a;
122
89
  if (wcClient.connected) {
@@ -125,7 +92,10 @@ const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => _tslib.
125
92
  }
126
93
  // createSession will trigger the QR code...
127
94
  yield wcClient.createSession();
128
- useDeepLink(metadata, wcClient, opts);
95
+ walletConnectorCore.performPlatformSpecificConnectionMethod(wcClient.uri, metadata, {
96
+ onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
97
+ onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
98
+ });
129
99
  const payload = yield createSession(wcClient);
130
100
  (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
131
101
  const [accountPublicAddress] = payload.params[0].accounts;
@@ -140,8 +110,10 @@ const signWalletConnectPersonalMessage = (messageToSign, metadata, client, rpcPr
140
110
  }
141
111
  const [accountPublicAddress] = client.accounts;
142
112
  if (utils.isMobile()) {
143
- const deepLink = getDeepLink(client.uri, metadata, {
144
- removeWCUri: utils.isIOS() && isCryptoWallet,
113
+ const deepLink = walletConnectorCore.getDeepLink({
114
+ metadata,
115
+ mode: 'regular',
116
+ uri: client.uri,
145
117
  });
146
118
  window.location.href = deepLink;
147
119
  }
@@ -219,10 +191,8 @@ const waitForSafeTransaction = (signature, messageToSign, contract) => _tslib.__
219
191
 
220
192
  exports.createSession = createSession;
221
193
  exports.fetchWalletConnectEVMPublicAddress = fetchWalletConnectEVMPublicAddress;
222
- exports.getDeepLink = getDeepLink;
223
194
  exports.initClient = initClient;
224
195
  exports.killWalletConnectSession = killWalletConnectSession;
225
196
  exports.setupWalletConnectEventListeners = setupWalletConnectEventListeners;
226
197
  exports.signWalletConnectPersonalMessage = signWalletConnectPersonalMessage;
227
198
  exports.teardownWalletConnectEventListeners = teardownWalletConnectEventListeners;
228
- exports.useDeepLink = useDeepLink;
@@ -12,10 +12,6 @@ export declare const teardownWalletConnectEventListeners: (client: Client) => vo
12
12
  * Initialize a client from a stored session and terminate the connection.
13
13
  */
14
14
  export declare const killWalletConnectSession: (client: Client) => Promise<void>;
15
- export declare const getDeepLink: (uri: string, metadata: WalletSchema, { removeWCUri, }?: {
16
- removeWCUri?: boolean | undefined;
17
- }) => string;
18
15
  export declare const createSession: (client: Client) => Promise<PayloadParams>;
19
- export declare const useDeepLink: (metadata: WalletSchema, wcClient: Client, opts?: FetchPublicAddressOpts) => void;
20
16
  export declare const fetchWalletConnectEVMPublicAddress: (metadata: WalletSchema, wcClient: Client, opts?: FetchPublicAddressOpts) => Promise<string | undefined>;
21
17
  export declare const signWalletConnectPersonalMessage: (messageToSign: string, metadata: WalletSchema, client: Client, rpcProvider?: () => Promise<ethers.providers.JsonRpcProvider | undefined>) => Promise<string | undefined>;
@@ -1,8 +1,8 @@
1
1
  import { __awaiter } from '../../../_virtual/_tslib.js';
2
2
  import Client from '@walletconnect/client';
3
3
  import { Contract, ethers } from 'ethers';
4
- import { isSameAddress, logger } from '@dynamic-labs/wallet-connector-core';
5
- import { isMobile, isIOS } from '@dynamic-labs/utils';
4
+ import { isSameAddress, logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
5
+ import { isMobile } from '@dynamic-labs/utils';
6
6
 
7
7
  const initClient = (name, settings) => {
8
8
  const storageId = `walletconnect-${name}`;
@@ -64,26 +64,6 @@ const killWalletConnectSession = (client) => __awaiter(void 0, void 0, void 0, f
64
64
  logger.debug(e);
65
65
  }
66
66
  });
67
- const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
68
- var _a, _b, _c, _d;
69
- if (!isMobile()) {
70
- const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
71
- if (removeWCUri)
72
- return origin || '';
73
- return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
74
- }
75
- // deeplinks for ios require special treatment
76
- // see: https://docs.walletconnect.com/mobile-linking#for-ios
77
- else if (isIOS()) {
78
- const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
79
- if (removeWCUri)
80
- return origin || '';
81
- return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
82
- }
83
- // on android, the deeplink is simply the uri
84
- // see: https://docs.walletconnect.com/mobile-linking#for-android
85
- return uri;
86
- };
87
67
  const createSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
88
68
  return new Promise((resolve, reject) => {
89
69
  client.on('connect', (error, payload) => __awaiter(void 0, void 0, void 0, function* () {
@@ -96,19 +76,6 @@ const createSession = (client) => __awaiter(void 0, void 0, void 0, function* ()
96
76
  });
97
77
  });
98
78
  });
99
- const useDeepLink = (metadata, wcClient, opts) => {
100
- var _a, _b, _c;
101
- const deepLink = getDeepLink(wcClient.uri, metadata);
102
- if (isMobile()) {
103
- window.location.href = deepLink;
104
- }
105
- else {
106
- if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
107
- (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
108
- }
109
- (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
110
- }
111
- };
112
79
  const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => __awaiter(void 0, void 0, void 0, function* () {
113
80
  var _a;
114
81
  if (wcClient.connected) {
@@ -117,7 +84,10 @@ const fetchWalletConnectEVMPublicAddress = (metadata, wcClient, opts) => __await
117
84
  }
118
85
  // createSession will trigger the QR code...
119
86
  yield wcClient.createSession();
120
- useDeepLink(metadata, wcClient, opts);
87
+ performPlatformSpecificConnectionMethod(wcClient.uri, metadata, {
88
+ onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
89
+ onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
90
+ });
121
91
  const payload = yield createSession(wcClient);
122
92
  (_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
123
93
  const [accountPublicAddress] = payload.params[0].accounts;
@@ -132,8 +102,10 @@ const signWalletConnectPersonalMessage = (messageToSign, metadata, client, rpcPr
132
102
  }
133
103
  const [accountPublicAddress] = client.accounts;
134
104
  if (isMobile()) {
135
- const deepLink = getDeepLink(client.uri, metadata, {
136
- removeWCUri: isIOS() && isCryptoWallet,
105
+ const deepLink = getDeepLink({
106
+ metadata,
107
+ mode: 'regular',
108
+ uri: client.uri,
137
109
  });
138
110
  window.location.href = deepLink;
139
111
  }
@@ -209,4 +181,4 @@ const waitForSafeTransaction = (signature, messageToSign, contract) => __awaiter
209
181
  }
210
182
  });
211
183
 
212
- export { createSession, fetchWalletConnectEVMPublicAddress, getDeepLink, initClient, killWalletConnectSession, setupWalletConnectEventListeners, signWalletConnectPersonalMessage, teardownWalletConnectEventListeners, useDeepLink };
184
+ export { createSession, fetchWalletConnectEVMPublicAddress, initClient, killWalletConnectSession, setupWalletConnectEventListeners, signWalletConnectPersonalMessage, teardownWalletConnectEventListeners };
@@ -78,8 +78,10 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
78
78
  if (!utils.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
79
79
  return undefined;
80
80
  }
81
- return client.getDeepLink(this.getClient().uri, wallet, {
82
- removeWCUri: utils.isIOS() && walletConnectorCore.normalizeWalletName(this.name) === 'cryptocom',
81
+ return walletConnectorCore.getDeepLink({
82
+ metadata: wallet,
83
+ mode: 'regular',
84
+ uri: this.getClient().uri,
83
85
  });
84
86
  }
85
87
  signMessage(messageToSign) {
@@ -99,7 +101,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
99
101
  providerSwitchNetwork: { get: () => super.providerSwitchNetwork }
100
102
  });
101
103
  return _tslib.__awaiter(this, void 0, void 0, function* () {
102
- const client$1 = this.getClient();
104
+ const client = this.getClient();
103
105
  const currentNetworkId = yield this.getNetwork();
104
106
  if (currentNetworkId && currentNetworkId === network.chainId) {
105
107
  return;
@@ -111,11 +113,15 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
111
113
  if (!this.supportsNetworkSwitching()) {
112
114
  throw new utils.DynamicError('Network switching not supported');
113
115
  }
114
- if (!client$1) {
116
+ if (!client) {
115
117
  throw new utils.DynamicError('Client not found');
116
118
  }
117
119
  if (utils.isMobile()) {
118
- const deepLink = client.getDeepLink(client$1.uri, walletBook.getWalletBookWallet(this.name));
120
+ const deepLink = walletConnectorCore.getDeepLink({
121
+ metadata: walletBook.getWalletBookWallet(this.name),
122
+ mode: 'regular',
123
+ uri: client.uri,
124
+ });
119
125
  window.location.href = deepLink;
120
126
  }
121
127
  return _super.providerSwitchNetwork.call(this, { network, provider });
@@ -1,12 +1,12 @@
1
1
  import { __rest, __awaiter } from '../../_virtual/_tslib.js';
2
2
  import WalletConnectProvider from '@walletconnect/ethereum-provider';
3
3
  import { ethers } from 'ethers';
4
- import { normalizeWalletName } from '@dynamic-labs/wallet-connector-core';
4
+ import { normalizeWalletName, getDeepLink } from '@dynamic-labs/wallet-connector-core';
5
5
  import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
6
- import { isMobile, isIOS, DynamicError } from '@dynamic-labs/utils';
6
+ import { isMobile, DynamicError } from '@dynamic-labs/utils';
7
7
  import { EthWalletConnector } from '../EthWalletConnector.js';
8
8
  import { INFURA_ID } from '../constants.js';
9
- import { initClient, setupWalletConnectEventListeners, teardownWalletConnectEventListeners, fetchWalletConnectEVMPublicAddress, getDeepLink, signWalletConnectPersonalMessage, killWalletConnectSession } from './client/client.js';
9
+ import { initClient, setupWalletConnectEventListeners, teardownWalletConnectEventListeners, fetchWalletConnectEVMPublicAddress, signWalletConnectPersonalMessage, killWalletConnectSession } from './client/client.js';
10
10
 
11
11
  class WalletConnect extends EthWalletConnector {
12
12
  constructor(_a) {
@@ -70,8 +70,10 @@ class WalletConnect extends EthWalletConnector {
70
70
  if (!isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
71
71
  return undefined;
72
72
  }
73
- return getDeepLink(this.getClient().uri, wallet, {
74
- removeWCUri: isIOS() && normalizeWalletName(this.name) === 'cryptocom',
73
+ return getDeepLink({
74
+ metadata: wallet,
75
+ mode: 'regular',
76
+ uri: this.getClient().uri,
75
77
  });
76
78
  }
77
79
  signMessage(messageToSign) {
@@ -107,7 +109,11 @@ class WalletConnect extends EthWalletConnector {
107
109
  throw new DynamicError('Client not found');
108
110
  }
109
111
  if (isMobile()) {
110
- const deepLink = getDeepLink(client.uri, getWalletBookWallet(this.name));
112
+ const deepLink = getDeepLink({
113
+ metadata: getWalletBookWallet(this.name),
114
+ mode: 'regular',
115
+ uri: client.uri,
116
+ });
111
117
  window.location.href = deepLink;
112
118
  }
113
119
  return _super.providerSwitchNetwork.call(this, { network, provider });
@@ -9,26 +9,11 @@ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
9
  var walletBook = require('@dynamic-labs/wallet-book');
10
10
  var utils = require('@dynamic-labs/utils');
11
11
  var EthWalletConnector = require('../EthWalletConnector.cjs');
12
- var client = require('./client/client.cjs');
13
12
 
14
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
14
 
16
15
  var Provider__default = /*#__PURE__*/_interopDefaultLegacy(Provider);
17
16
 
18
- const performPlatformSpecificConnectionMethod = (uri, metadata, opts) => {
19
- var _a, _b, _c;
20
- if (utils.isMobile()) {
21
- const deepLink = client.getDeepLink(uri, metadata);
22
- window.location.href = deepLink;
23
- }
24
- else {
25
- if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
26
- const desktopUri = client.getDeepLink(uri, metadata);
27
- (_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, desktopUri);
28
- }
29
- (_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, uri);
30
- }
31
- };
32
17
  const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
33
18
  class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
34
19
  constructor(opts) {
@@ -40,46 +25,61 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
40
25
  this.name = opts.walletName;
41
26
  this.projectId = opts.projectId;
42
27
  }
28
+ initConnection() {
29
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
30
+ const { provider } = WalletConnectV2;
31
+ if (!provider) {
32
+ throw new utils.DynamicError('No provider found (init connection)');
33
+ }
34
+ // this means there is already a connection in progress, so don't call connect again
35
+ if (provider === null || provider === void 0 ? void 0 : provider.uri) {
36
+ return;
37
+ }
38
+ yield provider.connect({
39
+ namespaces: {
40
+ eip155: {
41
+ chains: this.evmNetworks
42
+ // filtering out Palm for now since it causes Trust to crash
43
+ .filter((network) => network.chainId !== 11297108109)
44
+ .map((network) => `eip155:${network.chainId}`),
45
+ events: ['chainChanged', 'accountsChanged'],
46
+ methods: [
47
+ 'eth_sendTransaction',
48
+ 'eth_signTransaction',
49
+ 'eth_sign',
50
+ 'personal_sign',
51
+ 'eth_signTypedData',
52
+ ],
53
+ rpcMap: this.evmNetworkRpcMap(),
54
+ },
55
+ },
56
+ });
57
+ });
58
+ }
43
59
  initProvider() {
44
60
  return _tslib.__awaiter(this, void 0, void 0, function* () {
45
- if (this.projectId && !WalletConnectV2.provider) {
46
- WalletConnectV2.provider = yield Provider__default["default"].init({
61
+ let { provider } = WalletConnectV2;
62
+ if (!provider) {
63
+ provider = yield Provider__default["default"].init({
47
64
  projectId: this.projectId,
48
65
  });
49
- const connection = yield WalletConnectV2.provider.client.connect({
50
- requiredNamespaces: {
51
- eip155: {
52
- chains: this.evmNetworks
53
- // filtering out Palm for now since it causes Trust to crash
54
- .filter((network) => network.chainId !== 11297108109)
55
- .map((network) => `eip155:${network.chainId}`),
56
- events: ['chainChanged', 'accountsChanged'],
57
- methods: [
58
- 'eth_sendTransaction',
59
- 'eth_signTransaction',
60
- 'eth_sign',
61
- 'personal_sign',
62
- 'eth_signTypedData',
63
- ],
64
- },
65
- },
66
- });
67
- // eslint-disable-next-line prefer-destructuring
68
- WalletConnectV2.provider.uri = connection.uri;
69
- WalletConnectV2.createSession = connection.approval;
66
+ WalletConnectV2.provider = provider;
70
67
  }
71
68
  });
72
69
  }
73
- init() {
70
+ refreshSession() {
74
71
  var _a, _b, _c, _d;
72
+ if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
73
+ if (localStorage.getItem(this.sessionTopicKey) ===
74
+ ((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
75
+ this.session = WalletConnectV2.provider.session;
76
+ }
77
+ }
78
+ }
79
+ init() {
75
80
  return _tslib.__awaiter(this, void 0, void 0, function* () {
76
81
  yield this.initProvider();
77
- if ((_b = (_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.topic) {
78
- if (localStorage.getItem(this.sessionTopicKey) ===
79
- ((_d = (_c = WalletConnectV2.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
80
- this.session = WalletConnectV2.provider.session;
81
- }
82
- }
82
+ yield this.initConnection();
83
83
  });
84
84
  }
85
85
  get sessionTopicKey() {
@@ -135,7 +135,11 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
135
135
  if (!utils.isMobile() && !((_b = wallet.desktop) === null || _b === void 0 ? void 0 : _b.native)) {
136
136
  return undefined;
137
137
  }
138
- return client.getDeepLink(WalletConnectV2.provider.uri, wallet);
138
+ return walletConnectorCore.getDeepLink({
139
+ metadata: wallet,
140
+ mode: 'regular',
141
+ uri: WalletConnectV2.provider.uri,
142
+ });
139
143
  }
140
144
  getWeb3Provider() {
141
145
  if (!WalletConnectV2.provider) {
@@ -148,49 +152,31 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
148
152
  if (this.session) {
149
153
  return this.session.namespaces.eip155.accounts[0].split(':')[2];
150
154
  }
151
- const metadata = walletBook.getWalletBookWallet(this.name);
152
155
  if (!WalletConnectV2.provider) {
153
156
  throw new utils.DynamicError('No provider found');
154
157
  }
155
- if (!WalletConnectV2.provider.uri || !WalletConnectV2.createSession) {
156
- throw new utils.DynamicError('No uri or approval found');
158
+ if (!WalletConnectV2.provider.uri) {
159
+ throw new utils.DynamicError('No uri found');
157
160
  }
158
- performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
161
+ const metadata = walletBook.getWalletBookWallet(this.name);
162
+ walletConnectorCore.performPlatformSpecificConnectionMethod(WalletConnectV2.provider.uri, metadata, {
159
163
  onDesktopUri: opts === null || opts === void 0 ? void 0 : opts.onDesktopUri,
160
164
  onDisplayUri: opts === null || opts === void 0 ? void 0 : opts.onDisplayUri,
161
165
  });
162
- const session = yield WalletConnectV2.createSession();
163
- if (!session) {
164
- return undefined;
165
- }
166
- this.session = session;
167
- localStorage.setItem(this.sessionTopicKey, session.topic);
168
- // need to "reconnect" the provider so that we can tell it what the rpc urls are
169
- yield WalletConnectV2.provider.connect({
170
- namespaces: {
171
- eip155: {
172
- chains: this.evmNetworks
173
- // filtering out Palm for now since it causes Trust to crash
174
- .filter((network) => network.chainId !== 11297108109)
175
- .map((network) => `eip155:${network.chainId}`),
176
- events: ['chainChanged', 'accountsChanged'],
177
- methods: [
178
- 'eth_sendTransaction',
179
- 'eth_signTransaction',
180
- 'eth_sign',
181
- 'personal_sign',
182
- 'eth_signTypedData',
183
- ],
184
- rpcMap: this.evmNetworkRpcMap(),
185
- },
186
- },
187
- skipPairing: true,
166
+ return new Promise((resolve, reject) => {
167
+ if (!WalletConnectV2.provider) {
168
+ reject(new utils.DynamicError('No provider found'));
169
+ return;
170
+ }
171
+ WalletConnectV2.provider.on('connect', ({ session }) => {
172
+ if (!session) {
173
+ reject(new utils.DynamicError('No session found'));
174
+ }
175
+ this.session = session;
176
+ localStorage.setItem(this.sessionTopicKey, session.topic);
177
+ resolve(this.session.namespaces.eip155.accounts[0].split(':')[2]);
178
+ });
188
179
  });
189
- // THIS LINE IS SUPER IMPORTANT
190
- // since we are skipping pairing, (see: skipPairing: true above), we need to manually set the session
191
- // so that future provider requests work (like getNetwork)
192
- WalletConnectV2.provider.session = session;
193
- return session.namespaces.eip155.accounts[0].split(':')[2];
194
180
  });
195
181
  }
196
182
  signMessage(messageToSign) {
@@ -205,7 +191,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
205
191
  if (utils.isMobile()) {
206
192
  // for sign message, no uri is needed because the uri encodes connection details,
207
193
  // and at this point we are already connected
208
- const deepLink = client.getDeepLink('', metadata);
194
+ const deepLink = walletConnectorCore.getDeepLink({ metadata, mode: 'regular' });
209
195
  window.location.href = deepLink;
210
196
  }
211
197
  // eslint-disable-next-line prefer-destructuring
@@ -227,7 +213,9 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
227
213
  }
228
214
  try {
229
215
  yield WalletConnectV2.provider.disconnect();
216
+ WalletConnectV2.provider.uri = undefined;
230
217
  localStorage.removeItem(this.sessionTopicKey);
218
+ this.session = undefined;
231
219
  }
232
220
  catch (e) {
233
221
  walletConnectorCore.logger.debug(e);
@@ -257,6 +245,8 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
257
245
  }
258
246
  getConnectedAccounts() {
259
247
  return _tslib.__awaiter(this, void 0, void 0, function* () {
248
+ yield this.initProvider();
249
+ this.refreshSession();
260
250
  if (!this.session) {
261
251
  return [];
262
252
  }
@@ -15,10 +15,11 @@ export declare class WalletConnectV2 extends EthWalletConnector {
15
15
  canConnectViaQrCode: boolean;
16
16
  isWalletConnect: boolean;
17
17
  private static provider;
18
- private static createSession;
19
18
  private projectId?;
20
19
  constructor(opts: WalletConnectorV2Opts);
20
+ private initConnection;
21
21
  private initProvider;
22
+ private refreshSession;
22
23
  init(): Promise<void>;
23
24
  get sessionTopicKey(): string;
24
25
  supportsNetworkSwitching(): boolean;