Skip to content

Commit

Permalink
fix delegation center not loading results (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
v-almonacid authored May 26, 2021
1 parent c7f39cd commit 54d16f6
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/components/Delegation/StakingCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -74,8 +74,8 @@ type SelectedPool = {|
* @param {*} poolList : Array of delegated pool hash
*/
const prepareStakingURL = (
poolList: ?Array<string>,
amountToDelegate: ?string,
poolList: Array<string> | null,
amountToDelegate: string | null,
locale: string,
): string => {
// source=mobile is constant and already included
Expand Down Expand Up @@ -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<string | null>(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<void> = 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([])
Expand Down Expand Up @@ -263,9 +263,12 @@ const StakingCenter = ({
}
}

useEffect(() => {
getAmountToDelegate()
})
useEffect(
() => {
getAmountToDelegate()
},
[utxos],
)

return (
<>
Expand Down

0 comments on commit 54d16f6

Please sign in to comment.