Skip to content

Commit

Permalink
add getOfflineSignerByType helper and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettiOverload committed Jul 20, 2023
1 parent cda199b commit dad46df
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cudosjs",
"version": "1.3.3",
"version": "1.3.4",
"author": "",
"description": "JavaScript SDK for Cudos Network",
"license": "ISC",
Expand Down
24 changes: 23 additions & 1 deletion src/ledgers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { detect as detectBrowser } from 'detect-browser';
import { decodeSignature, OfflineAminoSigner, StdSignature } from '../amino';
import { verifyADR36Amino } from '@keplr-wallet/cosmos';
import { bech32 } from 'bech32'
import { Cosmos } from '@cosmostation/extension-client';
import { cosmos, Cosmos } from '@cosmostation/extension-client';
import { RequestAccountResponse, SignAminoDoc } from '@cosmostation/extension-client/types/message';
import { OfflineSigner } from '@cosmjs/proto-signing';
import { getOfflineSigner } from '@cosmostation/cosmos-client';

declare let window: {
getOfflineSignerAuto: any;
keplr: any;
cosmostation: any;
}
Expand Down Expand Up @@ -518,3 +521,22 @@ export const getLedgerSigner = async (
}
return signer
}

const cosmostationSigner = async (chainId: string): Promise<OfflineSigner> => {
const provider = await cosmos()
const account = await provider.requestAccount(chainId)
if (account.isLedger) {
return getLedgerSigner(provider, account, chainId)
}
return getOfflineSigner(chainId);
}

export const getOfflineSignerByType = async (walletName: SUPPORTED_WALLET, chainId: string): Promise<OfflineSigner | undefined> => {
if (walletName === SUPPORTED_WALLET.Keplr) {
return await window.getOfflineSignerAuto(chainId);
}
if (walletName === SUPPORTED_WALLET.Cosmostation) {
return cosmostationSigner(chainId)
}
return undefined
}
1 change: 1 addition & 0 deletions src/ledgers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './KeplrWallet'
export * from './CosmostationWallet'
export * from './Ledger'
export {
getOfflineSignerByType,
getCosmosNetworkImg,
getAtomscanExplorerUrl,
getCosmosNetworkPrettyName,
Expand Down

0 comments on commit dad46df

Please sign in to comment.