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

Stats page - total system surplus #605

Merged
merged 10 commits into from
Jul 3, 2024
Merged

Stats page - total system surplus #605

merged 10 commits into from
Jul 3, 2024

Conversation

alekseevaiana
Copy link
Member

closes #585

Question

Why we add 1 if min decimals <= then format decimals? If we put format decimals, don't we want to be exact this number?
I changed the logic so it doesn't work if format decimals === 0, but let me know if we should change it (hope it breaks nothing else)

Before

Screenshot 2024-07-01 at 1 29 36 PM

After

Screenshot 2024-07-01 at 1 31 51 PM

Screenshot

Screenshot 2024-07-01 at 1 40 24 PM

Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
od-app ✅ Ready (Inspect) Visit Preview Jul 3, 2024 6:10pm
od-app-hai ✅ Ready (Inspect) Visit Preview Jul 3, 2024 6:10pm
od-app-testnet ✅ Ready (Inspect) Visit Preview Jul 3, 2024 6:10pm

@@ -324,7 +333,7 @@ const Analytics = () => {
analyticsData.globalDebt,
analyticsData.globalDebtCeiling
),
surplusInTreasury: formatDataNumber(analyticsData.surplusInTreasury, 18, 0, true),
surplusInTreasury: `${formatDataNumber(analyticsData.surplusInTreasury, 18, 0)} OD`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting with "OD" should only be added downstream, where it is displayed

Comment on lines +34 to +36
minimumDecimals >= formatDecimal && formatDecimal !== 0
? Math.min(minimumDecimals, formatDecimal) + 1
: formatDecimal,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please verify throughout the app that this doesn't create unintended effects. After testing, please request Jacobs review

@alekseevaiana
Copy link
Member Author

alekseevaiana commented Jul 2, 2024

Notes

Testing

I added few checks for formatDataNumber function (run yarn test src/utils/index.test.ts)

How did I test function changes

I checked function with this piece of code checking that new result not causing unexpecting changes.

export function formatDataNumber(
    input: string,
    decimals = 18,
    formatDecimal = 2,
    currency?: boolean,
    compact?: boolean,
    minimumDecimals: number = 0
) {
    if (minimumDecimals >= formatDecimal) {
        let res: number = Number.parseFloat(input)

        if (decimals !== 0) res = Number.parseFloat(utils.formatUnits(input, decimals))

        if (res < 0.01) {
            let resString = res.toFixed(minimumDecimals)
            return `${currency ? '$' : ''}${resString}`
        }

        const oldResult = new Intl.NumberFormat('en-US', {
            minimumFractionDigits: minimumDecimals,
            maximumFractionDigits:
                minimumDecimals >= formatDecimal ? Math.min(minimumDecimals, formatDecimal) + 1 : formatDecimal,
            notation: compact ? 'compact' : 'standard',
            style: currency ? 'currency' : 'decimal',
            currency: 'USD',
        }).format(res)

        const newResult = new Intl.NumberFormat('en-US', {
            minimumFractionDigits: minimumDecimals,
            maximumFractionDigits:
                minimumDecimals > formatDecimal && formatDecimal !== 0
                    ? Math.min(minimumDecimals, formatDecimal) + 1
                    : formatDecimal,
            notation: compact ? 'compact' : 'standard',
            style: currency ? 'currency' : 'decimal',
            currency: 'USD',
        }).format(res)

        if (oldResult !== newResult)
            console.error('newResult !== oldResult', newResult !== oldResult, oldResult, newResult)
    }

    let res: number = Number.parseFloat(input)

    if (decimals !== 0) res = Number.parseFloat(utils.formatUnits(input, decimals))

    if (res < 0.01) {
        let resString = res.toFixed(minimumDecimals)
        return `${currency ? '$' : ''}${resString}`
        // old return
        // return `${currency ? '$' : ''}${formatNumber(res.toString(), formatDecimal)}`
    }
    // console.log(Math.min(minimumDecimals, formatDecimal))

    return new Intl.NumberFormat('en-US', {
        minimumFractionDigits: minimumDecimals,
        maximumFractionDigits:
            minimumDecimals >= formatDecimal && formatDecimal !== 0
                ? Math.min(minimumDecimals, formatDecimal) + 1
                : formatDecimal,
        notation: compact ? 'compact' : 'standard',
        style: currency ? 'currency' : 'decimal',
        currency: 'USD',
    }).format(res)
}

@alekseevaiana
Copy link
Member Author

alekseevaiana commented Jul 3, 2024

@pi0neerpat we don't use this function on vaults creation.
Also, I removed 'join testnet' from footer in this PR. Hope that is ok.
Screenshot 2024-07-03 at 11 01 37 AM

@alekseevaiana alekseevaiana merged commit 1478661 into dev Jul 3, 2024
8 checks passed
@alekseevaiana alekseevaiana deleted the iana/surplus-back-585 branch July 3, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stats page - total system surplus
2 participants