-
Notifications
You must be signed in to change notification settings - Fork 79
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(earn): Add enter amount screen #5399
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5399 +/- ##
==========================================
- Coverage 86.35% 86.29% -0.06%
==========================================
Files 755 756 +1
Lines 30942 31162 +220
Branches 5281 5338 +57
==========================================
+ Hits 26719 26891 +172
- Misses 3996 4039 +43
- Partials 227 232 +5
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
src/send/EnterAmount.tsx
Outdated
disableProceed || (disableBalanceCheck ? !!tokenAmount?.isZero() : !transactionIsPossible) | ||
disableProceed || | ||
(disableBalanceCheck | ||
? !!tokenAmount?.isZero() || (!!tokenAmount?.lte(token.balance) && !transactionIsPossible) |
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.
We want to disable the continue button when checking if the prepared transaction is possible, even if we are disabling the warnings.
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.
this is getting super hard to read, either consider breaking this up or leave a comment explaining the different scenarios
src/send/EnterAmount.tsx
Outdated
@@ -441,14 +465,13 @@ function EnterAmount({ | |||
/> | |||
)} | |||
|
|||
{children} |
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.
With children here, the bottom sheets were acting super weird. Need to go through and double check that this doesn't mess anything else up.
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.
Pretty sure this will affect the InLineNotification in the jumpstart screen. I guess one option would be to pass bottomsheets in a separate prop.. Not ideal but should work for now
locales/base/translation.json
Outdated
"info": "This pool is powered by Aave", | ||
"infoBottomSheet": { | ||
"title": "Why this pool?", | ||
"description": "This Aave pool has over $150M TVL and more than 6,000 contributors, indicating strong liquidity and trustworthiness. It also uses USDC as its token and Abritrum as its network, which reduces volatility and ensures users will receive inexpensive gas rates.\n\nAll together this makes it a safe and attractive option with competitive APY, ensuring a beneficial investment opportunity for our users.\n\nYou can explore other Aave pools here.", |
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.
The "here" is supposed to be a link, but I'm not sure what it is supposed to link to. Also, this is used as the description
param for a bottom sheet so I'm not sure how to format links for translations when it is passed as a param.
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.
maybe something like https://app.aave.com/markets/? Would be good to check with product. And re description, can we render this as a content inside the bottom sheet instead of using the existing prop?
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.
Confirmed with John that that link is good so I'll add it in
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.
src/analytics/Properties.tsx
Outdated
@@ -1583,6 +1583,8 @@ interface EarnEventsProperties { | |||
[EarnEvents.earn_deposit_complete]: undefined | |||
[EarnEvents.earn_deposit_cancel]: undefined | |||
[EarnEvents.earn_view_pools_press]: undefined | |||
[EarnEvents.earn_enter_amount_info_press]: undefined | |||
[EarnEvents.earn_enter_amount_continue_press]: { userHasFunds: boolean } |
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.
would be good to include some additional props here like the amount the user entered, tokenId etc.
src/send/EnterAmount.tsx
Outdated
@@ -441,14 +465,13 @@ function EnterAmount({ | |||
/> | |||
)} | |||
|
|||
{children} |
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.
Pretty sure this will affect the InLineNotification in the jumpstart screen. I guess one option would be to pass bottomsheets in a separate prop.. Not ideal but should work for now
src/send/EnterAmount.tsx
Outdated
disableProceed?: boolean | ||
children?: React.ReactNode | ||
ProceedComponent: ComponentType<ProceedComponentProps> | ||
disableBalanceCheck?: boolean | ||
proceedComponentStatic?: boolean |
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.
can we document what this prop means, doesn't seem super obvious
src/send/EnterAmount.tsx
Outdated
disableProceed || (disableBalanceCheck ? !!tokenAmount?.isZero() : !transactionIsPossible) | ||
disableProceed || | ||
(disableBalanceCheck | ||
? !!tokenAmount?.isZero() || (!!tokenAmount?.lte(token.balance) && !transactionIsPossible) |
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.
this is getting super hard to read, either consider breaking this up or leave a comment explaining the different scenarios
src/send/EnterAmount.tsx
Outdated
contentContainerStyle={ | ||
proceedComponentStatic | ||
? styles.contentContainer | ||
: { ...styles.contentContainer, flexGrow: 1 } |
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.
contentContainerStyle={ | |
proceedComponentStatic | |
? styles.contentContainer | |
: { ...styles.contentContainer, flexGrow: 1 } | |
contentContainerStyle=[styles.contentContainer, !proceedComponentStatic && {flexGrow: 1}] |
locales/base/translation.json
Outdated
"info": "This pool is powered by Aave", | ||
"infoBottomSheet": { | ||
"title": "Why this pool?", | ||
"description": "This Aave pool has over $150M TVL and more than 6,000 contributors, indicating strong liquidity and trustworthiness. It also uses USDC as its token and Abritrum as its network, which reduces volatility and ensures users will receive inexpensive gas rates.\n\nAll together this makes it a safe and attractive option with competitive APY, ensuring a beneficial investment opportunity for our users.\n\nYou can explore other Aave pools here.", |
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.
maybe something like https://app.aave.com/markets/? Would be good to check with product. And re description, can we render this as a content inside the bottom sheet instead of using the existing prop?
src/earn/EarnEnterAmount.tsx
Outdated
token={token} | ||
tokenAmount={tokenAmount.minus(token.balance)} | ||
/> | ||
{prepareTransactionsResult && prepareTransactionsResult.type === 'possible' && ( |
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.
{prepareTransactionsResult && prepareTransactionsResult.type === 'possible' && ( | |
{prepareTransactionsResult?.type === 'possible' && ( |
does this work?
src/send/EnterAmount.tsx
Outdated
@@ -150,10 +154,13 @@ function EnterAmount({ | |||
prepareTransactionError, | |||
tokenSelectionDisabled = false, | |||
onPressProceed, | |||
onPressInfo, | |||
onSetTokenAmount, |
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.
onSetTokenAmount, | |
onChangeTokenAmount, |
src/send/EnterAmount.tsx
Outdated
@@ -71,10 +72,13 @@ interface Props { | |||
prepareTransactionError?: Error | |||
tokenSelectionDisabled?: boolean | |||
onPressProceed(args: ProceedArgs): void | |||
onPressInfo?(): void |
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.
is onPressInfo
needed in EnterAmount? Seems like it just gets it as a prop and passes in back to proceed component, which can all be done within EarnEnterAmount
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.
no, I'll update it to just be within the proceed component
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.
actually, I think to do this I would have to have the EarnProceed function inside EarnEnterAmount, and this causes issues with the token amount state value and also rendering APY.
So I think EarnProceed (which needs access to onPressInfo) needs to be outside of EarnEnterAmount so I'm not sure then how it would have access to onPressInfo. @satish-ravi is there some way to access it from outside the function it is declared without passing as a prop?
1 build increased size
Celo (test) 1.85.0 (150)
|
Item | Install Size Change |
---|---|
main.jsbundle | ⬆️ 32.8 kB |
🛸 Powered by Emerge Tools
token={token} | ||
amountEnteredIn={enteredIn} | ||
onPressProceed={onPressContinue} | ||
onPressInfo={onPressInfo} |
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.
Still need to pass this here. I tried having EarnProceed be a const inside of EarnEnterAmount rather than a function outside of it, but this was causing it to re-render everytime the input amount was changed and so the APY was flashing a lot.
Follow up issue to use EnterAmount: https://linear.app/valora/issue/ACT-1199/placeholder-clean-up-have-earnenteramount-use-enteramount-component |
src/earn/prepareTransactions.ts
Outdated
export function usePrepareSupplyTransactions() { | ||
const prepareTransactions = useAsyncCallback(prepareSupplyTransactions, { | ||
onError: (error) => { | ||
Logger.error(TAG, `usePrepareSupplyTransactions: ${error}`) |
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.
Logger.error(TAG, `usePrepareSupplyTransactions: ${error}`) | |
Logger.error(TAG, 'usePrepareSupplyTransactions', error) |
so the error is logged with trace, you may need an ensureError potentially
src/earn/EarnEnterAmount.tsx
Outdated
prepareTransactionsResult.transactions.length > 0 | ||
|
||
const disabled = | ||
!!tokenAmount?.isZero() || (!!tokenAmount?.lte(token.balance) && !transactionIsPossible) // Should disable if the user enters 0 or has enough balance but the transaction is not possible, shouldn't disable if they enter an amount larger than their balance as they will go to add flow |
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.
nit: this won't be readable in the editor, move the comment to one line above and break it up to multiple lines. would be nice if prettier can do this.
src/earn/EarnEnterAmount.tsx
Outdated
prepareTransactionError, | ||
} = usePrepareSupplyTransactions() | ||
|
||
const walletAddress = useSelector(walletAddressSelector) as Address |
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.
can we avoid the as Address, I think we've been doing a isAddress
check where required
src/analytics/Properties.tsx
Outdated
tokenAmount: string | null | ||
amountInUsd: string | null | ||
amountEnteredIn: AmountEnteredIn | ||
tokenId: string | null | ||
networkId: string | null |
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.
do these need to be nulls?
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.
no, they should all have values, I'll update to not take null
src/earn/EarnEnterAmount.tsx
Outdated
|
||
const onPressContinue = ({ tokenAmount, token, amountEnteredIn }: ProceedArgs) => { | ||
ValoraAnalytics.track(EarnEvents.earn_enter_amount_continue_press, { | ||
userHasFunds: token.balance?.gte(tokenAmount), |
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.
reuse isAmountLessThanBalance
}) | ||
}) | ||
|
||
it('should handle navigating to the deposit bottom sheet', async () => { |
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.
can this assert the appropriate bottom sheet was opened?
} | ||
) | ||
}) | ||
it('should handle navigating to the add crypto bottom sheet', async () => { |
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.
same comment as above
src/earn/EarnEnterAmount.tsx
Outdated
<EarnDepositBottomSheet | ||
forwardedRef={reviewBottomSheetRef} | ||
preparedTransaction={prepareTransactionsResult} | ||
amount={tokenAmount ? tokenAmount.toString() : '0'} |
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.
tokenAmount should be defined with tx is possible right? You can just add this as another condition to the conditional rendering check above instead of the ternary here.
paddingVertical: Spacing.Thick24, | ||
}, | ||
valuesText: { | ||
...typeScale.labelSemiBoldSmall, |
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.
add color to all text styles
src/earn/EarnEnterAmount.tsx
Outdated
} | ||
const onPressMorePools = () => { | ||
ValoraAnalytics.track(EarnEvents.earn_enter_amount_info_more_pools) | ||
navigate(Screens.WebViewScreen, { uri: 'https://app.aave.com/markets/' }) |
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.
can we move this to the earn_stablecoin_config dynamic config?
src/earn/prepareTransactions.ts
Outdated
import { fetchWithTimeout } from 'src/utils/fetchWithTimeout' | ||
import { publicClient } from 'src/viem' | ||
import { TransactionRequest, prepareTransactions } from 'src/viem/prepareTransactions' | ||
import networkConfig, { networkIdToNetwork } from 'src/web3/networkConfig' | ||
import { Address, encodeFunctionData, isAddress, parseUnits } from 'viem' | ||
|
||
const TAG = 'src/earn/prepareTransactions' |
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.
const TAG = 'src/earn/prepareTransactions' | |
const TAG = 'earn/prepareTransactions' |
nit: usually we don't include src in the tags.
Description
Add EarnEnterAmount screen.
Test plan
Unit tests added.
Manual tests:
When a user has USDC on arbitrum:
enough.mp4
When a user doesn't have enough USDC on arbitrum:
not-enough.mp4
Clicking the info button:
info.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: