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(earn): Add earn withdraw bottom sheet #6142

Merged
merged 26 commits into from
Oct 22, 2024
Merged

Conversation

finnian0826
Copy link
Contributor

@finnian0826 finnian0826 commented Oct 10, 2024

Description

Add bottom sheet for different withdraw options, show if >=2 of those options exist for a user.

Test plan

Unit tests added and updated

Manual:

Can partial withdraw:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-10-14.at.11.09.25.mp4

Can't partial withdraw:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-10-14.at.11.12.22.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)

Copy link

codecov bot commented Oct 10, 2024

Codecov Report

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

Project coverage is 88.89%. Comparing base (0f20649) to head (e18782f).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/earn/poolInfoScreen/WithdrawBottomSheet.tsx 98.68% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6142      +/-   ##
==========================================
+ Coverage   88.87%   88.89%   +0.01%     
==========================================
  Files         730      734       +4     
  Lines       31029    31136     +107     
  Branches     5693     5413     -280     
==========================================
+ Hits        27577    27678     +101     
- Misses       3256     3415     +159     
+ Partials      196       43     -153     
Files with missing lines Coverage Δ
src/analytics/Events.tsx 100.00% <100.00%> (ø)
src/analytics/Properties.tsx 100.00% <ø> (ø)
src/earn/ActionCard.tsx 100.00% <100.00%> (ø)
...c/earn/poolInfoScreen/BeforeDepositBottomSheet.tsx 100.00% <100.00%> (ø)
src/earn/poolInfoScreen/EarnPoolInfoScreen.tsx 93.82% <100.00%> (+0.29%) ⬆️
src/earn/types.ts 100.00% <ø> (ø)
src/icons/Exit.tsx 100.00% <100.00%> (ø)
src/icons/Trophy.tsx 100.00% <100.00%> (ø)
src/earn/poolInfoScreen/WithdrawBottomSheet.tsx 98.68% <98.68%> (ø)

... and 71 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 0f20649...e18782f. Read the comment docs.

@finnian0826 finnian0826 marked this pull request as ready for review October 18, 2024 17:00
@@ -25,14 +25,14 @@ import { Spacing } from 'src/styles/styles'
import { TokenBalance } from 'src/tokens/slice'
import { getTokenAnalyticsProps } from 'src/tokens/utils'

function ActionCard({ action }: { action: BeforeDepositAction }) {
export function ActionCard({ action }: { action: BeforeDepositAction | WithdrawAction }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth moving this into its own file. Maybe even share with other parts of the app (token details, etc), seems like it's something we use throughout the app and would be nice to change styles in a single place for mobile stack apps

expect(getByTestId('Earn/ActionCard/Claim')).toBeTruthy()
expect(getByTestId('Earn/ActionCard/Exit')).toBeTruthy()
})
it('tapping withdraw on WithdrawBottomSheet navigates to enter amount screen', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this file is getting too big, I've started breaking EarnPoolInfoScreen into multiple files on #6176, haven't broken out tests yet. But would it be possible to have all the bottom sheet specific tests in a WithdrawBottomSheet.test.tsx? and then EarnPoolInfoScreen.test.tsx can have a single test to ensure bottom sheet is opened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@satish-ravi yeah I can do that, for having the bottom sheet tests in their own file, would I still render the pool info screen and then have it tap to open the bottom sheet, or is there a way to render just the bottoms sheet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to their own file in 5ceadc2, did it similar to EarnDepositBottomSheet.test.tsx where I could just render the bottom sheet and seems to work as expected!

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 name the icon Trophy? Would be good to keep it in sync with the name in the design system https://www.figma.com/design/erFfzHvSTm5g1sjK6jWyEH/Working-Design-System?node-id=2100-5070&node-type=frame&t=lvQvczdzHRWQBGKn-0

@@ -25,6 +25,11 @@ export interface EarningItem {
includedInPoolBalance?: boolean
}

export enum ClaimType {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this just be a string literal type instead of an enum?

@@ -1639,6 +1639,7 @@ interface EarnEventsProperties {
hasTokensOnSameNetwork: boolean
hasTokensOnOtherNetworks: boolean
}
[EarnEvents.earn_select_withdraw_type]: { type: 'partialWithdraw' | 'claim' | 'exit' }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: keep all the pool_info_tap ones together

@@ -609,6 +609,7 @@ export const eventDocs: Record<AnalyticsEventType, string> = {
[EarnEvents.earn_pool_info_tap_info_icon]: `When the user taps an info icon on the earn pool info screen`,
[EarnEvents.earn_pool_info_tap_withdraw]: `When the user taps the withdraw button on the pool info screen`,
[EarnEvents.earn_pool_info_tap_deposit]: `When the user taps the deposit button on the pool info screen`,
[EarnEvents.earn_select_withdraw_type]: `When a use selects a withdraw type on the withdraw bottom sheet`,
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

src/analytics/Properties.tsx Outdated Show resolved Hide resolved
src/earn/types.ts Outdated Show resolved Hide resolved
src/analytics/docs.ts Outdated Show resolved Hide resolved
Co-authored-by: Tom McGuire <Mcgtom10@gmail.com>
src/earn/types.ts Outdated Show resolved Hide resolved
MuckT
MuckT previously approved these changes Oct 21, 2024
locales/base/translation.json Outdated Show resolved Hide resolved
Co-authored-by: Tom McGuire <Mcgtom10@gmail.com>
Copy link
Contributor

Choose a reason for hiding this comment

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

we generally don't put components in utils, you can leave this at src/earn. I believe eventually this should go to src/components and reused across the other bottom sheets. Can you make an issue for it?

Comment on lines 134 to 136
{canPartialWithdraw && (
<PartialWithdrawAction forwardedRef={forwardedRef} pool={pool} hasRewards={canClaim} />
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

is the gate check needed here? this bottom sheet will never show up if the gate is disabled per changes in EarnPoolInfoScreen right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is needed, in EarnPoolInfoScreen, we show the bottom sheet if (hasRewards || partialWithdrawalsEnabled), so if the user has rewards but the gate is disabled, then the bottom sheet will still be shown with the options to claim rewards or exit.

},
})

it('tapping withdraw on WithdrawBottomSheet navigates to enter amount screen', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

wrap these in a describe

expect(AppAnalytics.track).toHaveBeenCalledWith(EarnEvents.earn_select_withdraw_type, {
type: 'PartialWithdraw',
})
expect(navigate).toHaveBeenCalledWith(Screens.EarnEnterAmount, {
Copy link
Contributor

Choose a reason for hiding this comment

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

needs a jest.clearAllMocks in a beforeEach to ensure clean assertions

src/earn/poolInfoScreen/EarnPoolInfoScreen.tsx Outdated Show resolved Hide resolved
Comment on lines 205 to 208
const rewardsPositions = useSelector(positionsWithBalanceSelector).filter((position) =>
pool.dataProps.rewardsPositionIds?.includes(position.positionId)
)
const hasRewards = useMemo(() => rewardsPositions.length > 0, [rewardsPositions])
Copy link
Contributor

Choose a reason for hiding this comment

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

can the filter also go inside the useMemo?

@@ -1642,6 +1647,7 @@ interface EarnEventsProperties {
[EarnEvents.earn_pool_info_tap_safety_details]: EarnCommonProperties & {
action: 'expand' | 'collapse'
}
[EarnEvents.earn_select_withdraw_type]: { type: WithdrawActionName }
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 EarnCommonProperties here?

@MuckT MuckT self-requested a review October 21, 2024 22:36
@MuckT MuckT dismissed their stale review October 21, 2024 22:36

Missed feature gating

@finnian0826 finnian0826 enabled auto-merge October 22, 2024 19:25
@finnian0826 finnian0826 added this pull request to the merge queue Oct 22, 2024
Merged via the queue into main with commit a1f5862 Oct 22, 2024
15 checks passed
@finnian0826 finnian0826 deleted the finnian0826/act-1385 branch October 22, 2024 19:58
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.

3 participants