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

BEDS-1106/fix percent formatting #1247

Merged
merged 2 commits into from
Jan 9, 2025
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
20 changes: 9 additions & 11 deletions frontend/components/dashboard/DashboardValidatorOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,25 @@ const openValidatorModal = () => {
}

const efficiencyInfos = computed(() =>
TimeFrames.map(k => ({
label: $t(`statistics.${k}`),
value: formatPercent(overview.value?.efficiency[k] ?? 0),
TimeFrames.map(timeFrame => ({
label: $t(`statistics.${timeFrame}`),
value: formatToPercent(overview.value?.efficiency[timeFrame] ?? 0),
})),
)

const rewardsInfos = TimeFrames.map(k =>
createInfo(k, overview.value?.rewards[k] ?? {
const rewardsInfos = TimeFrames.map(timeFrame =>
createInfo(timeFrame, overview.value?.rewards[timeFrame] ?? {
cl: '0',
el: '0',
}, formatValueWei),
)

const apr = computed(() => formatPercent(totalElClNumbers(overview.value?.apr.last_30d ?? {
const apr = computed(() => formatToPercent(totalElClNumbers(overview.value?.apr.last_30d ?? {
cl: 0,
el: 0,
})),
)

const aprInfos = TimeFrames.map(k =>
createInfo(k, overview.value?.apr[k] ?? {
})))
const aprInfos = TimeFrames.map(timeFrame =>
createInfo(timeFrame, overview.value?.apr[timeFrame] ?? {
cl: 0,
el: 0,
}, formatToPercent),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ const openValidatorModal = () => {
{{
$t(`dashboard.validator.summary.tooltip.${compare}`, {
name: groupName,
average: formatPercent(row.average_network_efficiency),
average: formatToPercent(row.average_network_efficiency),
})
}}
</span>
Expand Down
5 changes: 1 addition & 4 deletions frontend/utils/bigMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ export const subWei = (total: string, value: string): BigNumber | undefined => {

export const totalElClNumbers = (
value: ClElValue<number>,
): number | undefined => {
if (!value) {
return
}
) => {
return value.el + value.cl
}
35 changes: 0 additions & 35 deletions frontend/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ export function commmifyLeft(value: string): string {
return formatted
}

export function formatAndCalculatePercent(
value?: number,
base?: number,
config?: NumberFormatConfig,
): string {
if (!base) {
return ''
}
return formatPercent(calculatePercent(value, base), config)
}

/**
* Should be used only when you work with a network different from the current one.
* Wherever you would write `formatEpochToDate(currentNetwork.value, ...)` you
Expand Down Expand Up @@ -146,30 +135,6 @@ export function formatNumber(value?: number): string {
return value?.toLocaleString('en-US') ?? ''
}

export function formatPercent(
percent?: number,
config?: NumberFormatConfig,
): string {
if (percent === undefined) {
return ''
}
const {
addPositiveSign, fixed, precision,
} = {
...{
addPositiveSign: false,
fixed: 2,
precision: 2,
},
...config,
}
let result = trim(percent, precision, fixed)
if (addPositiveSign) {
result = addPlusSign(result)
}
return `${result}%`
}

/**
* Should be used only when you work with a network different from the current one.
* Wherever you would write `formatSlotToDateTime(currentNetwork.value, ...)`
Expand Down
Loading