import { ObservableChainQuery, ObservableChainQueryMap, } from "../../chain-query"; import { ChainGetter, requireCosmosInfo } from "../../../chain"; import { ChannelResponse } from "./types"; import { autorun } from "mobx"; import { QuerySharedContext } from "../../../common"; export class ObservableChainQueryIBCChannel extends ObservableChainQuery { protected disposer?: () => void; constructor( sharedContext: QuerySharedContext, chainId: string, chainGetter: ChainGetter, protected readonly portId: string, protected readonly channelId: string ) { super( sharedContext, chainId, chainGetter, `/ibc/core/channel/v1beta1/channels/${channelId}/ports/${portId}` ); } protected override onStart(): void { super.onStart(); this.disposer = autorun(() => { const mcInfo2 = this.chainGetter.getModularChain(this.chainId); const cosmosInfo = requireCosmosInfo(mcInfo2); if (cosmosInfo.features && cosmosInfo.features.includes("ibc-go")) { this.setUrl( `/ibc/core/channel/v1/channels/${this.channelId}/ports/${this.portId}` ); } }); } protected override onStop() { if (this.disposer) { this.disposer(); this.disposer = undefined; } super.onStop(); } } export class ObservableQueryIBCChannel extends ObservableChainQueryMap { constructor( sharedContext: QuerySharedContext, chainId: string, chainGetter: ChainGetter ) { super(sharedContext, chainId, chainGetter, (key: string) => { const params = JSON.parse(key); return new ObservableChainQueryIBCChannel( this.sharedContext, this.chainId, this.chainGetter, params.portId, params.channelId ); }); } getTransferChannel(channelId: string) { return this.getChannel("transfer", channelId); } getChannel( portId: string, channelId: string ): ObservableChainQuery { // Use key as the JSON encoded Object. const key = JSON.stringify({ portId, channelId, }); return this.get(key); } }