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

feat(TokenEnterAmount): add new flow to EnterAmount.tsx #6245

Merged
merged 77 commits into from
Dec 2, 2024

Conversation

sviderock
Copy link
Contributor

@sviderock sviderock commented Nov 19, 2024

Description

3/5 PR for new Enter Amount component. This PR uses the new component and hook in the Send flow. A lot of tests are adjusted to follow the new flow.

AmountInput component was moved purely for compatibility with EarnEnterAmount component. This is an outdated boilerplate code which will be removed in the next PR (4/5). Most of the line changes is this specific component and a lot of tests' adjusting. There's really not many changes other than replacing boilerplate code with the same code from a reusable hook.

Test plan

Changes a bunch of test files to relate to the new changes. All the tests related to MAX button are skipped for now.

send.flow.mp4

Related issues

Backwards compatibility

Yes

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

@sviderock sviderock changed the base branch from main to slava/add-enter-amount-hook November 19, 2024 06:29
@sviderock sviderock force-pushed the slava/change-send-flow branch from 6f89ffd to 1aa17d6 Compare November 19, 2024 06:58
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 98.96907% with 1 line in your changes missing coverage. Please review.

Project coverage is 88.93%. Comparing base (1ea0927) to head (5e2dbee).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/components/TokenEnterAmount.tsx 97.56% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6245      +/-   ##
==========================================
- Coverage   88.95%   88.93%   -0.02%     
==========================================
  Files         739      739              
  Lines       31644    31609      -35     
  Branches     5892     5883       -9     
==========================================
- Hits        28149    28113      -36     
+ Misses       3450     3296     -154     
- Partials       45      200     +155     
Files with missing lines Coverage Δ
src/components/LabelWithInfo.tsx 100.00% <100.00%> (ø)
src/components/TokenDisplay.tsx 100.00% <100.00%> (ø)
src/icons/DownArrowIcon.tsx 100.00% <ø> (ø)
src/jumpstart/JumpstartEnterAmount.tsx 93.33% <ø> (ø)
src/send/EnterAmount.tsx 94.03% <100.00%> (-1.27%) ⬇️
src/send/SendEnterAmount.tsx 93.75% <100.00%> (+0.13%) ⬆️
src/send/usePrepareSendTransactions.ts 86.20% <ø> (ø)
src/components/TokenEnterAmount.tsx 94.51% <97.56%> (+2.09%) ⬆️

... and 68 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ea0927...5e2dbee. Read the comment docs.

@sviderock sviderock marked this pull request as ready for review November 19, 2024 09:08
Copy link
Collaborator

@kathaypacific kathaypacific left a comment

Choose a reason for hiding this comment

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

amazing work!!! it looks really great 🚀 i had some small ponderings, and i think you may also need to adjust the e2e tests for the send flow?

@@ -355,58 +225,62 @@ function EnterAmount({
>
<View style={styles.inputContainer}>
<Text style={styles.title}>{t('sendEnterAmountScreen.title')}</Text>
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think there is some vertical padding missing between the enter amount and title?
Simulator Screenshot - iPhone 15 Pro - 2024-11-26 at 16 03 02

Copy link
Collaborator

Choose a reason for hiding this comment

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

(i think this is outdated)

Copy link
Contributor Author

@sviderock sviderock Nov 29, 2024

Choose a reason for hiding this comment

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

@kathaypacific should be outdated as it was missing after initial merge with "max" functionality but then I fixed it.

return value.replaceAll(groupingSeparator, '').replaceAll(decimalSeparator, '.')
}

export function roundLocalNumber(value: BigNumber | null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export function roundLocalNumber(value: BigNumber | null) {
export function roundFiatValue(value: BigNumber | null) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

side thought, no need to address now but i wonder if this will be handy to have as a general function that can be used in other places like the transaction feed....

Copy link
Contributor Author

@sviderock sviderock Nov 29, 2024

Choose a reason for hiding this comment

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

@kathaypacific I think it definitely will be. Considering that it is currently only used in this file - there's no point in moving it to a general utility yet file but we should keep this in mind for when its gonna be useful.

@@ -48,6 +49,16 @@ export function formatNumber(value: string) {
.replaceAll('_', groupingSeparator)
}

export function unformatNumberForProcessing(value: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export function unformatNumberForProcessing(value: string) {
export function formatNumberToStandard(value: string) {

or parseNumberToStandardFormat or applyUSNumberFormatting?

Copy link
Contributor Author

@sviderock sviderock Nov 29, 2024

Choose a reason for hiding this comment

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

@kathaypacific hmm, I'm still unsure on this one. It is only used in a single place so far to actually un-format already formatted number that comes from the input and format it for the processing purposes. I think it makes a more clear distinction for the specific purpose of the function:

  • it unformats the number (which implies it was formatted in the first place)
  • it formats it specifically for processing

I've only made is a separate function to simplify description as otherwise I'd need to write a comment explaining what it does and why, which feels more concise in a form of a clear function name.

In case of formatNumberToStandard/parseNumberToStandardFormat - we need to define what we mean by "standard". And in case of applyUSNumberFormatting - we need to understand why we specifically use US number formatting (even though I'm not sure it's US specific as up to this point I thought this was a general format that everyone uses and was always using it myself 😄)

At least, that's my train of though. What do you think about it?

handleToggleAmountType,
handleAmountInputChange,
handlePercentage,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
handlePercentage,
handleSelectPercentageAmount,

tokenBottomSheetRef.current?.close()
const onSelectToken: TokenBottomSheetProps['onTokenSelected'] = (selectedToken) => {
setToken(selectedToken)
setAmount('')
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, i was wondering how this setAmount would be used. generally i don't like the pattern of components that have a state and give other components access to the state and the state setter because it gives consumers of this component the ability to do a lot (and blurs the responsibility of the consumer and the component, since the component can be controlled absolutely).

if the consumers only need to be able to reset the amount, what do you think about changing the return property of useEnterAmount here from setAmount to something like resetAmount?

Copy link
Contributor Author

@sviderock sviderock Nov 29, 2024

Choose a reason for hiding this comment

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

@kathaypacific I totally agree and I tried to refrain from exposing this state setter till the very end but in this particular case it felt like it was the clearest way to do this without trying to overcomplicate it.

I will rename it to replaceAmount as I already have an identical functionality incoming in Swap flow (cause we have two fields there and second is always un-editable and have to be set programatically).

// NOTE: analytics is already fired by the bottom sheet, don't need one here
}

const onSelectPercentageAmount = (percentage: number) => {
setTokenAmountInput(token.balance.multipliedBy(percentage).toFormat({ decimalSeparator }))
setEnteredIn('token')
handlePercentage(percentage)
setSelectedPercentage(percentage)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the handlePercentage and setSelectedPercentage calls in series made me think that it might make sense to move the EnterAmountOptions into TokenEnterAmount, what do you think? (not in this PR, but seems like a fun friday afternoon thing for someone at some point)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const isAmountLessThanBalance =
processedAmounts.token.bignum && processedAmounts.token.bignum.lte(token.balance)
const showLowerAmountError =
processedAmounts.token.bignum && !isAmountLessThanBalance && !disableBalanceCheck
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this be simplified to const showLowerAmountError = processedAmounts.token.bignum && processedAmounts.token.bignum.gt(token.balance) && !disableBalanceCheck?

}, FETCH_UPDATED_TRANSACTIONS_DEBOUNCE_TIME_MS)
return () => clearTimeout(debouncedRefreshTransactions)
},
[processedAmounts.token.bignum, token]
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we try to use primitive values here? i'm not sure how effective BigNumber and TokenBalance is at triggering this effect

Suggested change
[processedAmounts.token.bignum, token]
[processedAmounts.token.bignum.toString(), token.tokenId]

onOpenTokenPicker={tokenSelectionDisabled ? undefined : onOpenTokenPicker}
/>

{!!maxFeeAmount && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is also something that we can consider as a follow up, wanted to note it while it's fresh in my mind. i think one of the goals of the enter amount work is also to standardise errors and the fees display. so perhaps it makes sense to move these parts into the TokenEnterAmount (or have a component that wraps them, idk). i think that there's going to be some amount of duplication for handling these things in the various flows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kathaypacific I'm all for it! I will create a task for this and would love to work on it!

@@ -158,12 +160,12 @@ describe('EnterAmount', () => {
})

expect(getByTestId('SendEnterAmount/TokenAmountInput')).toBeTruthy()
expect(getByTestId('SendEnterAmount/LocalAmountInput')).toBeTruthy()
// expect(getByTestId('SendEnterAmount/Max')).toBeTruthy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove?

Copy link
Collaborator

@kathaypacific kathaypacific left a comment

Choose a reason for hiding this comment

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

🥳

ios/Podfile.lock Outdated
@@ -1339,4 +1339,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: e49ec411923f9bb1906dff8d0e27d0aa410bf3ad

COCOAPODS: 1.16.2
COCOAPODS: 1.15.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, perhaps we don't include this change since it's unrelated

Copy link

emerge-tools bot commented Dec 2, 2024

📸 Snapshot Test

Base build not found

No build was found for the base commit 1ea0927. This is required to generate a snapshot diff for your pull request.

It's possible that you created a branch off the base commit before all of the CI steps have finished processing, e.g. the one that uploads a build to our system. If that's the case, no problem! Just wait and this will eventually resolve.


🛸 Powered by Emerge Tools

@kathaypacific
Copy link
Collaborator

kathaypacific commented Dec 2, 2024

hey @sviderock this is awesome!! i will merge in your absence :)

i added a few minor changes after testing on android, noting it here in case you disagree with the changes / have ideas for how to fix the issues in a better way:

  • fixed fee amount formatting on Android (the "network fee" label was always clipped and showed only "N...") by adjusting some styles (use flex: 0 instead of flexShrink: 1)
  • fix the amount set by the "max" amount - the token around was rounded to 6 decimals however this uses the round up policy which means the "you need to lower the amount" error is always triggered and the user cannot proceed. i am using token.decimals for now
  • perhaps related to a laggy android device but on clearing the amount, the network fee was still displayed. i added a condition to hide the network fee if the amount is an empty string
  • removed the secondary amount maxWidth so that we can always see the token symbol
  • (this one is personal preference during testing) removed the keyboard dismiss on tap of switch token / local amount, to make it easier to switch to fiat amount on screen open (since there is an autofocus on screen open and the keyboard would be dismissed and need to be manually opened again)

here are some "before changes" screenshots:
Screenshot_20241202_113131_Valora (dev)
Screenshot_20241202_113225_Valora (dev)

Screen_Recording_20241202_113305_Valora.dev.mp4

after changes video:

Screen_Recording_20241202_131828_Valora.dev.mp4

@kathaypacific kathaypacific added this pull request to the merge queue Dec 2, 2024
Merged via the queue into main with commit 295b9f5 Dec 2, 2024
15 of 16 checks passed
@kathaypacific kathaypacific deleted the slava/change-send-flow branch December 2, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants