Skip to content

Commit

Permalink
hyper
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Jan 4, 2024
1 parent cbadab4 commit de9dce0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ import { enableWebln } from "./utils/webln";
const Create = () => {
let receiveAmountRef: HTMLInputElement, sendAmountRef: HTMLInputElement;

// if btc and amount > 100, switch to sat
// if btc and amount > 99, switch to sat
// user failed to notice the non satoshi denomination
const changeDenomination = (amount: number) => {
if (denomination() === denominations.btc && amount > 99) {
setDenomination(denominations.sat);
} else if (denomination() === denominations.sat && amount < 1) {
setDenomination(denominations.btc);
}
};

Expand Down Expand Up @@ -109,6 +111,9 @@ const Create = () => {
const validateInput = (evt: KeyboardEvent) => {
const input = evt.currentTarget as HTMLInputElement;
const keycode = evt.key;
if (denomination() == "sat" && keycode === ".") {
setDenomination(denominations.btc);
}
const hasDot = input.value.includes(".");
const regex = denomination() == "sat" || hasDot ? /[0-9]/ : /[0-9]|\./;
if (!regex.test(keycode)) {
Expand All @@ -120,6 +125,7 @@ const Create = () => {
const validatePaste = (evt: ClipboardEvent) => {
const clipboardData = evt.clipboardData || globalThis.clipboardData;
const pastedData = clipboardData.getData("Text").trim();
changeDenomination(Number(pastedData));
if (!getValidationRegex().test(pastedData)) {
evt.stopPropagation();
evt.preventDefault();
Expand Down

0 comments on commit de9dce0

Please sign in to comment.