From 82f834d00faac304f9742045a9c03904ae789a50 Mon Sep 17 00:00:00 2001 From: jorbuedo Date: Fri, 3 Nov 2023 19:18:28 +0100 Subject: [PATCH] Fix display switch and errors --- .../Swap/common/AmountCard/AmountCard.tsx | 2 +- .../features/Swap/common/SwapFormProvider.tsx | 19 +++++++++++++------ .../EditBuyAmount/EditBuyAmount.tsx | 2 -- .../EditSellAmount/EditSellAmount.tsx | 1 - .../Swap/common/AmountCard/AmountCard.json | 8 ++++---- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/apps/wallet-mobile/src/features/Swap/common/AmountCard/AmountCard.tsx b/apps/wallet-mobile/src/features/Swap/common/AmountCard/AmountCard.tsx index 08cc0d5236..631f68eecf 100644 --- a/apps/wallet-mobile/src/features/Swap/common/AmountCard/AmountCard.tsx +++ b/apps/wallet-mobile/src/features/Swap/common/AmountCard/AmountCard.tsx @@ -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)} diff --git a/apps/wallet-mobile/src/features/Swap/common/SwapFormProvider.tsx b/apps/wallet-mobile/src/features/Swap/common/SwapFormProvider.tsx index 9c788cc4e2..8955518940 100644 --- a/apps/wallet-mobile/src/features/Swap/common/SwapFormProvider.tsx +++ b/apps/wallet-mobile/src/features/Swap/common/SwapFormProvider.tsx @@ -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, }) @@ -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 @@ -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 @@ -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 diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/EditBuyAmount.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/EditBuyAmount.tsx index 2aac51f319..1a8f599e4b 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/EditBuyAmount.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditBuyAmount/EditBuyAmount.tsx @@ -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}) @@ -32,7 +31,6 @@ export const EditBuyAmount = () => { navigateTo={navigate.selectBuyToken} touched={isBuyTouched} inputRef={buyInputRef} - inputEditable={pool !== undefined} error={buyError} /> ) diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditSellAmount/EditSellAmount.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditSellAmount/EditSellAmount.tsx index 76722e1af2..9067ac05f9 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditSellAmount/EditSellAmount.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditSellAmount/EditSellAmount.tsx @@ -32,7 +32,6 @@ export const EditSellAmount = () => { touched={isSellTouched} inputRef={sellInputRef} error={error} - // inputEditable={orderData.selectedPoolCalculation?.pool !== undefined} /> ) } diff --git a/apps/wallet-mobile/translations/messages/src/features/Swap/common/AmountCard/AmountCard.json b/apps/wallet-mobile/translations/messages/src/features/Swap/common/AmountCard/AmountCard.json index d127348e65..56d4732094 100644 --- a/apps/wallet-mobile/translations/messages/src/features/Swap/common/AmountCard/AmountCard.json +++ b/apps/wallet-mobile/translations/messages/src/features/Swap/common/AmountCard/AmountCard.json @@ -6,12 +6,12 @@ "start": { "line": 128, "column": 15, - "index": 4075 + "index": 4086 }, "end": { "line": 131, "column": 3, - "index": 4158 + "index": 4169 } }, { @@ -21,12 +21,12 @@ "start": { "line": 132, "column": 18, - "index": 4178 + "index": 4189 }, "end": { "line": 135, "column": 3, - "index": 4267 + "index": 4278 } } ] \ No newline at end of file