diff --git a/src/classes/govHandler.ts b/src/classes/govHandler.ts index 9000ebbc..9bce5036 100644 --- a/src/classes/govHandler.ts +++ b/src/classes/govHandler.ts @@ -6,7 +6,8 @@ import { IDelegationSummaryMap, IStakingValidator, IStakingValidatorExtendedMap, - IStakingValidatorMap + IStakingValidatorMap, + IStakingValidatorStakedMap } from '@/interfaces' import { TValidatorStatus } from '@/types/TValidatorStatus' @@ -54,6 +55,19 @@ export default class GovHandler implements IGovHandler { return acc }, {}) } + async getStakedValidatorDetailsMap (): Promise { + const allVals = await this.getCompleteMergedValidatorDetailsMap() + const staked = await this.getStakedMap() + const final: IStakingValidatorStakedMap = {} + for (let val in staked) { + if (allVals[val]) { + final[val] = { ...allVals[val], stakedDetails: staked[val] } + } else { + // do nothing + } + } + return final + } async getDelegatorValidatorDetails (validatorAddress: string): Promise { const result = (await this.pH.stakingQuery.queryDelegatorValidator({ delegatorAddr: this.walletRef.getJackalAddress(), @@ -105,7 +119,21 @@ export default class GovHandler implements IGovHandler { const staked = await this.getAllDelegatorValidatorDetailsMap() const allOfStatus = await this.getAllValidatorDetailsMap(status) return flagStaked(allOfStatus, staked) - + } + async getMergedValidatorDetailsStakedMap (status: TValidatorStatus): Promise { + const staked = await this.getAllDelegatorValidatorDetailsMap() + const allOfStatus = await this.getAllValidatorDetailsMap(status) + const flagged = flagStaked(allOfStatus, staked) + const stakedMap = await this.getStakedMap() + const final: IStakingValidatorStakedMap = {} + for (let val in stakedMap) { + if (flagged[val]) { + final[val] = { ...flagged[val], stakedDetails: stakedMap[val] } + } else { + final[val] = { ...flagged[val] } + } + } + return final } async getCompleteMergedValidatorDetailsMap (): Promise { const staked = await this.getAllDelegatorValidatorDetailsMap() diff --git a/src/interfaces/IStakingValidatorStaked.ts b/src/interfaces/IStakingValidatorStaked.ts new file mode 100644 index 00000000..91f45935 --- /dev/null +++ b/src/interfaces/IStakingValidatorStaked.ts @@ -0,0 +1,5 @@ +import { IDelegationSummary, IStakingValidatorExtended } from '@/interfaces' + +export default interface IStakingValidatorStaked extends IStakingValidatorExtended { + stakedDetails?: IDelegationSummary +} diff --git a/src/interfaces/IStakingValidatorStakedMap.ts b/src/interfaces/IStakingValidatorStakedMap.ts new file mode 100644 index 00000000..0749a6f6 --- /dev/null +++ b/src/interfaces/IStakingValidatorStakedMap.ts @@ -0,0 +1,5 @@ +import { IStakingValidatorStaked } from '@/interfaces' + +export default interface IStakingValidatorStakedMap { + [key: string]: IStakingValidatorStaked +} diff --git a/src/interfaces/classes/IGovHandler.ts b/src/interfaces/classes/IGovHandler.ts index b63b208c..ea298e96 100644 --- a/src/interfaces/classes/IGovHandler.ts +++ b/src/interfaces/classes/IGovHandler.ts @@ -3,7 +3,8 @@ import { IDelegationSummaryMap, IStakingValidator, IStakingValidatorExtendedMap, - IStakingValidatorMap + IStakingValidatorMap, + IStakingValidatorStakedMap } from '@/interfaces/' import ICoin from '@/interfaces/ICoin' import { TValidatorStatus } from '@/types/TValidatorStatus' @@ -14,6 +15,7 @@ export default interface IGovHandler { getRewards (validatorAddress: string): Promise getTotalStaked (): Promise getStakedMap (): Promise + getStakedValidatorDetailsMap (): Promise getDelegatorValidatorDetails (validatorAddress: string): Promise getAllDelegatorValidatorDetails (): Promise getAllDelegatorValidatorDetailsMap (): Promise @@ -21,6 +23,7 @@ export default interface IGovHandler { getAllValidatorDetails (status: string): Promise getAllValidatorDetailsMap (status: TValidatorStatus): Promise getMergedValidatorDetailsMap (status: TValidatorStatus): Promise + getMergedValidatorDetailsStakedMap (status: TValidatorStatus): Promise getCompleteMergedValidatorDetailsMap (): Promise claimDelegatorRewards (validatorAddresses: string[]): Promise delegateTokens (validatorAddress: string, amount: number): Promise diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 7ad8b3bc..2803de55 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -47,6 +47,8 @@ import IStakingValidator from '@/interfaces/IStakingValidator' import IStakingValidatorExtended from '@/interfaces/IStakingValidatorExtended' import IStakingValidatorExtendedMap from '@/interfaces/IStakingValidatorExtendedMap' import IStakingValidatorMap from '@/interfaces/IStakingValidatorMap' +import IStakingValidatorStaked from '@/interfaces/IStakingValidatorStaked' +import IStakingValidatorStakedMap from '@/interfaces/IStakingValidatorStakedMap' import IStorageClientFree from '@/interfaces/IStorageClientFree' import IStoragePaymentInfo from '@/interfaces/IStoragePaymentInfo' import IStray from '@/interfaces/IStray' @@ -102,6 +104,8 @@ export { IStakingValidatorExtended, IStakingValidatorExtendedMap, IStakingValidatorMap, + IStakingValidatorStaked, + IStakingValidatorStakedMap, IStorageClientFree, IStoragePaymentInfo, IStray,