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

fix: Incorrect change pair order behaviour #2872

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const AmountCard = ({
style={styles.amountInput}
underlineColorAndroid="transparent"
ref={inputRef}
editable={inputEditable}
editable={inputEditable && touched}
selectTextOnFocus
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
Expand Down
19 changes: 13 additions & 6 deletions apps/wallet-mobile/src/features/Swap/common/SwapFormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ export const SwapFormProvider = ({
...defaultState,
buyQuantity: {
...defaultState.buyQuantity,
displayValue: Quantities.format(buyQuantity, buyTokenInfo.decimals ?? 0),
...(defaultState.buyQuantity.isTouched && {
displayValue: Quantities.format(buyQuantity, buyTokenInfo.decimals ?? 0),
}),
},
sellQuantity: {
...defaultState.sellQuantity,
displayValue: Quantities.format(sellQuantity, sellTokenInfo.decimals ?? 0),
...(defaultState.sellQuantity.isTouched && {
displayValue: Quantities.format(sellQuantity, sellTokenInfo.decimals ?? 0),
}),
},
...initialState,
})
Expand Down Expand Up @@ -196,8 +200,9 @@ export const SwapFormProvider = ({
}

if (
(!Quantities.isZero(buyQuantity) && !hasBuyTokenSupply) ||
(state.sellQuantity.isTouched && state.buyQuantity.isTouched && pool === undefined)
state.sellQuantity.isTouched &&
state.buyQuantity.isTouched &&
(pool === undefined || (!Quantities.isZero(buyQuantity) && !hasBuyTokenSupply))
) {
actions.buyAmountErrorChanged(strings.notEnoughSupply)
return
Expand Down Expand Up @@ -331,6 +336,8 @@ const swapFormReducer = (state: SwapFormState, action: SwapFormAction) => {
case SwapFormActionType.SwitchTouched:
draft.sellQuantity.isTouched = state.buyQuantity.isTouched
draft.buyQuantity.isTouched = state.sellQuantity.isTouched
draft.sellQuantity.displayValue = ''
draft.buyQuantity.displayValue = ''
draft.sellQuantity.error = undefined
draft.buyQuantity.error = undefined

Expand Down Expand Up @@ -358,12 +365,12 @@ const swapFormReducer = (state: SwapFormState, action: SwapFormAction) => {
break

case SwapFormActionType.SellInputValueChanged:
draft.sellQuantity.displayValue = action.value
if (state.sellQuantity.isTouched) draft.sellQuantity.displayValue = action.value

break

case SwapFormActionType.BuyInputValueChanged:
draft.buyQuantity.displayValue = action.value
if (state.buyQuantity.isTouched) draft.buyQuantity.displayValue = action.value

break

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const EditBuyAmount = () => {
onChangeBuyQuantity,
buyInputRef,
} = useSwapForm()
const pool = orderData.selectedPoolCalculation?.pool
const {tokenId} = orderData.amounts.buy
const balance = useBalance({wallet, tokenId})

Expand All @@ -32,7 +31,6 @@ export const EditBuyAmount = () => {
navigateTo={navigate.selectBuyToken}
touched={isBuyTouched}
inputRef={buyInputRef}
inputEditable={pool !== undefined}
error={buyError}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export const EditSellAmount = () => {
touched={isSellTouched}
inputRef={sellInputRef}
error={error}
// inputEditable={orderData.selectedPoolCalculation?.pool !== undefined}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"start": {
"line": 128,
"column": 15,
"index": 4075
"index": 4086
},
"end": {
"line": 131,
"column": 3,
"index": 4158
"index": 4169
}
},
{
Expand All @@ -21,12 +21,12 @@
"start": {
"line": 132,
"column": 18,
"index": 4178
"index": 4189
},
"end": {
"line": 135,
"column": 3,
"index": 4267
"index": 4278
}
}
]
Loading