@@ -2,14 +2,14 @@ import { SigningStargateClient } from '@cosmjs/stargate'
22import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx.js'
33import { BridgeType } from '../../const/bridges'
44import { ChainType , chainIDs , ibcChannels } from '../../const/chains'
5- import { Tx , TxResult , Wallet } from '../Wallet'
5+ import { QueryResult , Tx , TxResult , Wallet } from '../Wallet'
66import { getAxelarDepositAddress } from '../../packages/axelar'
77
88type KeplrChain = ChainType . cosmos | ChainType . osmosis
99
1010const keplrRpc : Record < KeplrChain , string > = {
11- [ ChainType . cosmos ] : 'https://rpc-cosmoshub-ia.notional.ventures /' ,
12- [ ChainType . osmosis ] : '' ,
11+ [ ChainType . cosmos ] : 'https://cosmos-mainnet-rpc.allthatnode.com:26657 /' ,
12+ [ ChainType . osmosis ] : 'https://rpc.osmosis.zone/ ' ,
1313}
1414
1515declare global {
@@ -21,6 +21,7 @@ declare global {
2121export class KeplrWallet implements Wallet {
2222 private address : string = ''
2323 private signer : SigningStargateClient | null = null
24+ private chain : ChainType | null = null
2425
2526 isSupported ( ) : boolean {
2627 // supported on chrome, edge and firefox (only on desktop)
@@ -46,6 +47,7 @@ export class KeplrWallet implements Wallet {
4647 const accounts = await keplrOfflineSigner . getAccounts ( )
4748
4849 this . address = accounts [ 0 ] . address
50+ this . chain = chain
4951 this . signer = await SigningStargateClient . connectWithSigner (
5052 rpc || keplrRpc [ chain as KeplrChain ] ,
5153 keplrOfflineSigner ,
@@ -61,17 +63,34 @@ export class KeplrWallet implements Wallet {
6163 return { address : accounts [ 0 ] . address }
6264 }
6365
66+ async getBalance (
67+ token : string ,
68+ ) : Promise < QueryResult < number > > {
69+ if ( ! this . signer ) {
70+ return {
71+ success : false ,
72+ error : `You must connect the wallet before the query` ,
73+ }
74+ }
75+
76+ const res = await this . signer . getBalance ( this . address , token )
77+ return {
78+ success : true ,
79+ data : parseInt ( res . amount ) ,
80+ }
81+ }
82+
6483 async transfer ( tx : Tx ) : Promise < TxResult > {
6584 if ( ! this . address || ! this . signer ) {
6685 return {
6786 success : false ,
6887 error : `You must connect the wallet before the transfer` ,
6988 }
7089 }
71- if ( ! this . supportedChains . includes ( tx . src ) ) {
90+ if ( tx . src !== this . chain ) {
7291 return {
7392 success : false ,
74- error : `${ tx . src } is not supported by ${ this . description . name } ` ,
93+ error : `You must connect to ${ tx . src } before the transfer ` ,
7594 }
7695 }
7796 if ( tx . src === tx . dst ) {
0 commit comments