Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashboard): regression when staking multiple #1002

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading