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

refactor numbers to strings and HugeDecimals to support arbitrary-precision decimal inputs, and merge DaoVotingTokenStaked and DaoVotingNativeStaked voting module adapters #1817

Merged
merged 26 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1add0ff
started refactoring to use bignumber.js
NoahSaso Sep 26, 2024
0ff4101
created HugeDecimal and replaced BigNumber usage with it
NoahSaso Sep 26, 2024
40ad933
replaced single unit denom converters
NoahSaso Sep 27, 2024
43637c2
replaced one conversion util with HugeDecimal
NoahSaso Sep 27, 2024
c98f80d
replaced remaining conversion utils with HugeDecimal
NoahSaso Sep 27, 2024
adba151
accept HugeDecimal and auto-convert decimals in TokenAmountDisplay
NoahSaso Sep 28, 2024
f8c143a
added international formatting and compaction to HugeDecimal, and use…
NoahSaso Sep 29, 2024
1ff1e8f
fix HugeDecimal.isPositive implementation
NoahSaso Sep 30, 2024
9162c91
add available suffix to unstaked tokens
NoahSaso Sep 30, 2024
ac187df
added more tests for abbreviation formatting
NoahSaso Sep 30, 2024
02dad2b
improve some number formatting
NoahSaso Sep 30, 2024
ea68897
use HugeDecimal in StakingModal and PercentButton
NoahSaso Sep 30, 2024
1bf293e
created new HugeDecimalInput and started replacing NumberInputs with it
NoahSaso Sep 30, 2024
8173bb7
transform final data instead of partial import data
NoahSaso Oct 1, 2024
51eede4
replace NumberInput with HugeDecimalInput
NoahSaso Oct 1, 2024
14b0e26
replace more NumberInput with HugeDecimalInput
NoahSaso Oct 1, 2024
4ac4e92
replace even more NumberInput with HugeDecimalInput
NoahSaso Oct 1, 2024
9bb2b87
replace even mooooore NumberInput with HugeDecimalInput
NoahSaso Oct 2, 2024
4e5c6c7
renamed HugeDecimalInput to NumericInput
NoahSaso Oct 2, 2024
54d2688
fix IBC amount out comparison
NoahSaso Oct 2, 2024
3b7279f
tweaked formatting
NoahSaso Oct 2, 2024
c7ab840
misc improvements
NoahSaso Oct 2, 2024
83c261c
replaced a bunch of numbers with HugeDecimals, consolidated DaoVoting…
NoahSaso Oct 3, 2024
7aa813a
consolidated DAO context hooks
NoahSaso Oct 3, 2024
ce15169
convert some more to HugeDecimals
NoahSaso Oct 3, 2024
c06fa11
fixed token value sorting and small token amount display
NoahSaso Oct 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ If something is misconfigured, check out the docs for
| [`dispatch`](./packages/dispatch) | DAO DAO Dispatch. |
| [`email`](./packages/email) | Email template and generator tools. |
| [`i18n`](./packages/i18n) | Internationalization/translation system. |
| [`math`](./packages/math) | Math utilities. |
| [`state`](./packages/state) | State retrieval and management for the DAO DAO UI. |
| [`stateful`](./packages/stateful) | Stateful components, hooks, and systems that access and manipulate live data. |
| [`stateless`](./packages/stateless) | React components, React hooks, and other stateless rendering utilities which do not access live data. |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"utils": "yarn workspace @dao-dao/utils",
"email": "yarn workspace @dao-dao/email",
"dispatch": "yarn workspace @dao-dao/dispatch",
"math": "yarn workspace @dao-dao/math",
"publish-all": "find . -name '*.log' -delete && lerna publish --no-private from-package"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,7 @@
"addedToProfile": "Added to profile successfully.",
"addedToken": "Added token to Keplr.",
"claimedRewards": "Claimed rewards.",
"claimedTokens": "Claimed {{amount}} ${{tokenSymbol}}.",
"compensationCycleCompleted_noProposal": "Compensation cycle completed.",
"compensationCycleCompleted_withProposal": "Compensation cycle completed. Redirecting to proposal...",
"compensationCycleCreated": "Compensation cycle created.",
Expand Down Expand Up @@ -1649,10 +1650,12 @@
"restaked": "Restaked successfully.",
"saved": "Saved successfully.",
"staked": "Staked successfully.",
"stakedTokens": "Staked {{amount}} ${{tokenSymbol}}.",
"tokenSwapContractInstantiated": "Token swap created successfully.",
"transactionExecuted": "Transaction executed successfully.",
"unregistered": "Unregistered successfully.",
"unstaked": "Unstaked successfully.",
"unstakedTokens": "Unstaked {{amount}} ${{tokenSymbol}}.",
"voteCast": "Vote successfully cast.",
"withdrewPayment": "Withdrew payment."
},
Expand Down
10 changes: 10 additions & 0 deletions packages/math/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

/** @type {import("eslint").Linter.Config} */
const eslintConfig = {
extends: [require.resolve('@dao-dao/config/eslint')],
ignorePatterns: ['node_modules'],
root: true,
}

module.exports = eslintConfig
161 changes: 161 additions & 0 deletions packages/math/HugeDecimal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { HugeDecimal } from './HugeDecimal'

test('HugeDecimal', () => {
expect(
HugeDecimal.fromHumanReadable(
1234.5678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
})
).toBe('1,234.5678')

expect(
HugeDecimal.fromHumanReadable(
1234.5678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
minDecimals: 6,
})
).toBe('1,234.567800')

expect(
HugeDecimal.fromHumanReadable(
1234.5678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
})
).toBe('1.23K')

expect(
HugeDecimal.fromHumanReadable(
1234.5678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
minDecimals: 0,
})
).toBe('1.23K')

expect(
HugeDecimal.fromHumanReadable(
1234.5678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
minDecimals: 4,
})
).toBe('1.2346K')

expect(
HugeDecimal.fromHumanReadable(
1234.5678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
minDecimals: 8,
})
).toBe('1.23456780K')

expect(
HugeDecimal.fromHumanReadable(
0.001,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
})
).toBe('0.001')

expect(
HugeDecimal.fromHumanReadable(1, 6).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
})
).toBe('1')

expect(
HugeDecimal.from(
'4901849977581594372686'
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: true,
})
).toBe('4,901,849,977,581,594.372686')

expect(
HugeDecimal.from(
'4901849977581594372686'
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: true,
minDecimals: 8,
})
).toBe('4,901,849,977,581,594.37268600')

expect(
HugeDecimal.from(
'4901849977581594372686'
).toInternationalizedHumanReadableString({
decimals: 0,
showFullAmount: false,
})
).toBe('4,901,849,977.58T')

expect(
HugeDecimal.from(
// (BigInt(Number.MAX_SAFE_INTEGER) * 10000n).toString()
'90071992547409910000'
).toInternationalizedHumanReadableString({
decimals: 0,
showFullAmount: false,
})
).toBe('90,071,992.55T')

expect(
HugeDecimal.from(
// (BigInt(Number.MAX_SAFE_INTEGER) * 10000n).toString()
'90071992547409910000'
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
})
).toBe('90.07T')

expect(
HugeDecimal.from(
// (BigInt(Number.MAX_SAFE_INTEGER) * 10000n).toString()
'90071992547409910000'
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
minDecimals: 6,
})
).toBe('90.071993T')

expect(
HugeDecimal.fromHumanReadable(
11000027,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
})
).toBe('11.00M')

expect(
HugeDecimal.fromHumanReadable(
12345678,
6
).toInternationalizedHumanReadableString({
decimals: 6,
showFullAmount: false,
})
).toBe('12.35M')
})
Loading
Loading