@dynamic-labs/ethereum 2.0.0-alpha.30 → 2.0.0-alpha.32
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 +15 -0
- package/package.json +8 -8
- package/src/EthWalletConnector.cjs +12 -1
- package/src/EthWalletConnector.d.ts +13 -10
- package/src/EthWalletConnector.js +12 -1
- package/src/coinbase/coinbase.cjs +1 -1
- package/src/coinbase/coinbase.js +1 -1
- package/src/ethProviderHelper.cjs +4 -4
- package/src/ethProviderHelper.d.ts +3 -2
- package/src/ethProviderHelper.js +4 -4
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/injected/InjectedWalletBase.cjs +1 -1
- package/src/injected/InjectedWalletBase.js +1 -1
- package/src/utils/index.d.ts +1 -0
- package/src/utils/isEthWalletConnector/index.d.ts +1 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.cjs +7 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.d.ts +3 -0
- package/src/utils/isEthWalletConnector/isEthWalletConnector.js +3 -0
- package/src/walletConnect/walletConnect.cjs +17 -15
- package/src/walletConnect/walletConnect.d.ts +10 -12
- package/src/walletConnect/walletConnect.js +17 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
|
|
2
|
+
## [2.0.0-alpha.32](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.31...v2.0.0-alpha.32) (2024-04-15)
|
|
3
|
+
|
|
4
|
+
## [2.0.0-alpha.31](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.30...v2.0.0-alpha.31) (2024-04-11)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* support adding email for recovery to existing embedded wallet ([#5128](https://github.com/dynamic-labs/DynamicAuth/issues/5128)) ([477fd81](https://github.com/dynamic-labs/DynamicAuth/commit/477fd81ac00864284d9d2183c0b8c078a0a23a2b))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* issue where customer also tries to use i18n.init ([#5267](https://github.com/dynamic-labs/DynamicAuth/issues/5267)) ([7f81f1e](https://github.com/dynamic-labs/DynamicAuth/commit/7f81f1e010fbc6408f6a5d6a37608235e947befa))
|
|
15
|
+
* smart wallet not loading correctly upon refresh when using non-embedded eoa wallet ([#5301](https://github.com/dynamic-labs/DynamicAuth/issues/5301)) ([e957317](https://github.com/dynamic-labs/DynamicAuth/commit/e9573173f6209773a0be5f4af37323f2be8d7906))
|
|
16
|
+
|
|
2
17
|
## [2.0.0-alpha.30](https://github.com/dynamic-labs/DynamicAuth/compare/v2.0.0-alpha.29...v2.0.0-alpha.30) (2024-04-11)
|
|
3
18
|
|
|
4
19
|
|
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.32",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
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.32",
|
|
34
|
+
"@dynamic-labs/turnkey": "2.0.0-alpha.32",
|
|
35
|
+
"@dynamic-labs/types": "2.0.0-alpha.32",
|
|
36
|
+
"@dynamic-labs/utils": "2.0.0-alpha.32",
|
|
37
|
+
"@dynamic-labs/viem-utils": "2.0.0-alpha.32",
|
|
38
|
+
"@dynamic-labs/wallet-book": "2.0.0-alpha.32",
|
|
39
|
+
"@dynamic-labs/wallet-connector-core": "2.0.0-alpha.32",
|
|
40
40
|
"stream": "0.0.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
@@ -4,6 +4,7 @@ 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');
|
|
9
10
|
var findEvmNetwork = require('./utils/findEvmNetwork.cjs');
|
|
@@ -130,10 +131,14 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
130
131
|
const provider = this.getWalletClient();
|
|
131
132
|
if (!provider)
|
|
132
133
|
return [];
|
|
133
|
-
|
|
134
|
+
const addresses = yield utils.retryableFn(provider.getAddresses, {
|
|
134
135
|
fallbackValue: [],
|
|
135
136
|
timeoutMs: 300,
|
|
136
137
|
});
|
|
138
|
+
if (addresses.length) {
|
|
139
|
+
this.setActiveAccount(addresses[0]);
|
|
140
|
+
}
|
|
141
|
+
return addresses;
|
|
137
142
|
});
|
|
138
143
|
}
|
|
139
144
|
providerSwitchNetwork({ network, provider, }) {
|
|
@@ -187,6 +192,12 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
187
192
|
}
|
|
188
193
|
});
|
|
189
194
|
}
|
|
195
|
+
setActiveAccount(account) {
|
|
196
|
+
this.activeAccount = account ? accounts.toAccount(account) : undefined;
|
|
197
|
+
}
|
|
198
|
+
getActiveAccount() {
|
|
199
|
+
return this.activeAccount;
|
|
200
|
+
}
|
|
190
201
|
}
|
|
191
202
|
|
|
192
203
|
exports.EthWalletConnector = EthWalletConnector;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WalletClient, PublicClient } from 'viem';
|
|
1
|
+
import { WalletClient, PublicClient, Account, Hex } from 'viem';
|
|
2
2
|
import { NameServiceData, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { EvmNetwork, GenericNetwork } from '@dynamic-labs/types';
|
|
4
4
|
import { IChainRpcProviders } from '@dynamic-labs/rpc-provider-ethereum';
|
|
@@ -17,13 +17,14 @@ export type EthWalletConnectorOpts = {
|
|
|
17
17
|
};
|
|
18
18
|
export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
19
19
|
evmNetworks: EvmNetwork[];
|
|
20
|
+
private activeAccount;
|
|
20
21
|
abstract getWalletClient(): WalletClient | undefined;
|
|
21
22
|
getPublicClient(): Promise<PublicClient | undefined>;
|
|
22
23
|
constructor(props: EthWalletConnectorOpts);
|
|
23
24
|
getNetwork(): Promise<number | undefined>;
|
|
24
25
|
getNameService(): Promise<NameServiceData | undefined>;
|
|
25
26
|
getSigner(): Promise<{
|
|
26
|
-
account:
|
|
27
|
+
account: Account | undefined;
|
|
27
28
|
batch?: {
|
|
28
29
|
multicall?: boolean | {
|
|
29
30
|
batchSize?: number | undefined;
|
|
@@ -40,20 +41,20 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
40
41
|
type: string;
|
|
41
42
|
uid: string;
|
|
42
43
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
43
|
-
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi, import("viem").Chain | undefined,
|
|
44
|
+
deployContract: <const abi extends import("viem").Abi | readonly unknown[], chainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<abi, import("viem").Chain | undefined, Account | undefined, chainOverride>) => Promise<`0x${string}`>;
|
|
44
45
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
45
46
|
getChainId: () => Promise<number>;
|
|
46
47
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
47
|
-
prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends import("viem").Chain | undefined = undefined, TAccountOverride extends `0x${string}` |
|
|
48
|
+
prepareTransactionRequest: <TParameterType extends import("viem").PrepareTransactionRequestParameterType, TChainOverride extends import("viem").Chain | undefined = undefined, TAccountOverride extends `0x${string}` | Account | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain | undefined, Account | undefined, TChainOverride, TAccountOverride, TParameterType>) => Promise<import("viem").PrepareTransactionRequestReturnType<import("viem").Chain, Account | undefined, TChainOverride, TAccountOverride, TParameterType>>;
|
|
48
49
|
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
49
50
|
requestPermissions: (args: {
|
|
50
51
|
[x: string]: Record<string, any>;
|
|
51
52
|
eth_accounts: Record<string, any>;
|
|
52
53
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
53
54
|
sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
54
|
-
sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain | undefined,
|
|
55
|
-
signMessage: (args: import("viem").SignMessageParameters<
|
|
56
|
-
signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain | undefined,
|
|
55
|
+
sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain | undefined, Account | undefined, TChainOverride_1>) => Promise<`0x${string}`>;
|
|
56
|
+
signMessage: (args: import("viem").SignMessageParameters<Account | undefined>) => Promise<`0x${string}`>;
|
|
57
|
+
signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain | undefined, Account | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
57
58
|
signTypedData: <const TTypedData extends {
|
|
58
59
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
59
60
|
[x: `string[${string}]`]: undefined;
|
|
@@ -261,10 +262,10 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
261
262
|
uint256?: undefined;
|
|
262
263
|
} | {
|
|
263
264
|
[key: string]: unknown;
|
|
264
|
-
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType,
|
|
265
|
+
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, Account | undefined>) => Promise<`0x${string}`>;
|
|
265
266
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
266
267
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
267
|
-
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 | undefined,
|
|
268
|
+
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 | undefined, Account | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
268
269
|
extend: <const client extends {
|
|
269
270
|
[x: string]: unknown;
|
|
270
271
|
account?: undefined;
|
|
@@ -278,7 +279,7 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
278
279
|
transport?: undefined;
|
|
279
280
|
type?: undefined;
|
|
280
281
|
uid?: undefined;
|
|
281
|
-
} & Partial<Pick<import("viem").PublicActions<import("viem").Transport, import("viem").Chain | undefined,
|
|
282
|
+
} & Partial<Pick<import("viem").PublicActions<import("viem").Transport, import("viem").Chain | undefined, Account | undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<import("viem").WalletActions<import("viem").Chain | undefined, Account | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain | undefined, Account | undefined>>) => client) => import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, Account | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain | undefined, Account | undefined>>;
|
|
282
283
|
} | undefined>;
|
|
283
284
|
getBalance(): Promise<string | undefined>;
|
|
284
285
|
supportsNetworkSwitching(): boolean;
|
|
@@ -293,5 +294,7 @@ export declare abstract class EthWalletConnector extends WalletConnectorBase {
|
|
|
293
294
|
provider: WalletClient;
|
|
294
295
|
}): Promise<void>;
|
|
295
296
|
protected evmNetworkRpcMap: () => EvmRpcMap;
|
|
297
|
+
setActiveAccount(account: Hex | undefined): void;
|
|
298
|
+
getActiveAccount(): Account | undefined;
|
|
296
299
|
}
|
|
297
300
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
2
|
import { formatEther } from 'viem';
|
|
3
|
+
import { toAccount } from 'viem/accounts';
|
|
3
4
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
4
5
|
import { parseEvmNetworks, retryableFn, FALLBACK_UNDEFINED, DynamicError, getOrMapViemChain } from '@dynamic-labs/utils';
|
|
5
6
|
import { findEvmNetwork } from './utils/findEvmNetwork.js';
|
|
@@ -126,10 +127,14 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
126
127
|
const provider = this.getWalletClient();
|
|
127
128
|
if (!provider)
|
|
128
129
|
return [];
|
|
129
|
-
|
|
130
|
+
const addresses = yield retryableFn(provider.getAddresses, {
|
|
130
131
|
fallbackValue: [],
|
|
131
132
|
timeoutMs: 300,
|
|
132
133
|
});
|
|
134
|
+
if (addresses.length) {
|
|
135
|
+
this.setActiveAccount(addresses[0]);
|
|
136
|
+
}
|
|
137
|
+
return addresses;
|
|
133
138
|
});
|
|
134
139
|
}
|
|
135
140
|
providerSwitchNetwork({ network, provider, }) {
|
|
@@ -183,6 +188,12 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
183
188
|
}
|
|
184
189
|
});
|
|
185
190
|
}
|
|
191
|
+
setActiveAccount(account) {
|
|
192
|
+
this.activeAccount = account ? toAccount(account) : undefined;
|
|
193
|
+
}
|
|
194
|
+
getActiveAccount() {
|
|
195
|
+
return this.activeAccount;
|
|
196
|
+
}
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
export { EthWalletConnector };
|
|
@@ -27,7 +27,7 @@ class Coinbase extends EthWalletConnector.EthWalletConnector {
|
|
|
27
27
|
const wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
28
28
|
if (!wallet)
|
|
29
29
|
return;
|
|
30
|
-
this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet);
|
|
30
|
+
this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(wallet, this);
|
|
31
31
|
}
|
|
32
32
|
setupEventListeners() {
|
|
33
33
|
var _a, _b, _c;
|
package/src/coinbase/coinbase.js
CHANGED
|
@@ -23,7 +23,7 @@ class Coinbase extends EthWalletConnector {
|
|
|
23
23
|
const wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
24
24
|
if (!wallet)
|
|
25
25
|
return;
|
|
26
|
-
this.ethProviderHelper = new EthProviderHelper(wallet);
|
|
26
|
+
this.ethProviderHelper = new EthProviderHelper(wallet, this);
|
|
27
27
|
}
|
|
28
28
|
setupEventListeners() {
|
|
29
29
|
var _a, _b, _c;
|
|
@@ -4,15 +4,15 @@ 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');
|
|
8
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
8
|
var utils = require('@dynamic-labs/utils');
|
|
10
9
|
var viemUtils = require('@dynamic-labs/viem-utils');
|
|
11
10
|
var eip6963Provider = require('./eip6963Provider.cjs');
|
|
12
11
|
|
|
13
12
|
class EthProviderHelper {
|
|
14
|
-
constructor(wallet) {
|
|
13
|
+
constructor(wallet, connector) {
|
|
15
14
|
this.wallet = wallet;
|
|
15
|
+
this.connector = connector;
|
|
16
16
|
}
|
|
17
17
|
getInstalledProvider() {
|
|
18
18
|
const eip6963Config = this.getEip6963Config();
|
|
@@ -83,7 +83,7 @@ class EthProviderHelper {
|
|
|
83
83
|
return undefined;
|
|
84
84
|
}
|
|
85
85
|
return viem.createWalletClient({
|
|
86
|
-
account: this.
|
|
86
|
+
account: this.connector.getActiveAccount(),
|
|
87
87
|
chain: chainId ? viemUtils.chainsMap[chainId] : undefined,
|
|
88
88
|
transport: viem.custom(provider),
|
|
89
89
|
});
|
|
@@ -102,7 +102,7 @@ class EthProviderHelper {
|
|
|
102
102
|
try {
|
|
103
103
|
const [lowercaseAddress] = yield client.requestAddresses();
|
|
104
104
|
const publicAddress = viem.getAddress(lowercaseAddress);
|
|
105
|
-
this.
|
|
105
|
+
this.connector.setActiveAccount(publicAddress);
|
|
106
106
|
return publicAddress;
|
|
107
107
|
}
|
|
108
108
|
catch (err) {
|
|
@@ -2,10 +2,11 @@ import { Hex, WalletClient } from 'viem';
|
|
|
2
2
|
import { ProviderCondition, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
4
4
|
import { IEthereum, ProviderFlag } from './types';
|
|
5
|
+
import { EthWalletConnector } from '.';
|
|
5
6
|
export declare class EthProviderHelper {
|
|
6
7
|
private wallet;
|
|
7
|
-
private
|
|
8
|
-
constructor(wallet: WalletSchema);
|
|
8
|
+
private connector;
|
|
9
|
+
constructor(wallet: WalletSchema, connector: EthWalletConnector);
|
|
9
10
|
getInstalledProvider(): IEthereum | undefined;
|
|
10
11
|
getEip6963Config(): {
|
|
11
12
|
rdns: string;
|
package/src/ethProviderHelper.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
2
|
import { createWalletClient, custom, getAddress } from 'viem';
|
|
3
|
-
import { toAccount } from 'viem/accounts';
|
|
4
3
|
import { ProviderLookup, eventListenerHandlers, logger } from '@dynamic-labs/wallet-connector-core';
|
|
5
4
|
import { getProvidersFromWindow } from '@dynamic-labs/utils';
|
|
6
5
|
import { chainsMap } from '@dynamic-labs/viem-utils';
|
|
7
6
|
import { Eip6963ProviderSingleton } from './eip6963Provider.js';
|
|
8
7
|
|
|
9
8
|
class EthProviderHelper {
|
|
10
|
-
constructor(wallet) {
|
|
9
|
+
constructor(wallet, connector) {
|
|
11
10
|
this.wallet = wallet;
|
|
11
|
+
this.connector = connector;
|
|
12
12
|
}
|
|
13
13
|
getInstalledProvider() {
|
|
14
14
|
const eip6963Config = this.getEip6963Config();
|
|
@@ -79,7 +79,7 @@ class EthProviderHelper {
|
|
|
79
79
|
return undefined;
|
|
80
80
|
}
|
|
81
81
|
return createWalletClient({
|
|
82
|
-
account: this.
|
|
82
|
+
account: this.connector.getActiveAccount(),
|
|
83
83
|
chain: chainId ? chainsMap[chainId] : undefined,
|
|
84
84
|
transport: custom(provider),
|
|
85
85
|
});
|
|
@@ -98,7 +98,7 @@ class EthProviderHelper {
|
|
|
98
98
|
try {
|
|
99
99
|
const [lowercaseAddress] = yield client.requestAddresses();
|
|
100
100
|
const publicAddress = getAddress(lowercaseAddress);
|
|
101
|
-
this.
|
|
101
|
+
this.connector.setActiveAccount(publicAddress);
|
|
102
102
|
return publicAddress;
|
|
103
103
|
}
|
|
104
104
|
catch (err) {
|
package/src/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@ require('@dynamic-labs/rpc-provider-ethereum');
|
|
|
14
14
|
var EthWalletConnector = require('./EthWalletConnector.cjs');
|
|
15
15
|
var ethProviderHelper = require('./ethProviderHelper.cjs');
|
|
16
16
|
var constants = require('./constants.cjs');
|
|
17
|
+
var isEthWalletConnector = require('./utils/isEthWalletConnector/isEthWalletConnector.cjs');
|
|
17
18
|
|
|
18
19
|
const EthereumWalletConnectors = (props) => [
|
|
19
20
|
...fetchInjectedWalletConnectors.injectedWalletOverrides,
|
|
@@ -31,4 +32,5 @@ exports.injectedWalletOverrides = fetchInjectedWalletConnectors.injectedWalletOv
|
|
|
31
32
|
exports.EthWalletConnector = EthWalletConnector.EthWalletConnector;
|
|
32
33
|
exports.EthProviderHelper = ethProviderHelper.EthProviderHelper;
|
|
33
34
|
exports.INFURA_ID = constants.INFURA_ID;
|
|
35
|
+
exports.isEthWalletConnector = isEthWalletConnector.isEthWalletConnector;
|
|
34
36
|
exports.EthereumWalletConnectors = EthereumWalletConnectors;
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import '@dynamic-labs/rpc-provider-ethereum';
|
|
|
11
11
|
export { EthWalletConnector } from './EthWalletConnector.js';
|
|
12
12
|
export { EthProviderHelper } from './ethProviderHelper.js';
|
|
13
13
|
export { INFURA_ID } from './constants.js';
|
|
14
|
+
export { isEthWalletConnector } from './utils/isEthWalletConnector/isEthWalletConnector.js';
|
|
14
15
|
|
|
15
16
|
const EthereumWalletConnectors = (props) => [
|
|
16
17
|
...injectedWalletOverrides,
|
|
@@ -21,7 +21,7 @@ class InjectedWalletBase extends EthWalletConnector.EthWalletConnector {
|
|
|
21
21
|
this.wallet = walletBook.findWalletBookWallet(this.walletBook, this.key);
|
|
22
22
|
}
|
|
23
23
|
if (this.wallet && !this.ethProviderHelper) {
|
|
24
|
-
this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(this.wallet);
|
|
24
|
+
this.ethProviderHelper = new ethProviderHelper.EthProviderHelper(this.wallet, this);
|
|
25
25
|
}
|
|
26
26
|
// this.ethProviderHelper is undefined if the wallet is not installed or found in walletbook
|
|
27
27
|
return this.ethProviderHelper;
|
|
@@ -19,7 +19,7 @@ class InjectedWalletBase extends EthWalletConnector {
|
|
|
19
19
|
this.wallet = findWalletBookWallet(this.walletBook, this.key);
|
|
20
20
|
}
|
|
21
21
|
if (this.wallet && !this.ethProviderHelper) {
|
|
22
|
-
this.ethProviderHelper = new EthProviderHelper(this.wallet);
|
|
22
|
+
this.ethProviderHelper = new EthProviderHelper(this.wallet, this);
|
|
23
23
|
}
|
|
24
24
|
// this.ethProviderHelper is undefined if the wallet is not installed or found in walletbook
|
|
25
25
|
return this.ethProviderHelper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './isEthWalletConnector';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isEthWalletConnector } from './isEthWalletConnector';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const isEthWalletConnector = (connector) => Boolean(connector === null || connector === void 0 ? void 0 : connector.getActiveAccount);
|
|
6
|
+
|
|
7
|
+
exports.isEthWalletConnector = isEthWalletConnector;
|
|
@@ -6,7 +6,6 @@ var _tslib = require('../../_virtual/_tslib.cjs');
|
|
|
6
6
|
var EthereumProvider = require('@walletconnect/ethereum-provider');
|
|
7
7
|
var EventEmitter = require('eventemitter3');
|
|
8
8
|
var viem = require('viem');
|
|
9
|
-
var accounts = require('viem/accounts');
|
|
10
9
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
10
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
12
11
|
var utils = require('@dynamic-labs/utils');
|
|
@@ -105,7 +104,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
105
104
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
106
105
|
const walletConnect = this.createProvider();
|
|
107
106
|
const walletClient = viem.createWalletClient({
|
|
108
|
-
account: this.
|
|
107
|
+
account: this.getActiveAccount(),
|
|
109
108
|
transport: viem.custom(yield walletConnect),
|
|
110
109
|
});
|
|
111
110
|
return walletClient;
|
|
@@ -138,7 +137,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
138
137
|
if (localStorage.getItem(this.sessionTopicKey) ===
|
|
139
138
|
((_d = (_c = WalletConnect.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
|
|
140
139
|
this.session = WalletConnect.provider.session;
|
|
141
|
-
this.
|
|
140
|
+
this.setActiveAccount(((_e = localStorage.getItem(this.activeAccountKey)) !== null && _e !== void 0 ? _e : undefined));
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
143
|
}
|
|
@@ -223,7 +222,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
223
222
|
}
|
|
224
223
|
// eslint-disable-next-line prefer-destructuring
|
|
225
224
|
const account = data[0].split(':')[2];
|
|
226
|
-
this.
|
|
225
|
+
this.setWCActiveAccount(account);
|
|
227
226
|
}
|
|
228
227
|
};
|
|
229
228
|
WalletConnect.provider.on('session_event', this.sessionEventHandler);
|
|
@@ -245,7 +244,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
245
244
|
return;
|
|
246
245
|
}
|
|
247
246
|
return viem.createWalletClient({
|
|
248
|
-
account: this.
|
|
247
|
+
account: this.getActiveAccount(),
|
|
249
248
|
chain: viemUtils.chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
|
|
250
249
|
transport: viem.custom(WalletConnect.provider),
|
|
251
250
|
});
|
|
@@ -253,8 +252,9 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
253
252
|
getAddress(opts) {
|
|
254
253
|
var _a, _b;
|
|
255
254
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
const activeAccount = this.getActiveAccount();
|
|
256
|
+
if (activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.address) {
|
|
257
|
+
return activeAccount.address;
|
|
258
258
|
}
|
|
259
259
|
if (!WalletConnect.provider || !((_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.signer.uri)) {
|
|
260
260
|
walletConnectorCore.logger.debug('No WC2 provider found, re-initializing...');
|
|
@@ -305,10 +305,11 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
307
|
this.setSession(session);
|
|
308
|
-
this.
|
|
308
|
+
this.setWCActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
309
309
|
this.getNetwork().then((chainId) => {
|
|
310
|
+
var _a;
|
|
310
311
|
this.currentChainId = chainId;
|
|
311
|
-
resolve(this.
|
|
312
|
+
resolve((_a = this.getActiveAccount()) === null || _a === void 0 ? void 0 : _a.address);
|
|
312
313
|
});
|
|
313
314
|
// We must clean up the onConnect and onFail listeners
|
|
314
315
|
// whenever the connection attempt either succeeds or fails
|
|
@@ -380,7 +381,7 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
380
381
|
window.location.href = deepLink;
|
|
381
382
|
}
|
|
382
383
|
const signMessageFn = (messageToSign) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
383
|
-
const
|
|
384
|
+
const activeAccount = this.getActiveAccount();
|
|
384
385
|
if (!activeAccount) {
|
|
385
386
|
return;
|
|
386
387
|
}
|
|
@@ -396,15 +397,15 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
396
397
|
}
|
|
397
398
|
clearActiveAccount() {
|
|
398
399
|
localStorage.removeItem(this.activeAccountKey);
|
|
399
|
-
this.
|
|
400
|
+
this.setActiveAccount(undefined);
|
|
400
401
|
}
|
|
401
402
|
clearSession() {
|
|
402
403
|
localStorage.removeItem(this.sessionTopicKey);
|
|
403
404
|
this.session = undefined;
|
|
404
405
|
}
|
|
405
|
-
|
|
406
|
+
setWCActiveAccount(account) {
|
|
406
407
|
localStorage.setItem(this.activeAccountKey, account);
|
|
407
|
-
this.
|
|
408
|
+
this.setActiveAccount(account);
|
|
408
409
|
this.emit('accountChange', { accounts: [account] });
|
|
409
410
|
}
|
|
410
411
|
setSession(session) {
|
|
@@ -485,10 +486,11 @@ class WalletConnect extends EthWalletConnector.EthWalletConnector {
|
|
|
485
486
|
this.refreshSession();
|
|
486
487
|
this.isInitialized = true;
|
|
487
488
|
}
|
|
488
|
-
|
|
489
|
+
const activeAccount = this.getActiveAccount();
|
|
490
|
+
if (!(activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.address)) {
|
|
489
491
|
return [];
|
|
490
492
|
}
|
|
491
|
-
return [
|
|
493
|
+
return [activeAccount.address];
|
|
492
494
|
});
|
|
493
495
|
}
|
|
494
496
|
isMetaMask() {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { SessionTypes } from '@walletconnect/types';
|
|
2
|
-
import { Hex } from 'viem';
|
|
3
2
|
import { Chain, GetAddressOpts, DeepLinkVariant, IWalletConnectConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
3
|
import { EvmNetwork } from '@dynamic-labs/types';
|
|
5
4
|
import { EthWalletConnector, EthWalletConnectorOpts } from '../EthWalletConnector';
|
|
@@ -14,7 +13,6 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
14
13
|
connectedChain: Chain;
|
|
15
14
|
name: string;
|
|
16
15
|
session: SessionTypes.Struct | undefined;
|
|
17
|
-
activeAccount: Hex | undefined;
|
|
18
16
|
isInitialized: boolean;
|
|
19
17
|
initializePromise: Promise<void> | undefined;
|
|
20
18
|
canConnectViaQrCode: boolean;
|
|
@@ -49,7 +47,7 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
49
47
|
setupEventListeners(): void;
|
|
50
48
|
teardownEventListeners(): void;
|
|
51
49
|
getWalletClient(chainId?: string): {
|
|
52
|
-
account: import("viem").JsonRpcAccount | undefined;
|
|
50
|
+
account: import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined;
|
|
53
51
|
batch?: {
|
|
54
52
|
multicall?: boolean | {
|
|
55
53
|
batchSize?: number | undefined;
|
|
@@ -66,20 +64,20 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
66
64
|
type: string;
|
|
67
65
|
uid: string;
|
|
68
66
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
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}`>;
|
|
67
|
+
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<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, chainOverride>) => Promise<`0x${string}`>;
|
|
70
68
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
71
69
|
getChainId: () => Promise<number>;
|
|
72
70
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
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>>;
|
|
71
|
+
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<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, TChainOverride, TAccountOverride, TParameterType>) => Promise<import("viem").PrepareTransactionRequestReturnType<import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, TChainOverride, TAccountOverride, TParameterType>>;
|
|
74
72
|
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
75
73
|
requestPermissions: (args: {
|
|
76
74
|
[x: string]: Record<string, any>;
|
|
77
75
|
eth_accounts: Record<string, any>;
|
|
78
76
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
79
77
|
sendRawTransaction: (args: import("viem").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
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}`>;
|
|
81
|
-
signMessage: (args: import("viem").SignMessageParameters<import("viem").JsonRpcAccount | undefined>) => Promise<`0x${string}`>;
|
|
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}`>;
|
|
78
|
+
sendTransaction: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, TChainOverride_1>) => Promise<`0x${string}`>;
|
|
79
|
+
signMessage: (args: import("viem").SignMessageParameters<import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined>) => Promise<`0x${string}`>;
|
|
80
|
+
signTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SignTransactionParameters<import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
83
81
|
signTypedData: <const TTypedData extends {
|
|
84
82
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
85
83
|
[x: `string[${string}]`]: undefined;
|
|
@@ -287,10 +285,10 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
287
285
|
uint256?: undefined;
|
|
288
286
|
} | {
|
|
289
287
|
[key: string]: unknown;
|
|
290
|
-
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, import("viem").JsonRpcAccount | undefined>) => Promise<`0x${string}`>;
|
|
288
|
+
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined>) => Promise<`0x${string}`>;
|
|
291
289
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
292
290
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
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}`>;
|
|
291
|
+
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<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
294
292
|
extend: <const client extends {
|
|
295
293
|
[x: string]: unknown;
|
|
296
294
|
account?: undefined;
|
|
@@ -304,7 +302,7 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
304
302
|
transport?: undefined;
|
|
305
303
|
type?: undefined;
|
|
306
304
|
uid?: undefined;
|
|
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>>;
|
|
305
|
+
} & Partial<Pick<import("viem").PublicActions<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | 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<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined>>) => client) => import("viem").Client<import("viem").CustomTransport, import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain, import("viem").JsonRpcAccount<`0x${string}`> | import("viem").LocalAccount<string, `0x${string}`> | undefined>>;
|
|
308
306
|
} | undefined;
|
|
309
307
|
getAddress(opts?: GetAddressOpts): Promise<string | undefined>;
|
|
310
308
|
/**
|
|
@@ -323,7 +321,7 @@ export declare class WalletConnect extends EthWalletConnector implements IWallet
|
|
|
323
321
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
324
322
|
private clearActiveAccount;
|
|
325
323
|
private clearSession;
|
|
326
|
-
private
|
|
324
|
+
private setWCActiveAccount;
|
|
327
325
|
private setSession;
|
|
328
326
|
endSession(): Promise<void>;
|
|
329
327
|
getNetwork(): Promise<number | undefined>;
|
|
@@ -2,7 +2,6 @@ import { __awaiter } from '../../_virtual/_tslib.js';
|
|
|
2
2
|
import EthereumProvider from '@walletconnect/ethereum-provider';
|
|
3
3
|
import EventEmitter from 'eventemitter3';
|
|
4
4
|
import { createWalletClient, custom } from 'viem';
|
|
5
|
-
import { toAccount } from 'viem/accounts';
|
|
6
5
|
import { logger, performPlatformSpecificConnectionMethod, getDeepLink } from '@dynamic-labs/wallet-connector-core';
|
|
7
6
|
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
8
7
|
import { DynamicError, sleep, isMobile } from '@dynamic-labs/utils';
|
|
@@ -96,7 +95,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
96
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
96
|
const walletConnect = this.createProvider();
|
|
98
97
|
const walletClient = createWalletClient({
|
|
99
|
-
account: this.
|
|
98
|
+
account: this.getActiveAccount(),
|
|
100
99
|
transport: custom(yield walletConnect),
|
|
101
100
|
});
|
|
102
101
|
return walletClient;
|
|
@@ -129,7 +128,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
129
128
|
if (localStorage.getItem(this.sessionTopicKey) ===
|
|
130
129
|
((_d = (_c = WalletConnect.provider) === null || _c === void 0 ? void 0 : _c.session) === null || _d === void 0 ? void 0 : _d.topic)) {
|
|
131
130
|
this.session = WalletConnect.provider.session;
|
|
132
|
-
this.
|
|
131
|
+
this.setActiveAccount(((_e = localStorage.getItem(this.activeAccountKey)) !== null && _e !== void 0 ? _e : undefined));
|
|
133
132
|
}
|
|
134
133
|
}
|
|
135
134
|
}
|
|
@@ -214,7 +213,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
214
213
|
}
|
|
215
214
|
// eslint-disable-next-line prefer-destructuring
|
|
216
215
|
const account = data[0].split(':')[2];
|
|
217
|
-
this.
|
|
216
|
+
this.setWCActiveAccount(account);
|
|
218
217
|
}
|
|
219
218
|
};
|
|
220
219
|
WalletConnect.provider.on('session_event', this.sessionEventHandler);
|
|
@@ -236,7 +235,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
236
235
|
return;
|
|
237
236
|
}
|
|
238
237
|
return createWalletClient({
|
|
239
|
-
account: this.
|
|
238
|
+
account: this.getActiveAccount(),
|
|
240
239
|
chain: chainsMap[chainId !== null && chainId !== void 0 ? chainId : String(this.currentChainId)],
|
|
241
240
|
transport: custom(WalletConnect.provider),
|
|
242
241
|
});
|
|
@@ -244,8 +243,9 @@ class WalletConnect extends EthWalletConnector {
|
|
|
244
243
|
getAddress(opts) {
|
|
245
244
|
var _a, _b;
|
|
246
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
const activeAccount = this.getActiveAccount();
|
|
247
|
+
if (activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.address) {
|
|
248
|
+
return activeAccount.address;
|
|
249
249
|
}
|
|
250
250
|
if (!WalletConnect.provider || !((_a = WalletConnect.provider) === null || _a === void 0 ? void 0 : _a.signer.uri)) {
|
|
251
251
|
logger.debug('No WC2 provider found, re-initializing...');
|
|
@@ -296,10 +296,11 @@ class WalletConnect extends EthWalletConnector {
|
|
|
296
296
|
return;
|
|
297
297
|
}
|
|
298
298
|
this.setSession(session);
|
|
299
|
-
this.
|
|
299
|
+
this.setWCActiveAccount(session.namespaces.eip155.accounts[0].split(':')[2]);
|
|
300
300
|
this.getNetwork().then((chainId) => {
|
|
301
|
+
var _a;
|
|
301
302
|
this.currentChainId = chainId;
|
|
302
|
-
resolve(this.
|
|
303
|
+
resolve((_a = this.getActiveAccount()) === null || _a === void 0 ? void 0 : _a.address);
|
|
303
304
|
});
|
|
304
305
|
// We must clean up the onConnect and onFail listeners
|
|
305
306
|
// whenever the connection attempt either succeeds or fails
|
|
@@ -371,7 +372,7 @@ class WalletConnect extends EthWalletConnector {
|
|
|
371
372
|
window.location.href = deepLink;
|
|
372
373
|
}
|
|
373
374
|
const signMessageFn = (messageToSign) => __awaiter(this, void 0, void 0, function* () {
|
|
374
|
-
const
|
|
375
|
+
const activeAccount = this.getActiveAccount();
|
|
375
376
|
if (!activeAccount) {
|
|
376
377
|
return;
|
|
377
378
|
}
|
|
@@ -387,15 +388,15 @@ class WalletConnect extends EthWalletConnector {
|
|
|
387
388
|
}
|
|
388
389
|
clearActiveAccount() {
|
|
389
390
|
localStorage.removeItem(this.activeAccountKey);
|
|
390
|
-
this.
|
|
391
|
+
this.setActiveAccount(undefined);
|
|
391
392
|
}
|
|
392
393
|
clearSession() {
|
|
393
394
|
localStorage.removeItem(this.sessionTopicKey);
|
|
394
395
|
this.session = undefined;
|
|
395
396
|
}
|
|
396
|
-
|
|
397
|
+
setWCActiveAccount(account) {
|
|
397
398
|
localStorage.setItem(this.activeAccountKey, account);
|
|
398
|
-
this.
|
|
399
|
+
this.setActiveAccount(account);
|
|
399
400
|
this.emit('accountChange', { accounts: [account] });
|
|
400
401
|
}
|
|
401
402
|
setSession(session) {
|
|
@@ -476,10 +477,11 @@ class WalletConnect extends EthWalletConnector {
|
|
|
476
477
|
this.refreshSession();
|
|
477
478
|
this.isInitialized = true;
|
|
478
479
|
}
|
|
479
|
-
|
|
480
|
+
const activeAccount = this.getActiveAccount();
|
|
481
|
+
if (!(activeAccount === null || activeAccount === void 0 ? void 0 : activeAccount.address)) {
|
|
480
482
|
return [];
|
|
481
483
|
}
|
|
482
|
-
return [
|
|
484
|
+
return [activeAccount.address];
|
|
483
485
|
});
|
|
484
486
|
}
|
|
485
487
|
isMetaMask() {
|