import { KVStore } from "@keplr-wallet/common" ; import { ChainGetter } from "../../../../common" ; import { ObservableChainQuery } from "../../../chain-query" ; import { Epochs } from "./types" ; import { computed , observable } from "mobx" ; export class ObservableQueryOsmosisEpochsInner { constructor ( protected readonly identifier , protected readonly queryEpochs ) { } @ computed get epoch ( ) : Epochs [ "epochs" ] [ 0 ] | undefined { return this . queryEpochs . response ?. data . epochs . find ( ( epoch ) => epoch . identifier === this . identifier ) ; } @ computed get duration ( ) : number { if ( ! this . epoch ) { return 0 ; } return parseInt ( this . epoch . duration . replace ( "s" , "" ) ) ; } @ computed get startTime ( ) : Date { if ( ! this . epoch ) { return new Date ( 0 ) ; } return new Date ( this . epoch . current_epoch_start_time ) ; } @ computed get endTime ( ) : Date { const startTime = this . startTime ; if ( ! this . duration ) { return startTime ; } return new Date ( startTime . getTime ( ) + this . duration * 1000 ) ; } } export class ObservableQueryOsmosisEpochs extends ObservableChainQuery < Epochs > { @ observable . shallow protected map : Map < string , ObservableQueryOsmosisEpochsInner > = new Map ( ) ; constructor ( kvStore , chainId , chainGetter ) { super ( kvStore , chainId , chainGetter , "/osmosis/epochs/v1beta1/epochs" ) ; } getEpoch ( identifier ) { if ( ! this . map . has ( identifier ) ) { const inner = new ObservableQueryOsmosisEpochsInner ( identifier , this ) ; this . map . set ( identifier , inner ) ; } return this . map . get ( identifier ) ! ; } }