@dynamic-labs/ethereum 1.0.0-alpha.8 → 1.0.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 +69 -0
- package/package.json +7 -7
- package/src/EthWalletConnector.cjs +9 -8
- package/src/EthWalletConnector.js +9 -8
- package/src/coinbase/coinbase.d.ts +12 -12
- package/src/eip6963Provider.cjs +39 -0
- package/src/eip6963Provider.d.ts +25 -0
- package/src/eip6963Provider.js +34 -0
- package/src/ethProviderHelper.cjs +18 -0
- package/src/ethProviderHelper.d.ts +4 -0
- package/src/ethProviderHelper.js +18 -0
- package/src/walletConnect/walletConnectV2.cjs +79 -59
- package/src/walletConnect/walletConnectV2.d.ts +9 -4
- package/src/walletConnect/walletConnectV2.js +79 -59
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,73 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.0.0](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.14...v1.0.0) (2023-12-12)
|
|
3
|
+
|
|
4
|
+
Changelog: https://docs.dynamic.xyz/changelog/v1
|
|
5
|
+
Upgrade guide: https://docs.dynamic.xyz/react-sdk/upgrade
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## [1.0.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.13...v1.0.0-alpha.14) (2023-12-12)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* add user_media scope to instagram ([#4144](https://github.com/dynamic-labs/DynamicAuth/issues/4144)) ([57b9140](https://github.com/dynamic-labs/DynamicAuth/commit/57b91400cae7287157988cd6dfe7f30aeced10de))
|
|
14
|
+
* enable buy button onramp even with pregenerated wallets ([#4135](https://github.com/dynamic-labs/DynamicAuth/issues/4135)) ([fd94ecd](https://github.com/dynamic-labs/DynamicAuth/commit/fd94ecdcbe7190dc9abeb829cdcd933561afdd77))
|
|
15
|
+
* make the pin input fields responsive ([#4140](https://github.com/dynamic-labs/DynamicAuth/issues/4140)) ([4244744](https://github.com/dynamic-labs/DynamicAuth/commit/42447445ec32a3bca48a48d001c24dcd5b5cf004))
|
|
16
|
+
|
|
17
|
+
## [1.0.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2023-12-12)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* embedded wallet connected flag not picking up ([#4128](https://github.com/dynamic-labs/DynamicAuth/issues/4128)) ([c6fbb1d](https://github.com/dynamic-labs/DynamicAuth/commit/c6fbb1de2027b186a4277a75545fd66d0d11ba95))
|
|
23
|
+
|
|
24
|
+
## [1.0.0-alpha.12](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.11...v1.0.0-alpha.12) (2023-12-11)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* add useFunding hook ([#4098](https://github.com/dynamic-labs/DynamicAuth/issues/4098)) ([27424ab](https://github.com/dynamic-labs/DynamicAuth/commit/27424ab1a15202ee2b7c73c8a19f11e480e1794a))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Bug Fixes
|
|
33
|
+
|
|
34
|
+
* add primary color to the secure wallet text ([#4127](https://github.com/dynamic-labs/DynamicAuth/issues/4127)) ([7c642d0](https://github.com/dynamic-labs/DynamicAuth/commit/7c642d0385112289df52874bc5dd2eaa0e6cdf50))
|
|
35
|
+
|
|
36
|
+
## [1.0.0-alpha.11](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.10...v1.0.0-alpha.11) (2023-12-11)
|
|
37
|
+
|
|
38
|
+
## [1.0.0-alpha.10](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2023-12-08)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* allow transaction error to read from viem error ([#4101](https://github.com/dynamic-labs/DynamicAuth/issues/4101)) ([0f46cbe](https://github.com/dynamic-labs/DynamicAuth/commit/0f46cbea1eb260c2efdeee9b62f669fb3cf4ab93))
|
|
44
|
+
* trigger claim flow for unclaimed embedded smart contract wallet signer ([#4108](https://github.com/dynamic-labs/DynamicAuth/issues/4108)) ([37c9013](https://github.com/dynamic-labs/DynamicAuth/commit/37c9013109f2d6a37bde041da9072c5f5fa2df67))
|
|
45
|
+
* WalletConnect v2 connector with non active chains ([#4085](https://github.com/dynamic-labs/DynamicAuth/issues/4085)) ([f69cbe9](https://github.com/dynamic-labs/DynamicAuth/commit/f69cbe96012563f71e89939c96f2a46926e7b394))
|
|
46
|
+
|
|
47
|
+
## [1.0.0-alpha.9](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2023-12-07)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### ⚠ BREAKING CHANGES
|
|
51
|
+
|
|
52
|
+
* how to migrate
|
|
53
|
+
Whenever you would use the property wallets from the object returned by useDynamicContext, you must now rename it to walletConnectorOptions.
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
* add support for eip6963 ([#4064](https://github.com/dynamic-labs/DynamicAuth/issues/4064)) ([3f8cf0e](https://github.com/dynamic-labs/DynamicAuth/commit/3f8cf0e4250945f3a331f701d491a308fab5f7b8))
|
|
58
|
+
* allow AA wallets to access owner features ([#4079](https://github.com/dynamic-labs/DynamicAuth/issues/4079)) ([9efc2be](https://github.com/dynamic-labs/DynamicAuth/commit/9efc2bee87ec9193c3682863d72024b3586de724))
|
|
59
|
+
* introduce UserWalletsContext ([#4083](https://github.com/dynamic-labs/DynamicAuth/issues/4083)) ([b9ca7f6](https://github.com/dynamic-labs/DynamicAuth/commit/b9ca7f6b0aff4b3992325b70cc9a903ece445c7f))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Bug Fixes
|
|
63
|
+
|
|
64
|
+
* ensure zero dev provider will receive a signer ([#4084](https://github.com/dynamic-labs/DynamicAuth/issues/4084)) ([f02a540](https://github.com/dynamic-labs/DynamicAuth/commit/f02a54036d39bfc5fb0c262f292acf914e4bd653))
|
|
65
|
+
* render recovery section only when turnkey provider is enabled ([#4093](https://github.com/dynamic-labs/DynamicAuth/issues/4093)) ([5f29bd2](https://github.com/dynamic-labs/DynamicAuth/commit/5f29bd23ccca2e307822377be28396edc7ab1fda))
|
|
66
|
+
* reset selected social provider on logout ([#4078](https://github.com/dynamic-labs/DynamicAuth/issues/4078)) ([85dc611](https://github.com/dynamic-labs/DynamicAuth/commit/85dc611d9c0e733bdb9d316b008bdaa35bcc2a91))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
* rename wallets > walletConnectorOptions ([#4086](https://github.com/dynamic-labs/DynamicAuth/issues/4086)) ([10a7795](https://github.com/dynamic-labs/DynamicAuth/commit/10a779567e751469a667095726da52d78facbd57))
|
|
70
|
+
|
|
2
71
|
## [1.0.0-alpha.8](https://github.com/dynamic-labs/DynamicAuth/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2023-12-05)
|
|
3
72
|
|
|
4
73
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/dynamic-labs/DynamicAuth.git",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"@walletconnect/universal-provider": "2.10.6",
|
|
33
33
|
"eventemitter3": "5.0.1",
|
|
34
34
|
"buffer": "6.0.3",
|
|
35
|
-
"@dynamic-labs/rpc-providers": "1.0.0
|
|
36
|
-
"@dynamic-labs/turnkey": "1.0.0
|
|
37
|
-
"@dynamic-labs/types": "1.0.0
|
|
38
|
-
"@dynamic-labs/utils": "1.0.0
|
|
39
|
-
"@dynamic-labs/wallet-book": "1.0.0
|
|
40
|
-
"@dynamic-labs/wallet-connector-core": "1.0.0
|
|
35
|
+
"@dynamic-labs/rpc-providers": "1.0.0",
|
|
36
|
+
"@dynamic-labs/turnkey": "1.0.0",
|
|
37
|
+
"@dynamic-labs/types": "1.0.0",
|
|
38
|
+
"@dynamic-labs/utils": "1.0.0",
|
|
39
|
+
"@dynamic-labs/wallet-book": "1.0.0",
|
|
40
|
+
"@dynamic-labs/wallet-connector-core": "1.0.0",
|
|
41
41
|
"stream": "0.0.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
@@ -149,7 +149,7 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
151
|
providerSwitchNetwork({ network, provider, }) {
|
|
152
|
-
var _a, _b, _c;
|
|
152
|
+
var _a, _b, _c, _d;
|
|
153
153
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
154
154
|
const { chainId } = network;
|
|
155
155
|
const currentNetworkId = yield this.getNetwork();
|
|
@@ -163,18 +163,19 @@ class EthWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
163
163
|
return yield provider.switchChain(utils.getOrMapViemChain(network));
|
|
164
164
|
}
|
|
165
165
|
catch (error) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
else if (error.code === 4902 ||
|
|
171
|
-
error.message.includes('Unrecognized chain') ||
|
|
166
|
+
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
167
|
+
if (error.code === 4902 ||
|
|
168
|
+
((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Unrecognized chain')) ||
|
|
172
169
|
// https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
|
|
173
|
-
((_c = (_b = error
|
|
170
|
+
((_c = (_b = error.data) === null || _b === void 0 ? void 0 : _b.orginalError) === null || _c === void 0 ? void 0 : _c.code) === 4902) {
|
|
174
171
|
// error code indicates the chain has not been added yet
|
|
175
172
|
// https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
|
|
176
173
|
return this.providerAddNetwork({ network, provider });
|
|
177
174
|
}
|
|
175
|
+
else if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('rejected')) ||
|
|
176
|
+
(typeof error === 'string' && error.includes('rejected'))) {
|
|
177
|
+
throw new utils.DynamicError("User rejected the wallet's request to switch network");
|
|
178
|
+
}
|
|
178
179
|
else {
|
|
179
180
|
throw error;
|
|
180
181
|
}
|
|
@@ -145,7 +145,7 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
providerSwitchNetwork({ network, provider, }) {
|
|
148
|
-
var _a, _b, _c;
|
|
148
|
+
var _a, _b, _c, _d;
|
|
149
149
|
return __awaiter(this, void 0, void 0, function* () {
|
|
150
150
|
const { chainId } = network;
|
|
151
151
|
const currentNetworkId = yield this.getNetwork();
|
|
@@ -159,18 +159,19 @@ class EthWalletConnector extends WalletConnectorBase {
|
|
|
159
159
|
return yield provider.switchChain(getOrMapViemChain(network));
|
|
160
160
|
}
|
|
161
161
|
catch (error) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
else if (error.code === 4902 ||
|
|
167
|
-
error.message.includes('Unrecognized chain') ||
|
|
162
|
+
// we need to check for unrecognized chain error first because it also contains 'rejected' in message
|
|
163
|
+
if (error.code === 4902 ||
|
|
164
|
+
((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Unrecognized chain')) ||
|
|
168
165
|
// https://github.com/MetaMask/metamask-mobile/issues/3312#issuecomment-1065923294
|
|
169
|
-
((_c = (_b = error
|
|
166
|
+
((_c = (_b = error.data) === null || _b === void 0 ? void 0 : _b.orginalError) === null || _c === void 0 ? void 0 : _c.code) === 4902) {
|
|
170
167
|
// error code indicates the chain has not been added yet
|
|
171
168
|
// https://docs.metamask.io/guide/rpc-api.html#usage-with-wallet-switchethereumchain
|
|
172
169
|
return this.providerAddNetwork({ network, provider });
|
|
173
170
|
}
|
|
171
|
+
else if (((_d = error.message) === null || _d === void 0 ? void 0 : _d.includes('rejected')) ||
|
|
172
|
+
(typeof error === 'string' && error.includes('rejected'))) {
|
|
173
|
+
throw new DynamicError("User rejected the wallet's request to switch network");
|
|
174
|
+
}
|
|
174
175
|
else {
|
|
175
176
|
throw error;
|
|
176
177
|
}
|
|
@@ -30,20 +30,20 @@ export declare class Coinbase extends EthWalletConnector {
|
|
|
30
30
|
type: string;
|
|
31
31
|
uid: string;
|
|
32
32
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
33
|
-
deployContract: <const TAbi extends import("viem").Abi | readonly unknown[], TChainOverride extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<TAbi, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride>) => Promise<`0x${string}`>;
|
|
33
|
+
deployContract: <const TAbi extends import("viem").Abi | readonly unknown[], TChainOverride extends import("viem").Chain | undefined = undefined>(args: import("viem").DeployContractParameters<TAbi, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride>) => Promise<`0x${string}`>;
|
|
34
34
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
35
35
|
getChainId: () => Promise<number>;
|
|
36
36
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
37
|
-
prepareTransactionRequest: <TChainOverride_1 extends import("viem").Chain | undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_1>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
37
|
+
prepareTransactionRequest: <TChainOverride_1 extends import("viem").Chain | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_1>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
38
38
|
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
39
39
|
requestPermissions: (args: {
|
|
40
40
|
[x: string]: Record<string, any>;
|
|
41
41
|
eth_accounts: Record<string, any>;
|
|
42
42
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
43
43
|
sendRawTransaction: (args: import("viem/_types/actions/wallet/sendRawTransaction").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
44
|
-
sendTransaction: <TChainOverride_2 extends import("viem").Chain | undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
44
|
+
sendTransaction: <TChainOverride_2 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_2>) => Promise<`0x${string}`>;
|
|
45
45
|
signMessage: (args: import("viem").SignMessageParameters<import("viem").Account | undefined>) => Promise<`0x${string}`>;
|
|
46
|
-
signTransaction: <TChainOverride_3 extends import("viem").Chain | undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
46
|
+
signTransaction: <TChainOverride_3 extends import("viem").Chain | undefined = undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_3>) => Promise<`0x${string}`>;
|
|
47
47
|
signTypedData: <const TTypedData extends {
|
|
48
48
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
49
49
|
[x: `string[${string}]`]: undefined;
|
|
@@ -254,7 +254,7 @@ export declare class Coinbase extends EthWalletConnector {
|
|
|
254
254
|
}, TPrimaryType extends string>(args: import("viem").SignTypedDataParameters<TTypedData, TPrimaryType, import("viem").Account | undefined>) => Promise<`0x${string}`>;
|
|
255
255
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
256
256
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
257
|
-
writeContract: <const TAbi_1 extends import("viem").Abi | readonly unknown[], TFunctionName extends string, TChainOverride_4 extends import("viem").Chain | undefined>(args: import("viem").WriteContractParameters<TAbi_1, TFunctionName, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_4>) => Promise<`0x${string}`>;
|
|
257
|
+
writeContract: <const TAbi_1 extends import("viem").Abi | readonly unknown[], TFunctionName extends string, TChainOverride_4 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<TAbi_1, TFunctionName, import("viem").Chain | undefined, import("viem").Account | undefined, TChainOverride_4>) => Promise<`0x${string}`>;
|
|
258
258
|
extend: <const client extends {
|
|
259
259
|
[x: string]: unknown;
|
|
260
260
|
account?: undefined;
|
|
@@ -268,7 +268,7 @@ export declare class Coinbase extends EthWalletConnector {
|
|
|
268
268
|
transport?: undefined;
|
|
269
269
|
type?: undefined;
|
|
270
270
|
uid?: undefined;
|
|
271
|
-
}>(fn: (client: import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>) => client) => import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>;
|
|
271
|
+
} & Partial<Pick<import("viem").PublicActions, "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, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>) => client) => import("viem").Client<import("viem").Transport, import("viem").Chain | undefined, import("viem").Account | undefined, import("viem").WalletRpcSchema, { [K in keyof client]: client[K]; } & import("viem").WalletActions<import("viem").Chain | undefined, import("viem").Account | undefined>>;
|
|
272
272
|
} | {
|
|
273
273
|
account: undefined;
|
|
274
274
|
batch?: {
|
|
@@ -287,20 +287,20 @@ export declare class Coinbase extends EthWalletConnector {
|
|
|
287
287
|
type: string;
|
|
288
288
|
uid: string;
|
|
289
289
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
290
|
-
deployContract: <const TAbi_2 extends import("viem").Abi | readonly unknown[], TChainOverride_5 extends import("viem").Chain | undefined>(args: import("viem").DeployContractParameters<TAbi_2, undefined, undefined, TChainOverride_5>) => Promise<`0x${string}`>;
|
|
290
|
+
deployContract: <const TAbi_2 extends import("viem").Abi | readonly unknown[], TChainOverride_5 extends import("viem").Chain | undefined = undefined>(args: import("viem").DeployContractParameters<TAbi_2, undefined, undefined, TChainOverride_5>) => Promise<`0x${string}`>;
|
|
291
291
|
getAddresses: () => Promise<import("viem").GetAddressesReturnType>;
|
|
292
292
|
getChainId: () => Promise<number>;
|
|
293
293
|
getPermissions: () => Promise<import("viem").GetPermissionsReturnType>;
|
|
294
|
-
prepareTransactionRequest: <TChainOverride_6 extends import("viem").Chain | undefined>(args: import("viem").PrepareTransactionRequestParameters<undefined, undefined, TChainOverride_6>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
294
|
+
prepareTransactionRequest: <TChainOverride_6 extends import("viem").Chain | undefined = undefined>(args: import("viem").PrepareTransactionRequestParameters<undefined, undefined, TChainOverride_6>) => Promise<import("viem").PrepareTransactionRequestReturnType>;
|
|
295
295
|
requestAddresses: () => Promise<import("viem").RequestAddressesReturnType>;
|
|
296
296
|
requestPermissions: (args: {
|
|
297
297
|
[x: string]: Record<string, any>;
|
|
298
298
|
eth_accounts: Record<string, any>;
|
|
299
299
|
}) => Promise<import("viem").RequestPermissionsReturnType>;
|
|
300
300
|
sendRawTransaction: (args: import("viem/_types/actions/wallet/sendRawTransaction").SendRawTransactionParameters) => Promise<`0x${string}`>;
|
|
301
|
-
sendTransaction: <TChainOverride_7 extends import("viem").Chain | undefined>(args: import("viem").SendTransactionParameters<undefined, undefined, TChainOverride_7>) => Promise<`0x${string}`>;
|
|
301
|
+
sendTransaction: <TChainOverride_7 extends import("viem").Chain | undefined = undefined>(args: import("viem").SendTransactionParameters<undefined, undefined, TChainOverride_7>) => Promise<`0x${string}`>;
|
|
302
302
|
signMessage: (args: import("viem").SignMessageParameters<undefined>) => Promise<`0x${string}`>;
|
|
303
|
-
signTransaction: <TChainOverride_8 extends import("viem").Chain | undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<undefined, undefined, TChainOverride_8>) => Promise<`0x${string}`>;
|
|
303
|
+
signTransaction: <TChainOverride_8 extends import("viem").Chain | undefined = undefined>(args: import("viem/_types/actions/wallet/signTransaction").SignTransactionParameters<undefined, undefined, TChainOverride_8>) => Promise<`0x${string}`>;
|
|
304
304
|
signTypedData: <const TTypedData_1 extends {
|
|
305
305
|
[x: string]: readonly import("viem").TypedDataParameter[];
|
|
306
306
|
[x: `string[${string}]`]: undefined;
|
|
@@ -511,7 +511,7 @@ export declare class Coinbase extends EthWalletConnector {
|
|
|
511
511
|
}, TPrimaryType_1 extends string>(args: import("viem").SignTypedDataParameters<TTypedData_1, TPrimaryType_1, undefined>) => Promise<`0x${string}`>;
|
|
512
512
|
switchChain: (args: import("viem").SwitchChainParameters) => Promise<void>;
|
|
513
513
|
watchAsset: (args: import("viem").WatchAssetParams) => Promise<boolean>;
|
|
514
|
-
writeContract: <const TAbi_3 extends import("viem").Abi | readonly unknown[], TFunctionName_1 extends string, TChainOverride_9 extends import("viem").Chain | undefined>(args: import("viem").WriteContractParameters<TAbi_3, TFunctionName_1, undefined, undefined, TChainOverride_9>) => Promise<`0x${string}`>;
|
|
514
|
+
writeContract: <const TAbi_3 extends import("viem").Abi | readonly unknown[], TFunctionName_1 extends string, TChainOverride_9 extends import("viem").Chain | undefined = undefined>(args: import("viem").WriteContractParameters<TAbi_3, TFunctionName_1, undefined, undefined, TChainOverride_9>) => Promise<`0x${string}`>;
|
|
515
515
|
extend: <const client_1 extends {
|
|
516
516
|
[x: string]: unknown;
|
|
517
517
|
account?: undefined;
|
|
@@ -525,7 +525,7 @@ export declare class Coinbase extends EthWalletConnector {
|
|
|
525
525
|
transport?: undefined;
|
|
526
526
|
type?: undefined;
|
|
527
527
|
uid?: undefined;
|
|
528
|
-
}>(fn: (client: import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<undefined, undefined>>) => client_1) => import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, { [K_1 in keyof client_1]: client_1[K_1]; } & import("viem").WalletActions<undefined, undefined>>;
|
|
528
|
+
} & Partial<Pick<import("viem").PublicActions, "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, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<undefined, undefined>>) => client_1) => import("viem").Client<import("viem").CustomTransport, undefined, undefined, import("viem").WalletRpcSchema, { [K_1 in keyof client_1]: client_1[K_1]; } & import("viem").WalletActions<undefined, undefined>>;
|
|
529
529
|
} | undefined;
|
|
530
530
|
isInstalledOnBrowser(): boolean;
|
|
531
531
|
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const isEip9693Event = (event) => event.type === 'eip6963:announceProvider' &&
|
|
6
|
+
event.detail !== undefined;
|
|
7
|
+
class Eip6963Provider {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.providers = [];
|
|
10
|
+
}
|
|
11
|
+
registerProviders() {
|
|
12
|
+
if (typeof window === 'undefined') {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
window.addEventListener('eip6963:announceProvider', (event) => {
|
|
16
|
+
if (!isEip9693Event(event)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.providers.push(event.detail);
|
|
20
|
+
});
|
|
21
|
+
window.dispatchEvent(new Event('eip6963:requestProvider'));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class Eip6963ProviderSingleton {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.eip6963Provider = new Eip6963Provider();
|
|
27
|
+
}
|
|
28
|
+
static get() {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!((_a = Eip6963ProviderSingleton.instance) === null || _a === void 0 ? void 0 : _a.eip6963Provider)) {
|
|
31
|
+
Eip6963ProviderSingleton.instance = new Eip6963ProviderSingleton();
|
|
32
|
+
Eip6963ProviderSingleton.instance.eip6963Provider.registerProviders();
|
|
33
|
+
}
|
|
34
|
+
return Eip6963ProviderSingleton.instance.eip6963Provider;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.Eip6963Provider = Eip6963Provider;
|
|
39
|
+
exports.Eip6963ProviderSingleton = Eip6963ProviderSingleton;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IEthereum } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the assets needed to display a wallet
|
|
4
|
+
*/
|
|
5
|
+
type Eip6963ProviderInfo = {
|
|
6
|
+
uuid: string;
|
|
7
|
+
name: string;
|
|
8
|
+
icon: string;
|
|
9
|
+
rdns: string;
|
|
10
|
+
};
|
|
11
|
+
type Eip6963ProviderDetail = {
|
|
12
|
+
info: Eip6963ProviderInfo;
|
|
13
|
+
provider: IEthereum;
|
|
14
|
+
};
|
|
15
|
+
export declare class Eip6963Provider {
|
|
16
|
+
providers: Eip6963ProviderDetail[];
|
|
17
|
+
registerProviders(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare class Eip6963ProviderSingleton {
|
|
20
|
+
readonly eip6963Provider: Eip6963Provider;
|
|
21
|
+
private constructor();
|
|
22
|
+
private static instance;
|
|
23
|
+
static get(): Eip6963Provider;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const isEip9693Event = (event) => event.type === 'eip6963:announceProvider' &&
|
|
2
|
+
event.detail !== undefined;
|
|
3
|
+
class Eip6963Provider {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.providers = [];
|
|
6
|
+
}
|
|
7
|
+
registerProviders() {
|
|
8
|
+
if (typeof window === 'undefined') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
window.addEventListener('eip6963:announceProvider', (event) => {
|
|
12
|
+
if (!isEip9693Event(event)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.providers.push(event.detail);
|
|
16
|
+
});
|
|
17
|
+
window.dispatchEvent(new Event('eip6963:requestProvider'));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class Eip6963ProviderSingleton {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.eip6963Provider = new Eip6963Provider();
|
|
23
|
+
}
|
|
24
|
+
static get() {
|
|
25
|
+
var _a;
|
|
26
|
+
if (!((_a = Eip6963ProviderSingleton.instance) === null || _a === void 0 ? void 0 : _a.eip6963Provider)) {
|
|
27
|
+
Eip6963ProviderSingleton.instance = new Eip6963ProviderSingleton();
|
|
28
|
+
Eip6963ProviderSingleton.instance.eip6963Provider.registerProviders();
|
|
29
|
+
}
|
|
30
|
+
return Eip6963ProviderSingleton.instance.eip6963Provider;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { Eip6963Provider, Eip6963ProviderSingleton };
|
|
@@ -7,12 +7,20 @@ var viem = require('viem');
|
|
|
7
7
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
8
|
var utils = require('@dynamic-labs/utils');
|
|
9
9
|
var eventListenerHandlers = require('./utils/eventListenerHandlers.cjs');
|
|
10
|
+
var eip6963Provider = require('./eip6963Provider.cjs');
|
|
10
11
|
|
|
11
12
|
class EthProviderHelper {
|
|
12
13
|
constructor(wallet) {
|
|
13
14
|
this.wallet = wallet;
|
|
14
15
|
}
|
|
15
16
|
getInstalledProvider() {
|
|
17
|
+
const eip6963Config = this.getEip6963Config();
|
|
18
|
+
if (eip6963Config) {
|
|
19
|
+
const eip6963Provider = this.eip6963ProviderLookup(eip6963Config.rdns);
|
|
20
|
+
if (eip6963Provider) {
|
|
21
|
+
return eip6963Provider;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
16
24
|
const config = this.getInjectedConfig();
|
|
17
25
|
if (!config ||
|
|
18
26
|
!config.extensionLocators ||
|
|
@@ -20,6 +28,11 @@ class EthProviderHelper {
|
|
|
20
28
|
return undefined;
|
|
21
29
|
return this.installedProviderLookup(config.extensionLocators);
|
|
22
30
|
}
|
|
31
|
+
getEip6963Config() {
|
|
32
|
+
if (!this.wallet || !this.wallet.eip6963Config)
|
|
33
|
+
return;
|
|
34
|
+
return this.wallet.eip6963Config;
|
|
35
|
+
}
|
|
23
36
|
getInjectedConfig() {
|
|
24
37
|
if (!this.wallet || !this.wallet.injectedConfig)
|
|
25
38
|
return;
|
|
@@ -52,6 +65,11 @@ class EthProviderHelper {
|
|
|
52
65
|
const allInstalledProviders = this.installedProviders();
|
|
53
66
|
return walletConnectorCore.ProviderLookup(allInstalledProviders, providerFlags);
|
|
54
67
|
}
|
|
68
|
+
eip6963ProviderLookup(rdns) {
|
|
69
|
+
var _a;
|
|
70
|
+
const { providers } = eip6963Provider.Eip6963ProviderSingleton.get();
|
|
71
|
+
return (_a = providers.find((provider) => provider.info.rdns === rdns)) === null || _a === void 0 ? void 0 : _a.provider;
|
|
72
|
+
}
|
|
55
73
|
isInstalledHelper() {
|
|
56
74
|
return this.findProvider() !== undefined;
|
|
57
75
|
}
|
|
@@ -6,6 +6,9 @@ export declare class EthProviderHelper {
|
|
|
6
6
|
private wallet;
|
|
7
7
|
constructor(wallet: WalletSchema);
|
|
8
8
|
getInstalledProvider(): IEthereum | undefined;
|
|
9
|
+
getEip6963Config(): {
|
|
10
|
+
rdns: string;
|
|
11
|
+
} | undefined;
|
|
9
12
|
getInjectedConfig(): {
|
|
10
13
|
chain: string;
|
|
11
14
|
extensionLocators: {
|
|
@@ -16,6 +19,7 @@ export declare class EthProviderHelper {
|
|
|
16
19
|
} | undefined;
|
|
17
20
|
installedProviders(): IEthereum[];
|
|
18
21
|
installedProviderLookup(providerFlags: Array<ProviderCondition<ProviderFlag>>): IEthereum | undefined;
|
|
22
|
+
eip6963ProviderLookup(rdns: string): IEthereum | undefined;
|
|
19
23
|
isInstalledHelper(): boolean;
|
|
20
24
|
findProvider(): IEthereum | undefined;
|
|
21
25
|
findWalletClient(): WalletClient | undefined;
|
package/src/ethProviderHelper.js
CHANGED
|
@@ -3,12 +3,20 @@ import { createWalletClient, custom, getAddress } from 'viem';
|
|
|
3
3
|
import { ProviderLookup, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { getProvidersFromWindow } from '@dynamic-labs/utils';
|
|
5
5
|
import { eventListenerHandlers } from './utils/eventListenerHandlers.js';
|
|
6
|
+
import { Eip6963ProviderSingleton } from './eip6963Provider.js';
|
|
6
7
|
|
|
7
8
|
class EthProviderHelper {
|
|
8
9
|
constructor(wallet) {
|
|
9
10
|
this.wallet = wallet;
|
|
10
11
|
}
|
|
11
12
|
getInstalledProvider() {
|
|
13
|
+
const eip6963Config = this.getEip6963Config();
|
|
14
|
+
if (eip6963Config) {
|
|
15
|
+
const eip6963Provider = this.eip6963ProviderLookup(eip6963Config.rdns);
|
|
16
|
+
if (eip6963Provider) {
|
|
17
|
+
return eip6963Provider;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
12
20
|
const config = this.getInjectedConfig();
|
|
13
21
|
if (!config ||
|
|
14
22
|
!config.extensionLocators ||
|
|
@@ -16,6 +24,11 @@ class EthProviderHelper {
|
|
|
16
24
|
return undefined;
|
|
17
25
|
return this.installedProviderLookup(config.extensionLocators);
|
|
18
26
|
}
|
|
27
|
+
getEip6963Config() {
|
|
28
|
+
if (!this.wallet || !this.wallet.eip6963Config)
|
|
29
|
+
return;
|
|
30
|
+
return this.wallet.eip6963Config;
|
|
31
|
+
}
|
|
19
32
|
getInjectedConfig() {
|
|
20
33
|
if (!this.wallet || !this.wallet.injectedConfig)
|
|
21
34
|
return;
|
|
@@ -48,6 +61,11 @@ class EthProviderHelper {
|
|
|
48
61
|
const allInstalledProviders = this.installedProviders();
|
|
49
62
|
return ProviderLookup(allInstalledProviders, providerFlags);
|
|
50
63
|
}
|
|
64
|
+
eip6963ProviderLookup(rdns) {
|
|
65
|
+
var _a;
|
|
66
|
+
const { providers } = Eip6963ProviderSingleton.get();
|
|
67
|
+
return (_a = providers.find((provider) => provider.info.rdns === rdns)) === null || _a === void 0 ? void 0 : _a.provider;
|
|
68
|
+
}
|
|
51
69
|
isInstalledHelper() {
|
|
52
70
|
return this.findProvider() !== undefined;
|
|
53
71
|
}
|
|
@@ -19,9 +19,12 @@ var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
|
|
|
19
19
|
|
|
20
20
|
const activeAccountKey = (walletName) => `dynamic-wc2-active-account-${walletName}`;
|
|
21
21
|
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
|
22
|
+
const swicthedNetworkKey = (walletName) => `dynamic-wc2-switched-network-${walletName}`;
|
|
23
|
+
const currentChainKey = (walletName) => `dynamic-wc2-current-chain-${walletName}`;
|
|
22
24
|
const ee = new EventEmitter__default["default"]();
|
|
23
25
|
class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
24
26
|
constructor(opts) {
|
|
27
|
+
var _a;
|
|
25
28
|
super(opts);
|
|
26
29
|
this.supportedChains = ['EVM', 'ETH'];
|
|
27
30
|
this.connectedChain = 'EVM';
|
|
@@ -29,6 +32,9 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
29
32
|
this.canConnectViaQrCode = true;
|
|
30
33
|
this.isWalletConnect = true;
|
|
31
34
|
this.preferredChains = [];
|
|
35
|
+
// When trying to switch network for MetaMask, the switch promise gets stuck
|
|
36
|
+
// if the switch got trigged once already, so we need to keep track of that
|
|
37
|
+
this._hasSwitchedNetwork = false;
|
|
32
38
|
this.name = opts.walletName;
|
|
33
39
|
this.projectId = opts.projectId;
|
|
34
40
|
this.deepLinkPreference = opts.deepLinkPreference || 'native';
|
|
@@ -36,40 +42,17 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
36
42
|
if (!this.preferredChains.includes('eip155:1')) {
|
|
37
43
|
this.preferredChains.push('eip155:1');
|
|
38
44
|
}
|
|
45
|
+
this.hasSwitchedNetwork =
|
|
46
|
+
(_a = Boolean(localStorage.getItem(this.swicthedNetworkKey))) !== null && _a !== void 0 ? _a : false;
|
|
47
|
+
const lsCurrentChain = localStorage.getItem(this.currentChainKey);
|
|
48
|
+
this.currentChainId = lsCurrentChain
|
|
49
|
+
? parseIntSafe.parseIntSafe(lsCurrentChain)
|
|
50
|
+
: undefined;
|
|
39
51
|
}
|
|
40
|
-
|
|
41
|
-
const preferredNetwork = this.preferredChains.find((chain) => this.supportedChain(chain));
|
|
42
|
-
if (preferredNetwork) {
|
|
43
|
-
return preferredNetwork;
|
|
44
|
-
}
|
|
45
|
-
else if (this.findSupportedChains().length) {
|
|
46
|
-
return this.findSupportedChains()[0];
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return 'eip155:1';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
findSupportedChains() {
|
|
53
|
-
var _a;
|
|
54
|
-
try {
|
|
55
|
-
const wallet = walletBook.getWalletBookWallet(this.walletBook, this.key);
|
|
56
|
-
const supportedChains = (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.filter((network) => { var _a; return (_a = wallet === null || wallet === void 0 ? void 0 : wallet.chains) === null || _a === void 0 ? void 0 : _a.includes(`eip155:${network.chainId}`); }).map((network) => `eip155:${network.chainId}`);
|
|
57
|
-
return supportedChains;
|
|
58
|
-
}
|
|
59
|
-
catch (_b) {
|
|
60
|
-
// pass
|
|
61
|
-
}
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
supportedChain(chainId) {
|
|
65
|
-
var _a;
|
|
66
|
-
return (_a = this.findSupportedChains().filter((chain) => [`eip155:${chainId}`, chainId].includes(chain))) === null || _a === void 0 ? void 0 : _a[0];
|
|
67
|
-
}
|
|
68
|
-
optionalChains() {
|
|
52
|
+
getMappedChains() {
|
|
69
53
|
return (this.evmNetworks
|
|
70
|
-
// Filters out
|
|
71
|
-
.filter((network) => network.chainId !== 11297108109
|
|
72
|
-
`eip155:${network.chainId}` !== this.defaultChainId())
|
|
54
|
+
// Filters out palm that crashes Trust Wallet
|
|
55
|
+
.filter((network) => network.chainId !== 11297108109)
|
|
73
56
|
.map((network) => `eip155:${network.chainId}`));
|
|
74
57
|
}
|
|
75
58
|
initConnection() {
|
|
@@ -82,34 +65,26 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
82
65
|
if (provider === null || provider === void 0 ? void 0 : provider.uri) {
|
|
83
66
|
return;
|
|
84
67
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}
|
|
68
|
+
const optionalNamespaces = {
|
|
69
|
+
eip155: {
|
|
70
|
+
chains: this.getMappedChains(),
|
|
71
|
+
events: ['chainChanged', 'accountsChanged'],
|
|
72
|
+
methods: [
|
|
73
|
+
'eth_chainId',
|
|
74
|
+
'eth_signTypedData',
|
|
75
|
+
'eth_signTransaction',
|
|
76
|
+
'eth_sign',
|
|
77
|
+
'personal_sign',
|
|
78
|
+
'eth_sendTransaction',
|
|
79
|
+
'eth_signTypedData_v4',
|
|
80
|
+
'wallet_switchEthereumChain',
|
|
81
|
+
'wallet_addEthereumChain',
|
|
82
|
+
],
|
|
83
|
+
rpcMap: this.evmNetworkRpcMap(),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
103
86
|
provider
|
|
104
87
|
.connect({
|
|
105
|
-
namespaces: {
|
|
106
|
-
eip155: {
|
|
107
|
-
chains: [this.defaultChainId()],
|
|
108
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
109
|
-
methods: ['personal_sign', 'eth_sendTransaction'],
|
|
110
|
-
rpcMap: this.evmNetworkRpcMap(),
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
88
|
optionalNamespaces,
|
|
114
89
|
})
|
|
115
90
|
.catch((e) => {
|
|
@@ -125,6 +100,8 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
125
100
|
projectId: this.projectId,
|
|
126
101
|
});
|
|
127
102
|
WalletConnectV2.provider = provider;
|
|
103
|
+
this.teardownEventListeners();
|
|
104
|
+
this.setupEventListeners();
|
|
128
105
|
});
|
|
129
106
|
}
|
|
130
107
|
initProvider() {
|
|
@@ -161,6 +138,36 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
161
138
|
get activeAccountKey() {
|
|
162
139
|
return activeAccountKey(this.key);
|
|
163
140
|
}
|
|
141
|
+
get swicthedNetworkKey() {
|
|
142
|
+
return swicthedNetworkKey(this.key);
|
|
143
|
+
}
|
|
144
|
+
get currentChainKey() {
|
|
145
|
+
return currentChainKey(this.key);
|
|
146
|
+
}
|
|
147
|
+
set currentChainId(value) {
|
|
148
|
+
this._currentChainId = value;
|
|
149
|
+
if (value) {
|
|
150
|
+
localStorage.setItem(this.currentChainKey, value.toString());
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
localStorage.removeItem(this.currentChainKey);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
get currentChainId() {
|
|
157
|
+
return this._currentChainId;
|
|
158
|
+
}
|
|
159
|
+
set hasSwitchedNetwork(value) {
|
|
160
|
+
this._hasSwitchedNetwork = value;
|
|
161
|
+
if (value) {
|
|
162
|
+
localStorage.setItem(this.swicthedNetworkKey, value.toString());
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
localStorage.removeItem(this.swicthedNetworkKey);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
get hasSwitchedNetwork() {
|
|
169
|
+
return this._hasSwitchedNetwork;
|
|
170
|
+
}
|
|
164
171
|
supportsNetworkSwitching() {
|
|
165
172
|
return true;
|
|
166
173
|
}
|
|
@@ -169,6 +176,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
169
176
|
return;
|
|
170
177
|
}
|
|
171
178
|
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
179
|
+
walletConnectorCore.logger.debug('session_event was called', { params });
|
|
172
180
|
if (!params || !params.event) {
|
|
173
181
|
walletConnectorCore.logger.debug('session_event was called without params or params.event');
|
|
174
182
|
return;
|
|
@@ -180,6 +188,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
180
188
|
walletConnectorCore.logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
181
189
|
return;
|
|
182
190
|
}
|
|
191
|
+
this.currentChainId = chainId;
|
|
183
192
|
this.emit('chainChange', { chain: String(chainId) });
|
|
184
193
|
// When a user switches network from their wallet, we need the provider to change network
|
|
185
194
|
// such that any future calls to `getNetwork` will return the correct network
|
|
@@ -358,6 +367,8 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
358
367
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
359
368
|
this.clearActiveAccount();
|
|
360
369
|
this.clearSession();
|
|
370
|
+
this.hasSwitchedNetwork = false;
|
|
371
|
+
this.currentChainId = undefined;
|
|
361
372
|
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session)) {
|
|
362
373
|
return;
|
|
363
374
|
}
|
|
@@ -377,6 +388,9 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
377
388
|
getNetwork: { get: () => super.getNetwork }
|
|
378
389
|
});
|
|
379
390
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
391
|
+
if (this.currentChainId) {
|
|
392
|
+
return this.currentChainId;
|
|
393
|
+
}
|
|
380
394
|
yield this.initProvider();
|
|
381
395
|
return _super.getNetwork.call(this);
|
|
382
396
|
});
|
|
@@ -400,6 +414,8 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
400
414
|
throw new utils.DynamicError('Provider not found');
|
|
401
415
|
}
|
|
402
416
|
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
417
|
+
this.currentChainId = network.chainId;
|
|
418
|
+
this.hasSwitchedNetwork = true;
|
|
403
419
|
this.emit('chainChange', { chain: String(network.chainId) });
|
|
404
420
|
});
|
|
405
421
|
}
|
|
@@ -417,7 +433,11 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
417
433
|
});
|
|
418
434
|
}
|
|
419
435
|
getSupportedNetworks() {
|
|
436
|
+
var _a;
|
|
420
437
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
438
|
+
if (!this.hasSwitchedNetwork) {
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
421
441
|
yield this.initProvider();
|
|
422
442
|
this.refreshSession();
|
|
423
443
|
if (!this.session) {
|
|
@@ -431,7 +451,7 @@ class WalletConnectV2 extends EthWalletConnector.EthWalletConnector {
|
|
|
431
451
|
chains.push(key.split(':')[1]);
|
|
432
452
|
}
|
|
433
453
|
});
|
|
434
|
-
this.session.namespaces.eip155.accounts.forEach((account) => chains.push(account.split(':')[1]));
|
|
454
|
+
(_a = this.session.namespaces.eip155) === null || _a === void 0 ? void 0 : _a.accounts.forEach((account) => chains.push(account.split(':')[1]));
|
|
435
455
|
return chains.length ? chains : undefined;
|
|
436
456
|
});
|
|
437
457
|
}
|
|
@@ -23,11 +23,10 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
23
23
|
private projectId?;
|
|
24
24
|
private deepLinkPreference;
|
|
25
25
|
private preferredChains;
|
|
26
|
+
private _currentChainId;
|
|
27
|
+
private _hasSwitchedNetwork;
|
|
26
28
|
constructor(opts: WalletConnectorV2Opts);
|
|
27
|
-
private
|
|
28
|
-
private findSupportedChains;
|
|
29
|
-
private supportedChain;
|
|
30
|
-
private optionalChains;
|
|
29
|
+
private getMappedChains;
|
|
31
30
|
private initConnection;
|
|
32
31
|
private createInitProviderPromise;
|
|
33
32
|
private initProvider;
|
|
@@ -35,6 +34,12 @@ export declare class WalletConnectV2 extends EthWalletConnector {
|
|
|
35
34
|
init(): Promise<void>;
|
|
36
35
|
get sessionTopicKey(): string;
|
|
37
36
|
get activeAccountKey(): string;
|
|
37
|
+
get swicthedNetworkKey(): string;
|
|
38
|
+
get currentChainKey(): string;
|
|
39
|
+
private set currentChainId(value);
|
|
40
|
+
private get currentChainId();
|
|
41
|
+
private set hasSwitchedNetwork(value);
|
|
42
|
+
private get hasSwitchedNetwork();
|
|
38
43
|
supportsNetworkSwitching(): boolean;
|
|
39
44
|
setupEventListeners(): void;
|
|
40
45
|
teardownEventListeners(): void;
|
|
@@ -10,9 +10,12 @@ import { parseIntSafe } from '../utils/parseIntSafe.js';
|
|
|
10
10
|
|
|
11
11
|
const activeAccountKey = (walletName) => `dynamic-wc2-active-account-${walletName}`;
|
|
12
12
|
const sessionTopicKey = (walletName) => `dynamic-wc2-session-topic-${walletName}`;
|
|
13
|
+
const swicthedNetworkKey = (walletName) => `dynamic-wc2-switched-network-${walletName}`;
|
|
14
|
+
const currentChainKey = (walletName) => `dynamic-wc2-current-chain-${walletName}`;
|
|
13
15
|
const ee = new EventEmitter();
|
|
14
16
|
class WalletConnectV2 extends EthWalletConnector {
|
|
15
17
|
constructor(opts) {
|
|
18
|
+
var _a;
|
|
16
19
|
super(opts);
|
|
17
20
|
this.supportedChains = ['EVM', 'ETH'];
|
|
18
21
|
this.connectedChain = 'EVM';
|
|
@@ -20,6 +23,9 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
20
23
|
this.canConnectViaQrCode = true;
|
|
21
24
|
this.isWalletConnect = true;
|
|
22
25
|
this.preferredChains = [];
|
|
26
|
+
// When trying to switch network for MetaMask, the switch promise gets stuck
|
|
27
|
+
// if the switch got trigged once already, so we need to keep track of that
|
|
28
|
+
this._hasSwitchedNetwork = false;
|
|
23
29
|
this.name = opts.walletName;
|
|
24
30
|
this.projectId = opts.projectId;
|
|
25
31
|
this.deepLinkPreference = opts.deepLinkPreference || 'native';
|
|
@@ -27,40 +33,17 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
27
33
|
if (!this.preferredChains.includes('eip155:1')) {
|
|
28
34
|
this.preferredChains.push('eip155:1');
|
|
29
35
|
}
|
|
36
|
+
this.hasSwitchedNetwork =
|
|
37
|
+
(_a = Boolean(localStorage.getItem(this.swicthedNetworkKey))) !== null && _a !== void 0 ? _a : false;
|
|
38
|
+
const lsCurrentChain = localStorage.getItem(this.currentChainKey);
|
|
39
|
+
this.currentChainId = lsCurrentChain
|
|
40
|
+
? parseIntSafe(lsCurrentChain)
|
|
41
|
+
: undefined;
|
|
30
42
|
}
|
|
31
|
-
|
|
32
|
-
const preferredNetwork = this.preferredChains.find((chain) => this.supportedChain(chain));
|
|
33
|
-
if (preferredNetwork) {
|
|
34
|
-
return preferredNetwork;
|
|
35
|
-
}
|
|
36
|
-
else if (this.findSupportedChains().length) {
|
|
37
|
-
return this.findSupportedChains()[0];
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return 'eip155:1';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
findSupportedChains() {
|
|
44
|
-
var _a;
|
|
45
|
-
try {
|
|
46
|
-
const wallet = getWalletBookWallet(this.walletBook, this.key);
|
|
47
|
-
const supportedChains = (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.filter((network) => { var _a; return (_a = wallet === null || wallet === void 0 ? void 0 : wallet.chains) === null || _a === void 0 ? void 0 : _a.includes(`eip155:${network.chainId}`); }).map((network) => `eip155:${network.chainId}`);
|
|
48
|
-
return supportedChains;
|
|
49
|
-
}
|
|
50
|
-
catch (_b) {
|
|
51
|
-
// pass
|
|
52
|
-
}
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
supportedChain(chainId) {
|
|
56
|
-
var _a;
|
|
57
|
-
return (_a = this.findSupportedChains().filter((chain) => [`eip155:${chainId}`, chainId].includes(chain))) === null || _a === void 0 ? void 0 : _a[0];
|
|
58
|
-
}
|
|
59
|
-
optionalChains() {
|
|
43
|
+
getMappedChains() {
|
|
60
44
|
return (this.evmNetworks
|
|
61
|
-
// Filters out
|
|
62
|
-
.filter((network) => network.chainId !== 11297108109
|
|
63
|
-
`eip155:${network.chainId}` !== this.defaultChainId())
|
|
45
|
+
// Filters out palm that crashes Trust Wallet
|
|
46
|
+
.filter((network) => network.chainId !== 11297108109)
|
|
64
47
|
.map((network) => `eip155:${network.chainId}`));
|
|
65
48
|
}
|
|
66
49
|
initConnection() {
|
|
@@ -73,34 +56,26 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
73
56
|
if (provider === null || provider === void 0 ? void 0 : provider.uri) {
|
|
74
57
|
return;
|
|
75
58
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
}
|
|
59
|
+
const optionalNamespaces = {
|
|
60
|
+
eip155: {
|
|
61
|
+
chains: this.getMappedChains(),
|
|
62
|
+
events: ['chainChanged', 'accountsChanged'],
|
|
63
|
+
methods: [
|
|
64
|
+
'eth_chainId',
|
|
65
|
+
'eth_signTypedData',
|
|
66
|
+
'eth_signTransaction',
|
|
67
|
+
'eth_sign',
|
|
68
|
+
'personal_sign',
|
|
69
|
+
'eth_sendTransaction',
|
|
70
|
+
'eth_signTypedData_v4',
|
|
71
|
+
'wallet_switchEthereumChain',
|
|
72
|
+
'wallet_addEthereumChain',
|
|
73
|
+
],
|
|
74
|
+
rpcMap: this.evmNetworkRpcMap(),
|
|
75
|
+
},
|
|
76
|
+
};
|
|
94
77
|
provider
|
|
95
78
|
.connect({
|
|
96
|
-
namespaces: {
|
|
97
|
-
eip155: {
|
|
98
|
-
chains: [this.defaultChainId()],
|
|
99
|
-
events: ['chainChanged', 'accountsChanged'],
|
|
100
|
-
methods: ['personal_sign', 'eth_sendTransaction'],
|
|
101
|
-
rpcMap: this.evmNetworkRpcMap(),
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
79
|
optionalNamespaces,
|
|
105
80
|
})
|
|
106
81
|
.catch((e) => {
|
|
@@ -116,6 +91,8 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
116
91
|
projectId: this.projectId,
|
|
117
92
|
});
|
|
118
93
|
WalletConnectV2.provider = provider;
|
|
94
|
+
this.teardownEventListeners();
|
|
95
|
+
this.setupEventListeners();
|
|
119
96
|
});
|
|
120
97
|
}
|
|
121
98
|
initProvider() {
|
|
@@ -152,6 +129,36 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
152
129
|
get activeAccountKey() {
|
|
153
130
|
return activeAccountKey(this.key);
|
|
154
131
|
}
|
|
132
|
+
get swicthedNetworkKey() {
|
|
133
|
+
return swicthedNetworkKey(this.key);
|
|
134
|
+
}
|
|
135
|
+
get currentChainKey() {
|
|
136
|
+
return currentChainKey(this.key);
|
|
137
|
+
}
|
|
138
|
+
set currentChainId(value) {
|
|
139
|
+
this._currentChainId = value;
|
|
140
|
+
if (value) {
|
|
141
|
+
localStorage.setItem(this.currentChainKey, value.toString());
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
localStorage.removeItem(this.currentChainKey);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
get currentChainId() {
|
|
148
|
+
return this._currentChainId;
|
|
149
|
+
}
|
|
150
|
+
set hasSwitchedNetwork(value) {
|
|
151
|
+
this._hasSwitchedNetwork = value;
|
|
152
|
+
if (value) {
|
|
153
|
+
localStorage.setItem(this.swicthedNetworkKey, value.toString());
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
localStorage.removeItem(this.swicthedNetworkKey);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
get hasSwitchedNetwork() {
|
|
160
|
+
return this._hasSwitchedNetwork;
|
|
161
|
+
}
|
|
155
162
|
supportsNetworkSwitching() {
|
|
156
163
|
return true;
|
|
157
164
|
}
|
|
@@ -160,6 +167,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
160
167
|
return;
|
|
161
168
|
}
|
|
162
169
|
WalletConnectV2.provider.client.on('session_event', ({ params }) => {
|
|
170
|
+
logger.debug('session_event was called', { params });
|
|
163
171
|
if (!params || !params.event) {
|
|
164
172
|
logger.debug('session_event was called without params or params.event');
|
|
165
173
|
return;
|
|
@@ -171,6 +179,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
171
179
|
logger.debug(`received unexpected data for chainChanged: ${data} with type ${typeof data}}`);
|
|
172
180
|
return;
|
|
173
181
|
}
|
|
182
|
+
this.currentChainId = chainId;
|
|
174
183
|
this.emit('chainChange', { chain: String(chainId) });
|
|
175
184
|
// When a user switches network from their wallet, we need the provider to change network
|
|
176
185
|
// such that any future calls to `getNetwork` will return the correct network
|
|
@@ -349,6 +358,8 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
349
358
|
return __awaiter(this, void 0, void 0, function* () {
|
|
350
359
|
this.clearActiveAccount();
|
|
351
360
|
this.clearSession();
|
|
361
|
+
this.hasSwitchedNetwork = false;
|
|
362
|
+
this.currentChainId = undefined;
|
|
352
363
|
if (!((_a = WalletConnectV2.provider) === null || _a === void 0 ? void 0 : _a.session)) {
|
|
353
364
|
return;
|
|
354
365
|
}
|
|
@@ -368,6 +379,9 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
368
379
|
getNetwork: { get: () => super.getNetwork }
|
|
369
380
|
});
|
|
370
381
|
return __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
if (this.currentChainId) {
|
|
383
|
+
return this.currentChainId;
|
|
384
|
+
}
|
|
371
385
|
yield this.initProvider();
|
|
372
386
|
return _super.getNetwork.call(this);
|
|
373
387
|
});
|
|
@@ -391,6 +405,8 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
391
405
|
throw new DynamicError('Provider not found');
|
|
392
406
|
}
|
|
393
407
|
yield _super.providerSwitchNetwork.call(this, { network, provider });
|
|
408
|
+
this.currentChainId = network.chainId;
|
|
409
|
+
this.hasSwitchedNetwork = true;
|
|
394
410
|
this.emit('chainChange', { chain: String(network.chainId) });
|
|
395
411
|
});
|
|
396
412
|
}
|
|
@@ -408,7 +424,11 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
408
424
|
});
|
|
409
425
|
}
|
|
410
426
|
getSupportedNetworks() {
|
|
427
|
+
var _a;
|
|
411
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
429
|
+
if (!this.hasSwitchedNetwork) {
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
412
432
|
yield this.initProvider();
|
|
413
433
|
this.refreshSession();
|
|
414
434
|
if (!this.session) {
|
|
@@ -422,7 +442,7 @@ class WalletConnectV2 extends EthWalletConnector {
|
|
|
422
442
|
chains.push(key.split(':')[1]);
|
|
423
443
|
}
|
|
424
444
|
});
|
|
425
|
-
this.session.namespaces.eip155.accounts.forEach((account) => chains.push(account.split(':')[1]));
|
|
445
|
+
(_a = this.session.namespaces.eip155) === null || _a === void 0 ? void 0 : _a.accounts.forEach((account) => chains.push(account.split(':')[1]));
|
|
426
446
|
return chains.length ? chains : undefined;
|
|
427
447
|
});
|
|
428
448
|
}
|