diff --git a/apps/dashboard/src/lib/validators/uptime-module.spec.ts b/apps/dashboard/src/lib/validators/uptime-module.spec.ts index 898bfcfb1..da5fa4ae0 100644 --- a/apps/dashboard/src/lib/validators/uptime-module.spec.ts +++ b/apps/dashboard/src/lib/validators/uptime-module.spec.ts @@ -32,10 +32,10 @@ describe('uptime module', () => { expect(uptimeModule.getDataForUptime('1month')).toEqual({}) }) - it('should throw when trying to get APY', () => { - expect(() => + it('should return undefined when trying to get APY', () => { + expect( uptimeModule.getApy({} as ValidatorCollectionItem, '1month') - ).toThrowError(/Invalid totalAmountStaked/) + ).toBeUndefined() }) }) diff --git a/apps/dashboard/src/lib/validators/uptime-module.ts b/apps/dashboard/src/lib/validators/uptime-module.ts index c8e75f297..3b54414a0 100644 --- a/apps/dashboard/src/lib/validators/uptime-module.ts +++ b/apps/dashboard/src/lib/validators/uptime-module.ts @@ -60,7 +60,7 @@ export const UptimeModule = ( getDataForUptime: (uptime: UptimeValue) => uptimeData[uptime] || {}, getApy: (validator: ValidatorCollectionItem, uptime: UptimeValue) => { if (!totalAmountStaked || totalAmountStaked.isZero()) { - throw new Error('Invalid totalAmountStaked') + return undefined } const address = validator.address const fee = Number(validator.effective_fee_factor?.current?.fee_factor) diff --git a/apps/dashboard/src/pages/navbar-pages/staking/validator-details/ApyDetail.svelte b/apps/dashboard/src/pages/navbar-pages/staking/validator-details/ApyDetail.svelte index 80219a814..51dd8bc44 100644 --- a/apps/dashboard/src/pages/navbar-pages/staking/validator-details/ApyDetail.svelte +++ b/apps/dashboard/src/pages/navbar-pages/staking/validator-details/ApyDetail.svelte @@ -23,11 +23,9 @@ uptimeModule.getDataForUptime($lastQueriedUptime)} {#if validatorsUptimeData && Object.keys(validatorsUptimeData).length > 0} {@const data = validator.typed.value} - - {validator.typed.value.percentageTotalStake - ? `${truncateNumber( - uptimeModule.getApy(data.validator, $lastQueriedUptime) - )}%` + {@const apy = uptimeModule.getApy(data.validator, $lastQueriedUptime)} + {validator.typed.value.percentageTotalStake && apy + ? `${truncateNumber(apy)}%` : 'N/A'} {:else} diff --git a/apps/dashboard/src/pages/navbar-pages/staking/validator-list/ValidatorList.svelte b/apps/dashboard/src/pages/navbar-pages/staking/validator-list/ValidatorList.svelte index 123b7f131..c4fc133e6 100644 --- a/apps/dashboard/src/pages/navbar-pages/staking/validator-list/ValidatorList.svelte +++ b/apps/dashboard/src/pages/navbar-pages/staking/validator-list/ValidatorList.svelte @@ -135,7 +135,7 @@ ) => { const apy1 = uptimeModule.getApy(v1.validator, selectedUptime) const apy2 = uptimeModule.getApy(v2.validator, selectedUptime) - return sortBasic(apy1, apy2, direction) + return sortBasic(apy1 || 0, apy2 || 0, direction) }, header: { label: 'APY', diff --git a/apps/dashboard/src/pages/navbar-pages/staking/validator-list/row/ValidatorRowApy.svelte b/apps/dashboard/src/pages/navbar-pages/staking/validator-list/row/ValidatorRowApy.svelte index 71e109c99..e13460e32 100644 --- a/apps/dashboard/src/pages/navbar-pages/staking/validator-list/row/ValidatorRowApy.svelte +++ b/apps/dashboard/src/pages/navbar-pages/staking/validator-list/row/ValidatorRowApy.svelte @@ -21,7 +21,7 @@ )}
{#if validators && Object.keys(validators).length > 0} - {input.validator.percentageTotalStake + {input.validator.percentageTotalStake && apy ? `${truncateNumber(apy)}%` : 'N/A'} {#if input.validator.percentageTotalStake} diff --git a/apps/dashboard/src/routes/(navbar-pages)/network-staking/(load-validators)/+layout.ts b/apps/dashboard/src/routes/(navbar-pages)/network-staking/(load-validators)/+layout.ts index b4d6c2a5f..d925a7a51 100644 --- a/apps/dashboard/src/routes/(navbar-pages)/network-staking/(load-validators)/+layout.ts +++ b/apps/dashboard/src/routes/(navbar-pages)/network-staking/(load-validators)/+layout.ts @@ -16,7 +16,7 @@ const ERROR_MSG = 'Failed to load validators.' const handleGatewayWithErrorMessage = handleGatewayResult((_) => ERROR_MSG) -export const load: LayoutLoad = () => { +export const load: LayoutLoad = ({ fetch }) => { uptimeModule.clean() const bookmarkedValidators = bookmarkedValidatorsApi @@ -56,6 +56,7 @@ export const load: LayoutLoad = () => { uptimeModule.setValidators( validatorsResponse.then(({ validators }) => validators) ) + uptimeModule.maybeQueryUptime('1month') return { promises: {