From 54da432e394d269e9c0cfe0781c12a89f201b9d6 Mon Sep 17 00:00:00 2001 From: benalleng Date: Wed, 21 Jun 2023 12:49:22 -0400 Subject: [PATCH] feat: use handleClose function --- src/components/AmountEditable.tsx | 50 +++++++++-------------------- src/components/BetaWarningModal.tsx | 2 +- src/logic/browserCompatibility.ts | 7 +++- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/components/AmountEditable.tsx b/src/components/AmountEditable.tsx index fb8c294..d6d7699 100644 --- a/src/components/AmountEditable.tsx +++ b/src/components/AmountEditable.tsx @@ -247,6 +247,20 @@ export const AmountEditable: ParentComponent<{ } } + function handleClose() { + props.setAmountSats(BigInt(props.initialAmountSats)); + setIsOpen(false); + setLocalSats(props.initialAmountSats); + setLocalFiat( + satsToUsd( + state.price, + parseInt(props.initialAmountSats || "0") || 0, + false + ) + ); + props.exitRoute && navigate(props.exitRoute); + } + // What we're all here for in the first place: returning a value function handleSubmit(e: SubmitEvent | MouseEvent) { e.preventDefault(); @@ -328,44 +342,12 @@ export const AmountEditable: ParentComponent<{
{ - props.setAmountSats( - BigInt(props.initialAmountSats) - ); - setIsOpen(false); - setLocalSats(props.initialAmountSats); - setLocalFiat( - satsToUsd( - state.price, - parseInt(props.initialAmountSats || "0") || - 0, - false - ) - ); - props.exitRoute && navigate(props.exitRoute); - }} + onEscapeKeyDown={handleClose} > {/* TODO: figure out how to submit on enter */}