@dynamic-labs/multi-wallet 0.17.0-RC.6 → 0.17.0-RC.8
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 +53 -0
- package/package.json +8 -6
- package/src/index.cjs +0 -18
- package/src/index.d.ts +0 -4
- package/src/index.js +1 -4
- package/src/multi-wallet.cjs +53 -96
- package/src/multi-wallet.js +53 -96
- package/src/types.d.ts +9 -47
- package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.d.ts +1 -1
- package/src/utils/getApiProviders.cjs +15 -0
- package/src/utils/getApiProviders.d.ts +10 -0
- package/src/utils/getApiProviders.js +11 -0
- package/src/utils/message.cjs +2 -2
- package/src/utils/message.d.ts +2 -2
- package/src/utils/message.js +1 -1
- package/src/utils/walletConnect.cjs +11 -8
- package/src/utils/walletConnect.d.ts +4 -4
- package/src/utils/walletConnect.js +11 -8
- package/src/wallets/algorand/MyAlgoWalletConnector.cjs +3 -3
- package/src/wallets/algorand/MyAlgoWalletConnector.js +1 -1
- package/src/wallets/clients/coinbase/coinbase.cjs +4 -4
- package/src/wallets/clients/coinbase/coinbase.js +1 -1
- package/src/wallets/clients/coinbase/types.d.ts +2 -2
- package/src/wallets/clients/walletConnect/walletConnect.cjs +20 -46
- package/src/wallets/clients/walletConnect/walletConnect.d.ts +1 -3
- package/src/wallets/clients/walletConnect/walletConnect.js +18 -43
- package/src/wallets/cosmos/KeplrWalletConnect.cjs +18 -16
- package/src/wallets/cosmos/KeplrWalletConnect.d.ts +7 -6
- package/src/wallets/cosmos/KeplrWalletConnect.js +14 -12
- package/src/wallets/cosmos/KeplrWalletConnector.cjs +21 -6
- package/src/wallets/cosmos/KeplrWalletConnector.d.ts +10 -5
- package/src/wallets/cosmos/KeplrWalletConnector.js +21 -6
- package/src/wallets/cosmos/wcClient.lib.cjs +100 -0
- package/src/wallets/cosmos/wcClient.lib.d.ts +20 -0
- package/src/wallets/cosmos/wcClient.lib.js +87 -0
- package/src/wallets/ethereum/BloctoEvm.cjs +10 -12
- package/src/wallets/ethereum/BloctoEvm.d.ts +2 -7
- package/src/wallets/ethereum/BloctoEvm.js +8 -10
- package/src/wallets/ethereum/EthWalletConnector.cjs +34 -19
- package/src/wallets/ethereum/EthWalletConnector.d.ts +8 -4
- package/src/wallets/ethereum/EthWalletConnector.js +28 -13
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.cjs +0 -2
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.js +0 -2
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.cjs +2 -2
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.js +1 -1
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.cjs +14 -38
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.d.ts +5 -7
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.js +14 -38
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.cjs +10 -4
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.js +9 -3
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.cjs +15 -11
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.d.ts +9 -8
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.js +13 -9
- package/src/wallets/ethereum/coinbase.cjs +9 -11
- package/src/wallets/ethereum/coinbase.d.ts +7 -11
- package/src/wallets/ethereum/coinbase.js +10 -12
- package/src/wallets/ethereum/ethProviderHelper.cjs +103 -101
- package/src/wallets/ethereum/ethProviderHelper.d.ts +24 -31
- package/src/wallets/ethereum/ethProviderHelper.js +100 -98
- package/src/wallets/ethereum/evm-network.cjs +2 -2
- package/src/wallets/ethereum/evm-network.d.ts +1 -17
- package/src/wallets/ethereum/evm-network.js +2 -2
- package/src/wallets/ethereum/injected/BloctoInjected.cjs +2 -3
- package/src/wallets/ethereum/injected/BloctoInjected.d.ts +2 -3
- package/src/wallets/ethereum/injected/BloctoInjected.js +2 -3
- package/src/wallets/ethereum/injected/BraveEvm.cjs +2 -3
- package/src/wallets/ethereum/injected/BraveEvm.d.ts +2 -3
- package/src/wallets/ethereum/injected/BraveEvm.js +2 -3
- package/src/wallets/ethereum/injected/Dawn.cjs +2 -3
- package/src/wallets/ethereum/injected/Dawn.d.ts +2 -3
- package/src/wallets/ethereum/injected/Dawn.js +2 -3
- package/src/wallets/ethereum/injected/ExodusEvm.cjs +2 -3
- package/src/wallets/ethereum/injected/ExodusEvm.d.ts +2 -3
- package/src/wallets/ethereum/injected/ExodusEvm.js +2 -3
- package/src/wallets/ethereum/injected/Frame.cjs +2 -3
- package/src/wallets/ethereum/injected/Frame.d.ts +2 -3
- package/src/wallets/ethereum/injected/Frame.js +2 -3
- package/src/wallets/ethereum/injected/GameStop.cjs +2 -3
- package/src/wallets/ethereum/injected/GameStop.d.ts +2 -3
- package/src/wallets/ethereum/injected/GameStop.js +2 -3
- package/src/wallets/ethereum/injected/InjectedWalletBase.cjs +74 -0
- package/src/wallets/ethereum/{meta-mask.d.ts → injected/InjectedWalletBase.d.ts} +7 -9
- package/src/wallets/ethereum/injected/InjectedWalletBase.js +72 -0
- package/src/wallets/ethereum/injected/MetaMask.cjs +13 -0
- package/src/wallets/ethereum/injected/MetaMask.d.ts +6 -0
- package/src/wallets/ethereum/injected/MetaMask.js +11 -0
- package/src/wallets/ethereum/injected/Opera.cjs +2 -3
- package/src/wallets/ethereum/injected/Opera.d.ts +2 -3
- package/src/wallets/ethereum/injected/Opera.js +2 -3
- package/src/wallets/ethereum/injected/PhantomEvm.cjs +2 -3
- package/src/wallets/ethereum/injected/PhantomEvm.d.ts +2 -3
- package/src/wallets/ethereum/injected/PhantomEvm.js +2 -3
- package/src/wallets/ethereum/injected/Trust.cjs +3 -3
- package/src/wallets/ethereum/injected/Trust.d.ts +3 -3
- package/src/wallets/ethereum/injected/Trust.js +3 -3
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.cjs +2 -3
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.d.ts +2 -3
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.js +2 -3
- package/src/wallets/ethereum/injected/Zerion.cjs +3 -3
- package/src/wallets/ethereum/injected/Zerion.d.ts +3 -3
- package/src/wallets/ethereum/injected/Zerion.js +3 -3
- package/src/wallets/flow/FlowWalletConnector.cjs +7 -8
- package/src/wallets/flow/FlowWalletConnector.js +2 -3
- package/src/wallets/getWalletConnectConnector.cjs +7 -10
- package/src/wallets/getWalletConnectConnector.d.ts +2 -5
- package/src/wallets/getWalletConnectConnector.js +7 -10
- package/src/wallets/solana/CoinbaseSolana.cjs +8 -11
- package/src/wallets/solana/CoinbaseSolana.d.ts +1 -3
- package/src/wallets/solana/CoinbaseSolana.js +8 -11
- package/src/wallets/solana/glow.cjs +8 -11
- package/src/wallets/solana/glow.d.ts +1 -3
- package/src/wallets/solana/glow.js +8 -11
- package/src/wallets/solana/injected/BraveSol.cjs +2 -1
- package/src/wallets/solana/injected/BraveSol.js +2 -1
- package/src/wallets/solana/phantom-ledger.cjs +5 -5
- package/src/wallets/solana/phantom-ledger.js +1 -1
- package/src/wallets/solana/phantom.cjs +8 -12
- package/src/wallets/solana/phantom.d.ts +1 -3
- package/src/wallets/solana/phantom.js +8 -12
- package/src/wallets/solana/slope.cjs +4 -4
- package/src/wallets/solana/slope.js +1 -1
- package/src/wallets/solana/solProviderHelper.cjs +47 -48
- package/src/wallets/solana/solProviderHelper.d.ts +18 -18
- package/src/wallets/solana/solProviderHelper.js +47 -48
- package/src/wallets/solana/solWalletConnector.cjs +24 -6
- package/src/wallets/solana/solWalletConnector.d.ts +8 -5
- package/src/wallets/solana/solWalletConnector.js +23 -5
- package/src/wallets/solana/solflare.cjs +6 -7
- package/src/wallets/solana/solflare.d.ts +0 -2
- package/src/wallets/solana/solflare.js +6 -7
- package/src/wallets/starknet/starknetWalletConnector.cjs +5 -6
- package/src/wallets/starknet/starknetWalletConnector.js +2 -3
- package/src/wallets/walletConnect/index.d.ts +1 -1
- package/src/wallets/walletConnect/walletConnect.cjs +8 -7
- package/src/wallets/walletConnect/walletConnect.d.ts +7 -7
- package/src/wallets/walletConnect/walletConnect.js +6 -5
- package/src/wallets/walletConnect/walletConnectV2.cjs +14 -14
- package/src/wallets/walletConnect/walletConnectV2.d.ts +7 -7
- package/src/wallets/walletConnect/walletConnectV2.js +3 -3
- package/src/wallets/walletConnect/zerion.d.ts +2 -4
- package/src/errors.cjs +0 -66
- package/src/errors.d.ts +0 -34
- package/src/errors.js +0 -54
- package/src/rpcProviders.cjs +0 -76
- package/src/rpcProviders.d.ts +0 -5
- package/src/rpcProviders.js +0 -69
- package/src/utils/CancellablePromise/CancellablePromise.cjs +0 -33
- package/src/utils/CancellablePromise/CancellablePromise.d.ts +0 -9
- package/src/utils/CancellablePromise/CancellablePromise.js +0 -29
- package/src/utils/CancellablePromise/index.d.ts +0 -1
- package/src/utils/logger.cjs +0 -9
- package/src/utils/logger.d.ts +0 -2
- package/src/utils/logger.js +0 -5
- package/src/wallets/cosmos/getKeplrConnector.cjs +0 -18
- package/src/wallets/cosmos/getKeplrConnector.d.ts +0 -6
- package/src/wallets/cosmos/getKeplrConnector.js +0 -14
- package/src/wallets/ethereum/fortmatic.cjs +0 -75
- package/src/wallets/ethereum/fortmatic.d.ts +0 -26
- package/src/wallets/ethereum/fortmatic.js +0 -69
- package/src/wallets/ethereum/meta-mask.cjs +0 -63
- package/src/wallets/ethereum/meta-mask.js +0 -61
- package/src/wallets/getMobileOrInjectedWallet.cjs +0 -26
- package/src/wallets/getMobileOrInjectedWallet.d.ts +0 -8
- package/src/wallets/getMobileOrInjectedWallet.js +0 -22
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
5
5
|
var walletBook = require('@dynamic-labs/wallet-book');
|
|
6
|
+
var utils = require('@dynamic-labs/utils');
|
|
6
7
|
var walletConnect = require('../clients/walletConnect/walletConnect.cjs');
|
|
7
8
|
var isMobile = require('../../utils/isMobile.cjs');
|
|
8
|
-
var logger = require('../../utils/logger.cjs');
|
|
9
9
|
var wcClient = require('./wcClient.cjs');
|
|
10
|
+
var wcClient_lib = require('./wcClient.lib.cjs');
|
|
10
11
|
|
|
11
12
|
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_wc_network_id';
|
|
12
13
|
class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
super();
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
16
|
this.name = 'Keplr';
|
|
17
17
|
this.isWalletConnect = true;
|
|
18
18
|
this.canConnectViaQrCode = true;
|
|
@@ -29,22 +29,24 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
29
29
|
};
|
|
30
30
|
this.supportedChains = ['COSMOS'];
|
|
31
31
|
this.connectedChain = 'COSMOS';
|
|
32
|
-
this.evmNetworks =
|
|
32
|
+
this.evmNetworks = utils.parseEvmNetworks(props.cosmosNetworks);
|
|
33
33
|
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
34
34
|
if (persistedNetworkId) {
|
|
35
35
|
this.selectedNetworkId = Number(persistedNetworkId);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
this.selectedNetworkId =
|
|
38
|
+
this.selectedNetworkId =
|
|
39
|
+
(this.evmNetworks[0] && utils.parseChainId(this.evmNetworks[0].chainId)) ||
|
|
40
|
+
401;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
get evmNetwork() {
|
|
42
44
|
var _a;
|
|
43
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.chainId === this.selectedNetworkId);
|
|
45
|
+
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => utils.parseChainId(network.chainId) === this.selectedNetworkId);
|
|
44
46
|
}
|
|
45
47
|
get selectedNetwork() {
|
|
46
48
|
var _a;
|
|
47
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.networkId === this.selectedNetworkId);
|
|
49
|
+
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => utils.parseChainId(network.networkId) === this.selectedNetworkId);
|
|
48
50
|
}
|
|
49
51
|
get lcdUrl() {
|
|
50
52
|
var _a;
|
|
@@ -58,7 +60,7 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
58
60
|
if (!this.selectedNetwork) {
|
|
59
61
|
return 'osmosis-1';
|
|
60
62
|
}
|
|
61
|
-
return this.chainIdMap[this.selectedNetwork.chainId];
|
|
63
|
+
return this.chainIdMap[utils.parseChainId(this.selectedNetwork.chainId)];
|
|
62
64
|
}
|
|
63
65
|
getProvider() {
|
|
64
66
|
if (!this._keplrInstance) {
|
|
@@ -70,7 +72,7 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
70
72
|
if (this.client) {
|
|
71
73
|
return this.client;
|
|
72
74
|
}
|
|
73
|
-
this.client =
|
|
75
|
+
this.client = wcClient_lib.initClient(this.key, this.clientOptions);
|
|
74
76
|
return this.client;
|
|
75
77
|
}
|
|
76
78
|
getNetwork() {
|
|
@@ -87,7 +89,7 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
87
89
|
localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, networkChainId.toString());
|
|
88
90
|
}
|
|
89
91
|
catch (e) {
|
|
90
|
-
|
|
92
|
+
walletConnectorCore.logger.error(e);
|
|
91
93
|
}
|
|
92
94
|
});
|
|
93
95
|
}
|
|
@@ -115,7 +117,7 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
115
117
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
116
118
|
const client = this.getClient();
|
|
117
119
|
const keplr = this.getProvider();
|
|
118
|
-
return
|
|
120
|
+
return wcClient_lib.fetchWalletConnectCosmosPublicAddress(walletBook.getWalletBookWallet(this.name), client, keplr, Object.assign(Object.assign({}, opts), { chainId: this.chainId, onConnect: (payload) => {
|
|
119
121
|
var _a;
|
|
120
122
|
payload.params[0].chainId = this.selectedNetworkId;
|
|
121
123
|
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
@@ -138,14 +140,14 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
138
140
|
return balance.toString();
|
|
139
141
|
}
|
|
140
142
|
catch (e) {
|
|
141
|
-
|
|
143
|
+
walletConnectorCore.logger.error(e);
|
|
142
144
|
return '0';
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
148
|
endSession() {
|
|
147
149
|
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
|
|
150
|
+
wcClient_lib.killWalletConnectSession(this.getClient());
|
|
149
151
|
});
|
|
150
152
|
}
|
|
151
153
|
getConnectedAccounts() {
|
|
@@ -162,7 +164,7 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
162
164
|
if (!isMobile.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
|
|
163
165
|
return undefined;
|
|
164
166
|
}
|
|
165
|
-
return
|
|
167
|
+
return wcClient_lib.getDeepLink(this.getClient().uri, wallet, {
|
|
166
168
|
removeWCUri: isMobile.isIOS() && this.key === 'cryptocom',
|
|
167
169
|
});
|
|
168
170
|
}
|
|
@@ -179,7 +181,7 @@ class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
|
179
181
|
return this.getProvider();
|
|
180
182
|
}
|
|
181
183
|
setupEventListeners(listeners) {
|
|
182
|
-
|
|
184
|
+
walletConnect.setupWalletConnectEventListeners({
|
|
183
185
|
onAccountChange: listeners.onAccountChange,
|
|
184
186
|
onChainChange: listeners.onChainChange,
|
|
185
187
|
onDisconnect: listeners.onDisconnect,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import Client from '@walletconnect/client';
|
|
2
2
|
import { OfflineAminoSigner } from '@keplr-wallet/types';
|
|
3
3
|
import { Chain, FetchPublicAddressOpts, WalletConnectorBase, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { EvmNetwork } from '
|
|
4
|
+
import { EvmNetwork, GenericNetwork } from '@dynamic-labs/types';
|
|
5
5
|
import { SwitchNetworkOps } from '../ethereum/EthWalletConnector';
|
|
6
6
|
import { KeplrWalletConnectV1 } from './wcClient';
|
|
7
|
+
export type KeplrWalletConnectProps = {
|
|
8
|
+
cosmosNetworks: GenericNetwork[];
|
|
9
|
+
};
|
|
7
10
|
declare class KeplrWalletConnect extends WalletConnectorBase {
|
|
8
|
-
constructor(
|
|
9
|
-
evmNetworks: EvmNetwork[];
|
|
10
|
-
});
|
|
11
|
+
constructor(props: KeplrWalletConnectProps);
|
|
11
12
|
name: string;
|
|
12
13
|
isWalletConnect: boolean;
|
|
13
14
|
canConnectViaQrCode: boolean;
|
|
@@ -22,7 +23,7 @@ declare class KeplrWalletConnect extends WalletConnectorBase {
|
|
|
22
23
|
connectedChain: Chain;
|
|
23
24
|
_keplrInstance: KeplrWalletConnectV1 | undefined;
|
|
24
25
|
get evmNetwork(): EvmNetwork | undefined;
|
|
25
|
-
get selectedNetwork():
|
|
26
|
+
get selectedNetwork(): GenericNetwork | undefined;
|
|
26
27
|
get lcdUrl(): string | undefined;
|
|
27
28
|
get denom(): string | undefined;
|
|
28
29
|
get chainId(): string;
|
|
@@ -39,7 +40,7 @@ declare class KeplrWalletConnect extends WalletConnectorBase {
|
|
|
39
40
|
getRpcProvider(): Promise<unknown>;
|
|
40
41
|
getSigner(): Promise<OfflineAminoSigner | undefined>;
|
|
41
42
|
getWeb3Provider(): KeplrWalletConnectV1 | undefined;
|
|
42
|
-
setupEventListeners(listeners: WalletEventListeners):
|
|
43
|
+
setupEventListeners(listeners: WalletEventListeners): void;
|
|
43
44
|
teardownEventListeners(): void;
|
|
44
45
|
supportsNetworkSwitching(): boolean;
|
|
45
46
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
|
-
import {
|
|
4
|
+
import { parseEvmNetworks, parseChainId } from '@dynamic-labs/utils';
|
|
5
|
+
import { setupWalletConnectEventListeners, teardownWalletConnectEventListeners } from '../clients/walletConnect/walletConnect.js';
|
|
5
6
|
import { isMobile, isIOS } from '../../utils/isMobile.js';
|
|
6
|
-
import { logger } from '../../utils/logger.js';
|
|
7
7
|
import { KeplrWalletConnectV1 } from './wcClient.js';
|
|
8
|
+
import { initClient, fetchWalletConnectCosmosPublicAddress, killWalletConnectSession, getDeepLink } from './wcClient.lib.js';
|
|
8
9
|
|
|
9
10
|
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_wc_network_id';
|
|
10
11
|
class KeplrWalletConnect extends WalletConnectorBase {
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
13
|
-
super();
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(props);
|
|
14
14
|
this.name = 'Keplr';
|
|
15
15
|
this.isWalletConnect = true;
|
|
16
16
|
this.canConnectViaQrCode = true;
|
|
@@ -27,22 +27,24 @@ class KeplrWalletConnect extends WalletConnectorBase {
|
|
|
27
27
|
};
|
|
28
28
|
this.supportedChains = ['COSMOS'];
|
|
29
29
|
this.connectedChain = 'COSMOS';
|
|
30
|
-
this.evmNetworks =
|
|
30
|
+
this.evmNetworks = parseEvmNetworks(props.cosmosNetworks);
|
|
31
31
|
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
32
32
|
if (persistedNetworkId) {
|
|
33
33
|
this.selectedNetworkId = Number(persistedNetworkId);
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
this.selectedNetworkId =
|
|
36
|
+
this.selectedNetworkId =
|
|
37
|
+
(this.evmNetworks[0] && parseChainId(this.evmNetworks[0].chainId)) ||
|
|
38
|
+
401;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
get evmNetwork() {
|
|
40
42
|
var _a;
|
|
41
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.chainId === this.selectedNetworkId);
|
|
43
|
+
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => parseChainId(network.chainId) === this.selectedNetworkId);
|
|
42
44
|
}
|
|
43
45
|
get selectedNetwork() {
|
|
44
46
|
var _a;
|
|
45
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.networkId === this.selectedNetworkId);
|
|
47
|
+
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => parseChainId(network.networkId) === this.selectedNetworkId);
|
|
46
48
|
}
|
|
47
49
|
get lcdUrl() {
|
|
48
50
|
var _a;
|
|
@@ -56,7 +58,7 @@ class KeplrWalletConnect extends WalletConnectorBase {
|
|
|
56
58
|
if (!this.selectedNetwork) {
|
|
57
59
|
return 'osmosis-1';
|
|
58
60
|
}
|
|
59
|
-
return this.chainIdMap[this.selectedNetwork.chainId];
|
|
61
|
+
return this.chainIdMap[parseChainId(this.selectedNetwork.chainId)];
|
|
60
62
|
}
|
|
61
63
|
getProvider() {
|
|
62
64
|
if (!this._keplrInstance) {
|
|
@@ -177,7 +179,7 @@ class KeplrWalletConnect extends WalletConnectorBase {
|
|
|
177
179
|
return this.getProvider();
|
|
178
180
|
}
|
|
179
181
|
setupEventListeners(listeners) {
|
|
180
|
-
|
|
182
|
+
setupWalletConnectEventListeners({
|
|
181
183
|
onAccountChange: listeners.onAccountChange,
|
|
182
184
|
onChainChange: listeners.onChainChange,
|
|
183
185
|
onDisconnect: listeners.onDisconnect,
|
|
@@ -4,14 +4,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
-
var
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var KeplrWalletConnect = require('./KeplrWalletConnect.cjs');
|
|
8
9
|
|
|
9
10
|
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_network_id';
|
|
10
11
|
class KeplrWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
getMobileOrInstalledWallet() {
|
|
13
|
+
if (this.isInstalledOnBrowser()) {
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return new KeplrWalletConnect(this.constructorProps);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
13
22
|
this.switchNetworkOnlyFromWallet = true;
|
|
14
|
-
this.
|
|
23
|
+
this._selectedNetworkId = 401;
|
|
15
24
|
this.name = 'Keplr';
|
|
16
25
|
this.connectedChain = 'COSMOS';
|
|
17
26
|
this.supportedChains = ['COSMOS'];
|
|
@@ -20,13 +29,19 @@ class KeplrWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
20
29
|
402: 'axelar-dojo-1',
|
|
21
30
|
403: 'osmosis-1',
|
|
22
31
|
};
|
|
23
|
-
this.evmNetworks =
|
|
32
|
+
this.evmNetworks = utils.parseEvmNetworks(props.cosmosNetworks);
|
|
24
33
|
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
25
34
|
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
26
35
|
if (persistedNetworkId) {
|
|
27
36
|
this.selectedNetworkId = Number(persistedNetworkId);
|
|
28
37
|
}
|
|
29
38
|
}
|
|
39
|
+
get selectedNetworkId() {
|
|
40
|
+
return this._selectedNetworkId;
|
|
41
|
+
}
|
|
42
|
+
set selectedNetworkId(networkId) {
|
|
43
|
+
this._selectedNetworkId = utils.parseChainId(networkId);
|
|
44
|
+
}
|
|
30
45
|
getWeb3Provider() {
|
|
31
46
|
return this.keplr;
|
|
32
47
|
}
|
|
@@ -175,7 +190,7 @@ class KeplrWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
175
190
|
return balance.toString();
|
|
176
191
|
}
|
|
177
192
|
catch (e) {
|
|
178
|
-
|
|
193
|
+
walletConnectorCore.logger.error(e);
|
|
179
194
|
return '0';
|
|
180
195
|
}
|
|
181
196
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Keplr as KeplrWallet } from '@keplr-wallet/types';
|
|
2
2
|
import { Chain, WalletConnectorBase, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { EvmNetwork, GenericNetwork } from '@dynamic-labs/types';
|
|
3
4
|
import { SwitchNetworkOps } from '../ethereum/EthWalletConnector';
|
|
4
|
-
import
|
|
5
|
+
import KeplrWalletConnect from './KeplrWalletConnect';
|
|
5
6
|
export interface IFetchBalanceResponse {
|
|
6
7
|
balances: IFetchBalanceBalance[];
|
|
7
8
|
pagination: IFetchBalancePagination;
|
|
@@ -14,17 +15,21 @@ export interface IFetchBalancePagination {
|
|
|
14
15
|
next_key: any;
|
|
15
16
|
total: string;
|
|
16
17
|
}
|
|
18
|
+
export type KeplrWalletConnectorProps = {
|
|
19
|
+
cosmosNetworks: GenericNetwork[];
|
|
20
|
+
};
|
|
17
21
|
export declare class KeplrWalletConnector extends WalletConnectorBase {
|
|
18
22
|
evmNetworks: EvmNetwork[];
|
|
19
23
|
switchNetworkOnlyFromWallet: boolean;
|
|
20
|
-
|
|
24
|
+
private _selectedNetworkId;
|
|
21
25
|
name: string;
|
|
22
26
|
connectedChain: Chain;
|
|
23
27
|
supportedChains: Chain[];
|
|
24
28
|
chainIdMap: Record<number, string>;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
getMobileOrInstalledWallet(): this | KeplrWalletConnect;
|
|
30
|
+
constructor(props: KeplrWalletConnectorProps);
|
|
31
|
+
get selectedNetworkId(): number;
|
|
32
|
+
set selectedNetworkId(networkId: number);
|
|
28
33
|
getWeb3Provider(): KeplrWallet;
|
|
29
34
|
getDeepLink(): string | undefined;
|
|
30
35
|
get selectedNetwork(): EvmNetwork | undefined;
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import {
|
|
2
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { parseEvmNetworks, parseChainId } from '@dynamic-labs/utils';
|
|
4
|
+
import KeplrWalletConnect from './KeplrWalletConnect.js';
|
|
4
5
|
|
|
5
6
|
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_network_id';
|
|
6
7
|
class KeplrWalletConnector extends WalletConnectorBase {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
getMobileOrInstalledWallet() {
|
|
9
|
+
if (this.isInstalledOnBrowser()) {
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return new KeplrWalletConnect(this.constructorProps);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
9
18
|
this.switchNetworkOnlyFromWallet = true;
|
|
10
|
-
this.
|
|
19
|
+
this._selectedNetworkId = 401;
|
|
11
20
|
this.name = 'Keplr';
|
|
12
21
|
this.connectedChain = 'COSMOS';
|
|
13
22
|
this.supportedChains = ['COSMOS'];
|
|
@@ -16,13 +25,19 @@ class KeplrWalletConnector extends WalletConnectorBase {
|
|
|
16
25
|
402: 'axelar-dojo-1',
|
|
17
26
|
403: 'osmosis-1',
|
|
18
27
|
};
|
|
19
|
-
this.evmNetworks =
|
|
28
|
+
this.evmNetworks = parseEvmNetworks(props.cosmosNetworks);
|
|
20
29
|
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
21
30
|
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
22
31
|
if (persistedNetworkId) {
|
|
23
32
|
this.selectedNetworkId = Number(persistedNetworkId);
|
|
24
33
|
}
|
|
25
34
|
}
|
|
35
|
+
get selectedNetworkId() {
|
|
36
|
+
return this._selectedNetworkId;
|
|
37
|
+
}
|
|
38
|
+
set selectedNetworkId(networkId) {
|
|
39
|
+
this._selectedNetworkId = parseChainId(networkId);
|
|
40
|
+
}
|
|
26
41
|
getWeb3Provider() {
|
|
27
42
|
return this.keplr;
|
|
28
43
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib = require('tslib');
|
|
6
|
+
var Client = require('@walletconnect/client');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var isMobile = require('../../utils/isMobile.cjs');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var Client__default = /*#__PURE__*/_interopDefaultLegacy(Client);
|
|
13
|
+
|
|
14
|
+
const initClient = (name, settings) => {
|
|
15
|
+
const storageId = `walletconnect-${name}`;
|
|
16
|
+
const session = localStorage.getItem(storageId);
|
|
17
|
+
const clientArgs = session
|
|
18
|
+
? { session: JSON.parse(session), storageId }
|
|
19
|
+
: { bridge: 'https://bridge.walletconnect.org', storageId };
|
|
20
|
+
return new Client__default["default"](Object.assign(Object.assign({}, clientArgs), settings));
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Initialize a client from a stored session and terminate the connection.
|
|
24
|
+
*/
|
|
25
|
+
const killWalletConnectSession = (client) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
if (client === null || client === void 0 ? void 0 : client.connected) {
|
|
28
|
+
yield client.killSession();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
walletConnectorCore.logger.debug(e);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const useDeepLink = (metadata, wcClient, opts) => {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
const deepLink = getDeepLink(wcClient.uri, metadata);
|
|
38
|
+
if (isMobile.isMobile()) {
|
|
39
|
+
window.location.href = deepLink;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
|
|
43
|
+
(_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
|
|
44
|
+
}
|
|
45
|
+
(_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
|
|
49
|
+
var _a, _b, _c, _d;
|
|
50
|
+
if (!isMobile.isMobile()) {
|
|
51
|
+
const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
|
|
52
|
+
if (removeWCUri)
|
|
53
|
+
return origin || '';
|
|
54
|
+
return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
|
|
55
|
+
}
|
|
56
|
+
// deeplinks for ios require special treatment
|
|
57
|
+
// see: https://docs.walletconnect.com/mobile-linking#for-ios
|
|
58
|
+
else if (isMobile.isIOS()) {
|
|
59
|
+
const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
|
|
60
|
+
if (removeWCUri)
|
|
61
|
+
return origin || '';
|
|
62
|
+
return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
|
|
63
|
+
}
|
|
64
|
+
// on android, the deeplink is simply the uri
|
|
65
|
+
// see: https://docs.walletconnect.com/mobile-linking#for-android
|
|
66
|
+
return uri;
|
|
67
|
+
};
|
|
68
|
+
const createSession = (client) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
client.on('connect', (error, payload) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
if (error)
|
|
72
|
+
throw error;
|
|
73
|
+
resolve(payload);
|
|
74
|
+
}));
|
|
75
|
+
client.on('disconnect', (error, payload) => {
|
|
76
|
+
reject(error || payload.params[0].message);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const fetchWalletConnectCosmosPublicAddress = (metadata, wcClient, provider, opts) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
var _a;
|
|
82
|
+
if (wcClient.connected) {
|
|
83
|
+
const key = yield provider.getKey(opts.chainId);
|
|
84
|
+
return key.bech32Address;
|
|
85
|
+
}
|
|
86
|
+
yield wcClient.createSession();
|
|
87
|
+
useDeepLink(metadata, wcClient, opts);
|
|
88
|
+
const payload = yield createSession(wcClient);
|
|
89
|
+
const key = yield provider.getKey(opts.chainId);
|
|
90
|
+
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
91
|
+
wcClient.accounts = [key.bech32Address];
|
|
92
|
+
return key.bech32Address;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
exports.createSession = createSession;
|
|
96
|
+
exports.fetchWalletConnectCosmosPublicAddress = fetchWalletConnectCosmosPublicAddress;
|
|
97
|
+
exports.getDeepLink = getDeepLink;
|
|
98
|
+
exports.initClient = initClient;
|
|
99
|
+
exports.killWalletConnectSession = killWalletConnectSession;
|
|
100
|
+
exports.useDeepLink = useDeepLink;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Client from '@walletconnect/client';
|
|
2
|
+
import { WalletSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
import { FetchPublicAddressOpts, PayloadParams, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { KeplrWalletConnectV1 } from './wcClient';
|
|
5
|
+
export declare const initClient: (name: string, settings?: any) => Client;
|
|
6
|
+
/**
|
|
7
|
+
* Initialize a client from a stored session and terminate the connection.
|
|
8
|
+
*/
|
|
9
|
+
export declare const killWalletConnectSession: (client: Client) => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Attach event handlers to WalletConnect events.
|
|
12
|
+
*/
|
|
13
|
+
export declare const setupWalletConnectEventListeners: (opts: WalletEventListeners, client: Client) => void;
|
|
14
|
+
export declare const teardownWalletConnectEventListeners: (client: Client) => void;
|
|
15
|
+
export declare const useDeepLink: (metadata: WalletSchema, wcClient: Client, opts?: FetchPublicAddressOpts) => void;
|
|
16
|
+
export declare const getDeepLink: (uri: string, metadata: WalletSchema, { removeWCUri, }?: {
|
|
17
|
+
removeWCUri?: boolean | undefined;
|
|
18
|
+
}) => string;
|
|
19
|
+
export declare const createSession: (client: Client) => Promise<PayloadParams>;
|
|
20
|
+
export declare const fetchWalletConnectCosmosPublicAddress: (metadata: WalletSchema, wcClient: Client, provider: KeplrWalletConnectV1, opts: FetchPublicAddressOpts & Required<Pick<FetchPublicAddressOpts, 'chainId'>>) => Promise<string>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import Client from '@walletconnect/client';
|
|
3
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { isMobile, isIOS } from '../../utils/isMobile.js';
|
|
5
|
+
|
|
6
|
+
const initClient = (name, settings) => {
|
|
7
|
+
const storageId = `walletconnect-${name}`;
|
|
8
|
+
const session = localStorage.getItem(storageId);
|
|
9
|
+
const clientArgs = session
|
|
10
|
+
? { session: JSON.parse(session), storageId }
|
|
11
|
+
: { bridge: 'https://bridge.walletconnect.org', storageId };
|
|
12
|
+
return new Client(Object.assign(Object.assign({}, clientArgs), settings));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Initialize a client from a stored session and terminate the connection.
|
|
16
|
+
*/
|
|
17
|
+
const killWalletConnectSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
if (client === null || client === void 0 ? void 0 : client.connected) {
|
|
20
|
+
yield client.killSession();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger.debug(e);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const useDeepLink = (metadata, wcClient, opts) => {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
const deepLink = getDeepLink(wcClient.uri, metadata);
|
|
30
|
+
if (isMobile()) {
|
|
31
|
+
window.location.href = deepLink;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.desktop) === null || _a === void 0 ? void 0 : _a.native) {
|
|
35
|
+
(_b = opts === null || opts === void 0 ? void 0 : opts.onDesktopUri) === null || _b === void 0 ? void 0 : _b.call(opts, deepLink);
|
|
36
|
+
}
|
|
37
|
+
(_c = opts === null || opts === void 0 ? void 0 : opts.onDisplayUri) === null || _c === void 0 ? void 0 : _c.call(opts, wcClient.uri);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const getDeepLink = (uri, metadata, { removeWCUri = false, } = {}) => {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
if (!isMobile()) {
|
|
43
|
+
const origin = ((_a = metadata.desktop) === null || _a === void 0 ? void 0 : _a.universal) || ((_b = metadata.desktop) === null || _b === void 0 ? void 0 : _b.native);
|
|
44
|
+
if (removeWCUri)
|
|
45
|
+
return origin || '';
|
|
46
|
+
return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
|
|
47
|
+
}
|
|
48
|
+
// deeplinks for ios require special treatment
|
|
49
|
+
// see: https://docs.walletconnect.com/mobile-linking#for-ios
|
|
50
|
+
else if (isIOS()) {
|
|
51
|
+
const origin = ((_c = metadata.mobile) === null || _c === void 0 ? void 0 : _c.universal) || ((_d = metadata.mobile) === null || _d === void 0 ? void 0 : _d.native);
|
|
52
|
+
if (removeWCUri)
|
|
53
|
+
return origin || '';
|
|
54
|
+
return `${origin}?uri=${encodeURIComponent(uri !== null && uri !== void 0 ? uri : '')}`;
|
|
55
|
+
}
|
|
56
|
+
// on android, the deeplink is simply the uri
|
|
57
|
+
// see: https://docs.walletconnect.com/mobile-linking#for-android
|
|
58
|
+
return uri;
|
|
59
|
+
};
|
|
60
|
+
const createSession = (client) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
client.on('connect', (error, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
if (error)
|
|
64
|
+
throw error;
|
|
65
|
+
resolve(payload);
|
|
66
|
+
}));
|
|
67
|
+
client.on('disconnect', (error, payload) => {
|
|
68
|
+
reject(error || payload.params[0].message);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
const fetchWalletConnectCosmosPublicAddress = (metadata, wcClient, provider, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
var _a;
|
|
74
|
+
if (wcClient.connected) {
|
|
75
|
+
const key = yield provider.getKey(opts.chainId);
|
|
76
|
+
return key.bech32Address;
|
|
77
|
+
}
|
|
78
|
+
yield wcClient.createSession();
|
|
79
|
+
useDeepLink(metadata, wcClient, opts);
|
|
80
|
+
const payload = yield createSession(wcClient);
|
|
81
|
+
const key = yield provider.getKey(opts.chainId);
|
|
82
|
+
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
83
|
+
wcClient.accounts = [key.bech32Address];
|
|
84
|
+
return key.bech32Address;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export { createSession, fetchWalletConnectCosmosPublicAddress, getDeepLink, initClient, killWalletConnectSession, useDeepLink };
|
|
@@ -3,32 +3,30 @@
|
|
|
3
3
|
var tslib = require('tslib');
|
|
4
4
|
var BloctoSDK = require('@blocto/sdk');
|
|
5
5
|
var ethers = require('ethers');
|
|
6
|
-
var
|
|
6
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
7
|
var EthWalletConnector = require('./EthWalletConnector.cjs');
|
|
8
|
-
var ethProviderHelper = require('./ethProviderHelper.cjs');
|
|
9
8
|
|
|
10
9
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
10
|
|
|
12
11
|
var BloctoSDK__default = /*#__PURE__*/_interopDefaultLegacy(BloctoSDK);
|
|
13
12
|
|
|
14
13
|
class BloctoEvm extends EthWalletConnector.EthWalletConnector {
|
|
15
|
-
constructor(
|
|
14
|
+
constructor(props) {
|
|
16
15
|
var _a, _b;
|
|
17
|
-
|
|
18
|
-
const BLOCTO_SUPPORTED_CHAIN_IDS = [1, 4, 56, 97, 137, 80001, 43114, 43113];
|
|
19
|
-
const bloctoSupportedNetworks = evmNetworks.filter((n) => BLOCTO_SUPPORTED_CHAIN_IDS.includes(n.chainId));
|
|
20
|
-
super({ evmNetworks: bloctoSupportedNetworks });
|
|
16
|
+
super(props);
|
|
21
17
|
this.LOCAL_STORAGE_KEY = 'dynamic_blocto_evm_chain_id';
|
|
22
18
|
this.name = 'bloctoevm';
|
|
23
19
|
this.canConnectViaCustodialService = true;
|
|
24
20
|
this.connectedChain = 'EVM';
|
|
25
21
|
this.supportedChains = ['EVM', 'ETH'];
|
|
26
|
-
this.ethProviderHelper = new ethProviderHelper.EthProviderHelper();
|
|
27
22
|
this.supportsNetworkSwitching = () => false;
|
|
23
|
+
// Taken from : https://docs.blocto.app/blocto-sdk/javascript-sdk/evm-sdk/provider
|
|
24
|
+
const BLOCTO_SUPPORTED_CHAIN_IDS = [1, 4, 56, 97, 137, 80001, 43114, 43113];
|
|
25
|
+
this.evmNetworks = this.evmNetworks.filter((n) => BLOCTO_SUPPORTED_CHAIN_IDS.includes(n.chainId));
|
|
28
26
|
this.chainId =
|
|
29
27
|
Number(localStorage.getItem(this.LOCAL_STORAGE_KEY)) ||
|
|
30
|
-
((_a =
|
|
31
|
-
((_b =
|
|
28
|
+
((_a = this.evmNetworks.find((n) => n.chainId === 137)) === null || _a === void 0 ? void 0 : _a.chainId) ||
|
|
29
|
+
((_b = this.evmNetworks[0]) === null || _b === void 0 ? void 0 : _b.chainId);
|
|
32
30
|
}
|
|
33
31
|
getClient() {
|
|
34
32
|
if (!this.client) {
|
|
@@ -42,7 +40,7 @@ class BloctoEvm extends EthWalletConnector.EthWalletConnector {
|
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
|
-
|
|
43
|
+
walletConnectorCore.logger.error("Couldn't find a configured network for Blocto EVM");
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
return this.client;
|
|
@@ -76,7 +74,7 @@ class BloctoEvm extends EthWalletConnector.EthWalletConnector {
|
|
|
76
74
|
return undefined;
|
|
77
75
|
}
|
|
78
76
|
catch (e) {
|
|
79
|
-
|
|
77
|
+
walletConnectorCore.logger.error(e);
|
|
80
78
|
return Promise.reject(e);
|
|
81
79
|
}
|
|
82
80
|
});
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
import { Chain } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import {
|
|
4
|
-
import { EthWalletConnector } from './EthWalletConnector';
|
|
5
|
-
import { EthProviderHelper } from './ethProviderHelper';
|
|
3
|
+
import { EthWalletConnector, EthWalletConnectorOpts } from './EthWalletConnector';
|
|
6
4
|
declare class BloctoEvm extends EthWalletConnector {
|
|
7
5
|
LOCAL_STORAGE_KEY: string;
|
|
8
6
|
private client?;
|
|
@@ -11,11 +9,8 @@ declare class BloctoEvm extends EthWalletConnector {
|
|
|
11
9
|
connectedChain: Chain;
|
|
12
10
|
supportedChains: Chain[];
|
|
13
11
|
chainId: number;
|
|
14
|
-
ethProviderHelper: EthProviderHelper;
|
|
15
12
|
supportsNetworkSwitching: () => boolean;
|
|
16
|
-
constructor(
|
|
17
|
-
evmNetworks: EvmNetwork[];
|
|
18
|
-
});
|
|
13
|
+
constructor(props: EthWalletConnectorOpts);
|
|
19
14
|
private getClient;
|
|
20
15
|
getWeb3Provider(): ethers.providers.Web3Provider | undefined;
|
|
21
16
|
fetchPublicAddress(): Promise<string | undefined>;
|