Skip to content

Commit

Permalink
use sort instead of reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
groninge01 committed Jan 22, 2025
1 parent 39d01b2 commit 1593f9e
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ export function useGetAmountDelegatedPerValidator(chain: GqlChain) {
const unstakeAmountAssets = (unstakeAmountShares * rate) / 10n ** 18n

// choose the validator with the most amount delegated
const validator = amountDelegatedPerValidator.reduce(
(max, current) =>
unstakeAmountAssets < current.amountDelegated &&
current.amountDelegated > max.amountDelegated
? current
: max,
amountDelegatedPerValidator[0]
)
const validator = amountDelegatedPerValidator
.filter(validator => unstakeAmountAssets < validator.amountDelegated)
.sort((a, b) => (b.amountDelegated > a.amountDelegated ? 1 : -1))[0]

// TODO: we should split the unstake amount across several validators down the line
return [
Expand Down

0 comments on commit 1593f9e

Please sign in to comment.