Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
fix: fix zero leading input when changing between SAT and USD units (#…
Browse files Browse the repository at this point in the history
…381)

* chore: disable period(.) button when amount unit is sat

* fix: fix zero leading inputs when switching between sat and usd units
  • Loading branch information
Extheoisah authored Dec 21, 2022
1 parent 27227d8 commit 7b18ebd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions components/ParsePOSPayment/Digit-Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { ACTIONS, ACTION_TYPE } from "../../pages/_reducer"

interface Props {
digit: string
disabled?: boolean
dispatch: React.Dispatch<ACTION_TYPE>
}

function DigitButton({ digit, dispatch }: Props) {
function DigitButton({ digit, disabled, dispatch }: Props) {
return (
<button onClick={() => dispatch({ type: ACTIONS.ADD_DIGIT, payload: digit })}>
<button
disabled={disabled}
onClick={() => dispatch({ type: ACTIONS.ADD_DIGIT, payload: digit })}
>
{digit}
</button>
)
Expand Down
6 changes: 5 additions & 1 deletion components/ParsePOSPayment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ function ParsePayment({ defaultWalletCurrency, walletId, dispatch, state }: Prop
<DigitButton digit={"7"} dispatch={dispatch} />
<DigitButton digit={"8"} dispatch={dispatch} />
<DigitButton digit={"9"} dispatch={dispatch} />
<DigitButton digit={"."} dispatch={dispatch} />
<DigitButton
digit={"."}
dispatch={dispatch}
disabled={unit === AmountUnit.Sat}
/>
<DigitButton digit={"0"} dispatch={dispatch} />
<button onClick={() => dispatch({ type: ACTIONS.DELETE_DIGIT })}>
<Image
Expand Down
5 changes: 5 additions & 0 deletions pages/_reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ function reducer(state: React.ComponentState, { type, payload }: ACTION_TYPE) {
case ACTIONS.SET_AMOUNT_FROM_PARAMS:
if (state.currentAmount == null) return state
if (payload?.toString().match(/(\.[0-9]{2,}$|\..*\.)/)) {
if (payload?.toString() === "0.00")
return {
...state,
currentAmount: "0",
}
return {
...state,
currentAmount: Number(payload).toFixed(2),
Expand Down

0 comments on commit 7b18ebd

Please sign in to comment.