Skip to content

Commit

Permalink
fix: dominanceRatio cannot be null
Browse files Browse the repository at this point in the history
  • Loading branch information
Albermonte committed Nov 19, 2024
1 parent 22ec0c8 commit e8365b2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/nimiq-validators-trustscore/src/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ScoreParams, ScoreValues } from './types'

export function getDominance({ threshold = 0.15, steepness = 7.5, dominanceRatio }: ScoreParams['dominance']) {
if (!threshold || !steepness || !dominanceRatio)
throw new Error('Balance, threshold, steepness, or total balance is not set')
throw new Error(`Dominance Ratio, threshold or steepness is not set. ${JSON.stringify({ threshold, steepness, dominanceRatio })}`)
if (dominanceRatio < 0 || dominanceRatio > 1)
throw new Error(`Invalid dominance ratio: ${dominanceRatio}`)
const s = Math.max(0, 1 - (dominanceRatio / threshold) ** steepness)
Expand Down
4 changes: 2 additions & 2 deletions server/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ export async function fetchValidators(params: FetchValidatorsOptions): Result<Fe
if (dominance)
// @ts-expect-error The wallet expects a score object, but until these values are stable, we will use null
v.score.dominance = dominance
else if (v.dominanceRatioViaBalance && v.dominanceRatioViaBalance !== -1)
else if (v.dominanceRatioViaBalance && v.dominanceRatioViaBalance && v.dominanceRatioViaBalance !== -1)
// @ts-expect-error The wallet expects a score object, but until these values are stable, we will use null
v.score = { ...nullScore, dominance: getDominance({ dominanceRatio: v.dominanceRatioViaBalance }) }
else if (v.dominanceRatioViaBalance && v.dominanceRatioViaSlots !== -1)
else if (v.dominanceRatioViaBalance && v.dominanceRatioViaSlots && v.dominanceRatioViaSlots !== -1)
// @ts-expect-error The wallet expects a score object, but until these values are stable, we will use null
v.score = { ...nullScore, dominance: getDominance({ dominanceRatio: v.dominanceRatioViaSlots }) }
})
Expand Down

0 comments on commit e8365b2

Please sign in to comment.