diff --git a/src/components/transaction-sum/transaction-sum.tsx b/src/components/transaction-sum/transaction-sum.tsx index ec0e19d5e..51f428cfa 100644 --- a/src/components/transaction-sum/transaction-sum.tsx +++ b/src/components/transaction-sum/transaction-sum.tsx @@ -35,7 +35,7 @@ export type TransactionSumProps = { to: string; from: string; contact: Contact | null; - onAmount: (amount: Balance) => void; + onPressPreview: (amount: Balance) => void; onContact: () => void; onToken: () => void; onNetworkPress: () => void; @@ -52,7 +52,7 @@ export const TransactionSum = observer( balance, fee, contact, - onAmount, + onPressPreview, onContact, onToken, onNetworkPress, @@ -105,14 +105,8 @@ export const TransactionSum = observer( ); const onDone = useCallback(() => { - onAmount( - new Balance( - parseFloat(amounts.amount), - undefined, - token.symbol ?? undefined, - ), - ); - }, [amounts, onAmount]); + onPressPreview(amounts.amountBalance); + }, [amounts, onPressPreview]); const onPressMax = useCallback(() => { vibrate(HapticEffects.impactLight); diff --git a/src/components/ui/sum-block.tsx b/src/components/ui/sum-block.tsx index 568026fd3..424f2cb35 100644 --- a/src/components/ui/sum-block.tsx +++ b/src/components/ui/sum-block.tsx @@ -88,7 +88,9 @@ export const SumBlock = observer( }); } - return new Balance(Number(value)).toFiat(); + return new Balance(Number(value)).toFiat({ + fixed: 'auto', + }); }, [token?.decimals, token?.symbol, value]); return ( diff --git a/src/hooks/use-sum-amount.ts b/src/hooks/use-sum-amount.ts index 736deb524..d41382a47 100644 --- a/src/hooks/use-sum-amount.ts +++ b/src/hooks/use-sum-amount.ts @@ -40,10 +40,10 @@ export const useSumAmount = ( numericality: { notValid: 'Invalid number', greaterThanOrEqualTo: minAmountRef.current.toFloat(), - lessThanOrEqualTo: maxAmountRef.current.toFloat(), - notGreaterThan: getText(I18N.sumAmountTooLow, { - amount: maxAmountRef.current.toBalanceString('auto'), + notGreaterThanOrEqualTo: getText(I18N.sumAmountTooLow, { + amount: minAmountRef.current.toBalanceString('auto'), }), + lessThanOrEqualTo: maxAmountRef.current.toFloat(), notLessThanOrEqualTo: getText(I18N.sumAmountNotEnough, { symbol: maxAmountRef.current.getSymbol(), }), @@ -73,6 +73,7 @@ export const useSumAmount = ( !error, maxAmount: maxAmount, amount: amountText, + amountBalance: amount, error, setMaxAmount(value = Balance.Empty) { maxAmountRef.current = value; @@ -104,7 +105,7 @@ export const useSumAmount = ( changed: _changed, })); }, - setAmount(text: string, precision = app.provider.decimals) { + setAmount(text: string, precision?: number) { if (text.match(/^[0-9].*/)) { let i = 0; const textFormatted = text @@ -118,7 +119,18 @@ export const useSumAmount = ( .replace(/\D&[^.]/g, '') .replace(/^0[0-9]/gm, '0'); - const newAmount = new Balance(+textFormatted, precision); + const decimals = + precision ?? + maxAmountRef.current?.getPrecission?.() ?? + minAmountRef.current?.getPrecission?.() ?? + app.provider.decimals; + + const denom = + maxAmountRef.current?.getSymbol?.() ?? + minAmountRef.current?.getSymbol?.() ?? + app.provider.denom; + + const newAmount = new Balance(+textFormatted, decimals, denom); if (typeof onChange === 'function') { onChange(newAmount, textFormatted); } diff --git a/src/screens/HomeStack/TransactionStack/transaction-sum.tsx b/src/screens/HomeStack/TransactionStack/transaction-sum.tsx index 172ca5bd3..e74e80c84 100644 --- a/src/screens/HomeStack/TransactionStack/transaction-sum.tsx +++ b/src/screens/HomeStack/TransactionStack/transaction-sum.tsx @@ -69,7 +69,7 @@ export const TransactionSumScreen = memo(() => { }); } } catch (err) { - Logger.log('err onAmount', err); + Logger.log('tx sum err getFee', err); return null; } }, @@ -87,8 +87,8 @@ export const TransactionSumScreen = memo(() => { }; }, [event, onAddress]); - const onAmount = useCallback( - async (amount: Balance) => { + const onPressPreview = useCallback( + async (amount: Balance, repeated = false) => { setLoading(true); const estimate = await getFee(amount); @@ -104,9 +104,13 @@ export const TransactionSumScreen = memo(() => { showModal(ModalType.error, { title: getText(I18N.feeCalculatingRpcErrorTitle), description: getText(I18N.feeCalculatingRpcErrorDescription), - close: getText(I18N.feeCalculatingRpcErrorClose), + close: getText( + repeated ? I18N.cancel : I18N.feeCalculatingRpcErrorClose, + ), onClose: () => { - onAmount(amount); + if (!repeated) { + onPressPreview(amount, true); + } }, }); } @@ -156,7 +160,7 @@ export const TransactionSumScreen = memo(() => { fee={fee} to={to} from={route.params.from} - onAmount={onAmount} + onPressPreview={onPressPreview} onContact={onContact} onToken={onToken} onNetworkPress={onNetworkPress}