import { ObservableQuery, QueryError, QuerySharedContext } from "../common"; import { ChainGetter, getCosmosInfo } from "../chain"; import { HasMapStore } from "../common"; export class ObservableChainQuery< T = unknown, E = unknown > extends ObservableQuery { // Chain Id should not be changed after creation. protected readonly _chainId: string; protected readonly chainGetter: ChainGetter; protected readonly isCosmos: boolean; constructor( sharedContext: QuerySharedContext, chainId: string, chainGetter: ChainGetter, url: string ) { const cosmosInfo = getCosmosInfo(chainGetter.getModularChain(chainId)); super(sharedContext, cosmosInfo?.rest || "", url); this.isCosmos = !!cosmosInfo; this._chainId = chainId; this.chainGetter = chainGetter; } protected override canFetch(): boolean { return this.isCosmos && this.baseURL !== ""; } public override get error(): Readonly> | undefined { if (!this.isCosmos) { return { status: 400, statusText: `${this.chainId} is not for cosmos based chain`, message: `${this.chainId} is not for cosmos based chain`, }; } else { return super.error; } } get chainId(): string { return this._chainId; } } export class ObservableChainQueryMap< T = unknown, E = unknown > extends HasMapStore> { constructor( protected readonly sharedContext: QuerySharedContext, protected readonly chainId: string, protected readonly chainGetter: ChainGetter, creator: (key: string) => ObservableChainQuery ) { super(creator); } }