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

refactor(earn-types): combine withdraw actions and earn enter mode #6187

Open
wants to merge 2 commits into
base: tomm/act-1389
Choose a base branch
from

Conversation

MuckT
Copy link
Collaborator

@MuckT MuckT commented Oct 24, 2024

Description

There were two types previously used for the earn flow:

  • EarnEnterMode - Used to prepare the correct transaction in EarnEnterAmount.tsx and EarnDepositBottomSheet.tsx.
  • WithdrawActionName - Used to determine what to display on the EarnConfirmationScreen.tsx and prepare transactions for that screen.

This PR refactors this logic so that earn flow uses the new EarnActiveAction type which mirrors the currently available shortcuts plus an exit option. This should make determining the appropriate display and transaction preparation easier by being more consistent throughout the flow.

Test plan

  • Tested locally on iOS
  • Tested locally on Android
  • Unit tests updated

Related issues

Backwards compatibility

Yes

Network scalability

N/A

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.91%. Comparing base (01ec110) to head (b5fc84e).

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           tomm/act-1389    #6187      +/-   ##
=================================================
+ Coverage          88.90%   88.91%   +0.01%     
=================================================
  Files                733      733              
  Lines              31158    31160       +2     
  Branches            5427     5429       +2     
=================================================
+ Hits               27700    27705       +5     
+ Misses              3415     3412       -3     
  Partials              43       43              
Files with missing lines Coverage Δ
src/analytics/Properties.tsx 100.00% <ø> (ø)
src/analytics/types.ts 100.00% <ø> (ø)
src/earn/EarnConfirmationScreen.tsx 97.41% <100.00%> (ø)
src/earn/EarnDepositBottomSheet.tsx 98.75% <ø> (ø)
src/earn/EarnEnterAmount.tsx 89.58% <100.00%> (+0.06%) ⬆️
src/earn/poolInfoScreen/EarnPoolInfoScreen.tsx 93.82% <100.00%> (ø)
src/earn/poolInfoScreen/WithdrawBottomSheet.tsx 98.68% <100.00%> (ø)
src/earn/prepareTransactions.ts 92.59% <100.00%> (ø)
src/earn/types.ts 100.00% <ø> (ø)

... and 1 file 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 01ec110...b5fc84e. Read the comment docs.

Copy link
Contributor

@satish-ravi satish-ravi left a comment

Choose a reason for hiding this comment

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

I am not sure I see the benefits of combining the enums yet, but maybe I am missing some context. This just seems to broaden the type for things that need to remain specific, which opens up the possibility of bugs. Can you list where this common type would be beneficial?

@@ -69,11 +67,11 @@ export interface BeforeDepositAction {
}

export interface WithdrawAction {
name: WithdrawActionName
name: EarnActiveAction
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be using a broader type here. Since deposit, swap-deposit aren't valid "withdraw" actions. This opens up the possibility of bugs / handling invalid types. Can we still keep a narrow type here? You can still have a broader type if it makes things easier in other places, but we should keep types as narrow as possible

@@ -81,11 +81,11 @@ export type StackParamList = {
[Screens.EarnInfoScreen]: undefined
[Screens.EarnEnterAmount]: {
pool: EarnPosition
mode?: EarnEnterMode
mode?: EarnActiveAction
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above, the screen shouldn't need to deal with invalid action names.

@@ -196,7 +196,7 @@ export async function prepareWithdrawTransactions({
}
}

export function usePrepareTransactions(mode: EarnEnterMode) {
export function usePrepareTransactions(mode: EarnActiveAction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the implementation of this function seems wrong now, if mode is exit | claim-rewards this would end up calling prepareDepositTransactions

@@ -34,7 +34,7 @@ export async function prepareDepositTransactions({
feeCurrencies: TokenBalance[]
pool: EarnPosition
hooksApiUrl: string
shortcutId: EarnEnterMode
shortcutId: Exclude<EarnActiveAction, 'exit'>
Copy link
Contributor

Choose a reason for hiding this comment

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

can we include only deposit related shortcuts

@@ -163,7 +163,7 @@ export async function prepareWithdrawTransactions({
feeCurrencies: TokenBalance[]
pool: EarnPosition
hooksApiUrl: string
shortcutId: EarnEnterMode
shortcutId: Exclude<EarnActiveAction, 'exit'>
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above

title: string
details: string
iconComponent: React.MemoExoticComponent<({ color }: { color: Colors }) => JSX.Element>
onPress: () => void
}

export type EarnEnterMode = 'deposit' | 'swap-deposit' | 'withdraw'
export type EarnActiveAction = 'withdraw' | 'claim-rewards' | 'deposit' | 'swap-deposit' | 'exit'
Copy link
Contributor

Choose a reason for hiding this comment

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

if you're changing this to Action, can we also change variable names to be action instead of mode

}
[Screens.EarnConfirmationScreen]: {
pool: EarnPosition
mode: WithdrawActionName
mode: EarnActiveAction
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, seems like this screen is specific to the withdraw actions

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