diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index 0805cedf..7e79afcf 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -1,6 +1,6 @@ import { ref, toRaw } from '@distributedlab/reactivity' -import { getChainInfo as getChainInfoHelper, stub } from '@/helpers' +import { getChainInfo as _getChainInfo, stub } from '@/helpers' import { makeRarimoBroadcaster } from './broadcaster' import { makeRarimoQuerier } from './querier' @@ -24,7 +24,7 @@ export const makeRarimoClient = (config: Config): RarimoClient => { } const getChainInfo = async () => { - return getChainInfoHelper(config, query.value) + return _getChainInfo(config, query.value) } const connect = async (injectedWallet?: Wallet) => { diff --git a/packages/client/src/helpers/keplr.ts b/packages/client/src/helpers/keplr.ts index ba03cc1e..2d5cc30f 100644 --- a/packages/client/src/helpers/keplr.ts +++ b/packages/client/src/helpers/keplr.ts @@ -1,3 +1,4 @@ +import type { OfflineSigner } from '@cosmjs/proto-signing' import type { ChainInfo, Window as KeplrWindow } from '@keplr-wallet/types' import { WalletExtensionNotInstalledError } from '@/errors' @@ -7,29 +8,29 @@ declare global { interface Window extends KeplrWindow {} } -export const getKeplrDirectSigner = async (chainInfo: ChainInfo) => { - if (window.keplr === undefined) throw new WalletExtensionNotInstalledError() +const enableKeplr = async (chain: ChainInfo) => { + if (!window.keplr) throw new WalletExtensionNotInstalledError() - await window.keplr.experimentalSuggestChain(chainInfo) - await window.keplr.enable(chainInfo.chainId) - - return window.keplr.getOfflineSigner(chainInfo.chainId) + await window.keplr.experimentalSuggestChain(chain) + await window.keplr.enable(chain.chainId) } -export const getKeplrAminoSigner = async (chainInfo: ChainInfo) => { - if (window.keplr === undefined) throw new WalletExtensionNotInstalledError() - - await window.keplr.experimentalSuggestChain(chainInfo) - await window.keplr.enable(chainInfo.chainId) +export const getKeplrDirectSigner = async (chain: ChainInfo) => { + await enableKeplr(chain) - return window.keplr.getOfflineSignerOnlyAmino(chainInfo.chainId) + return window.keplr!.getOfflineSigner(chain.chainId) } -export const getKeplrSigner = async (chainInfo: ChainInfo) => { - if (window.keplr === undefined) throw new WalletExtensionNotInstalledError() +export const getKeplrAminoSigner = async (chain: ChainInfo) => { + await enableKeplr(chain) + + return window.keplr!.getOfflineSignerOnlyAmino(chain.chainId) +} - await window.keplr.experimentalSuggestChain(chainInfo) - await window.keplr.enable(chainInfo.chainId) +export const getKeplrSigner = async (chain: ChainInfo) => { + await enableKeplr(chain) - return window.keplr.getOfflineSignerAuto(chainInfo.chainId) + return (await window.keplr!.getOfflineSignerAuto( + chain.chainId, + )) as OfflineSigner } diff --git a/packages/client/src/wallet.ts b/packages/client/src/wallet.ts index 753352d6..3da5c50c 100644 --- a/packages/client/src/wallet.ts +++ b/packages/client/src/wallet.ts @@ -3,7 +3,7 @@ import { computed, ref, toRaw } from '@distributedlab/reactivity' import type { AccountData, ChainInfo } from '@keplr-wallet/types' import { WalletIsEmptyError } from '@/errors' -import { getKeplrDirectSigner, stub } from '@/helpers' +import { getKeplrSigner, stub } from '@/helpers' import type { Wallet } from '@/types' const initStub = stub('Wallet not initialized!') @@ -25,7 +25,7 @@ export const makeWallet = (injectedSigner?: OfflineSigner): Wallet => { }) const connect = async (chainInfo: ChainInfo) => { - signer.value = injectedSigner || (await getKeplrDirectSigner(chainInfo)) + signer.value = injectedSigner || (await getKeplrSigner(chainInfo)) chainId.value = chainInfo.chainId accounts.value = await signer.value.getAccounts()