From 1593f9e25e99965a7fb1b1b2b28100e3c0a2515a Mon Sep 17 00:00:00 2001 From: groninge Date: Wed, 22 Jan 2025 07:57:16 +0000 Subject: [PATCH] use sort instead of reduce --- .../lst/hooks/useGetAmountDelegatedPerValidator.tsx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/apps/beets-frontend-v3/lib/modules/lst/hooks/useGetAmountDelegatedPerValidator.tsx b/apps/beets-frontend-v3/lib/modules/lst/hooks/useGetAmountDelegatedPerValidator.tsx index c059469ad..202858c88 100644 --- a/apps/beets-frontend-v3/lib/modules/lst/hooks/useGetAmountDelegatedPerValidator.tsx +++ b/apps/beets-frontend-v3/lib/modules/lst/hooks/useGetAmountDelegatedPerValidator.tsx @@ -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 [