From 54d16f65a1671c820b7988f63f22cdebdd51d5f7 Mon Sep 17 00:00:00 2001 From: Vicente Date: Wed, 26 May 2021 08:17:32 +0200 Subject: [PATCH] fix delegation center not loading results (#1351) --- src/components/Delegation/StakingCenter.js | 45 ++++++++++++---------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/components/Delegation/StakingCenter.js b/src/components/Delegation/StakingCenter.js index 277726df4b..15291d1a90 100644 --- a/src/components/Delegation/StakingCenter.js +++ b/src/components/Delegation/StakingCenter.js @@ -11,7 +11,7 @@ import {STAKING_CENTER_ROUTES} from '../../RoutesList' import {CONFIG} from '../../config/config' import {withNavigationTitle} from '../../utils/renderUtils' import {Logger} from '../../utils/logging' -import {formatTokenInteger} from '../../utils/format' +import {normalizeTokenAmount} from '../../utils/format' import walletManager from '../../crypto/walletManager' import globalMessages, {errorMessages} from '../../i18n/global-messages' import {showErrorDialog} from '../../actions' @@ -74,8 +74,8 @@ type SelectedPool = {| * @param {*} poolList : Array of delegated pool hash */ const prepareStakingURL = ( - poolList: ?Array, - amountToDelegate: ?string, + poolList: Array | null, + amountToDelegate: string | null, locale: string, ): string => { // source=mobile is constant and already included @@ -213,22 +213,22 @@ const StakingCenter = ({ // pools user is currently delegating to const poolList = poolOperator != null ? [poolOperator] : null - const [amountToDelegate, setAmountToDelegate] = useState(null) + const [amountToDelegate, setAmountToDelegate] = useState(null) - const getAmountToDelegate = async () => { - const utxosForKey = - utxos != null ? await walletManager.getAllUtxosForKey(utxos) : null - // prettier-ignore - const amountToDelegate = - utxosForKey != null - ? utxosForKey - .map((utxo) => utxo.amount) - .reduce( - (x: BigNumber, y) => x.plus(new BigNumber(y || 0)), - new BigNumber(0), - ) - : BigNumber(0) - setAmountToDelegate(formatTokenInteger(amountToDelegate, defaultAsset)) + const getAmountToDelegate: () => Promise = async () => { + if (utxos != null) { + const utxosForKey = await walletManager.getAllUtxosForKey(utxos) + // prettier-ignore + const _amountToDelegate = utxosForKey + .map((utxo) => utxo.amount) + .reduce( + (x: BigNumber, y) => x.plus(new BigNumber(y || 0)), + new BigNumber(0), + ) + setAmountToDelegate( + normalizeTokenAmount(_amountToDelegate, defaultAsset).toString(), + ) + } } const [selectedPools, setSelectedPools] = useState([]) @@ -263,9 +263,12 @@ const StakingCenter = ({ } } - useEffect(() => { - getAmountToDelegate() - }) + useEffect( + () => { + getAmountToDelegate() + }, + [utxos], + ) return ( <>