fix(tipping): cap the tip preset buttons at three digits - #1381
Merged
Conversation
The preset buttons split the modal's width three ways, and the amount inside each is written out in full. In USD the tiers are $5 / $10 / $20 and fit, but the same tiers localized to a low-value currency do not: 7,500 / 15,000 / 30,000 pesos, Rp332,000, or a custom amount larger still. `Fiat.abbreviated()` caps the visible amount at three digits. Anything under 1,000 formats as it did before, and larger amounts scale to K/M/B/T with only the decimals the cap leaves room for, trailing zeros dropped: 7.5K, 25.5K, 123K, 1.25M. It rounds to significant digits before choosing the scale, so 999,999 prints as $1M rather than $1,000K. The button's content description still carries the full amount, so the abbreviation is visual only and TalkBack reads "332,000". It lives beside the existing `Number.abbreviated()` in core and follows its K/M/B/T casing, but formats through `Fiat` so the currency symbol, grouping, and per-currency fraction digits stay intact.
Collaborator
Author
|
Deliberately not identical to the iOS side, code-ios-app#704, which does the same job for the Send a Tip chips. That one keeps a decimal only while the scaled figure is a single digit; this keeps three significant digits. The same preset therefore reads Two smaller differences, same decision: this abbreviates the custom "…" slot as well, where iOS leaves it formatting exactly, and |
Discovery formatted market caps, holder counts and their deltas with its own
rule: two decimals at every scale, so a delta could take five digits
("+$999.99K"). It also picked the scale from the unrounded value, printing
999,999 as "1000K", and compared signed values against the scale thresholds,
so a negative holder delta never abbreviated at all — -12,345 rendered in
full despite the call site expecting "-12.3K".
Move the scale selection onto the three-digit rule the tip presets use and
share it between the two: round to three significant digits first, pick the
scale from the rounded value, then keep only the decimals the cap leaves room
for. Discovery now reads 1.23K / 693K / -12.3K.
Values below a thousand are now rounded rather than truncated, so a fractional
market cap delta of 42.7 shows as 43 instead of 42.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The preset buttons split the tip modal's width three ways and write the amount out in full. In USD the tiers are $5 / $10 / $20 and fit; localized to a low-value currency they do not. The same tiers are 7,500 / 15,000 / 30,000 pesos, and a custom amount can be larger still.
Fiat.abbreviated()caps the visible amount at three digits. Under 1,000 it formats exactly as before; above that it scales to K/M/B/T, keeping only the decimals the cap leaves room for and dropping trailing zeros. It rounds to significant digits before choosing the scale, so 999,999 prints as$1Mrather than$1,000K.The button's content description keeps the full amount, so the abbreviation is visual only and TalkBack still reads "332,000".
The helper formats through
Fiat, so the currency symbol, grouping, and per-currency fraction digits are preserved.FiatTestcovers the scale boundaries, the decimal cap, the carry into the next scale, and the currencies above.Discovery uses the same rule
The second commit moves discovery's market caps, holder counts and deltas onto it. They previously went through
Number.abbreviated(), which had its own rule — two decimals at every scale, so a delta could run to five digits (+$999.99K) — and two defects that the shared implementation does not have:$1000K.>=comparisons on the signed value, so no negative ever matched one. A holder delta of -12,345 rendered in full, even though the call site's comment expects the sign to carry through an abbreviation.Both helpers now share the rounding and scale selection; only the final formatting differs, because
Fiatneeds the currency symbol andNumberdoes not. Discovery reads 1.23K / 693K / -12.3K.One behaviour change below a thousand: values are now rounded instead of truncated, so a fractional market cap delta of 42.7 shows as 43. Holder counts are whole, so this only reaches market cap figures.
Unchanged by this PR, but worth knowing: ARS, IDR and COP resolve no single-character symbol through
CurrencyCode.singleCharacterCurrencySymbol, so those buttons show bare digits. Full formatting drops the symbol too, but it reads as more of a gap now that the number is short.