Skip to content

Commit

Permalink
feat: automatic denom switcher
Browse files Browse the repository at this point in the history
switches to sat denom of amount > x

change limit to 99

fixup change denom
  • Loading branch information
dni committed Jan 4, 2024
1 parent b31bc7d commit cbadab4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
sendAmountFormatted,
sendAmountValid,
setAmountChanged,
setDenomination,
setInvoice,
setReceiveAmount,
setReceiveAmountFormatted,
Expand All @@ -50,6 +51,7 @@ import { calculateReceiveAmount, calculateSendAmount } from "./utils/calculate";
import {
calculateDigits,
convertAmount,
denominations,
formatAmount,
getValidationRegex,
} from "./utils/denomination";
Expand All @@ -58,10 +60,19 @@ import { enableWebln } from "./utils/webln";
const Create = () => {
let receiveAmountRef: HTMLInputElement, sendAmountRef: HTMLInputElement;

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

const changeReceiveAmount = (evt: InputEvent) => {
const target = evt.currentTarget as HTMLInputElement;
const amount = target.value.trim();
const satAmount = convertAmount(Number(amount), denomination());
const amount = Number(target.value.trim());
changeDenomination(amount);
const satAmount = convertAmount(amount, denomination());
const sendAmount = calculateSendAmount(satAmount);
setAmountChanged(sideReceive);
setReceiveAmount(BigNumber(satAmount));
Expand All @@ -73,8 +84,9 @@ const Create = () => {

const changeSendAmount = (evt: InputEvent) => {
const target = evt.currentTarget as HTMLInputElement;
const amount = target.value.trim();
const satAmount = convertAmount(Number(amount), denomination());
const amount = Number(target.value.trim());
changeDenomination(amount);
const satAmount = convertAmount(amount, denomination());
const receiveAmount = calculateReceiveAmount(satAmount);
setAmountChanged(sideSend);
setSendAmount(BigNumber(satAmount));
Expand Down

0 comments on commit cbadab4

Please sign in to comment.