@dynamic-labs/multi-wallet 0.17.0-RC.2 → 0.17.0-RC.21
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 +242 -0
- package/package.json +10 -26
- package/src/index.cjs +0 -69
- package/src/index.d.ts +0 -18
- package/src/index.js +1 -23
- package/src/multi-wallet.cjs +38 -182
- package/src/multi-wallet.d.ts +1 -4
- package/src/multi-wallet.js +37 -180
- package/src/types.d.ts +12 -50
- package/src/utils/getApiProviders.cjs +15 -0
- package/src/utils/getApiProviders.d.ts +17 -0
- package/src/utils/getApiProviders.js +11 -0
- package/src/utils/message.cjs +3 -4
- package/src/utils/message.d.ts +2 -2
- package/src/utils/message.js +1 -2
- package/src/errors.cjs +0 -65
- package/src/errors.d.ts +0 -30
- package/src/errors.js +0 -53
- package/src/polyfills.cjs +0 -16
- package/src/polyfills.d.ts +0 -1
- package/src/polyfills.js +0 -14
- 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/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.cjs +0 -54
- package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.d.ts +0 -3
- package/src/utils/assignConfirmationScreenToProvider/assignConfirmationScreenToProvider.js +0 -50
- package/src/utils/assignConfirmationScreenToProvider/index.d.ts +0 -1
- package/src/utils/convertors.cjs +0 -43
- package/src/utils/convertors.d.ts +0 -3
- package/src/utils/convertors.js +0 -38
- package/src/utils/encoding.cjs +0 -18
- package/src/utils/encoding.d.ts +0 -4
- package/src/utils/encoding.js +0 -12
- package/src/utils/extractNonce.cjs +0 -13
- package/src/utils/extractNonce.d.ts +0 -1
- package/src/utils/extractNonce.js +0 -9
- package/src/utils/getChainInfo/getChainInfo.cjs +0 -59
- package/src/utils/getChainInfo/getChainInfo.d.ts +0 -2
- package/src/utils/getChainInfo/getChainInfo.js +0 -55
- package/src/utils/getChainInfo/index.d.ts +0 -1
- package/src/utils/getWalletConnectorByName.cjs +0 -19
- package/src/utils/getWalletConnectorByName.d.ts +0 -2
- package/src/utils/getWalletConnectorByName.js +0 -15
- package/src/utils/isEmailOTPWalletConnector/index.d.ts +0 -1
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.cjs +0 -7
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.d.ts +0 -2
- package/src/utils/isEmailOTPWalletConnector/isEmailOTPWalletConnector.js +0 -3
- package/src/utils/isEmailWalletConnector/index.d.ts +0 -1
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.cjs +0 -7
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.d.ts +0 -2
- package/src/utils/isEmailWalletConnector/isEmailWalletConnector.js +0 -3
- package/src/utils/isFunction/index.d.ts +0 -1
- package/src/utils/isFunction/isFunction.cjs +0 -8
- package/src/utils/isFunction/isFunction.d.ts +0 -1
- package/src/utils/isFunction/isFunction.js +0 -4
- package/src/utils/isMobile.cjs +0 -54
- package/src/utils/isMobile.d.ts +0 -13
- package/src/utils/isMobile.js +0 -46
- package/src/utils/isSameAddress/index.d.ts +0 -1
- package/src/utils/isSameAddress/isSameAddress.cjs +0 -9
- package/src/utils/isSameAddress/isSameAddress.d.ts +0 -1
- package/src/utils/isSameAddress/isSameAddress.js +0 -5
- package/src/utils/isSameAddress/utils/index.d.ts +0 -1
- package/src/utils/isSameAddress/utils/normalizeAddress/index.d.ts +0 -1
- package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.cjs +0 -17
- package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.d.ts +0 -1
- package/src/utils/isSameAddress/utils/normalizeAddress/normalizeAddress.js +0 -13
- package/src/utils/isSocialWalletConnector/index.d.ts +0 -1
- package/src/utils/isSocialWalletConnector/isSocialWalletConnector.cjs +0 -7
- package/src/utils/isSocialWalletConnector/isSocialWalletConnector.d.ts +0 -2
- package/src/utils/isSocialWalletConnector/isSocialWalletConnector.js +0 -3
- package/src/utils/isUnsupportedProviderError/index.d.ts +0 -1
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.cjs +0 -13
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.d.ts +0 -6
- package/src/utils/isUnsupportedProviderError/isUnsupportedProviderError.js +0 -9
- package/src/utils/localStorageAsync.cjs +0 -28
- package/src/utils/localStorageAsync.d.ts +0 -3
- package/src/utils/localStorageAsync.js +0 -22
- package/src/utils/logger.cjs +0 -9
- package/src/utils/logger.d.ts +0 -2
- package/src/utils/logger.js +0 -5
- package/src/utils/normalizeWalletName/index.d.ts +0 -1
- package/src/utils/normalizeWalletName/normalizeWalletName.cjs +0 -7
- package/src/utils/normalizeWalletName/normalizeWalletName.d.ts +0 -1
- package/src/utils/normalizeWalletName/normalizeWalletName.js +0 -3
- package/src/utils/shouldLowercaseAddress.cjs +0 -11
- package/src/utils/shouldLowercaseAddress.d.ts +0 -1
- package/src/utils/shouldLowercaseAddress.js +0 -7
- package/src/utils/walletConnect.cjs +0 -30
- package/src/utils/walletConnect.d.ts +0 -4
- package/src/utils/walletConnect.js +0 -26
- package/src/wallets/ProviderLookup.cjs +0 -18
- package/src/wallets/ProviderLookup.d.ts +0 -4
- package/src/wallets/ProviderLookup.js +0 -14
- package/src/wallets/algorand/MyAlgoWalletConnector.cjs +0 -149
- package/src/wallets/algorand/MyAlgoWalletConnector.d.ts +0 -21
- package/src/wallets/algorand/MyAlgoWalletConnector.js +0 -143
- package/src/wallets/algorand/myalgoSigner.cjs +0 -24
- package/src/wallets/algorand/myalgoSigner.d.ts +0 -21
- package/src/wallets/algorand/myalgoSigner.js +0 -20
- package/src/wallets/clients/coinbase/coinbase.cjs +0 -73
- package/src/wallets/clients/coinbase/coinbase.d.ts +0 -6
- package/src/wallets/clients/coinbase/coinbase.js +0 -66
- package/src/wallets/clients/coinbase/index.d.ts +0 -2
- package/src/wallets/clients/coinbase/types.d.ts +0 -14
- package/src/wallets/clients/walletConnect/index.d.ts +0 -1
- package/src/wallets/clients/walletConnect/types.d.ts +0 -4
- package/src/wallets/clients/walletConnect/walletConnect.cjs +0 -204
- package/src/wallets/clients/walletConnect/walletConnect.d.ts +0 -22
- package/src/wallets/clients/walletConnect/walletConnect.js +0 -187
- package/src/wallets/constants.cjs +0 -16
- package/src/wallets/constants.d.ts +0 -4
- package/src/wallets/constants.js +0 -10
- package/src/wallets/cosmos/KeplrWalletConnect.cjs +0 -196
- package/src/wallets/cosmos/KeplrWalletConnect.d.ts +0 -46
- package/src/wallets/cosmos/KeplrWalletConnect.js +0 -194
- package/src/wallets/cosmos/KeplrWalletConnector.cjs +0 -193
- package/src/wallets/cosmos/KeplrWalletConnector.d.ts +0 -70
- package/src/wallets/cosmos/KeplrWalletConnector.js +0 -189
- 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/cosmos/index.d.ts +0 -1
- package/src/wallets/cosmos/utils/indexDB.cjs +0 -97
- package/src/wallets/cosmos/utils/indexDB.d.ts +0 -18
- package/src/wallets/cosmos/utils/indexDB.js +0 -93
- package/src/wallets/cosmos/wcClient.cjs +0 -333
- package/src/wallets/cosmos/wcClient.d.ts +0 -104
- package/src/wallets/cosmos/wcClient.js +0 -325
- package/src/wallets/ethereum/BloctoEvm.cjs +0 -111
- package/src/wallets/ethereum/BloctoEvm.d.ts +0 -25
- package/src/wallets/ethereum/BloctoEvm.js +0 -105
- package/src/wallets/ethereum/EthWalletConnector.cjs +0 -191
- package/src/wallets/ethereum/EthWalletConnector.d.ts +0 -35
- package/src/wallets/ethereum/EthWalletConnector.js +0 -187
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.cjs +0 -63
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.d.ts +0 -12
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/EmailMagicWalletConnector.js +0 -59
- package/src/wallets/ethereum/MagicConnector/EmailMagicWalletConnector/index.d.ts +0 -1
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.cjs +0 -62
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.d.ts +0 -11
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/EmailOTPMagicWalletConnector.js +0 -58
- package/src/wallets/ethereum/MagicConnector/EmailOTPMagicWalletConnector/index.d.ts +0 -1
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.cjs +0 -102
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.d.ts +0 -33
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/MagicClientNetworkHandler.js +0 -98
- package/src/wallets/ethereum/MagicConnector/MagicClientNetworkHandler/index.d.ts +0 -2
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.cjs +0 -55
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.d.ts +0 -12
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/MagicSocialWalletConnector.js +0 -51
- package/src/wallets/ethereum/MagicConnector/MagicSocialWalletConnector/index.d.ts +0 -1
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.cjs +0 -175
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.d.ts +0 -53
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/MagicWalletConnector.js +0 -171
- package/src/wallets/ethereum/MagicConnector/MagicWalletConnector/index.d.ts +0 -2
- package/src/wallets/ethereum/MagicConnector/index.d.ts +0 -5
- package/src/wallets/ethereum/coinbase.cjs +0 -65
- package/src/wallets/ethereum/coinbase.d.ts +0 -26
- package/src/wallets/ethereum/coinbase.js +0 -63
- package/src/wallets/ethereum/ethProviderHelper.cjs +0 -197
- package/src/wallets/ethereum/ethProviderHelper.d.ts +0 -40
- package/src/wallets/ethereum/ethProviderHelper.js +0 -193
- package/src/wallets/ethereum/evm-network.cjs +0 -20
- package/src/wallets/ethereum/evm-network.d.ts +0 -22
- package/src/wallets/ethereum/evm-network.js +0 -16
- 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/injected/BloctoInjected.cjs +0 -13
- package/src/wallets/ethereum/injected/BloctoInjected.d.ts +0 -6
- package/src/wallets/ethereum/injected/BloctoInjected.js +0 -11
- package/src/wallets/ethereum/injected/BraveEvm.cjs +0 -13
- package/src/wallets/ethereum/injected/BraveEvm.d.ts +0 -6
- package/src/wallets/ethereum/injected/BraveEvm.js +0 -11
- package/src/wallets/ethereum/injected/Dawn.cjs +0 -13
- package/src/wallets/ethereum/injected/Dawn.d.ts +0 -6
- package/src/wallets/ethereum/injected/Dawn.js +0 -11
- package/src/wallets/ethereum/injected/ExodusEvm.cjs +0 -13
- package/src/wallets/ethereum/injected/ExodusEvm.d.ts +0 -6
- package/src/wallets/ethereum/injected/ExodusEvm.js +0 -11
- package/src/wallets/ethereum/injected/Frame.cjs +0 -13
- package/src/wallets/ethereum/injected/Frame.d.ts +0 -6
- package/src/wallets/ethereum/injected/Frame.js +0 -11
- package/src/wallets/ethereum/injected/GameStop.cjs +0 -13
- package/src/wallets/ethereum/injected/GameStop.d.ts +0 -6
- package/src/wallets/ethereum/injected/GameStop.js +0 -11
- package/src/wallets/ethereum/injected/Opera.cjs +0 -13
- package/src/wallets/ethereum/injected/Opera.d.ts +0 -6
- package/src/wallets/ethereum/injected/Opera.js +0 -11
- package/src/wallets/ethereum/injected/PhantomEvm.cjs +0 -37
- package/src/wallets/ethereum/injected/PhantomEvm.d.ts +0 -7
- package/src/wallets/ethereum/injected/PhantomEvm.js +0 -35
- package/src/wallets/ethereum/injected/Trust.cjs +0 -13
- package/src/wallets/ethereum/injected/Trust.d.ts +0 -6
- package/src/wallets/ethereum/injected/Trust.js +0 -11
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.cjs +0 -13
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.d.ts +0 -6
- package/src/wallets/ethereum/injected/UnknownInjectedWallet.js +0 -11
- package/src/wallets/ethereum/injected/Zerion.cjs +0 -13
- package/src/wallets/ethereum/injected/Zerion.d.ts +0 -6
- package/src/wallets/ethereum/injected/Zerion.js +0 -11
- package/src/wallets/ethereum/meta-mask.cjs +0 -63
- package/src/wallets/ethereum/meta-mask.d.ts +0 -26
- package/src/wallets/ethereum/meta-mask.js +0 -61
- package/src/wallets/flow/FlowWalletConnector.cjs +0 -163
- package/src/wallets/flow/FlowWalletConnector.d.ts +0 -29
- package/src/wallets/flow/FlowWalletConnector.js +0 -158
- package/src/wallets/flow/blocto.cjs +0 -22
- package/src/wallets/flow/blocto.d.ts +0 -7
- package/src/wallets/flow/blocto.js +0 -20
- package/src/wallets/flow/dapper.cjs +0 -22
- package/src/wallets/flow/dapper.d.ts +0 -7
- package/src/wallets/flow/dapper.js +0 -20
- package/src/wallets/flow/lilico.cjs +0 -42
- package/src/wallets/flow/lilico.d.ts +0 -8
- package/src/wallets/flow/lilico.js +0 -40
- package/src/wallets/getMobileOrInjectedWallet.cjs +0 -26
- package/src/wallets/getMobileOrInjectedWallet.d.ts +0 -8
- package/src/wallets/getMobileOrInjectedWallet.js +0 -22
- package/src/wallets/getWalletConnectConnector.cjs +0 -19
- package/src/wallets/getWalletConnectConnector.d.ts +0 -8
- package/src/wallets/getWalletConnectConnector.js +0 -15
- package/src/wallets/solana/CoinbaseSolana.cjs +0 -54
- package/src/wallets/solana/CoinbaseSolana.d.ts +0 -17
- package/src/wallets/solana/CoinbaseSolana.js +0 -52
- package/src/wallets/solana/glow.cjs +0 -51
- package/src/wallets/solana/glow.d.ts +0 -16
- package/src/wallets/solana/glow.js +0 -49
- package/src/wallets/solana/injected/BraveSol.cjs +0 -18
- package/src/wallets/solana/injected/BraveSol.d.ts +0 -6
- package/src/wallets/solana/injected/BraveSol.js +0 -16
- package/src/wallets/solana/injected/ExodusSol.cjs +0 -12
- package/src/wallets/solana/injected/ExodusSol.d.ts +0 -5
- package/src/wallets/solana/injected/ExodusSol.js +0 -10
- package/src/wallets/solana/phantom-ledger.cjs +0 -71
- package/src/wallets/solana/phantom-ledger.d.ts +0 -16
- package/src/wallets/solana/phantom-ledger.js +0 -65
- package/src/wallets/solana/phantom.cjs +0 -74
- package/src/wallets/solana/phantom.d.ts +0 -17
- package/src/wallets/solana/phantom.js +0 -72
- package/src/wallets/solana/slope.cjs +0 -96
- package/src/wallets/solana/slope.d.ts +0 -27
- package/src/wallets/solana/slope.js +0 -94
- package/src/wallets/solana/solProviderHelper.cjs +0 -164
- package/src/wallets/solana/solProviderHelper.d.ts +0 -29
- package/src/wallets/solana/solProviderHelper.js +0 -160
- package/src/wallets/solana/solWalletConnector.cjs +0 -57
- package/src/wallets/solana/solWalletConnector.d.ts +0 -18
- package/src/wallets/solana/solWalletConnector.js +0 -53
- package/src/wallets/solana/solflare.cjs +0 -65
- package/src/wallets/solana/solflare.d.ts +0 -14
- package/src/wallets/solana/solflare.js +0 -63
- package/src/wallets/starknet/argentx.cjs +0 -20
- package/src/wallets/starknet/argentx.d.ts +0 -7
- package/src/wallets/starknet/argentx.js +0 -18
- package/src/wallets/starknet/braavos.cjs +0 -33
- package/src/wallets/starknet/braavos.d.ts +0 -7
- package/src/wallets/starknet/braavos.js +0 -31
- package/src/wallets/starknet/ethereumContractAbi.cjs +0 -357
- package/src/wallets/starknet/ethereumContractAbi.js +0 -355
- package/src/wallets/starknet/starknetWalletConnector.cjs +0 -171
- package/src/wallets/starknet/starknetWalletConnector.d.ts +0 -34
- package/src/wallets/starknet/starknetWalletConnector.js +0 -169
- package/src/wallets/walletConnect/index.d.ts +0 -2
- package/src/wallets/walletConnect/walletConnect.cjs +0 -130
- package/src/wallets/walletConnect/walletConnect.d.ts +0 -34
- package/src/wallets/walletConnect/walletConnect.js +0 -124
- package/src/wallets/walletConnect/walletConnectV2.cjs +0 -268
- package/src/wallets/walletConnect/walletConnectV2.d.ts +0 -38
- package/src/wallets/walletConnect/walletConnectV2.js +0 -262
- package/src/wallets/walletConnect/zerion.d.ts +0 -8
- package/src/wallets/window.d.ts +0 -95
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var tslib = require('tslib');
|
|
4
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
5
|
-
var walletBook = require('@dynamic-labs/wallet-book');
|
|
6
|
-
var walletConnect = require('../clients/walletConnect/walletConnect.cjs');
|
|
7
|
-
var isMobile = require('../../utils/isMobile.cjs');
|
|
8
|
-
var logger = require('../../utils/logger.cjs');
|
|
9
|
-
var wcClient = require('./wcClient.cjs');
|
|
10
|
-
|
|
11
|
-
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_wc_network_id';
|
|
12
|
-
class KeplrWalletConnect extends walletConnectorCore.WalletConnectorBase {
|
|
13
|
-
constructor({ evmNetworks }) {
|
|
14
|
-
var _a;
|
|
15
|
-
super();
|
|
16
|
-
this.name = 'Keplr';
|
|
17
|
-
this.isWalletConnect = true;
|
|
18
|
-
this.canConnectViaQrCode = true;
|
|
19
|
-
this.clientOptions = {
|
|
20
|
-
signingMethods: [
|
|
21
|
-
'keplr_enable_wallet_connect_v1',
|
|
22
|
-
'keplr_sign_amino_wallet_connect_v1',
|
|
23
|
-
],
|
|
24
|
-
};
|
|
25
|
-
this.chainIdMap = {
|
|
26
|
-
401: 'cosmoshub-4',
|
|
27
|
-
402: 'axelar-dojo-1',
|
|
28
|
-
403: 'osmosis-1',
|
|
29
|
-
};
|
|
30
|
-
this.supportedChains = ['COSMOS'];
|
|
31
|
-
this.connectedChain = 'COSMOS';
|
|
32
|
-
this.evmNetworks = evmNetworks;
|
|
33
|
-
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
34
|
-
if (persistedNetworkId) {
|
|
35
|
-
this.selectedNetworkId = Number(persistedNetworkId);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
this.selectedNetworkId = ((_a = evmNetworks[0]) === null || _a === void 0 ? void 0 : _a.chainId) || 401;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
get evmNetwork() {
|
|
42
|
-
var _a;
|
|
43
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.chainId === this.selectedNetworkId);
|
|
44
|
-
}
|
|
45
|
-
get selectedNetwork() {
|
|
46
|
-
var _a;
|
|
47
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.networkId === this.selectedNetworkId);
|
|
48
|
-
}
|
|
49
|
-
get lcdUrl() {
|
|
50
|
-
var _a;
|
|
51
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.lcdUrl;
|
|
52
|
-
}
|
|
53
|
-
get denom() {
|
|
54
|
-
var _a;
|
|
55
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.nativeCurrency.denom;
|
|
56
|
-
}
|
|
57
|
-
get chainId() {
|
|
58
|
-
if (!this.selectedNetwork) {
|
|
59
|
-
return 'osmosis-1';
|
|
60
|
-
}
|
|
61
|
-
return this.chainIdMap[this.selectedNetwork.chainId];
|
|
62
|
-
}
|
|
63
|
-
getProvider() {
|
|
64
|
-
if (!this._keplrInstance) {
|
|
65
|
-
this._keplrInstance = new wcClient.KeplrWalletConnectV1(this.getClient());
|
|
66
|
-
}
|
|
67
|
-
return this._keplrInstance;
|
|
68
|
-
}
|
|
69
|
-
getClient() {
|
|
70
|
-
if (this.client) {
|
|
71
|
-
return this.client;
|
|
72
|
-
}
|
|
73
|
-
this.client = walletConnect.initClient(this.key, this.clientOptions);
|
|
74
|
-
return this.client;
|
|
75
|
-
}
|
|
76
|
-
getNetwork() {
|
|
77
|
-
return Promise.resolve(this.selectedNetworkId);
|
|
78
|
-
}
|
|
79
|
-
switchNetwork({ networkChainId, }) {
|
|
80
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
if (!networkChainId)
|
|
82
|
-
return;
|
|
83
|
-
try {
|
|
84
|
-
const keplr = this.getProvider();
|
|
85
|
-
yield keplr.enable(this.chainIdMap[networkChainId]);
|
|
86
|
-
this.selectedNetworkId = networkChainId;
|
|
87
|
-
localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, networkChainId.toString());
|
|
88
|
-
}
|
|
89
|
-
catch (e) {
|
|
90
|
-
logger.logger.error(e);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
signMessage(messageToSign) {
|
|
95
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const keplr = this.getProvider();
|
|
97
|
-
const key = yield keplr.getKey(this.chainId);
|
|
98
|
-
const res = yield keplr.signAmino(this.chainId, key.bech32Address, {
|
|
99
|
-
// The property is required in the amino doc
|
|
100
|
-
// https://cosmos.github.io/cosmjs/latest/amino/interfaces/StdSignDoc.html
|
|
101
|
-
account_number: '0',
|
|
102
|
-
chain_id: this.chainId,
|
|
103
|
-
fee: {
|
|
104
|
-
amount: [],
|
|
105
|
-
gas: '0',
|
|
106
|
-
},
|
|
107
|
-
memo: '',
|
|
108
|
-
msgs: [{ type: 'custom/MsgSignText', value: { text: messageToSign } }],
|
|
109
|
-
sequence: '0',
|
|
110
|
-
});
|
|
111
|
-
return JSON.stringify(res);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
fetchPublicAddress(opts) {
|
|
115
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const client = this.getClient();
|
|
117
|
-
const keplr = this.getProvider();
|
|
118
|
-
return walletConnect.fetchWalletConnectCosmosPublicAddress(walletBook.getWalletBookWallet(this.name), client, keplr, Object.assign(Object.assign({}, opts), { chainId: this.chainId, onConnect: (payload) => {
|
|
119
|
-
var _a;
|
|
120
|
-
payload.params[0].chainId = this.selectedNetworkId;
|
|
121
|
-
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
122
|
-
} }));
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
getBalance() {
|
|
126
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const address = yield this.fetchPublicAddress();
|
|
128
|
-
if (!address)
|
|
129
|
-
throw new Error('Address not found');
|
|
130
|
-
try {
|
|
131
|
-
const response = yield fetch(`${this.lcdUrl}/cosmos/bank/v1beta1/balances/${address}`).then((res) => res.json());
|
|
132
|
-
const balance = response.balances.reduce((acc, cur) => {
|
|
133
|
-
if (cur.denom === this.denom) {
|
|
134
|
-
return Number(cur.amount) / 1e6;
|
|
135
|
-
}
|
|
136
|
-
return acc;
|
|
137
|
-
}, 0);
|
|
138
|
-
return balance.toString();
|
|
139
|
-
}
|
|
140
|
-
catch (e) {
|
|
141
|
-
logger.logger.error(e);
|
|
142
|
-
return '0';
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
endSession() {
|
|
147
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
walletConnect.killWalletConnectSession(this.getClient());
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
getConnectedAccounts() {
|
|
152
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
const address = yield this.fetchPublicAddress({ chainId: this.chainId });
|
|
154
|
-
if (address)
|
|
155
|
-
return [address];
|
|
156
|
-
return [];
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
getDeepLink() {
|
|
160
|
-
var _a;
|
|
161
|
-
const wallet = walletBook.getWalletBookWallet(this.name);
|
|
162
|
-
if (!isMobile.isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
return walletConnect.getDeepLink(this.getClient().uri, wallet, {
|
|
166
|
-
removeWCUri: isMobile.isIOS() && this.key === 'cryptocom',
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
getRpcProvider() {
|
|
170
|
-
throw new Error('Method not implemented.');
|
|
171
|
-
}
|
|
172
|
-
getSigner() {
|
|
173
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
const keplr = this.getProvider();
|
|
175
|
-
return keplr.getOfflineSigner(this.chainId);
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
getWeb3Provider() {
|
|
179
|
-
return this.getProvider();
|
|
180
|
-
}
|
|
181
|
-
setupEventListeners(listeners) {
|
|
182
|
-
return walletConnect.setupWalletConnectEventListeners({
|
|
183
|
-
onAccountChange: listeners.onAccountChange,
|
|
184
|
-
onChainChange: listeners.onChainChange,
|
|
185
|
-
onDisconnect: listeners.onDisconnect,
|
|
186
|
-
}, this.getClient());
|
|
187
|
-
}
|
|
188
|
-
teardownEventListeners() {
|
|
189
|
-
walletConnect.teardownWalletConnectEventListeners(this.getClient());
|
|
190
|
-
}
|
|
191
|
-
supportsNetworkSwitching() {
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
module.exports = KeplrWalletConnect;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import Client from '@walletconnect/client';
|
|
2
|
-
import { OfflineAminoSigner } from '@keplr-wallet/types';
|
|
3
|
-
import { Chain, FetchPublicAddressOpts, WalletConnectorBase, WalletEventListeners } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
-
import { EvmNetwork } from '../ethereum/evm-network';
|
|
5
|
-
import { SwitchNetworkOps } from '../ethereum/EthWalletConnector';
|
|
6
|
-
import { KeplrWalletConnectV1 } from './wcClient';
|
|
7
|
-
declare class KeplrWalletConnect extends WalletConnectorBase {
|
|
8
|
-
constructor({ evmNetworks }: {
|
|
9
|
-
evmNetworks: EvmNetwork[];
|
|
10
|
-
});
|
|
11
|
-
name: string;
|
|
12
|
-
isWalletConnect: boolean;
|
|
13
|
-
canConnectViaQrCode: boolean;
|
|
14
|
-
client?: Client;
|
|
15
|
-
clientOptions: {
|
|
16
|
-
signingMethods: string[];
|
|
17
|
-
};
|
|
18
|
-
evmNetworks?: EvmNetwork[];
|
|
19
|
-
selectedNetworkId: number;
|
|
20
|
-
chainIdMap: Record<number, string>;
|
|
21
|
-
supportedChains: Chain[];
|
|
22
|
-
connectedChain: Chain;
|
|
23
|
-
_keplrInstance: KeplrWalletConnectV1 | undefined;
|
|
24
|
-
get evmNetwork(): EvmNetwork | undefined;
|
|
25
|
-
get selectedNetwork(): EvmNetwork | undefined;
|
|
26
|
-
get lcdUrl(): string | undefined;
|
|
27
|
-
get denom(): string | undefined;
|
|
28
|
-
get chainId(): string;
|
|
29
|
-
getProvider(): KeplrWalletConnectV1;
|
|
30
|
-
getClient(): Client;
|
|
31
|
-
getNetwork(): Promise<number>;
|
|
32
|
-
switchNetwork({ networkChainId, }: SwitchNetworkOps): Promise<void>;
|
|
33
|
-
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
34
|
-
fetchPublicAddress(opts?: FetchPublicAddressOpts): Promise<string | undefined>;
|
|
35
|
-
getBalance(): Promise<string>;
|
|
36
|
-
endSession(): Promise<void>;
|
|
37
|
-
getConnectedAccounts(): Promise<string[]>;
|
|
38
|
-
getDeepLink(): string | undefined;
|
|
39
|
-
getRpcProvider(): Promise<unknown>;
|
|
40
|
-
getSigner(): Promise<OfflineAminoSigner | undefined>;
|
|
41
|
-
getWeb3Provider(): KeplrWalletConnectV1 | undefined;
|
|
42
|
-
setupEventListeners(listeners: WalletEventListeners): () => void;
|
|
43
|
-
teardownEventListeners(): void;
|
|
44
|
-
supportsNetworkSwitching(): boolean;
|
|
45
|
-
}
|
|
46
|
-
export default KeplrWalletConnect;
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from 'tslib';
|
|
2
|
-
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
|
|
4
|
-
import { initClient, fetchWalletConnectCosmosPublicAddress, killWalletConnectSession, getDeepLink, setupWalletConnectEventListeners, teardownWalletConnectEventListeners } from '../clients/walletConnect/walletConnect.js';
|
|
5
|
-
import { isMobile, isIOS } from '../../utils/isMobile.js';
|
|
6
|
-
import { logger } from '../../utils/logger.js';
|
|
7
|
-
import { KeplrWalletConnectV1 } from './wcClient.js';
|
|
8
|
-
|
|
9
|
-
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_wc_network_id';
|
|
10
|
-
class KeplrWalletConnect extends WalletConnectorBase {
|
|
11
|
-
constructor({ evmNetworks }) {
|
|
12
|
-
var _a;
|
|
13
|
-
super();
|
|
14
|
-
this.name = 'Keplr';
|
|
15
|
-
this.isWalletConnect = true;
|
|
16
|
-
this.canConnectViaQrCode = true;
|
|
17
|
-
this.clientOptions = {
|
|
18
|
-
signingMethods: [
|
|
19
|
-
'keplr_enable_wallet_connect_v1',
|
|
20
|
-
'keplr_sign_amino_wallet_connect_v1',
|
|
21
|
-
],
|
|
22
|
-
};
|
|
23
|
-
this.chainIdMap = {
|
|
24
|
-
401: 'cosmoshub-4',
|
|
25
|
-
402: 'axelar-dojo-1',
|
|
26
|
-
403: 'osmosis-1',
|
|
27
|
-
};
|
|
28
|
-
this.supportedChains = ['COSMOS'];
|
|
29
|
-
this.connectedChain = 'COSMOS';
|
|
30
|
-
this.evmNetworks = evmNetworks;
|
|
31
|
-
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
32
|
-
if (persistedNetworkId) {
|
|
33
|
-
this.selectedNetworkId = Number(persistedNetworkId);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.selectedNetworkId = ((_a = evmNetworks[0]) === null || _a === void 0 ? void 0 : _a.chainId) || 401;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
get evmNetwork() {
|
|
40
|
-
var _a;
|
|
41
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.chainId === this.selectedNetworkId);
|
|
42
|
-
}
|
|
43
|
-
get selectedNetwork() {
|
|
44
|
-
var _a;
|
|
45
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.networkId === this.selectedNetworkId);
|
|
46
|
-
}
|
|
47
|
-
get lcdUrl() {
|
|
48
|
-
var _a;
|
|
49
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.lcdUrl;
|
|
50
|
-
}
|
|
51
|
-
get denom() {
|
|
52
|
-
var _a;
|
|
53
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.nativeCurrency.denom;
|
|
54
|
-
}
|
|
55
|
-
get chainId() {
|
|
56
|
-
if (!this.selectedNetwork) {
|
|
57
|
-
return 'osmosis-1';
|
|
58
|
-
}
|
|
59
|
-
return this.chainIdMap[this.selectedNetwork.chainId];
|
|
60
|
-
}
|
|
61
|
-
getProvider() {
|
|
62
|
-
if (!this._keplrInstance) {
|
|
63
|
-
this._keplrInstance = new KeplrWalletConnectV1(this.getClient());
|
|
64
|
-
}
|
|
65
|
-
return this._keplrInstance;
|
|
66
|
-
}
|
|
67
|
-
getClient() {
|
|
68
|
-
if (this.client) {
|
|
69
|
-
return this.client;
|
|
70
|
-
}
|
|
71
|
-
this.client = initClient(this.key, this.clientOptions);
|
|
72
|
-
return this.client;
|
|
73
|
-
}
|
|
74
|
-
getNetwork() {
|
|
75
|
-
return Promise.resolve(this.selectedNetworkId);
|
|
76
|
-
}
|
|
77
|
-
switchNetwork({ networkChainId, }) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
if (!networkChainId)
|
|
80
|
-
return;
|
|
81
|
-
try {
|
|
82
|
-
const keplr = this.getProvider();
|
|
83
|
-
yield keplr.enable(this.chainIdMap[networkChainId]);
|
|
84
|
-
this.selectedNetworkId = networkChainId;
|
|
85
|
-
localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, networkChainId.toString());
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
logger.error(e);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
signMessage(messageToSign) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const keplr = this.getProvider();
|
|
95
|
-
const key = yield keplr.getKey(this.chainId);
|
|
96
|
-
const res = yield keplr.signAmino(this.chainId, key.bech32Address, {
|
|
97
|
-
// The property is required in the amino doc
|
|
98
|
-
// https://cosmos.github.io/cosmjs/latest/amino/interfaces/StdSignDoc.html
|
|
99
|
-
account_number: '0',
|
|
100
|
-
chain_id: this.chainId,
|
|
101
|
-
fee: {
|
|
102
|
-
amount: [],
|
|
103
|
-
gas: '0',
|
|
104
|
-
},
|
|
105
|
-
memo: '',
|
|
106
|
-
msgs: [{ type: 'custom/MsgSignText', value: { text: messageToSign } }],
|
|
107
|
-
sequence: '0',
|
|
108
|
-
});
|
|
109
|
-
return JSON.stringify(res);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
fetchPublicAddress(opts) {
|
|
113
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const client = this.getClient();
|
|
115
|
-
const keplr = this.getProvider();
|
|
116
|
-
return fetchWalletConnectCosmosPublicAddress(getWalletBookWallet(this.name), client, keplr, Object.assign(Object.assign({}, opts), { chainId: this.chainId, onConnect: (payload) => {
|
|
117
|
-
var _a;
|
|
118
|
-
payload.params[0].chainId = this.selectedNetworkId;
|
|
119
|
-
(_a = opts === null || opts === void 0 ? void 0 : opts.onConnect) === null || _a === void 0 ? void 0 : _a.call(opts, payload);
|
|
120
|
-
} }));
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
getBalance() {
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
const address = yield this.fetchPublicAddress();
|
|
126
|
-
if (!address)
|
|
127
|
-
throw new Error('Address not found');
|
|
128
|
-
try {
|
|
129
|
-
const response = yield fetch(`${this.lcdUrl}/cosmos/bank/v1beta1/balances/${address}`).then((res) => res.json());
|
|
130
|
-
const balance = response.balances.reduce((acc, cur) => {
|
|
131
|
-
if (cur.denom === this.denom) {
|
|
132
|
-
return Number(cur.amount) / 1e6;
|
|
133
|
-
}
|
|
134
|
-
return acc;
|
|
135
|
-
}, 0);
|
|
136
|
-
return balance.toString();
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
logger.error(e);
|
|
140
|
-
return '0';
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
endSession() {
|
|
145
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
killWalletConnectSession(this.getClient());
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
getConnectedAccounts() {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const address = yield this.fetchPublicAddress({ chainId: this.chainId });
|
|
152
|
-
if (address)
|
|
153
|
-
return [address];
|
|
154
|
-
return [];
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
getDeepLink() {
|
|
158
|
-
var _a;
|
|
159
|
-
const wallet = getWalletBookWallet(this.name);
|
|
160
|
-
if (!isMobile() && !((_a = wallet.desktop) === null || _a === void 0 ? void 0 : _a.native)) {
|
|
161
|
-
return undefined;
|
|
162
|
-
}
|
|
163
|
-
return getDeepLink(this.getClient().uri, wallet, {
|
|
164
|
-
removeWCUri: isIOS() && this.key === 'cryptocom',
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
getRpcProvider() {
|
|
168
|
-
throw new Error('Method not implemented.');
|
|
169
|
-
}
|
|
170
|
-
getSigner() {
|
|
171
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
const keplr = this.getProvider();
|
|
173
|
-
return keplr.getOfflineSigner(this.chainId);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
getWeb3Provider() {
|
|
177
|
-
return this.getProvider();
|
|
178
|
-
}
|
|
179
|
-
setupEventListeners(listeners) {
|
|
180
|
-
return setupWalletConnectEventListeners({
|
|
181
|
-
onAccountChange: listeners.onAccountChange,
|
|
182
|
-
onChainChange: listeners.onChainChange,
|
|
183
|
-
onDisconnect: listeners.onDisconnect,
|
|
184
|
-
}, this.getClient());
|
|
185
|
-
}
|
|
186
|
-
teardownEventListeners() {
|
|
187
|
-
teardownWalletConnectEventListeners(this.getClient());
|
|
188
|
-
}
|
|
189
|
-
supportsNetworkSwitching() {
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export { KeplrWalletConnect as default };
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var tslib = require('tslib');
|
|
6
|
-
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
-
var logger = require('../../utils/logger.cjs');
|
|
8
|
-
|
|
9
|
-
const DYNAMIC_KEPLR_NETWORK_ID = 'dynamic_keplr_network_id';
|
|
10
|
-
class KeplrWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
11
|
-
constructor({ evmNetworks }) {
|
|
12
|
-
super();
|
|
13
|
-
this.switchNetworkOnlyFromWallet = true;
|
|
14
|
-
this.selectedNetworkId = 401;
|
|
15
|
-
this.name = 'Keplr';
|
|
16
|
-
this.connectedChain = 'COSMOS';
|
|
17
|
-
this.supportedChains = ['COSMOS'];
|
|
18
|
-
this.chainIdMap = {
|
|
19
|
-
401: 'cosmoshub-4',
|
|
20
|
-
402: 'axelar-dojo-1',
|
|
21
|
-
403: 'osmosis-1',
|
|
22
|
-
};
|
|
23
|
-
this.evmNetworks = evmNetworks;
|
|
24
|
-
this._handleAccountChange = this._handleAccountChange.bind(this);
|
|
25
|
-
const persistedNetworkId = localStorage.getItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
26
|
-
if (persistedNetworkId) {
|
|
27
|
-
this.selectedNetworkId = Number(persistedNetworkId);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
getWeb3Provider() {
|
|
31
|
-
return this.keplr;
|
|
32
|
-
}
|
|
33
|
-
getDeepLink() {
|
|
34
|
-
throw new Error('Method not implemented.');
|
|
35
|
-
}
|
|
36
|
-
get selectedNetwork() {
|
|
37
|
-
var _a;
|
|
38
|
-
return (_a = this.evmNetworks) === null || _a === void 0 ? void 0 : _a.find((network) => network.networkId === this.selectedNetworkId);
|
|
39
|
-
}
|
|
40
|
-
get chainId() {
|
|
41
|
-
if (!this.selectedNetwork) {
|
|
42
|
-
return '401';
|
|
43
|
-
}
|
|
44
|
-
return this.chainIdMap[this.selectedNetwork.chainId];
|
|
45
|
-
}
|
|
46
|
-
get lcdUrl() {
|
|
47
|
-
var _a;
|
|
48
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.lcdUrl;
|
|
49
|
-
}
|
|
50
|
-
get rpcUrl() {
|
|
51
|
-
var _a;
|
|
52
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.rpcUrls[0];
|
|
53
|
-
}
|
|
54
|
-
get denom() {
|
|
55
|
-
var _a;
|
|
56
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.nativeCurrency.denom;
|
|
57
|
-
}
|
|
58
|
-
get symbol() {
|
|
59
|
-
var _a;
|
|
60
|
-
return (_a = this.selectedNetwork) === null || _a === void 0 ? void 0 : _a.nativeCurrency.symbol;
|
|
61
|
-
}
|
|
62
|
-
getAccount() {
|
|
63
|
-
var _a, _b;
|
|
64
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const accountsList = yield ((_b = (_a = this.keplr) === null || _a === void 0 ? void 0 : _a.getOfflineSigner(this.chainId)) === null || _b === void 0 ? void 0 : _b.getAccounts());
|
|
66
|
-
if (!accountsList)
|
|
67
|
-
throw new Error('No accounts found');
|
|
68
|
-
const [account] = accountsList;
|
|
69
|
-
return account;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
get keplr() {
|
|
73
|
-
if (typeof window === 'undefined')
|
|
74
|
-
throw new Error('Keplr is not available');
|
|
75
|
-
// @ts-expect-error keplr is not defined if extension is not installed
|
|
76
|
-
return window.keplr;
|
|
77
|
-
}
|
|
78
|
-
endSession() {
|
|
79
|
-
return Promise.resolve();
|
|
80
|
-
}
|
|
81
|
-
connect() {
|
|
82
|
-
var _a;
|
|
83
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
yield ((_a = this.keplr) === null || _a === void 0 ? void 0 : _a.enable(this.chainId));
|
|
85
|
-
this.isWalletConnect = true;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
fetchPublicAddress() {
|
|
89
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
this.connect();
|
|
91
|
-
const account = yield this.getAccount();
|
|
92
|
-
return account.address;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
getBalance() {
|
|
96
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
const address = yield this.fetchPublicAddress();
|
|
98
|
-
const value = yield this.fetchBalance(address);
|
|
99
|
-
return value;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
getConnectedAccounts() {
|
|
103
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
const address = yield this.fetchPublicAddress();
|
|
105
|
-
return [address];
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
getNetwork() {
|
|
109
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
return Promise.resolve(this.selectedNetworkId);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
getSigner() {
|
|
114
|
-
var _a;
|
|
115
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
return (_a = this.keplr) === null || _a === void 0 ? void 0 : _a.getOfflineSigner(this.chainId);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
isInstalledOnBrowser() {
|
|
120
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
121
|
-
// @ts-ignore window.keplr is provided by extension
|
|
122
|
-
return typeof window.keplr !== 'undefined';
|
|
123
|
-
}
|
|
124
|
-
_handleAccountChange() {
|
|
125
|
-
var _a, _b;
|
|
126
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const address = yield this.fetchPublicAddress();
|
|
128
|
-
(_b = (_a = this._listeners) === null || _a === void 0 ? void 0 : _a.onAccountChange) === null || _b === void 0 ? void 0 : _b.call(_a, [address]);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
setupEventListeners(listeners) {
|
|
132
|
-
this._listeners = listeners;
|
|
133
|
-
window.addEventListener('keplr_keystorechange', this._handleAccountChange);
|
|
134
|
-
}
|
|
135
|
-
teardownEventListeners() {
|
|
136
|
-
window.removeEventListener('keplr_keystorechange', this._handleAccountChange);
|
|
137
|
-
this._listeners = undefined;
|
|
138
|
-
localStorage.removeItem(DYNAMIC_KEPLR_NETWORK_ID);
|
|
139
|
-
}
|
|
140
|
-
// SignDoc used for signAmin method;
|
|
141
|
-
getSignDoc(message) {
|
|
142
|
-
return {
|
|
143
|
-
account_number: '0',
|
|
144
|
-
chain_id: this.chainId,
|
|
145
|
-
fee: { amount: [], gas: '0' },
|
|
146
|
-
memo: '',
|
|
147
|
-
msgs: [{ type: 'custom/MsgSignText', value: { text: message } }],
|
|
148
|
-
sequence: '0',
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
signMessage(messageToSign) {
|
|
152
|
-
var _a;
|
|
153
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
const signDoc = this.getSignDoc(messageToSign);
|
|
155
|
-
const address = yield this.fetchPublicAddress();
|
|
156
|
-
const signatureResponse = yield ((_a = this.keplr) === null || _a === void 0 ? void 0 : _a.signAmino(this.chainId, address, signDoc));
|
|
157
|
-
if (!signatureResponse)
|
|
158
|
-
throw new Error('Could not sign message');
|
|
159
|
-
return JSON.stringify(signatureResponse);
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
supportsNetworkSwitching() {
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
fetchBalance(address) {
|
|
166
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
try {
|
|
168
|
-
const response = yield fetch(`${this.lcdUrl}/cosmos/bank/v1beta1/balances/${address}`).then((res) => res.json());
|
|
169
|
-
const balance = response.balances.reduce((acc, cur) => {
|
|
170
|
-
if (cur.denom === this.denom) {
|
|
171
|
-
return Number(cur.amount) / 1e6;
|
|
172
|
-
}
|
|
173
|
-
return acc;
|
|
174
|
-
}, 0);
|
|
175
|
-
return balance.toString();
|
|
176
|
-
}
|
|
177
|
-
catch (e) {
|
|
178
|
-
logger.logger.error(e);
|
|
179
|
-
return '0';
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
switchNetwork({ networkChainId, }) {
|
|
184
|
-
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
if (!networkChainId)
|
|
186
|
-
return;
|
|
187
|
-
this.selectedNetworkId = networkChainId;
|
|
188
|
-
localStorage.setItem(DYNAMIC_KEPLR_NETWORK_ID, networkChainId.toString());
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
exports.KeplrWalletConnector = KeplrWalletConnector;
|