Skip to content

Commit

Permalink
Set form isMaxSelected flag to false after switching asset (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarvu authored Jan 7, 2025
1 parent b30f98d commit 57f1415
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/app/src/features/dialogs/borrow/logic/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function getFormFieldsForBorrowDialog({
const changeAsset = (newSymbol: TokenSymbol): void => {
form.setValue('symbol', newSymbol)
form.setValue('value', '')
form.setValue('isMaxSelected', false)
form.clearErrors()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function getFieldsForTransferFromUserForm({
const changeAsset = (newSymbol: TokenSymbol): void => {
form.setValue('symbol', newSymbol)
form.setValue('value', '')
form.setValue('isMaxSelected', false)
form.clearErrors()
}

Expand Down
1 change: 1 addition & 0 deletions packages/app/src/features/dialogs/deposit/logic/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export function getFormFieldsForDepositDialog({
const changeAsset = (newSymbol: TokenSymbol): void => {
form.setValue('symbol', newSymbol)
form.setValue('value', '')
form.setValue('isMaxSelected', false)
form.clearErrors()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ test.describe('Savings deposit dialog', () => {
await depositDialog.openAssetSelectorAction()
await depositDialog.expectAssetSelectorOptions(['DAI', 'USDC', 'USDS'])
})

test('can click max after switching tokens', async () => {
await depositDialog.expectInputValue('')
await depositDialog.clickMaxAmountAction()
await depositDialog.expectInputValue('10000')
await depositDialog.selectAssetAction('USDC')
await depositDialog.expectInputValue('')
await depositDialog.clickMaxAmountAction()
await depositDialog.expectInputValue('10000')
})
})

test.describe('Gnosis', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { mainnet } from 'viem/chains'
import { SavingsDialogPageObject } from '../../../common/e2e/SavingsDialog.PageObject'

test.describe('Without send mode', () => {
test('can switch between tokens', async ({ page }) => {
let withdrawalDialog: SavingsDialogPageObject
let savingsPage: SavingsPageObject

test.beforeEach(async ({ page }) => {
const testContext = await setup(page, {
blockchain: {
chainId: mainnet.id,
Expand All @@ -22,12 +25,13 @@ test.describe('Without send mode', () => {
},
})

const savingsPage = new SavingsPageObject(testContext)

savingsPage = new SavingsPageObject(testContext)
await savingsPage.clickWithdrawSDaiButtonAction()

const withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' })
withdrawalDialog = new SavingsDialogPageObject({ testContext, type: 'withdraw' })
})

test('can switch between tokens', async () => {
await withdrawalDialog.fillAmountAction(1000)
await withdrawalDialog.actionsContainer.expectEnabledActionAtIndex(0)
await withdrawalDialog.actionsContainer.expectActions([
Expand All @@ -49,6 +53,16 @@ test.describe('Without send mode', () => {
{ type: 'withdrawFromSavings', asset: 'DAI', savingsAsset: 'sDAI', mode: 'withdraw' },
])
})

test('can click max after switching tokens', async () => {
await withdrawalDialog.expectInputValue('')
await withdrawalDialog.clickMaxAmountAction()
await withdrawalDialog.expectInputValue('1125.599162')
await withdrawalDialog.selectAssetAction('USDC')
await withdrawalDialog.expectInputValue('')
await withdrawalDialog.clickMaxAmountAction()
await withdrawalDialog.expectInputValue('1125.599162')
})
})

test.describe('With send mode', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function getFormFieldsForWithdrawDialog({
form.setValue('symbol', newSymbol)
form.setValue('value', '')
form.setValue('isMaxSelected', false)

form.clearErrors()
}

Expand Down
1 change: 1 addition & 0 deletions packages/app/src/features/dialogs/withdraw/logic/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function getFormFieldsForWithdrawDialog(
const changeAsset = (newSymbol: TokenSymbol): void => {
form.setValue('symbol', newSymbol)
form.setValue('value', '')
form.setValue('isMaxSelected', false)
form.clearErrors()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function getFormFieldsForUnstakeDialog({
form.setValue('symbol', newSymbol)
form.setValue('value', '')
form.setValue('isMaxSelected', false)

form.clearErrors()
}

Expand Down

0 comments on commit 57f1415

Please sign in to comment.