Skip to content

Commit

Permalink
feat: remove zero when focusing on the send asset input (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranroneill authored Feb 3, 2024
1 parent 06163a8 commit 32a3ad4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ const submitTransactionThunk: AsyncThunk<
> = createAsyncThunk<string, string, AsyncThunkConfig>(
SendAssetsThunkEnum.SubmitTransaction,
async (password, { getState, rejectWithValue }) => {
const amountInStandardUnits: string | null =
getState().sendAssets.amountInStandardUnits;
const amountInStandardUnits: string =
getState().sendAssets.amountInStandardUnits.length > 0
? getState().sendAssets.amountInStandardUnits
: '0';
const asset: IAssetTypes | INativeCurrency | null =
getState().sendAssets.selectedAsset;
const fromAddress: string | null = getState().sendAssets.fromAddress;
Expand All @@ -73,7 +75,7 @@ const submitTransactionThunk: AsyncThunk<
let privateKeyService: PrivateKeyService;
let suggestedParams: SuggestedParams;

if (!amountInStandardUnits || !asset || !fromAddress || !toAddress) {
if (!asset || !fromAddress || !toAddress) {
logger.debug(
`${SendAssetsThunkEnum.SubmitTransaction}: required fields not completed`
);
Expand Down
13 changes: 10 additions & 3 deletions src/extension/modals/SendAssetModal/SendAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,16 @@ const SendAmountInput: FC<IProps> = ({
})
);
};
const handleOnChange = (valueAsString: string | undefined) =>
onValueChange(valueAsString || '');
const handleOnFocus = (event: FocusEvent<HTMLInputElement>) => {
// remove the padded zero
if (event.target.value === '0') {
onValueChange('');
}
};
const handleMaximumAmountClick = () =>
onValueChange(maximumTransactionAmountInStandardUnit.toString());
const handleOnChange = (valueAsString: string | undefined) =>
onValueChange(valueAsString || '0');
// renders
const renderMaximumTransactionAmountLabel = () => {
let symbol: string = '';
Expand Down Expand Up @@ -216,7 +222,8 @@ const SendAmountInput: FC<IProps> = ({
focusBorderColor={primaryColor}
onBlur={handleOnBlur}
onChange={handleOnChange}
size="md"
onFocus={handleOnFocus}
size="lg"
value={value || undefined}
w="full"
>
Expand Down

0 comments on commit 32a3ad4

Please sign in to comment.