From 851419466eda29afe8e10a8e93750d5b84443d4c Mon Sep 17 00:00:00 2001 From: SorinC6 Date: Tue, 10 Oct 2023 13:00:56 +0300 Subject: [PATCH 1/2] fix: edit limit price --- .../CreateOrder/EditLimitPrice.tsx | 46 ++++++++++++------- .../ShowTokenActions/ClearQuantities.tsx | 3 +- .../ShowTokenActions/TopTokenActions.tsx | 3 +- .../Swap/common/AmountCard/AmountCard.json | 40 ++++++++-------- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx index 53d342cf13..cc5ccbcc49 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx @@ -1,7 +1,7 @@ /* eslint-disable react/jsx-newline */ import {useSwap} from '@yoroi/swap' import * as React from 'react' -import {StyleSheet, Text, TextInput, View} from 'react-native' +import {Pressable, StyleSheet, Text, TextInput, View} from 'react-native' import {useLanguage} from '../../../../../i18n' import {useSelectedWallet} from '../../../../../SelectedWallet' @@ -19,6 +19,7 @@ export const EditLimitPrice = () => { const {numberLocale} = useLanguage() const [text, setText] = React.useState('') const wallet = useSelectedWallet() + const inputRef = React.useRef(null) const {orderData, limitPriceChanged} = useSwap() const sellTokenInfo = useTokenInfo({wallet, tokenId: orderData.amounts.sell.tokenId}) @@ -33,7 +34,8 @@ export const EditLimitPrice = () => { React.useEffect(() => { if (orderData.type === 'limit') { - setText(Quantities.format(orderData.limitPrice ?? Quantities.zero, denomination, PRECISION)) + !inputRef?.current?.isFocused() && + setText(Quantities.format(orderData.limitPrice ?? Quantities.zero, denomination, PRECISION)) } else { setText( Quantities.format(orderData.selectedPoolCalculation?.prices.market ?? Quantities.zero, denomination, PRECISION), @@ -54,7 +56,7 @@ export const EditLimitPrice = () => { {disabled ? strings.marketPrice : strings.limitPrice} - + @@ -70,21 +72,33 @@ type AmountInputProps = { value?: string onChange(value: string): void editable: boolean + inputRef?: React.RefObject } -const AmountInput = ({onChange, value, editable}: AmountInputProps) => { +const AmountInput = ({onChange, value, editable, inputRef}: AmountInputProps) => { + const amountInputRef = React.useRef(inputRef?.current ?? null) + + const focusInput = () => { + if (amountInputRef?.current) { + amountInputRef.current.focus() + } + } + return ( - + + + ) } diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/ClearQuantities.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/ClearQuantities.tsx index 28c49f79e6..a5873c84c6 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/ClearQuantities.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/ClearQuantities.tsx @@ -1,6 +1,6 @@ import {useSwap} from '@yoroi/swap' import React from 'react' -import {StyleSheet, Text} from 'react-native' +import {Keyboard, StyleSheet, Text} from 'react-native' import {TouchableOpacity} from 'react-native-gesture-handler' import {COLORS} from '../../../../../../theme' @@ -13,6 +13,7 @@ export const ClearQuantities = () => { const {poolDefaulted} = useSwapTouched() const handleReset = () => { + Keyboard.dismiss() resetQuantities() poolDefaulted() } diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/TopTokenActions.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/TopTokenActions.tsx index 561123cbc4..d60ef48368 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/TopTokenActions.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/ShowTokenActions/TopTokenActions.tsx @@ -1,6 +1,6 @@ import {useSwap, useSwapPoolsByPair} from '@yoroi/swap' import React from 'react' -import {StyleSheet, View} from 'react-native' +import {Keyboard, StyleSheet, View} from 'react-native' import {TouchableOpacity} from 'react-native-gesture-handler' import {Icon} from '../../../../../../components' @@ -40,6 +40,7 @@ export const TopTokenActions = () => { } const handleRefresh = () => { + Keyboard.dismiss() refetch() } 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 7fa3933302..51c7130421 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 @@ -4,14 +4,14 @@ "defaultMessage": "!!!Select token", "file": "src/features/Swap/common/AmountCard/AmountCard.tsx", "start": { - "line": 134, + "line": 135, "column": 15, - "index": 4170 + "index": 4171 }, "end": { - "line": 137, + "line": 138, "column": 3, - "index": 4253 + "index": 4254 } }, { @@ -19,14 +19,14 @@ "defaultMessage": "!!!Current Balance", "file": "src/features/Swap/common/AmountCard/AmountCard.tsx", "start": { - "line": 138, + "line": 139, "column": 18, - "index": 4273 + "index": 4274 }, "end": { - "line": 141, + "line": 142, "column": 3, - "index": 4362 + "index": 4363 } }, { @@ -34,14 +34,14 @@ "defaultMessage": "!!!Not enough balance", "file": "src/features/Swap/common/AmountCard/AmountCard.tsx", "start": { - "line": 142, + "line": 143, "column": 20, - "index": 4384 + "index": 4385 }, "end": { - "line": 145, + "line": 146, "column": 3, - "index": 4478 + "index": 4479 } }, { @@ -49,14 +49,14 @@ "defaultMessage": "!!!Not enough supply in the pool", "file": "src/features/Swap/common/AmountCard/AmountCard.tsx", "start": { - "line": 146, + "line": 147, "column": 19, - "index": 4499 + "index": 4500 }, "end": { - "line": 149, + "line": 150, "column": 3, - "index": 4603 + "index": 4604 } }, { @@ -64,14 +64,14 @@ "defaultMessage": "!!! This pair is not available in any liquidity pool", "file": "src/features/Swap/common/AmountCard/AmountCard.tsx", "start": { - "line": 150, + "line": 151, "column": 10, - "index": 4615 + "index": 4616 }, "end": { - "line": 153, + "line": 154, "column": 3, - "index": 4730 + "index": 4731 } } ] \ No newline at end of file From 5edc963de4fb30f668a7810471fea4988666486d Mon Sep 17 00:00:00 2001 From: SorinC6 Date: Tue, 10 Oct 2023 13:42:49 +0300 Subject: [PATCH 2/2] remove pressable --- .../CreateOrder/EditLimitPrice.tsx | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx index cc5ccbcc49..74ae20f445 100644 --- a/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx +++ b/apps/wallet-mobile/src/features/Swap/useCases/StartSwapScreen/CreateOrder/EditLimitPrice.tsx @@ -1,7 +1,7 @@ /* eslint-disable react/jsx-newline */ import {useSwap} from '@yoroi/swap' import * as React from 'react' -import {Pressable, StyleSheet, Text, TextInput, View} from 'react-native' +import {StyleSheet, Text, TextInput, View} from 'react-native' import {useLanguage} from '../../../../../i18n' import {useSelectedWallet} from '../../../../../SelectedWallet' @@ -75,30 +75,20 @@ type AmountInputProps = { inputRef?: React.RefObject } const AmountInput = ({onChange, value, editable, inputRef}: AmountInputProps) => { - const amountInputRef = React.useRef(inputRef?.current ?? null) - - const focusInput = () => { - if (amountInputRef?.current) { - amountInputRef.current.focus() - } - } - return ( - - - + ) }