-
Notifications
You must be signed in to change notification settings - Fork 96
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(warning): Add generic gas fee warning component #6385
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6385 +/- ##
==========================================
- Coverage 89.05% 89.05% -0.01%
==========================================
Files 735 736 +1
Lines 31350 31386 +36
Branches 5820 5835 +15
==========================================
+ Hits 27919 27950 +31
- Misses 3237 3242 +5
Partials 194 194
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
src/components/GasFeeWarning.tsx
Outdated
const feeCurrencySymbol = | ||
prepareTransactionsResult.type === 'not-enough-balance-for-gas' | ||
? prepareTransactionsResult.feeCurrencies[0].symbol |
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.
In the designs, it seems like it leans towards hardcoding this to be CELO or ETH (this is cases 2-4), however in all of the use cases currently it is done like this (using prepareTransactionsResult.feeCurrencies[0]
). I think it is easier to keep it this way for two reasons:
- ETH tokenId is not available in NetworkConfig, and would be needed for CTA (in order to prefill in CICO flow), so would need to be added for all networks, increasing amount of hardcoded things
- The CTA is implemented in the component that uses this warning, so the implementer would have to get the hardcoded tokenId based on the network of the prepared transaction, rather than just looking at the first feeCurrencies.
I can add in the ETH tokenId's if we want but wanted to check first about doing it this way instead.
📸 Snapshot TestNo snapshots generated
🛸 Powered by Emerge Tools |
src/analytics/docs.ts
Outdated
@@ -67,6 +67,7 @@ export const eventDocs: Record<AnalyticsEventType, string> = { | |||
[AppEvents.in_app_review_impression]: `User sees an in-app review request`, | |||
[AppEvents.in_app_review_error]: `Error while attempting to display in-app review`, | |||
[AppEvents.handle_deeplink]: `When a deeplink that leads into the app is detected and handled`, | |||
[AppEvents.show_gas_fee_warning]: `When the gas fee warning is shown to the user`, |
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.
[AppEvents.show_gas_fee_warning]: `When the gas fee warning is shown to the user`, | |
[AppEvents.gas_fee_warning_impression]: `When the gas fee warning is shown to the user`, |
?
src/components/GasFeeWarning.tsx
Outdated
? prepareTransactionsResult.feeCurrencies[0] | ||
: prepareTransactionsResult.feeCurrency | ||
|
||
const flowToNotEnoughGasDescriptionString = { |
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.
you can consider using context
instead of doing this mapping yourself. E.g., the translation strings could be made something like gasFeeWarning.description.notEnoughGas_<GasFeeWarningFlow>
, and then you can just do t('gasFeeWarning.description.notEnoughGas', { context: <GasFeeWarningFlow>, tokenSymbol })
There are other places in the app where we do this if you want a complete example
expect(queryByTestId('test/GasFeeWarning')).toBeFalsy() | ||
}) | ||
it.each` | ||
scenario | flow | prepareTransactionsResult | feeCurrencyTokenId | title | description | ctaLabel |
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.
I guess it doesn't hurt but whats the value of testing all the different variants with 2 different symbols? We don't seem to be doing anything custom depending on symbols
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.
I was trying to have test coverage for all the cases outlined by product in the figma doc, and those cases include Celo and non-Celo chains so I had one of each
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.
ok, I guess figma had those differences because celo is the only one with multiple gas tokens, we don't really handle that in this component, so it seems superfluous to test the variations.
onPressCta={() => { | ||
AppAnalytics.track(EarnEvents.earn_deposit_add_gas_press, { | ||
gasTokenId: feeCurrencies[0].tokenId, | ||
depositTokenId: pool.dataProps.depositTokenId, | ||
networkId: pool.networkId, | ||
providerId: pool.appId, | ||
poolId: pool.positionId, | ||
}) | ||
if (prepareTransactionsResult && prepareTransactionsResult.type !== 'possible') { | ||
prepareTransactionsResult.type === 'not-enough-balance-for-gas' | ||
? navigate(Screens.FiatExchangeAmount, { | ||
tokenId: prepareTransactionsResult.feeCurrencies[0].tokenId, | ||
flow: CICOFlow.CashIn, | ||
tokenSymbol: prepareTransactionsResult.feeCurrencies[0].symbol, | ||
}) | ||
: handleAmountInputChange(prepareTransactionsResult.decreasedSpendAmount.toString()) | ||
} | ||
}} |
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 this something that can be done in the warning component? Seems inconsistent to have the component define the CTA label, but the action is defined by the consumer. I assume this is going to be the same for all usages?
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.
In the AC of the ticket it says that the component should have an optional action prop for handling the CTA, so I thought that meant to pass in an onPress function. But I agree I think it makes more sense for the CTA to exist within the component because "Buy CELO" should always do the same thing, regardless of flow. @MuckT was there a reason to pass in the CTA?
src/components/GasFeeWarning.tsx
Outdated
import { Spacing } from 'src/styles/styles' | ||
import { PreparedTransactionsResult } from 'src/viem/prepareTransactions' | ||
|
||
export enum GasFeeWarningFlow { |
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.
did you consider string literals over enum for this?
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 but I can change it to that, in Valora should we prefer string literals over enums? Or what is the convention?
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.
Don't think we have a defined convention, but we did talk about this in an eng sync and I think we've been favoring literals over enums recently
Description
Generic gas warning create in
GasFeeWarning.tsx
. Used inEarnEnterAmount
. For cases 2-5rounded n
is omitted, since it is difficult to find for cases 2-4, and in case 5 there is no cta so no immediate action to be taken (slack thread discussing here).Analytics added for when the error shows, analytics for cta press are to be included in the
onPressCta
prop.Test plan
EarnEnterAmount
unit test updatedGasFeeWarning
unit tests createdManual Testing:
Not enough gas currency:
| | |
Transacting with max amount:
| | |
Dapp:
Tapping CTA:
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-12-30.at.14.49.28.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-12-31.at.12.07.10.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: