From df960a71ed495d098ca1ec0f907257e42715c71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Tue, 12 Nov 2024 09:37:13 +0100 Subject: [PATCH 1/5] overall improvements in node admin --- src/components/Modal/node/AddAliasModal.tsx | 17 +++++++++++++++-- src/components/Modal/node/WithdrawModal.tsx | 20 ++++++++++++++++---- src/pages/node/info/index.tsx | 12 ++++++++++++ src/pages/node/tickets.tsx | 12 ------------ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/components/Modal/node/AddAliasModal.tsx b/src/components/Modal/node/AddAliasModal.tsx index ae3b6320..1c4bc8e6 100644 --- a/src/components/Modal/node/AddAliasModal.tsx +++ b/src/components/Modal/node/AddAliasModal.tsx @@ -28,19 +28,28 @@ export const CreateAliasModal = (props: CreateAliasModalProps) => { const [alias, set_alias] = useState(''); const [peerId, set_peerId] = useState(props.peerId ? props.peerId : ''); const [duplicateAlias, set_duplicateAlias] = useState(false); + const [duplicatePeerId, set_duplicatePeerId] = useState(false); const [openModal, setOpenModal] = useState(false); + const aliasesArr = aliases ? Object.keys(aliases) : []; + const aliasPeerIdsArr = aliases ? Object.values(aliases) : []; + const setPropPeerId = () => { if (props.peerId) set_peerId(props.peerId); }; useEffect(setPropPeerId, [props.peerId]); const handleChangePeerId = (event: React.ChangeEvent) => { + if (aliasPeerIdsArr.includes(event.target.value)) { + set_duplicatePeerId(true); + } else { + set_duplicatePeerId(false); + } set_peerId(event.target.value); }; const handleChangeAlias = (event: React.ChangeEvent) => { - if (aliases && Object.keys(aliases).includes(event.target.value)) { + if (aliasesArr.includes(event.target.value)) { set_duplicateAlias(true); } else { set_duplicateAlias(false); @@ -54,6 +63,7 @@ export const CreateAliasModal = (props: CreateAliasModalProps) => { const handleCloseModal = () => { set_duplicateAlias(false); + set_duplicatePeerId(false); setOpenModal(false); set_peerId(props.peerId ? props.peerId : ''); set_alias(''); @@ -150,6 +160,9 @@ export const CreateAliasModal = (props: CreateAliasModalProps) => { placeholder="12D3Ko...Z3rz5F" onChange={handleChangePeerId} value={peerId} + error={duplicatePeerId} + helperText={duplicatePeerId ? 'This Peer Id already has an alias!' : ''} + style={{ minHeight: '79px' }} /> { diff --git a/src/pages/node/info/index.tsx b/src/pages/node/info/index.tsx index bb61571d..4dbeabc7 100644 --- a/src/pages/node/info/index.tsx +++ b/src/pages/node/info/index.tsx @@ -65,6 +65,7 @@ function InfoPage() { : null; const blockNumber = blockNumberFromMetrics ?? blockNumberFromInfo; const blockNumberCheckSum = blockNumberCheckSumFromMetrics ?? blockNumberCheckSumFromInfo; + const ticketPrice = useAppSelector((store) => store.node.ticketPrice.data); useEffect(() => { fetchInfoData(); @@ -324,6 +325,17 @@ function InfoPage() { {blockNumberCheckSum ? blockNumberCheckSum : '-'} + + + + Current ticket price + + + {ticketPrice ? formatEther(BigInt(ticketPrice as string)) : '-'} wxHOPR + diff --git a/src/pages/node/tickets.tsx b/src/pages/node/tickets.tsx index 2f5e1ff9..049a88a5 100644 --- a/src/pages/node/tickets.tsx +++ b/src/pages/node/tickets.tsx @@ -22,7 +22,6 @@ function TicketsPage() { const statisticsFetching = useAppSelector((store) => store.node.statistics.isFetching); const redeemTicketsFetching = useAppSelector((store) => store.node.redeemTickets.isFetching); const redeemTicketsErrors = useAppSelector((store) => store.node.redeemTickets.error); - const ticketPrice = useAppSelector((store) => store.node.ticketPrice.data); const loginData = useAppSelector((store) => store.auth.loginData); useEffect(() => { @@ -92,17 +91,6 @@ function TicketsPage() { style={{ marginBottom: '32px' }} > - - - - Ticket price - - - {ticketPrice ? formatEther(BigInt(ticketPrice as string)) : '-'} wxHOPR - Date: Tue, 12 Nov 2024 10:10:13 +0100 Subject: [PATCH 2/5] better withdraw validation" --- src/components/Modal/node/WithdrawModal.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Modal/node/WithdrawModal.tsx b/src/components/Modal/node/WithdrawModal.tsx index d9a5e3ab..607e72d7 100644 --- a/src/components/Modal/node/WithdrawModal.tsx +++ b/src/components/Modal/node/WithdrawModal.tsx @@ -83,10 +83,15 @@ const WithdrawModal = ({ initialCurrency }: WithdrawModalProps) => { const [openModal, set_openModal] = useState(false); const [currency, set_currency] = useState<'HOPR' | 'NATIVE'>(initialCurrency ?? 'NATIVE'); const [amount, set_amount] = useState(''); + const [maxAmount, set_maxAmount] = useState(''); const [recipient, set_recipient] = useState(''); const [isLoading, set_isLoading] = useState(false); const [transactionHash, set_transactionHash] = useState(''); + + const withdrawingZeroOrLess = amount ? parseEther(amount) <= parseEther('0') : false + const withdrawingMoreThanTheWallet = amount ? parseEther(amount) > parseEther(maxAmount) : false; + useEffect(() => { setMaxAmount(); }, [currency]); @@ -102,8 +107,10 @@ const WithdrawModal = ({ initialCurrency }: WithdrawModalProps) => { const setMaxAmount = () => { if (currency === 'HOPR' && hoprBalance.formatted) { set_amount(hoprBalance.formatted); + set_maxAmount(hoprBalance.formatted); } else if (currency === 'NATIVE' && nativeBalance.formatted) { set_amount(nativeBalance.formatted); + set_maxAmount(nativeBalance.formatted); } }; @@ -232,7 +239,12 @@ const WithdrawModal = ({ initialCurrency }: WithdrawModalProps) => { From 5df51ec7d48e73e36129d30ce05c6a203b12c3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Tue, 12 Nov 2024 10:16:44 +0100 Subject: [PATCH 3/5] format --- src/components/Modal/node/WithdrawModal.tsx | 20 ++++++++------------ src/pages/node/channelsOutgoing.tsx | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/components/Modal/node/WithdrawModal.tsx b/src/components/Modal/node/WithdrawModal.tsx index 607e72d7..1edecd49 100644 --- a/src/components/Modal/node/WithdrawModal.tsx +++ b/src/components/Modal/node/WithdrawModal.tsx @@ -88,8 +88,7 @@ const WithdrawModal = ({ initialCurrency }: WithdrawModalProps) => { const [isLoading, set_isLoading] = useState(false); const [transactionHash, set_transactionHash] = useState(''); - - const withdrawingZeroOrLess = amount ? parseEther(amount) <= parseEther('0') : false + const withdrawingZeroOrLess = amount ? parseEther(amount) <= parseEther('0') : false; const withdrawingMoreThanTheWallet = amount ? parseEther(amount) > parseEther(maxAmount) : false; useEffect(() => { @@ -203,13 +202,13 @@ const WithdrawModal = ({ initialCurrency }: WithdrawModalProps) => { > xDai {HOPR_TOKEN_USED} @@ -226,25 +225,22 @@ const WithdrawModal = ({ initialCurrency }: WithdrawModalProps) => { Max ), - inputProps: { min: 0, step: "any" }, + inputProps: { min: 0, step: 'any' }, }} /> set_recipient(e.target.value)} /> diff --git a/src/pages/node/channelsOutgoing.tsx b/src/pages/node/channelsOutgoing.tsx index b6fb0e77..b07e8b25 100644 --- a/src/pages/node/channelsOutgoing.tsx +++ b/src/pages/node/channelsOutgoing.tsx @@ -111,7 +111,7 @@ function ChannelsPage() { e instanceof sdkApiError && e.hoprdErrorPayload?.error?.includes('channel closure time has not elapsed yet, remaining') ) { - let errMsg = `Closing of outgoing channel ${channelId} halted. C${e.hoprdErrorPayload?.error.substring(1)}`; + const errMsg = `Closing of outgoing channel ${channelId} halted. C${e.hoprdErrorPayload?.error.substring(1)}`; sendNotification({ notificationPayload: { source: 'node', From db86f0a060b23b4fe260cf7b5acf8a3ce0c01271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Tue, 12 Nov 2024 10:21:03 +0100 Subject: [PATCH 4/5] test for a space in an alias --- src/components/Modal/node/AddAliasModal.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/Modal/node/AddAliasModal.tsx b/src/components/Modal/node/AddAliasModal.tsx index 1c4bc8e6..d49737ec 100644 --- a/src/components/Modal/node/AddAliasModal.tsx +++ b/src/components/Modal/node/AddAliasModal.tsx @@ -33,6 +33,7 @@ export const CreateAliasModal = (props: CreateAliasModalProps) => { const aliasesArr = aliases ? Object.keys(aliases) : []; const aliasPeerIdsArr = aliases ? Object.values(aliases) : []; + const aliasIncludesASpace = alias.includes(" "); const setPropPeerId = () => { if (props.peerId) set_peerId(props.peerId); @@ -171,14 +172,14 @@ export const CreateAliasModal = (props: CreateAliasModalProps) => { placeholder="Alias" onChange={handleChangeAlias} value={alias} - error={duplicateAlias} - helperText={duplicateAlias ? 'This is a duplicate alias!' : ''} + error={duplicateAlias || alias.includes(" ")} + helperText={duplicateAlias ? 'This is a duplicate alias!' : aliasIncludesASpace ? 'An alias can\'t include a space' : ''} style={{ minHeight: '79px' }} />