Skip to content

Commit

Permalink
feat(earn): implement withdraw saga (#5433)
Browse files Browse the repository at this point in the history
### Description

Submits the withdraw and claim tx. Uses swap and transfer as types for
the pending tx, which will be updated in a followup

### Test plan

Unit tests, manual

Successful withdraw tx:
https://arbiscan.io/tx/0x1a478de2f1c87c47af5e1a86c8eef82b34c2f8563c9a4cdd1cc5c4022c3c436c
Successful reward tx:
https://arbiscan.io/tx/0x57294a12d68d58378b6e4fa07209dfa2ccfa94dd0d60279fbcb8a9ef6e123883

### Related issues

- Fixes ACT-1180

### Backwards compatibility

Yes

### Network scalability

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

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
satish-ravi committed May 20, 2024
1 parent 6c3366d commit a7efc6d
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 33 deletions.
4 changes: 4 additions & 0 deletions src/analytics/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -692,4 +692,8 @@ export enum EarnEvents {
earn_exit_pool_press = 'earn_exit_pool_press',
earn_feed_item_select = 'earn_feed_item_select',
earn_collect_earnings_press = 'earn_collect_earnings_press',
earn_withdraw_submit_start = 'earn_withdraw_submit_start',
earn_withdraw_submit_success = 'earn_withdraw_submit_success',
earn_withdraw_submit_error = 'earn_withdraw_submit_error',
earn_withdraw_submit_cancel = 'earn_withdraw_submit_cancel',
}
20 changes: 14 additions & 6 deletions src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,14 @@ interface EarnDepositProperties {
providerId: string
}

interface EarnWithdrawProperties {
tokenId: string
tokenAmount: string
networkId: NetworkId
providerId: string
rewards: SerializableRewardsInfo[]
}

interface EarnEventsProperties {
[EarnEvents.earn_cta_press]: undefined
[EarnEvents.earn_add_crypto_action_press]: {
Expand All @@ -1609,13 +1617,13 @@ interface EarnEventsProperties {
[EarnEvents.earn_feed_item_select]: {
origin: 'EarnDeposit' | 'EarnWithdraw' | 'EarnClaimReward'
}
[EarnEvents.earn_collect_earnings_press]: {
tokenId: string
amount: string
networkId: NetworkId
providerId: string
rewards: SerializableRewardsInfo[]
[EarnEvents.earn_collect_earnings_press]: EarnWithdrawProperties
[EarnEvents.earn_withdraw_submit_start]: EarnWithdrawProperties
[EarnEvents.earn_withdraw_submit_success]: EarnWithdrawProperties
[EarnEvents.earn_withdraw_submit_error]: EarnWithdrawProperties & {
error: string
}
[EarnEvents.earn_withdraw_submit_cancel]: EarnWithdrawProperties
}

export type AnalyticsPropertiesList = AppEventsProperties &
Expand Down
4 changes: 4 additions & 0 deletions src/analytics/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ export const eventDocs: Record<AnalyticsEventType, string> = {
[EarnEvents.earn_exit_pool_press]: `When the user taps on the exit pool button from the earn card in discover tab`,
[EarnEvents.earn_feed_item_select]: `When the users taps on an earn transaction feed item`,
[EarnEvents.earn_collect_earnings_press]: `When the user taps on the collect earnings button in the collect screen`,
[EarnEvents.earn_withdraw_submit_start]: `When the wallet is about to submit the withdraw and claim transactions to the network`,
[EarnEvents.earn_withdraw_submit_success]: `When the withdraw and claim transactions succeed`,
[EarnEvents.earn_withdraw_submit_error]: `When the withdraw and claim transactions fail`,
[EarnEvents.earn_withdraw_submit_cancel]: `When the user cancels the withdraw and claim transactions after submitting by cancelling PIN input`,

// Legacy event docs
// The below events had docs, but are no longer produced by the latest app version.
Expand Down
2 changes: 1 addition & 1 deletion src/earn/EarnCollectScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe('EarnCollectScreen', () => {

expect(ValoraAnalytics.track).toHaveBeenCalledWith(EarnEvents.earn_collect_earnings_press, {
tokenId: mockArbUsdcTokenId,
amount: '10.75',
tokenAmount: '10.75',
networkId: NetworkId['arbitrum-sepolia'],
providerId: 'aave-v3',
rewards: [{ amount: '0.01', tokenId: mockArbArbTokenId }],
Expand Down
2 changes: 1 addition & 1 deletion src/earn/EarnCollectScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function EarnCollectScreen({ route }: Props) {

ValoraAnalytics.track(EarnEvents.earn_collect_earnings_press, {
tokenId: depositTokenId,
amount: poolToken.balance.toString(),
tokenAmount: poolToken.balance.toString(),
networkId: depositToken.networkId,
providerId: 'aave-v3',
rewards: serializedRewards,
Expand Down
Loading

0 comments on commit a7efc6d

Please sign in to comment.