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): prepare transactions and use on confirmation screen #6192

Merged
merged 163 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 162 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
6f1d0ee
chore: replace EarnDepositMode with EarnEnterMode
MuckT Oct 2, 2024
06ce84e
feat(earn): support partial withdrawals
MuckT Oct 2, 2024
d7769d2
Merge branch 'main' into tomm/act-1386
MuckT Oct 3, 2024
f5a612b
Merge branch 'main' into tomm/act-1386
MuckT Oct 4, 2024
3feb5f8
feat(earn): support partial withdrawals for earn pools
MuckT Oct 8, 2024
5821ff8
Merge branch 'main' into tomm/act-1386
MuckT Oct 8, 2024
dc155d2
fix(earn): rename EarnDepositMode to EarnEnterMode
MuckT Oct 8, 2024
a33d30c
fix(earn): rename EarnDepositMode to EarnEnterMode
MuckT Oct 8, 2024
4d01e46
fix: remove unused export
MuckT Oct 8, 2024
73c5067
fix(earn): amount TransactionWithdrawDetails display
MuckT Oct 9, 2024
364f551
test(earn): earn partial withdrawal flow
MuckT Oct 9, 2024
292d739
chore: add feature gate for partial withdrawals
MuckT Oct 9, 2024
87990f0
test(earn): partial withdrawal feature gate and navigation
MuckT Oct 9, 2024
6363e9f
docs: remove stray todo
MuckT Oct 9, 2024
71b13b9
Merge branch 'main' into tomm/act-1386
MuckT Oct 9, 2024
a58d40f
Merge branch 'main' into tomm/act-1386
MuckT Oct 9, 2024
345b535
Update test/values.ts
MuckT Oct 9, 2024
5fb98c5
refactor(earn): combine deposit and withdrawal hooks
MuckT Oct 9, 2024
41cd62d
feat(earn): display partial withdrawals on confirmation screen
MuckT Oct 10, 2024
96caa2e
fix(earn): use correct token amounts
MuckT Oct 11, 2024
9e8dcbf
Merge branch 'main' into tomm/act-1386
MuckT Oct 11, 2024
584acfb
fix(earn): disable continue when transaction is not possible
MuckT Oct 11, 2024
4196505
style(earn): use transactionToken instead of isWithdrawal ternaries
MuckT Oct 11, 2024
6701f0a
Merge branch 'tomm/act-1386' into 'tomm/act-1389'
MuckT Oct 11, 2024
ecb86e1
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 11, 2024
ebe3a2a
chore: PR feedback
MuckT Oct 11, 2024
7061b66
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 11, 2024
1dbf295
style: naming
MuckT Oct 11, 2024
a65e9a9
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 11, 2024
ad16ffa
fix(earn): use withdraw token and adjust display
MuckT Oct 12, 2024
7420841
Merge branch 'main' into tomm/act-1386
MuckT Oct 14, 2024
3f77976
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 14, 2024
d6ef99a
chore: update root state schema
MuckT Oct 14, 2024
f5fecc5
fix: show correct withdrawal amounts
MuckT Oct 14, 2024
3879b52
fix: use correct fiat value display
MuckT Oct 14, 2024
9b29dfb
test(earn): show correct local amount
MuckT Oct 14, 2024
9ed4dfc
fix(earn): deposits should use input token
MuckT Oct 15, 2024
7b20e2d
fix(earn): use deposit token amounts in token input
MuckT Oct 15, 2024
6ed3c09
style(earn): use transaction token balance instead of pool balance
MuckT Oct 15, 2024
ca51c7d
test(earn): clean-up mock pool params
MuckT Oct 15, 2024
3150c45
Merge branch 'main' into tomm/act-1386
MuckT Oct 15, 2024
4bd8d62
Apply suggestions from code review
MuckT Oct 15, 2024
1f1db1e
style(earn): rename inputToken to depositToken in useTokens
MuckT Oct 15, 2024
819e297
fix(earn): set transaction token on token select for deposits
MuckT Oct 15, 2024
9c6a05d
fix(earn): display withdrawal text on fee bottom sheet
MuckT Oct 15, 2024
1da7fac
chore: pr feedback
MuckT Oct 15, 2024
686a01c
style: create reusable const balanceInTransactionToken
MuckT Oct 16, 2024
2681ce6
style: use input token directly
MuckT Oct 16, 2024
24c47be
fix(earn): use converted token amount in withdrawals
MuckT Oct 16, 2024
d6a1616
fix(earn): convert withdrawal amount correctly usd for analytics
MuckT Oct 16, 2024
6cef451
Merge branch 'main' into tomm/act-1386
MuckT Oct 16, 2024
9721bd7
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 16, 2024
2a29534
chore: remove unused export
MuckT Oct 16, 2024
7336c69
fix(earn-confirmation): pass correct token amount
MuckT Oct 16, 2024
5d960af
feat(earn): support partial withdrawals with claim and withdraw
MuckT Oct 16, 2024
da91f3d
fix(earn): remove duplicate condition
MuckT Oct 16, 2024
f85bed4
fix(earn): naming
MuckT Oct 16, 2024
c662e3b
docs: remove unnecessary comment
MuckT Oct 16, 2024
38853d8
style(earn): simplify dropdownEnabled
MuckT Oct 16, 2024
b989f05
fix(earn): use decimals from input token
MuckT Oct 16, 2024
2fe5293
style(earn): return single withdrawal and deposit token from useToken…
MuckT Oct 16, 2024
4af772d
style(earn): PR pair feedback
MuckT Oct 16, 2024
775a925
fix(earn): display correct amounts on input amount token toggle
MuckT Oct 16, 2024
176cb9d
Revert "fix(earn): display correct amounts on input amount token toggle"
MuckT Oct 16, 2024
2d87478
fix(earn): add inputToken to dependency array
MuckT Oct 17, 2024
8ccfbfc
chore(earn): update analytics for withdrawals
MuckT Oct 17, 2024
6924060
fix: analytics build errors
MuckT Oct 17, 2024
30c6ea9
test(earn): withdrawals from pools with high price per share
MuckT Oct 17, 2024
2e9eab4
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 17, 2024
ea9f94e
Merge branch 'main' into tomm/act-1386
MuckT Oct 17, 2024
e490094
Merge branch 'tomm/act-1386' into tomm/act-1389
MuckT Oct 17, 2024
bebc38a
feat(earn-confirmation): set title based on outlet mode
MuckT Oct 17, 2024
5d99133
Merge branch 'main' into tomm/act-1389
MuckT Oct 18, 2024
4af9d07
test(earn-confirmation): remove apy references
MuckT Oct 19, 2024
764ebb0
Merge branch 'main' into tomm/act-1389
MuckT Oct 19, 2024
33fe685
style(earn-confirmation): use balance util function
MuckT Oct 19, 2024
d0df609
Merge branch 'main' into tomm/act-1389
MuckT Oct 21, 2024
e639c20
Merge branch 'main' into tomm/act-1389
MuckT Oct 21, 2024
1b93af6
Merge branch 'main' into tomm/act-1389
MuckT Oct 21, 2024
f412fad
Merge branch 'main' into tomm/act-1389
MuckT Oct 22, 2024
ded3ddb
fix(earn): omit claim action when withdrawal includes claim
MuckT Oct 23, 2024
2192408
docs(earn): remove todo
MuckT Oct 23, 2024
c8f1f69
Merge branch 'main' into tomm/act-1389
MuckT Oct 23, 2024
390e9c5
style: pass inputAmount in deposit token
MuckT Oct 23, 2024
d1bf9ee
test(earn): navigation to confirmation screen
MuckT Oct 23, 2024
d2fd398
fix(earn-withdrawal): use amount in lp token for withdrawal transaction
MuckT Oct 23, 2024
5f2360d
test(earn): update expected amount to use deposit token
MuckT Oct 23, 2024
01ec110
fix(earn): revert hiding claim option when withdrawalIncludesClaim
MuckT Oct 23, 2024
1f75a59
refactor(earn-types): combine withdraw actions and earn enter mode
MuckT Oct 24, 2024
b5fc84e
docs(earn): mapping EarnActiveAction exit to withdraw shortcutId
MuckT Oct 25, 2024
935409c
feat(earn): prepare transactions and use on confirmation screen
MuckT Oct 25, 2024
e9f2c07
fix(earn): check rewardsPositions length
MuckT Oct 25, 2024
98a8bd0
fix(earn): remove conditional shortcutId assignment based on mode
MuckT Oct 25, 2024
f1ac2db
fix(earn): make rewardsPositions type optional
MuckT Oct 25, 2024
37dd5bb
chore(earn): remove unused PrepareWithdrawAndClaimParams
MuckT Oct 25, 2024
34379cf
fix(earn-confirmation): remove unused swap transaction
MuckT Oct 25, 2024
9f2d530
docs(earn-enter-amount): update ts-expect-error expect error
MuckT Oct 25, 2024
5a1af5d
fix(earn): add args to usePrepareTransactions for claim
MuckT Oct 26, 2024
d5792a4
style(earn): renameEarnActiveAction to EarnActiveMode
MuckT Oct 28, 2024
e48b248
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 28, 2024
fb877dc
chore: remove extra arg and add logger
MuckT Oct 28, 2024
d744664
chore(earn): restrict types for confirmation and enter amount
MuckT Oct 28, 2024
d1d6117
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 28, 2024
3f3ed88
fix(earn): remove unneeded props from prepare transaction functions
MuckT Oct 28, 2024
c650230
test(earn): mock usePrepareTransactions from hooks
MuckT Oct 28, 2024
9e2abfe
Merge branch 'main' into tomm/act-1389
MuckT Oct 28, 2024
be4e446
Merge branch 'tomm/act-1389' into tomm/act-1389-0
MuckT Oct 28, 2024
d194465
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 28, 2024
3a4784f
fix(earn): claim reward should not display total deposit
MuckT Oct 28, 2024
4e205ca
style(earn): always make withdrawAmountInDepositToken a BigNumber
MuckT Oct 28, 2024
3958cef
test(earn): partial withdrawals display and trigger correctly
MuckT Oct 28, 2024
c0f422d
fix(earn-saga): set amount in analytics
MuckT Oct 28, 2024
1e6f591
test(earn-saga): withdraw and claim when amount is set
MuckT Oct 28, 2024
85e1338
Merge branch 'main' into tomm/act-1389
MuckT Oct 28, 2024
76be928
Merge branch 'tomm/act-1389' into tomm/act-1389-0
MuckT Oct 28, 2024
2b60f7c
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 28, 2024
79d72d4
fix(earn): mode for confirmation screen render
MuckT Oct 28, 2024
37fdffa
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 28, 2024
d3a7950
fix(earn): use withdraw amount in deposit token in debounced transaction
MuckT Oct 29, 2024
7181e44
test(earn): mock usePrepareTransactions
MuckT Oct 29, 2024
7c0d875
fix(earn-confirmation): exclude rewards in partial withdrawals
MuckT Oct 29, 2024
b2d24bd
test(earn-confirmation): exclude rewards from partial withdrawals
MuckT Oct 29, 2024
2570742
Merge branch 'main' into tomm/act-1389
MuckT Oct 29, 2024
6d48cfa
Merge branch 'tomm/act-1389' into tomm/act-1389-0
MuckT Oct 29, 2024
95be3a5
fix(earn-confirmation): mode type use in comparison for render
MuckT Oct 29, 2024
d8caf02
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 29, 2024
7a2444d
test(earn-confirmation): test exit and withdraw flows
MuckT Oct 29, 2024
7978941
Merge branch 'main' into tomm/act-1389-0
MuckT Oct 29, 2024
7bdd90f
test(earn): prepareClaimTransactions
MuckT Oct 29, 2024
a89d17c
test(earn): add test stub for usePrepareTransactions earn hook
MuckT Oct 29, 2024
7d81bd2
fix(earn): exclude claim tx when withdrawalIncludesClaim is true
MuckT Oct 30, 2024
40d5d30
test(earn): usePrepareTransactions hook
MuckT Oct 30, 2024
ff2bd43
style(earn): use extract for clarity and narrow WithdrawAction types
MuckT Oct 31, 2024
b125473
Merge branch 'main' into tomm/act-1389-0
MuckT Oct 31, 2024
5169aac
Merge branch 'tomm/act-1389-0' into tomm/act-1389-1
MuckT Oct 31, 2024
557a473
Merge branch 'main' into tomm/act-1389-1
MuckT Oct 31, 2024
b57e331
chore(earn): add logging for withdraw transactions preparation
MuckT Oct 31, 2024
0de6368
fix(earn): use correct name
MuckT Oct 31, 2024
5b5087e
refactor(earn): hooks and prepare transactions
MuckT Nov 1, 2024
7f2e5e1
test(earn): hooks and prepare transactions
MuckT Nov 1, 2024
b7a025c
style: self review
MuckT Nov 1, 2024
d806a89
test(earn): remove optional param
MuckT Nov 1, 2024
e2d92f1
chore(earn): make useMax required
MuckT Nov 1, 2024
501c1c3
style(earn): use correct function name in logger
MuckT Nov 1, 2024
457a594
style(earn): rename hooks to reflect screens where they are used
MuckT Nov 1, 2024
3de16cd
style(earn): rename to usePrepareEnterAmountTransactionsCallback
MuckT Nov 1, 2024
34420b9
style(earn): use ternary and remove curry
MuckT Nov 1, 2024
502a676
test(earn) partial withdrawals don't include rewards by default
MuckT Nov 1, 2024
2c5c4c5
docs(earn): describe hook calls and tx preperation
MuckT Nov 2, 2024
8cffb5b
refactor(earn): avoid code duplication in tx preperation
MuckT Nov 2, 2024
d3493cc
Merge branch 'main' into tomm/act-1389-1
MuckT Nov 2, 2024
98b526f
Merge branch 'main' into tomm/act-1389-1
MuckT Nov 4, 2024
d5ee3e8
style: remove unneeded boolean coercion
MuckT Nov 5, 2024
3f2f2d1
docs: remove superfluous comments
MuckT Nov 5, 2024
455aebb
Merge branch 'main' into tomm/act-1389-1
MuckT Nov 5, 2024
28ae31f
Merge branch 'main' into tomm/act-1389-1
MuckT Nov 5, 2024
a65343a
pref(earn): avoid preparing transaction that could go unused
MuckT Nov 6, 2024
47787a8
test(earn): no claim tx included withdrawalIncludesClaim is true
MuckT Nov 6, 2024
26316f8
test(earn): tx prep called with correct args
MuckT Nov 6, 2024
c0c64fe
style(earn): add awaits in useAsync
MuckT Nov 6, 2024
8f19f38
Merge branch 'main' into tomm/act-1389-1
MuckT Nov 6, 2024
c850429
test(earn): update comment
MuckT Nov 6, 2024
d1558f3
style(earn): rename hook to usePrepareEarnConfirmationScreenTransactions
MuckT Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 78 additions & 19 deletions src/earn/EarnConfirmationScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { Provider } from 'react-redux'
import AppAnalytics from 'src/analytics/AppAnalytics'
import { EarnEvents } from 'src/analytics/Events'
import EarnConfirmationScreen from 'src/earn/EarnConfirmationScreen'
import { prepareWithdrawAndClaimTransactions } from 'src/earn/prepareTransactions'
import {
prepareClaimTransactions,
prepareWithdrawAndClaimTransactions,
prepareWithdrawTransactions,
} from 'src/earn/prepareTransactions'
import { withdrawStart } from 'src/earn/slice'
import { isGasSubsidizedForNetwork } from 'src/earn/utils'
import { navigate } from 'src/navigator/NavigationService'
Expand Down Expand Up @@ -92,8 +96,9 @@ const mockPreparedTransaction: PreparedTransactionsPossible = {
describe('EarnConfirmationScreen', () => {
beforeEach(() => {
jest.clearAllMocks()

jest.mocked(prepareWithdrawAndClaimTransactions).mockResolvedValue(mockPreparedTransaction)
jest.mocked(prepareClaimTransactions).mockResolvedValue(mockPreparedTransaction)
jest.mocked(prepareWithdrawTransactions).mockResolvedValue(mockPreparedTransaction)
jest
.mocked(getFeatureGate)
.mockImplementation(
Expand All @@ -103,14 +108,15 @@ describe('EarnConfirmationScreen', () => {
store.clearActions()
})

it('renders total balance, rewards and gas after fetching rewards and preparing tx for exit', async () => {
it('renders total balance, rewards and gas after fetching rewards and preparing tx', async () => {
const { getByText, getByTestId, queryByTestId } = render(
<Provider store={store}>
<MockedNavigator
component={EarnConfirmationScreen}
params={{
pool: { ...mockEarnPositions[0], balance: '10.75' },
mode: 'Exit',
mode: 'exit',
useMax: true,
}}
/>
</Provider>
Expand All @@ -124,6 +130,7 @@ describe('EarnConfirmationScreen', () => {
expect(getByTestId(`EarnConfirmation/${mockArbUsdcTokenId}/FiatAmount`)).toHaveTextContent(
'₱15.73'
)

expect(getByTestId('EarnConfirmation/GasLoading')).toBeTruthy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeDisabled()

Expand All @@ -138,6 +145,7 @@ describe('EarnConfirmationScreen', () => {
await waitFor(() => {
expect(queryByTestId('EarnConfirmation/GasLoading')).toBeFalsy()
})

expect(getByTestId('EarnConfirmation/GasFeeCryptoAmount')).toHaveTextContent('0.06 ETH')
expect(getByTestId('EarnConfirmation/GasFeeFiatAmount')).toHaveTextContent('₱119.70')
expect(queryByTestId('EarnConfirmation/GasSubsidized')).toBeFalsy()
Expand All @@ -149,19 +157,22 @@ describe('EarnConfirmationScreen', () => {
walletAddress: mockAccount.toLowerCase(),
hooksApiUrl: 'https://api.alfajores.valora.xyz/hooks-api',
amount: '10.75',
useMax: true,
})
expect(store.getActions()).toEqual([])
})

it('renders total balance and gas after fetching rewards and preparing tx for partial withdrawal', async () => {
it('renders total balance, rewards and gas after fetching rewards and preparing tx for partial withdrawal', async () => {
const inputAmount = (10.75 * +mockEarnPositions[0].pricePerShare) / 2 // Input amount is half of the balance
const txAmount = '5.37500000000000045455' // inputAmount divided by pricePerShare but with more precision
const { getByText, getByTestId, queryByTestId, queryByText } = render(
<Provider store={store}>
<MockedNavigator
component={EarnConfirmationScreen}
params={{
pool: { ...mockEarnPositions[0], balance: '10.75' },
mode: 'withdraw',
inputAmount: (10.75 * +mockEarnPositions[0].pricePerShare) / 2, // Input amount is half of the balance
inputAmount,
}}
/>
</Provider>
Expand All @@ -175,8 +186,6 @@ describe('EarnConfirmationScreen', () => {
expect(getByTestId(`EarnConfirmation/${mockArbUsdcTokenId}/FiatAmount`)).toHaveTextContent(
'₱7.86'
)
expect(getByTestId('EarnConfirmation/GasLoading')).toBeTruthy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeDisabled()

expect(queryByText('earnFlow.collect.reward')).toBeFalsy()

Expand All @@ -187,14 +196,60 @@ describe('EarnConfirmationScreen', () => {
expect(getByTestId('EarnConfirmation/GasFeeFiatAmount')).toHaveTextContent('₱119.70')
expect(queryByTestId('EarnConfirmation/GasSubsidized')).toBeFalsy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeEnabled()
// TODO(act-1389): update this test to make sure that reward positions are not included in partial withdrawals.
MuckT marked this conversation as resolved.
Show resolved Hide resolved
expect(prepareWithdrawAndClaimTransactions).toHaveBeenCalledWith({
expect(prepareWithdrawTransactions).toHaveBeenCalledWith({
feeCurrencies: mockStoreBalancesToTokenBalances([mockTokenBalances[mockArbEthTokenId]]),
pool: { ...mockEarnPositions[0], balance: '10.75' },
rewardsPositions: [mockRewardsPositions[1]],
walletAddress: mockAccount.toLowerCase(),
hooksApiUrl: 'https://api.alfajores.valora.xyz/hooks-api',
amount: '5.37500000000000045455',
amount: txAmount,
})
expect(queryByText('earnFlow.collect.reward')).toBeFalsy()
expect(store.getActions()).toEqual([])
})

it('renders rewards and gas after fetching rewards and preparing tx for claim rewards', async () => {
const { getByText, getByTestId, queryByTestId } = render(
<Provider store={store}>
<MockedNavigator
component={EarnConfirmationScreen}
params={{
pool: { ...mockEarnPositions[0], balance: '10.75' },
mode: 'claim-rewards',
useMax: true,
}}
/>
</Provider>
)

expect(getByText('earnFlow.collect.titleClaim')).toBeTruthy()
expect(getByTestId('EarnConfirmation/GasLoading')).toBeTruthy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeDisabled()

expect(getByText('earnFlow.collect.reward')).toBeTruthy()
expect(getByTestId(`EarnConfirmation/${mockArbArbTokenId}/CryptoAmount`)).toHaveTextContent(
'0.01 ARB'
)
expect(getByTestId(`EarnConfirmation/${mockArbArbTokenId}/FiatAmount`)).toHaveTextContent(
'₱0.016'
)

await waitFor(() => {
expect(queryByTestId('EarnConfirmation/GasLoading')).toBeFalsy()
})

expect(getByTestId('EarnConfirmation/GasFeeCryptoAmount')).toHaveTextContent('0.06 ETH')
expect(getByTestId('EarnConfirmation/GasFeeFiatAmount')).toHaveTextContent('₱119.70')
expect(queryByTestId('EarnConfirmation/GasSubsidized')).toBeFalsy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeEnabled()
expect(prepareClaimTransactions).toHaveBeenCalledWith({
feeCurrencies: mockStoreBalancesToTokenBalances([mockTokenBalances[mockArbEthTokenId]]),
pool: { ...mockEarnPositions[0], balance: '10.75' },
walletAddress: mockAccount.toLowerCase(),
hooksApiUrl: 'https://api.alfajores.valora.xyz/hooks-api',
amount: '10.75',
useMax: true,
rewardsPositions: [mockRewardsPositions[1]],
})
expect(store.getActions()).toEqual([])
})
Expand All @@ -218,6 +273,7 @@ describe('EarnConfirmationScreen', () => {
params={{
pool: { ...mockEarnPositions[0], balance: '10.75' },
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
Expand Down Expand Up @@ -245,24 +301,22 @@ describe('EarnConfirmationScreen', () => {
})

it('shows error and keeps cta disabled if prepare tx fails', async () => {
jest
.mocked(prepareWithdrawAndClaimTransactions)
.mockRejectedValue(new Error('Failed to prepare'))
jest.mocked(prepareWithdrawTransactions).mockRejectedValue(new Error('Failed to prepare'))
const { getByText, getByTestId, queryByTestId } = render(
<Provider store={store}>
<MockedNavigator
component={EarnConfirmationScreen}
params={{
pool: mockEarnPositions[0],
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
)

expect(getByText('earnFlow.collect.titleWithdraw')).toBeTruthy()
expect(getByText('earnFlow.collect.total')).toBeTruthy()
expect(getByTestId('EarnConfirmation/GasLoading')).toBeTruthy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeDisabled()

await waitFor(() => {
Expand All @@ -274,25 +328,26 @@ describe('EarnConfirmationScreen', () => {
})

it('disables cta if not enough balance for gas', async () => {
jest.mocked(prepareWithdrawAndClaimTransactions).mockResolvedValue({
jest.mocked(prepareWithdrawTransactions).mockResolvedValue({
type: 'not-enough-balance-for-gas',
feeCurrencies: [mockPreparedTransaction.feeCurrency],
})

const { getByText, getByTestId, queryByTestId } = render(
<Provider store={store}>
<MockedNavigator
component={EarnConfirmationScreen}
params={{
pool: mockEarnPositions[0],
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
)

expect(getByText('earnFlow.collect.titleWithdraw')).toBeTruthy()
expect(getByText('earnFlow.collect.total')).toBeTruthy()
expect(getByTestId('EarnConfirmation/GasLoading')).toBeTruthy()
expect(getByTestId('EarnConfirmationScreen/CTA')).toBeDisabled()

await waitFor(() => {
Expand All @@ -310,6 +365,7 @@ describe('EarnConfirmationScreen', () => {
params={{
pool: { ...mockEarnPositions[0], balance: '10.75' },
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
Expand Down Expand Up @@ -360,6 +416,7 @@ describe('EarnConfirmationScreen', () => {
params={{
pool: mockEarnPositions[0],
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
Expand All @@ -376,18 +433,18 @@ describe('EarnConfirmationScreen', () => {
})

it('navigate and fire analytics on no gas CTA press', async () => {
jest.mocked(prepareWithdrawAndClaimTransactions).mockResolvedValue({
jest.mocked(prepareWithdrawTransactions).mockResolvedValue({
type: 'not-enough-balance-for-gas',
feeCurrencies: [mockPreparedTransaction.feeCurrency],
})

const { getByText, queryByTestId } = render(
<Provider store={store}>
<MockedNavigator
component={EarnConfirmationScreen}
params={{
pool: mockEarnPositions[0],
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
Expand Down Expand Up @@ -428,6 +485,7 @@ describe('EarnConfirmationScreen', () => {
params={{
pool: mockEarnPositions[0],
mode: 'withdraw',
useMax: true,
}}
/>
</Provider>
Expand All @@ -447,6 +505,7 @@ describe('EarnConfirmationScreen', () => {
params={{
pool: mockEarnPositions[0],
mode,
useMax: true,
}}
/>
</Provider>
Expand Down
5 changes: 2 additions & 3 deletions src/earn/EarnConfirmationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Button, { BtnSizes } from 'src/components/Button'
import InLineNotification, { NotificationVariant } from 'src/components/InLineNotification'
import TokenDisplay from 'src/components/TokenDisplay'
import TokenIcon, { IconSize } from 'src/components/TokenIcon'
import { usePrepareWithdrawAndClaimTransactions } from 'src/earn/hooks'
import { usePrepareEnterConfirmationScreenTransactions } from 'src/earn/hooks'
import { withdrawStatusSelector } from 'src/earn/selectors'
import { withdrawStart } from 'src/earn/slice'
import { EarnActiveMode } from 'src/earn/types'
Expand Down Expand Up @@ -77,12 +77,11 @@ export default function EarnConfirmationScreen({ route }: Props) {
[withdrawToken, pool.pricePerShare, inputAmount]
)

// Will need this to handle preparing a claim transaction, a withdrawal transaction and a withdrawal and claim transaction
const {
result: prepareTransactionsResult,
loading: isPreparingTransactions,
error: prepareTransactionError,
} = usePrepareWithdrawAndClaimTransactions({
} = usePrepareEnterConfirmationScreenTransactions(mode, {
amount: withdrawAmountInDepositToken.dividedBy(pool.pricePerShare[0]).toString(),
pool,
walletAddress,
Expand Down
Loading