-
Notifications
You must be signed in to change notification settings - Fork 26
feat(decimal): decimal precision on send/swap, and amount input display fix #894
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
Open
raul-oliveira
wants to merge
1
commit into
master
Choose a base branch
from
feat/amount-format-two-line-input
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Copyright (c) Hathor Labs and its affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import React, { useState } from 'react'; | ||
| import { Text } from 'react-native'; | ||
| import { | ||
| computeAmountFontFit, | ||
| AMOUNT_FONT_BASE_SIZE, | ||
| AMOUNT_FONT_MIN_SIZE, | ||
| AMOUNT_MAX_LINES, | ||
| } from '../utils'; | ||
|
|
||
| // Line height as a fraction of font size; matches AmountTextInput's | ||
| // LINE_HEIGHT_RATIO so input and read-only display wrap identically. | ||
| const LINE_HEIGHT_RATIO = 1.2; | ||
|
|
||
| /** | ||
| * Read-only counterpart to AmountTextInput (transaction detail balance, home | ||
| * balance, ...), using the same shrink-first-then-wrap ladder (`computeAmountFontFit`). | ||
| * | ||
| * Intentionally NOT `<Text adjustsFontSizeToFit numberOfLines={3}>`: on iOS that | ||
| * wraps at the base size WITHOUT shrinking, so a long amount fills three full-size lines. | ||
| * | ||
| * Measures its own width via `onLayout`, so callers MUST let it stretch (defaults to | ||
| * `alignSelf: 'stretch'`); sizing to content instead feeds the measurement back on itself. | ||
| * | ||
| * @param {Object} props | ||
| * @param {string} props.children - The amount string to render (value plus symbol) | ||
| * @param {Object} [props.style] - Additional text styles (color, fontWeight, ...) | ||
| * @param {number} [props.baseFontSize] - Starting (largest) font size | ||
| * @param {number} [props.minFontSize] - Floor font size before wrapping | ||
| * @returns {React.ReactElement} | ||
| */ | ||
| const AmountDisplay = ({ | ||
| children, | ||
| style, | ||
| baseFontSize = AMOUNT_FONT_BASE_SIZE, | ||
| minFontSize = AMOUNT_FONT_MIN_SIZE, | ||
| ...rest | ||
| }) => { | ||
| const [availableWidth, setAvailableWidth] = useState(0); | ||
| const content = children == null ? '' : String(children); | ||
| const { fontSize } = computeAmountFontFit( | ||
| content.length, | ||
| availableWidth, | ||
| baseFontSize, | ||
| minFontSize, | ||
| ); | ||
| const lineHeight = Math.round(fontSize * LINE_HEIGHT_RATIO); | ||
|
|
||
| return ( | ||
| <Text | ||
| numberOfLines={AMOUNT_MAX_LINES} | ||
| onLayout={(e) => setAvailableWidth(e.nativeEvent.layout.width)} | ||
| style={[ | ||
| { alignSelf: 'stretch', textAlign: 'center' }, | ||
| style, | ||
| { fontSize, lineHeight }, | ||
| ]} | ||
| {...rest} | ||
| > | ||
| {content} | ||
| </Text> | ||
| ); | ||
| }; | ||
|
|
||
| export default AmountDisplay; |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue(blocking): typed decimals beyond the token's precision are silently truncated
getAmountParsed(parsedText, MAX_DECIMAL_PLACES)keeps 8 typed decimals, but line 97 scales with the token'sdecimalPlacesandgetIntegerAmountslices the excess away.On a 2-decimal network, typing
1.12345678displays that string and sends112n(1.12);0.00000001yields0n, whichisValidaccepts, so the field shows a value while Continue stays disabled with no error.Previously the text was clamped, so what you saw was what you sent. Consider
getAmountParsed(parsedText, decimalPlaces ?? MAX_DECIMAL_PLACES), which keeps the undefined-serverInfofallback without discarding entered precision.