Skip to content

Commit

Permalink
condensing duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Apr 11, 2023
1 parent 9edb41c commit 9b91e2e
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/classes/govHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,16 @@ export default class GovHandler implements IGovHandler {
async getMergedValidatorDetailsMap (status: TValidatorStatus): Promise<IStakingValidatorExtendedMap> {
const staked = await this.getAllDelegatorValidatorDetailsMap()
const allOfStatus = await this.getAllValidatorDetailsMap(status)
const complete: IStakingValidatorExtendedMap = {}
for (let val in allOfStatus) {
if (staked[val]) {
complete[val] = { ...allOfStatus[val], stakedWith: true }
} else {
complete[val] = { ...allOfStatus[val], stakedWith: false }
}
}
return complete
return flagStaked(allOfStatus, staked)

}
async getCompleteMergedValidatorDetailsMap (): Promise<IStakingValidatorExtendedMap> {
const staked = await this.getAllDelegatorValidatorDetailsMap()
const allUnbonding = this.getAllValidatorDetailsMap('UNBONDING')
const allUnbonded = this.getAllValidatorDetailsMap('UNBONDED')
const allActive = this.getAllValidatorDetailsMap('BONDED')
const merged = { ...await allUnbonding, ...await allUnbonded, ...await allActive }
const complete: IStakingValidatorExtendedMap = {}
for (let val in merged) {
if (staked[val]) {
complete[val] = { ...merged[val], stakedWith: true }
} else {
complete[val] = { ...merged[val], stakedWith: false }
}
}
return complete
return flagStaked(merged, staked)
}
async claimDelegatorRewards (validatorAddresses: string[]): Promise<void> {
const { msgWithdrawDelegatorReward } = await this.pH.distributionTx
Expand Down Expand Up @@ -147,3 +132,15 @@ const statusMap: { [key: string]: string } = {
'UNBONDING': 'BOND_STATUS_UNBONDING',
'BONDED': 'BOND_STATUS_BONDED'
}

function flagStaked (base: IStakingValidatorMap, staked: IStakingValidatorMap): IStakingValidatorExtendedMap {
const final: IStakingValidatorExtendedMap = {}
for (let val in base) {
if (staked[val]) {
final[val] = { ...base[val], stakedWith: true }
} else {
final[val] = { ...base[val], stakedWith: false }
}
}
return final
}

0 comments on commit 9b91e2e

Please sign in to comment.