import { KVStore } from "@keplr-wallet/common" ; import { ObservableChainQuery , ObservableChainQueryMap , } from "../../chain-query" ; import { ChainGetter } from "../../../common" ; import { ClientStateResponse } from "./types" ; import { autorun , computed } from "mobx" ; export class ObservableChainQueryClientState extends ObservableChainQuery < ClientStateResponse > { constructor ( kvStore , chainId , chainGetter , portId , channelId ) { super ( kvStore , chainId , chainGetter , `/ibc/core/channel/v1beta1/channels/${ channelId }/ports/${ portId }/client_state` ) ; autorun ( ( ) => { const chainInfo = this . chainGetter . getChain ( this . chainId ) ; if ( chainInfo . features && chainInfo . features . includes ( "ibc-go" ) ) { this . setUrl ( `/ibc/core/channel/v1/channels/${ channelId }/ports/${ portId }/client_state` ) ; } } ) ; } /**
     * clientChainId returns the chain id of the client state if the client state's type is known (currently, only tendermint is supported).
     */ @ computed get clientChainId ( ) : string | undefined { if ( ! this . response ) { return undefined ; } return this . response . data . identified_client_state ?. client_state ?. chain_id as string | undefined ; } } export class ObservableQueryIBCClientState extends ObservableChainQueryMap < ClientStateResponse > { constructor ( protected readonly kvStore , protected readonly chainId , protected readonly chainGetter ) { super ( kvStore , chainId , chainGetter , ( key ) => { const params = JSON . parse ( key ) ; return new ObservableChainQueryClientState ( this . kvStore , this . chainId , this . chainGetter , params . portId , params . channelId ) ; } ) ; } getClientStateOnTransferPort ( channelId ) { return this . getClientState ( "transfer" , channelId ) ; } getClientState ( portId , channelId ) { const key = JSON . stringify ( { portId , channelId , } ) ; return this . get ( key ) as ObservableChainQueryClientState ; } }