import { makeObservable , observable , runInAction } from "mobx" ; import { KVStore } from "@keplr-wallet/common" ; import { DeepReadonly } from "utility-types" ; import { ObservableQueryBalances } from "./balances" ; import { ChainGetter } from "../common" ; import { Keplr } from "@keplr-wallet/types" ; export class QueriesSetBase { public readonly queryBalances : DeepReadonly < ObservableQueryBalances > ; constructor ( kvStore , chainId , chainGetter ) { this . queryBalances = new ObservableQueryBalances ( kvStore , chainId , chainGetter ) ; } } export class QueriesStore < QueriesSet extends QueriesSetBase > { @ observable . shallow protected queriesMap : Map < string , QueriesSet > = new Map ( ) ; constructor ( protected readonly kvStore , protected readonly chainGetter , protected readonly apiGetter , protected readonly queriesCreator ) { makeObservable ( this ) ; } get ( chainId ) { if ( ! this . queriesMap . has ( chainId ) ) { const queries = new this . queriesCreator ( this . kvStore , chainId , this . chainGetter , this . apiGetter ) ; runInAction ( ( ) => { this . queriesMap . set ( chainId , queries ) ; } ) ; } return this . queriesMap . get ( chainId ) ! as DeepReadonly < QueriesSet > ; } }