Skip to content

Commit

Permalink
refactored after review
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Mar 21, 2024
1 parent 2ba1aa8 commit 56c86d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) => {
Expand Down
35 changes: 18 additions & 17 deletions packages/client/src/helpers/keplr.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
}
4 changes: 2 additions & 2 deletions packages/client/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
Expand All @@ -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()
Expand Down

0 comments on commit 56c86d5

Please sign in to comment.