Skip to content

Commit

Permalink
fix(dashboard): regression when staking multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Oct 16, 2024
1 parent 6d8fe82 commit 867c8a5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions apps/dashboard/src/lib/validators/uptime-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/lib/validators/uptime-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
<SkeletonLoader width={50} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)}
<div>
{#if validators && Object.keys(validators).length > 0}
{input.validator.percentageTotalStake
{input.validator.percentageTotalStake && apy
? `${truncateNumber(apy)}%`
: 'N/A'}
{#if input.validator.percentageTotalStake}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,6 +56,7 @@ export const load: LayoutLoad = () => {
uptimeModule.setValidators(
validatorsResponse.then(({ validators }) => validators)
)
uptimeModule.maybeQueryUptime('1month')

return {
promises: {
Expand Down

0 comments on commit 867c8a5

Please sign in to comment.