Skip to content

Commit

Permalink
fix: incorrect withdraw percentage amount (#6288)
Browse files Browse the repository at this point in the history
### Description

As the title - this was a copy paste error, restoring it to the
[previous
logic](https://github.com/valora-inc/wallet/blob/7714ddffef3b08d252fa6e6595b4b4114eb7e28c/src/earn/EarnEnterAmount.tsx#L348).

### Test plan

Applying the max amount now matches the max amount displayed in the
withdraw details.


https://github.com/user-attachments/assets/540854a7-9020-4208-930b-e0042c92a025


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

- [ ] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
kathaypacific authored Dec 3, 2024
1 parent 91cfca0 commit 5d544f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/earn/EarnEnterAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ describe('EarnEnterAmount', () => {
expect(queryByTestId('downArrowIcon')).toBeFalsy()
})

it('should apply the maximum amount if the user selects the max option', async () => {
const { getByTestId } = render(
<Provider store={store}>
<MockedNavigator component={EarnEnterAmount} params={depositParams} />
</Provider>
)
await act(() => {
DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates: { height: 100 } })
})

fireEvent.press(within(getByTestId('EarnEnterAmount/AmountOptions')).getByText('maxSymbol'))
expect(getByTestId('EarnEnterAmount/TokenAmountInput').props.value).toBe('10') // balance
})

it('should prepare transactions with the expected inputs', async () => {
const { getByTestId } = render(
<Provider store={store}>
Expand Down Expand Up @@ -413,6 +427,20 @@ describe('EarnEnterAmount', () => {
expect(queryByTestId('downArrowIcon')).toBeFalsy()
})

it('should apply the maximum amount if the user selects the max option', async () => {
const { getByTestId } = render(
<Provider store={store}>
<MockedNavigator component={EarnEnterAmount} params={withdrawParams} />
</Provider>
)
await act(() => {
DeviceEventEmitter.emit('keyboardDidShow', { endCoordinates: { height: 100 } })
})

fireEvent.press(within(getByTestId('EarnEnterAmount/AmountOptions')).getByText('maxSymbol'))
expect(getByTestId('EarnEnterAmount/TokenAmountInput').props.value).toBe('11') // balance * pool price per share
})

it('should prepare transactions with the expected inputs', async () => {
const { getByTestId } = render(
<Provider store={store}>
Expand Down Expand Up @@ -660,8 +688,7 @@ describe('EarnEnterAmount', () => {
},
})

// eslint-disable-next-line jest/no-disabled-tests
it.skip('selecting max token amount applies correct decimal separator', async () => {
it('selecting max token amount applies correct decimal separator', async () => {
const { getByTestId } = render(
<Provider store={mockStore}>
<MockedNavigator component={EarnEnterAmount} params={params} />
Expand Down
2 changes: 1 addition & 1 deletion src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ function EarnEnterAmount({ route }: Props) {
}

const onSelectPercentageAmount = (percentage: number) => {
setTokenAmountInput(inputToken.balance.multipliedBy(percentage).toFormat({ decimalSeparator }))
setTokenAmountInput(balanceInInputToken.multipliedBy(percentage).toFormat({ decimalSeparator }))
setEnteredIn('token')
setSelectedPercentage(percentage)

Expand Down

0 comments on commit 5d544f4

Please sign in to comment.