Skip to content

Commit

Permalink
Fix delegations query in Polkadot network (#475)
Browse files Browse the repository at this point in the history
* fetch delegations from stored valid. staking info

* Simplify

* Cleanup
  • Loading branch information
mariopino authored Mar 18, 2020
1 parent 2dede39 commit ef5d22c
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions lib/source/polkadotV0-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,29 +225,16 @@ class polkadotAPI {
delegatorAddress,
validatorsDictionary
) {
const api = await this.getAPI()
const nominations = JSON.parse(
JSON.stringify(await api.query.staking.nominators(delegatorAddress))
)
if (!nominations) return [] // HACK not all accounts do have nominations
const allNominations = nominations.reduce(
(all, { targets }) => all.concat(targets),
[]
)
let delegations = allNominations
.map(validatorAddress => {
const validator = validatorsDictionary[validatorAddress]
if (!validator) return undefined // HACK until we load all validators
const nomination = validator
? validator.nominations.find(({ who }) => who === delegatorAddress)
: undefined
return this.reducers.delegationReducer(
this.network,
nomination,
validator
)
let delegations = []
Object.values(validatorsDictionary).forEach(validator => {
validator.nominations.forEach(nomination => {
if (delegatorAddress === nomination.who) {
delegations.push(
this.reducers.delegationReducer(this.network, nomination, validator)
)
}
})
.filter(x => !!x) //filter out not existing validators
})
return delegations
}

Expand Down

0 comments on commit ef5d22c

Please sign in to comment.