Skip to content

Commit

Permalink
fix(earn): Fix Earn Deposit bottom sheet bug on Android (#6236)
Browse files Browse the repository at this point in the history
### Description

For
[ACT-1398](https://linear.app/valora/issue/ACT-1398/android-pin-modal-display-obscured-earn-review-bottom-sheet).
Fixes an issue where the deposit bottom sheet was obscuring the PIN
entry screen.

### Test plan

Unit and manual tested, see video below:


https://github.com/user-attachments/assets/27140fb2-3ad5-4363-b458-7a4e8a7f1bb1

### Related issues

- Fixes #[issue number here]

### Backwards compatibility

<!-- Brief explanation of why these changes are/are not backwards
compatible. -->

### 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)

---------

Co-authored-by: Tom McGuire <[email protected]>
  • Loading branch information
jophish and MuckT authored Dec 10, 2024
1 parent 9bec20a commit bc07228
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 28 deletions.
4 changes: 4 additions & 0 deletions src/earn/EarnDepositBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export default function EarnDepositBottomSheet({
})
)
AppAnalytics.track(EarnEvents.earn_deposit_complete, commonAnalyticsProperties)
// Dismiss the bottom sheet when transaction is submitted. This avoids a handful of issues,
// such as needing to manually dismiss the sheet for PIN entry, and the bottom sheet
// persisting onto the home screen.
forwardedRef.current?.close()
}

const onPressCancel = () => {
Expand Down
74 changes: 49 additions & 25 deletions src/earn/EarnEnterAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
mockTokenBalances,
mockUSDCAddress,
} from 'test/values'
import { Status as EarnStatus } from 'src/earn/slice'

jest.mock('src/earn/hooks')
jest.mock('react-native-localize')
Expand Down Expand Up @@ -117,33 +118,40 @@ const mockSwapTransaction: SwapTransaction = {
estimatedPriceImpact: '0.1',
}

const store = createMockStore({
tokens: {
tokenBalances: {
...mockTokenBalances,
mockArbUsdcTokenId: {
...mockTokenBalances[mockArbUsdcTokenId],
balance: '10',
},
mockArbEthTokenId: {
...mockTokenBalances[mockArbEthTokenId],
balance: '1',
},
mockArbArbTokenId: {
...mockTokenBalances[mockArbArbTokenId],
minimumAppVersionToSwap: '1.0.0',
balance: '1',
},
mockAaveArbUsdcTokenId: {
...mockTokenBalances[mockAaveArbUsdcTokenId],
balance: '10',
function createStore(depositStatus: EarnStatus = 'idle') {
return createMockStore({
tokens: {
tokenBalances: {
...mockTokenBalances,
mockArbUsdcTokenId: {
...mockTokenBalances[mockArbUsdcTokenId],
balance: '10',
},
mockArbEthTokenId: {
...mockTokenBalances[mockArbEthTokenId],
balance: '1',
},
mockArbArbTokenId: {
...mockTokenBalances[mockArbArbTokenId],
minimumAppVersionToSwap: '1.0.0',
balance: '1',
},
mockAaveArbUsdcTokenId: {
...mockTokenBalances[mockAaveArbUsdcTokenId],
balance: '10',
},
},
},
},
positions: {
positions: [...mockPositions, ...mockRewardsPositions],
},
})
positions: {
positions: [...mockPositions, ...mockRewardsPositions],
},
earn: {
depositStatus,
},
})
}

const store = createStore()

const params = {
pool: mockEarnPositions[0],
Expand Down Expand Up @@ -632,6 +640,22 @@ describe('EarnEnterAmount', () => {
expect(getByTestId('EarnEnterAmount/Continue')).toBeDisabled()
})

it('should show loading spinner when transaction submitted', async () => {
const mockStore = createStore('loading')
const { getByTestId } = render(
<Provider store={mockStore}>
<MockedNavigator component={EarnEnterAmount} params={params} />
</Provider>
)

await waitFor(() =>
expect(getByTestId('EarnEnterAmount/Continue')).toContainElement(
getByTestId('Button/Loading')
)
)
expect(getByTestId('EarnEnterAmount/Continue')).toBeDisabled()
})

it('should show loading spinner when preparing transaction', async () => {
jest.mocked(usePrepareEnterAmountTransactionsCallback).mockReturnValue({
prepareTransactionsResult: undefined,
Expand Down
14 changes: 11 additions & 3 deletions src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { parseInputAmount } from 'src/utils/parsing'
import { getFeeCurrencyAndAmounts, PreparedTransactionsResult } from 'src/viem/prepareTransactions'
import { walletAddressSelector } from 'src/web3/selectors'
import { isAddress } from 'viem'
import { depositStatusSelector } from 'src/earn/selectors'

type Props = NativeStackScreenProps<StackParamList, Screens.EarnEnterAmount>

Expand Down Expand Up @@ -100,6 +101,11 @@ function EarnEnterAmount({ route }: Props) {
const isWithdrawal = mode === 'withdraw'
const { depositToken, withdrawToken, eligibleSwappableTokens } = useTokens({ pool })

// We do not need to check withdrawal status/show a spinner for a pending
// withdrawal, since withdrawals navigate to a separate confirmation screen.
const depositStatus = useSelector(depositStatusSelector)
const transactionSubmitted = depositStatus === 'loading'

const availableInputTokens = useMemo(() => {
switch (mode) {
case 'deposit':
Expand Down Expand Up @@ -299,8 +305,10 @@ function EarnEnterAmount({ route }: Props) {
)

const disabled =
// Should disable if the user enters 0, has enough balance but the transaction is not possible, or does not have enough balance
!!tokenAmount?.isZero() || !transactionIsPossible
// Should disable if the user enters 0, has enough balance but the transaction
// is not possible, does not have enough balance, or if transaction is already
// submitted
!!tokenAmount?.isZero() || !transactionIsPossible || transactionSubmitted

const onTokenAmountInputChange = (value: string) => {
setSelectedPercentage(null)
Expand Down Expand Up @@ -549,7 +557,7 @@ function EarnEnterAmount({ route }: Props) {
size={BtnSizes.FULL}
disabled={disabled}
style={styles.continueButton}
showLoading={isPreparingTransactions}
showLoading={isPreparingTransactions || transactionSubmitted}
testID="EarnEnterAmount/Continue"
/>
</KeyboardAwareScrollView>
Expand Down

0 comments on commit bc07228

Please sign in to comment.