From fe66ac244c0bcc8e1a25c9b72572af6ed3762628 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Wed, 20 Dec 2023 17:38:03 +0100 Subject: [PATCH] ui(send): input group text prepend for sweeps --- src/components/Send/AmountInputField.tsx | 126 ++++++++++------------- 1 file changed, 54 insertions(+), 72 deletions(-) diff --git a/src/components/Send/AmountInputField.tsx b/src/components/Send/AmountInputField.tsx index f043ebb0..555a1deb 100644 --- a/src/components/Send/AmountInputField.tsx +++ b/src/components/Send/AmountInputField.tsx @@ -6,7 +6,7 @@ import { FieldInputProps, FormikContextType, useField, useFormikContext } from ' import * as Api from '../../libs/JmWalletApi' import Sprite from '../Sprite' import { AccountBalanceSummary } from '../../context/BalanceSummary' -import { formatBtc, isValidNumber, noop, satsToBtc } from '../../utils' +import { formatBtc, isValidNumber, satsToBtc } from '../../utils' import styles from './AmountInputField.module.css' export type AmountValue = { @@ -71,18 +71,16 @@ const UniversalBitcoinInput = forwardRef( <> {!enableInputUnitToggle ? ( - <> - - {inputType.type === 'number' ? ( - <> - {displayInputUnit === 'sats' && } - {displayInputUnit === 'BTC' && {'\u20BF'}} - - ) : ( - <>{field.value?.displayValue && {'\u20BF'}} - )} - - + + {inputType.type === 'number' ? ( + <> + {displayInputUnit === 'sats' && } + {displayInputUnit === 'BTC' && {'\u20BF'}} + + ) : ( + <>{field.value?.displayValue ? {'\u20BF'} : '…'} + )} + ) : ( <> {inputType.type === 'number' && ( @@ -144,9 +142,11 @@ const UniversalBitcoinInput = forwardRef( inputType.type === 'text' ? field.value?.displayValue ?? '' : String(field.value?.userRawInputValue ?? '') } placeholder={placeholder} - required min={displayInputUnit === 'sats' ? '1' : '0.00000001'} step={displayInputUnit === 'sats' ? '1' : '0.00000001'} + isInvalid={form.touched[field.name] && !!form.errors[field.name]} + disabled={disabled} + required onFocus={() => { setInputType({ type: 'number' }) }} @@ -208,14 +208,11 @@ const UniversalBitcoinInput = forwardRef( userRawInputValue: e.target.value, userSelectedInputUnit: field.value?.userSelectedInputUnit, displayValue: e.target.value, - fromJar: null, }, true, ) } }} - isInvalid={form.touched[field.name] && !!form.errors[field.name]} - disabled={disabled} /> {children} @@ -253,7 +250,7 @@ export const AmountInputField = ({ return ( <> - + {label} {isLoading ? ( @@ -261,19 +258,17 @@ export const AmountInputField = ({ ) : ( - <> - {field.value?.isSweep === true ? ( - - +
+ + {field.value?.isSweep === true && ( {t('send.button_clear_sweep')}
-
- ) : ( -
- { + if (!sourceJarBalance) return + form.setFieldValue( + field.name, + { + value: 0, + isSweep: true, + displayValue: formatBtcDisplayValue(sourceJarBalance.calculatedAvailableBalanceInSats), + }, + true, + ) + }} + disabled={disabled || !sourceJarBalance} > - {enableSweep && ( - { - if (!sourceJarBalance) return - form.setFieldValue( - field.name, - { - value: 0, - isSweep: true, - displayValue: formatBtcDisplayValue(sourceJarBalance.calculatedAvailableBalanceInSats), - }, - true, - ) - }} - disabled={disabled || !sourceJarBalance} - > -
- - {t('send.button_sweep')} -
-
- )} -
-
- )} - +
+ + {t('send.button_sweep')} +
+ + )} + + )}