Skip to content

Commit

Permalink
feat(earn): fetch token balances after a tx is submitted (#5448)
Browse files Browse the repository at this point in the history
### Description

Should help with
https://valora-app.slack.com/archives/C04B61SJ6DS/p1716315055922759?thread_ts=1716314300.065339&cid=C04B61SJ6DS

### Test plan

Unit tests

### Related issues

- N/A

### Backwards compatibility

Y

### 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 authored May 21, 2024
1 parent a36105f commit 211c71d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/earn/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from 'src/earn/slice'
import { navigateHome } from 'src/navigator/NavigationService'
import { CANCELLED_PIN_INPUT } from 'src/pincode/authentication'
import { fetchTokenBalances } from 'src/tokens/slice'
import { Network, NetworkId, TokenTransactionTypeV2 } from 'src/transactions/types'
import { publicClient } from 'src/viem'
import { SerializableTransactionRequest } from 'src/viem/preparedTransactionSerialization'
Expand Down Expand Up @@ -220,6 +221,7 @@ describe('depositSubmitSaga', () => {
.withState(createMockStore({ tokens: { tokenBalances: mockTokenBalances } }).getState())
.provide(sagaProviders)
.put(depositSuccess())
.put(fetchTokenBalances({ showLoading: false }))
.call.like({ fn: sendPreparedTransactions })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x1' })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x2' })
Expand Down Expand Up @@ -254,6 +256,7 @@ describe('depositSubmitSaga', () => {
.withState(createMockStore({ tokens: { tokenBalances: mockTokenBalances } }).getState())
.provide(sagaProviders)
.put(depositSuccess())
.put(fetchTokenBalances({ showLoading: false }))
.call.like({ fn: sendPreparedTransactions })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x2' })
.run()
Expand Down Expand Up @@ -290,6 +293,7 @@ describe('depositSubmitSaga', () => {
...sagaProviders,
])
.put(depositCancel())
.not.put.actionType(fetchTokenBalances.type)
.call.like({ fn: sendPreparedTransactions })
.not.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'])
.run()
Expand Down Expand Up @@ -321,6 +325,7 @@ describe('depositSubmitSaga', () => {
...sagaProviders,
])
.put(depositError())
.not.put.actionType(fetchTokenBalances.type)
.call.like({ fn: sendPreparedTransactions })
.not.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'])
.run()
Expand Down Expand Up @@ -358,6 +363,7 @@ describe('depositSubmitSaga', () => {
...sagaProviders,
])
.put(depositError())
.not.put.actionType(fetchTokenBalances.type)
.call.like({ fn: sendPreparedTransactions })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x1' })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x2' })
Expand Down Expand Up @@ -496,6 +502,7 @@ describe('withdrawSubmitSaga', () => {
.withState(createMockStore({ tokens: { tokenBalances: mockTokenBalances } }).getState())
.provide(sagaProviders)
.put(withdrawSuccess())
.put(fetchTokenBalances({ showLoading: false }))
.call.like({ fn: sendPreparedTransactions })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x1' })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x2' })
Expand Down Expand Up @@ -528,6 +535,7 @@ describe('withdrawSubmitSaga', () => {
.withState(createMockStore({ tokens: { tokenBalances: mockTokenBalances } }).getState())
.provide(sagaProviders)
.put(withdrawSuccess())
.put(fetchTokenBalances({ showLoading: false }))
.call.like({ fn: sendPreparedTransactions })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x1' })
.run()
Expand Down Expand Up @@ -561,6 +569,7 @@ describe('withdrawSubmitSaga', () => {
...sagaProviders,
])
.put(withdrawCancel())
.not.put.actionType(fetchTokenBalances.type)
.call.like({ fn: sendPreparedTransactions })
.not.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'])
.run()
Expand Down Expand Up @@ -592,6 +601,7 @@ describe('withdrawSubmitSaga', () => {
...sagaProviders,
])
.put(withdrawError())
.not.put.actionType(fetchTokenBalances.type)
.call.like({ fn: sendPreparedTransactions })
.not.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'])
.run()
Expand Down Expand Up @@ -632,6 +642,7 @@ describe('withdrawSubmitSaga', () => {
...sagaProviders,
])
.put(withdrawError())
.not.put.actionType(fetchTokenBalances.type)
.call.like({ fn: sendPreparedTransactions })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x1' })
.call([publicClient[Network.Arbitrum], 'waitForTransactionReceipt'], { hash: '0x2' })
Expand Down
4 changes: 3 additions & 1 deletion src/earn/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { CANCELLED_PIN_INPUT } from 'src/pincode/authentication'
import { vibrateError } from 'src/styles/hapticFeedback'
import { getTokenInfo } from 'src/tokens/saga'
import { tokensByIdSelector } from 'src/tokens/selectors'
import { TokenBalances } from 'src/tokens/slice'
import { TokenBalances, fetchTokenBalances } from 'src/tokens/slice'
import { BaseStandbyTransaction } from 'src/transactions/actions'
import {
NetworkId,
Expand Down Expand Up @@ -215,6 +215,7 @@ export function* depositSubmitSaga(action: PayloadAction<DepositInfo>) {
...getDepositTxsReceiptAnalyticsProperties(trackedTxs, networkId, tokensById),
})
yield* put(depositSuccess())
yield* put(fetchTokenBalances({ showLoading: false }))
} catch (err) {
if (err === CANCELLED_PIN_INPUT) {
Logger.info(`${TAG}/depositSubmitSaga`, 'Transaction cancelled by user')
Expand Down Expand Up @@ -366,6 +367,7 @@ export function* withdrawSubmitSaga(action: PayloadAction<WithdrawInfo>) {
})

yield* put(withdrawSuccess())
yield* put(fetchTokenBalances({ showLoading: false }))
ValoraAnalytics.track(EarnEvents.earn_withdraw_submit_success, commonAnalyticsProps)
} catch (err) {
if (err === CANCELLED_PIN_INPUT) {
Expand Down

0 comments on commit 211c71d

Please sign in to comment.