From 0ae63c50d23733f986813be06b66b2bc484fadac Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 27 Nov 2022 08:15:50 -0800 Subject: [PATCH] Fix reset advanced option on disable --- .../src/components/OrderDetails/index.tsx | 8 ++-- .../TradeBox/Forms/LightningPayout.tsx | 43 +++++++++++-------- frontend/src/components/TradeBox/index.tsx | 2 +- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/OrderDetails/index.tsx b/frontend/src/components/OrderDetails/index.tsx index 0b062056..d481ce13 100644 --- a/frontend/src/components/OrderDetails/index.tsx +++ b/frontend/src/components/OrderDetails/index.tsx @@ -99,13 +99,11 @@ const OrderDetails = ({ } // Render a countdown, bold when less than 25% return fraction_left < 0.25 ? ( - + {`${hours}h ${zeroPad(minutes)}m ${zeroPad(seconds)}s `} - + ) : ( - - {`${hours}h ${zeroPad(minutes)}m ${zeroPad(seconds)}s `} - + {`${hours}h ${zeroPad(minutes)}m ${zeroPad(seconds)}s `} ); } }; diff --git a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx index 9a314f93..620a7a65 100644 --- a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx +++ b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx @@ -22,7 +22,7 @@ import { } from '@mui/material'; import { Order, Settings } from '../../../models'; -import {decode} from 'light-bolt11-decoder' +import { decode } from 'light-bolt11-decoder'; import WalletsButton from '../WalletsButton'; import { LoadingButton } from '@mui/lab'; import { pn } from '../../../utils'; @@ -101,16 +101,16 @@ export const LightningPayoutForm = ({ const validateInvoice = function (invoice: string, targetAmount: number) { try { - const decoded = decode(invoice) - const invoiceAmount = Math.floor(decoded['sections'][2]['value']/1000) + const decoded = decode(invoice); + const invoiceAmount = Math.floor(decoded['sections'][2]['value'] / 1000); if (targetAmount != invoiceAmount) { return 'Invalid invoice amount'; } else { return ''; } - } catch(err) { - const error = err.toString() - return `${error.substring(0,100)}${error.length >100 ? '...' : ''}` + } catch (err) { + const error = err.toString(); + return `${error.substring(0, 100)}${error.length > 100 ? '...' : ''}`; } }; @@ -196,9 +196,9 @@ export const LightningPayoutForm = ({ .then((response) => response.text()) .then((text) => { if (text.includes('lnproxy error')) { - setLightning({ ...lightning, badLnproxy: text}); + setLightning({ ...lightning, badLnproxy: text }); } else { - const invoice = text.replace('\n',"") + const invoice = text.replace('\n', ''); setLightning({ ...lightning, invoice, badLnproxy: '' }); } }) @@ -210,6 +210,21 @@ export const LightningPayoutForm = ({ }); }; + const handleAdvancedOptions = function (checked: boolean) { + if (checked) { + setLightning({ + ...lightning, + advancedOptions: true, + }); + } else { + setLightning({ + ...defaultLightning, + invoice: lightning.invoice, + amount: lightning.amount, + }); + } + }; + const onProxyBudgetChange = function (e) { if (isFinite(e.target.value) && e.target.value >= 0) { let lnproxyBudgetSats; @@ -288,13 +303,7 @@ export const LightningPayoutForm = ({ { - const checked = e.target.checked; - setLightning({ - ...lightning, - advancedOptions: checked, - }); - }} + onChange={(e) => handleAdvancedOptions(e.target.checked)} /> @@ -521,7 +530,7 @@ export const LightningPayoutForm = ({ fullWidth={true} disabled={!lightning.useLnproxy} error={lightning.badLnproxy != ''} - FormHelperTextProps={{style:{wordBreak: 'break-all'}}} + FormHelperTextProps={{ style: { wordBreak: 'break-all' } }} helperText={lightning.badLnproxy ? t(lightning.badLnproxy) : ''} label={t('Invoice to wrap')} required @@ -543,7 +552,7 @@ export const LightningPayoutForm = ({ disabled={lightning.useLnproxy} error={lightning.badInvoice != ''} helperText={lightning.badInvoice ? t(lightning.badInvoice) : ''} - FormHelperTextProps={{style:{wordBreak: 'break-all'}}} + FormHelperTextProps={{ style: { wordBreak: 'break-all' } }} label={lightning.useLnproxy ? t('Wrapped invoice') : t('Payout Lightning Invoice')} required value={lightning.invoice} diff --git a/frontend/src/components/TradeBox/index.tsx b/frontend/src/components/TradeBox/index.tsx index 39dddb22..fca89565 100644 --- a/frontend/src/components/TradeBox/index.tsx +++ b/frontend/src/components/TradeBox/index.tsx @@ -287,7 +287,7 @@ const TradeBox = ({ }, [order.status]); const statusToContract = function (order: Order) { - const status = order.status; + const status = 6; const isBuyer = order.is_buyer; const isMaker = order.is_maker;