From dfbbde0129955504542fdb82e024a48fb0914d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Mon, 18 Nov 2024 14:32:40 +0100 Subject: [PATCH 01/11] use jazzicon for the navbar incon --- README.md | 6 ------ src/components/ConnectNode/index.tsx | 31 ++++++++++++++++++++++++---- src/pages/node/info/index.tsx | 26 +++++++++++------------ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4b49f3f5..e3d06790 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,6 @@ Builds the Node Admin. Builds the app for production to the `build` folder.\ It correctly bundles React in production mode and optimizes the build for the best performance. -### `yarn build-hub` - -Builds the Staking Hub. -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - ### `docker build --platform linux/amd64 -t europe-west3-docker.pkg.dev/hoprassociation/docker-images/hopr-admin .` Builds the Node Admin docker image with the name `node-admin`. diff --git a/src/components/ConnectNode/index.tsx b/src/components/ConnectNode/index.tsx index e18274f3..f4ee109c 100644 --- a/src/components/ConnectNode/index.tsx +++ b/src/components/ConnectNode/index.tsx @@ -1,6 +1,8 @@ import React, { useState, useEffect, useRef } from 'react'; import styled from '@emotion/styled'; import { Link, useNavigate } from 'react-router-dom'; +// @ts-ignore +import jazzicon, { } from "@metamask/jazzicon"; // Components import Modal from './modal'; @@ -38,8 +40,10 @@ const Container = styled(Button)` margin-left: 8px; width: 50px; img { - height: 100%; - width: 100%; + height: 38px; + width: 38px; + border-radius: 50px; + background: rgb(3, 94, 91); } } `; @@ -86,6 +90,7 @@ const Overlay = styled.div` export default function ConnectNode() { const dispatch = useAppDispatch(); const navigate = useNavigate(); + const ref = useRef(null); const [modalVisible, set_modalVisible] = useState(false); const connected = useAppSelector((store) => store.auth.status.connected); const connecting = useAppSelector((store) => store.auth.status.connecting); @@ -93,6 +98,8 @@ export default function ConnectNode() { const openLoginModalToNode = useAppSelector((store) => store.auth.helper.openLoginModalToNode); const peerId = useAppSelector((store) => store.node.addresses.data.hopr); const localName = useAppSelector((store) => store.auth.loginData.localName); + const nodeAddress = useAppSelector((store)=> store.node.addresses.data.native); + const [nodeAddressIcon, set_nodeAddressIcon] = useState(null); const [anchorEl, setAnchorEl] = useState(null); // State variable to hold the anchor element for the menu const containerRef = useRef(null); @@ -111,6 +118,20 @@ export default function ConnectNode() { }; }, []); + useEffect(() => { + if(!nodeAddress) return; + try{ + const jazzSvg = jazzicon(16, parseInt(nodeAddress.slice(2, 10), 16)); + const html = jazzSvg.children[0].outerHTML.replace(' { if (error) set_modalVisible(true); }, [error]); @@ -163,8 +184,10 @@ export default function ConnectNode() { onClick={handleContainerClick} ref={containerRef} > -
- +
+
{connected ? ( <> diff --git a/src/pages/node/info/index.tsx b/src/pages/node/info/index.tsx index 4dbeabc7..0d3cfe46 100644 --- a/src/pages/node/info/index.tsx +++ b/src/pages/node/info/index.tsx @@ -63,8 +63,8 @@ function InfoPage() { const blockNumberIndexedWithHOPRdata = blockNumberPrevIndexedWithHOPRdata ? blockNumberPrevIndexedWithHOPRdata + 1 : null; - const blockNumber = blockNumberFromMetrics ?? blockNumberFromInfo; - const blockNumberCheckSum = blockNumberCheckSumFromMetrics ?? blockNumberCheckSumFromInfo; + const blockNumber = blockNumberFromInfo ?? blockNumberFromMetrics; + const blockNumberCheckSum = blockNumberCheckSumFromInfo ?? blockNumberCheckSumFromMetrics; const ticketPrice = useAppSelector((store) => store.node.ticketPrice.data); useEffect(() => { @@ -325,17 +325,6 @@ function InfoPage() { {blockNumberCheckSum ? blockNumberCheckSum : '-'} - - - - Current ticket price - - - {ticketPrice ? formatEther(BigInt(ticketPrice as string)) : '-'} wxHOPR - @@ -415,6 +404,17 @@ function InfoPage() { wxHOPR + + + + Current ticket price + + + {ticketPrice ? formatEther(BigInt(ticketPrice as string)) : '-'} wxHOPR + From b9287ac0d7dc43395cba14337be147d7b01eb5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Mon, 18 Nov 2024 14:40:20 +0100 Subject: [PATCH 02/11] show node name in the navbar --- src/components/ConnectNode/index.tsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components/ConnectNode/index.tsx b/src/components/ConnectNode/index.tsx index f4ee109c..6ffb71b3 100644 --- a/src/components/ConnectNode/index.tsx +++ b/src/components/ConnectNode/index.tsx @@ -65,6 +65,10 @@ const NodeButton = styled.div` color: #414141; line-height: 12px; } + .node-info-localname{ + font-weight: 700; + color: #000050; + } `; const DropdownArrow = styled.img` @@ -98,6 +102,10 @@ export default function ConnectNode() { const openLoginModalToNode = useAppSelector((store) => store.auth.helper.openLoginModalToNode); const peerId = useAppSelector((store) => store.node.addresses.data.hopr); const localName = useAppSelector((store) => store.auth.loginData.localName); + const localNameToDisplay = localName && localName.length > 17 ? + `${localName?.substring(0,5)}…${localName?.substring(localName.length-11,localName.length)}` + : + localName; const nodeAddress = useAppSelector((store)=> store.node.addresses.data.native); const [nodeAddressIcon, set_nodeAddressIcon] = useState(null); const [anchorEl, setAnchorEl] = useState(null); // State variable to hold the anchor element for the menu @@ -192,9 +200,17 @@ export default function ConnectNode() { {connected ? ( <> -

- {peerId && `${peerId.substring(0, 6)}...${peerId.substring(peerId.length - 8, peerId.length)}`} -

+ + { + localNameToDisplay && +

+ {localNameToDisplay} +

+ } +

+ {peerId && `${peerId.substring(0, 6)}...${peerId.substring(peerId.length - 8, peerId.length)}`} +

+
From abbd9ddf4f6433366cafc98ceb035e7fe1929eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Mon, 18 Nov 2024 15:11:16 +0100 Subject: [PATCH 03/11] add ticket counter to strategies --- src/pages/node/configuration.tsx | 109 ++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/src/pages/node/configuration.tsx b/src/pages/node/configuration.tsx index 5afbd18e..0ac34030 100644 --- a/src/pages/node/configuration.tsx +++ b/src/pages/node/configuration.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import { useAppDispatch, useAppSelector } from '../../store'; import { nodeActionsAsync } from '../../store/slices/node'; +import { parseEther } from 'viem'; // HOPR Components import { SubpageTitle } from '../../components/SubpageTitle'; @@ -24,6 +25,8 @@ function SettingsPage() { const dispatch = useAppDispatch(); const prevNotificationSettings = useAppSelector((store) => store.app.configuration.notifications); const strategies = useAppSelector((store) => store.node.configuration.data?.hopr?.strategy); + const ticketPrice = useAppSelector((store) => store.node.ticketPrice.data); + const [strategiesString, set_strategiesString] = useState(null); const [localNotificationSettings, set_localNotificationSettings] = useState(); useEffect(() => { @@ -32,6 +35,108 @@ function SettingsPage() { } }, [prevNotificationSettings]); + useEffect(() => { + if (strategies) { + let tmp = JSON.stringify(strategies, null, 2); + + try{ + if(ticketPrice) { + // min_stake_threshold + if(strategies?.strategies?.AutoFunding?.min_stake_threshold){ + const key = 'min_stake_threshold'; + const min_stake_threshold = strategies.strategies.AutoFunding.min_stake_threshold.replace(' HOPR',''); + const min_stake_thresholdBigInt = BigInt(min_stake_threshold)*BigInt(1e18); + const ticketBigInt = BigInt(ticketPrice); + const ticketsBigInt = min_stake_thresholdBigInt / ticketBigInt; + const ticketsString = ticketsBigInt.toString(); + const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}"`; + if(tmp.includes(stringToReplace+',')) { + tmp = tmp.replace( + stringToReplace+',', + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}` + ); + } else { + tmp = tmp.replace( + stringToReplace, + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}` + ); + } + } + + // funding_amount + if(strategies?.strategies?.AutoFunding?.funding_amount){ + const key = 'funding_amount'; + const funding_amount = strategies.strategies.AutoFunding.funding_amount.replace(' HOPR',''); + const funding_amountBigInt = BigInt(funding_amount)*BigInt(1e18); + const ticketBigInt = BigInt(ticketPrice); + const ticketsBigInt = funding_amountBigInt / ticketBigInt; + const ticketsString = ticketsBigInt.toString(); + const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding.funding_amount}"`; + if(tmp.includes(stringToReplace+',')) { + tmp = tmp.replace( + stringToReplace+',', + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}` + ); + } else { + tmp = tmp.replace( + stringToReplace, + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}` + ); + } + } + + // minimum_redeem_ticket_value + if(strategies?.strategies?.AutoRedeeming?.minimum_redeem_ticket_value){ + const key = 'minimum_redeem_ticket_value'; + const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value.replace(' HOPR',''); + const minimum_redeem_ticket_valueBigInt = BigInt(minimum_redeem_ticket_value)*BigInt(1e18); + const ticketBigInt = BigInt(ticketPrice); + const ticketsBigInt = minimum_redeem_ticket_valueBigInt / ticketBigInt; + const ticketsString = ticketsBigInt.toString(); + const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}"`; + if(tmp.includes(stringToReplace+',')) { + tmp = tmp.replace( + stringToReplace+',', + `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}", // tickets: ${ticketsString}` + ); + } else { + tmp = tmp.replace( + stringToReplace, + `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}" // tickets: ${ticketsString}` + ); + } + } + + // on_close_redeem_single_tickets_value_min + if(strategies?.strategies?.AutoRedeeming?.on_close_redeem_single_tickets_value_min){ + const key = 'on_close_redeem_single_tickets_value_min'; + const on_close_redeem_single_tickets_value_min = strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min.replace(' HOPR',''); + const on_close_redeem_single_tickets_value_minBigInt = BigInt(on_close_redeem_single_tickets_value_min)*BigInt(1e18); + const ticketBigInt = BigInt(ticketPrice); + const ticketsBigInt = on_close_redeem_single_tickets_value_minBigInt / ticketBigInt; + const ticketsString = ticketsBigInt.toString(); + const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}"`; + if(tmp.includes(stringToReplace+',')) { + tmp = tmp.replace( + stringToReplace+',', + `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}", // tickets: ${ticketsString}` + ); + } else { + tmp = tmp.replace( + stringToReplace, + `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}" // tickets: ${ticketsString}` + ); + } + } + } + } catch(e) { + console.warn('Error while counting strategies against current ticket price.', e) + } + + set_strategiesString(tmp); + } + }, [strategies, ticketPrice]); + const handleSaveSettings = async () => { if (localNotificationSettings) { dispatch(appActions.setNotificationSettings(localNotificationSettings)); @@ -131,9 +236,9 @@ function SettingsPage() { Strategies - {strategies && ( + {strategiesString && ( )} From 5ded75fbb7ac2eea2442d23e8d12c6517155efc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Mon, 18 Nov 2024 15:47:14 +0100 Subject: [PATCH 04/11] add icon to connect node --- src/components/ConnectNode/index.tsx | 21 ++++---------- src/components/ConnectNode/modal.tsx | 8 +++++ .../Select/index.tsx | 29 ++++++++++++++++--- src/index.css | 12 ++++++++ src/utils/functions.ts | 28 ++++++++++++++++++ 5 files changed, 79 insertions(+), 19 deletions(-) diff --git a/src/components/ConnectNode/index.tsx b/src/components/ConnectNode/index.tsx index 6ffb71b3..57f6a93a 100644 --- a/src/components/ConnectNode/index.tsx +++ b/src/components/ConnectNode/index.tsx @@ -1,8 +1,7 @@ import React, { useState, useEffect, useRef } from 'react'; import styled from '@emotion/styled'; import { Link, useNavigate } from 'react-router-dom'; -// @ts-ignore -import jazzicon, { } from "@metamask/jazzicon"; +import { generateBase64Jazz } from '../../utils/functions'; // Components import Modal from './modal'; @@ -106,7 +105,7 @@ export default function ConnectNode() { `${localName?.substring(0,5)}…${localName?.substring(localName.length-11,localName.length)}` : localName; - const nodeAddress = useAppSelector((store)=> store.node.addresses.data.native); + const apiEndpoint = useAppSelector((store) => store.auth.loginData.apiEndpoint); const [nodeAddressIcon, set_nodeAddressIcon] = useState(null); const [anchorEl, setAnchorEl] = useState(null); // State variable to hold the anchor element for the menu @@ -127,18 +126,10 @@ export default function ConnectNode() { }, []); useEffect(() => { - if(!nodeAddress) return; - try{ - const jazzSvg = jazzicon(16, parseInt(nodeAddress.slice(2, 10), 16)); - const html = jazzSvg.children[0].outerHTML.replace(' { if (error) set_modalVisible(true); diff --git a/src/components/ConnectNode/modal.tsx b/src/components/ConnectNode/modal.tsx index 7849738c..23ad35f2 100644 --- a/src/components/ConnectNode/modal.tsx +++ b/src/components/ConnectNode/modal.tsx @@ -4,6 +4,7 @@ import { useAppDispatch, useAppSelector } from '../../store'; import styled from '@emotion/styled'; import { trackGoal } from 'fathom-client'; import { parseAndFormatUrl } from '../../utils/parseAndFormatUrl'; +import { generateBase64Jazz } from '../../utils/functions'; // Stores import { authActions, authActionsAsync } from '../../store/slices/auth'; @@ -352,6 +353,12 @@ function ConnectNodeModal(props: ConnectNodeModalProps) { set_localName(chosenNode.localName); }; + // useEffect(() => { + // if(!apiEndpoint) return; + // const b64 = generateBase64Jazz(apiEndpoint); + // if(b64) set_nodeAddressIcon(b64); + // }, [apiEndpoint]); + return ( <> diff --git a/src/future-hopr-lib-components/Select/index.tsx b/src/future-hopr-lib-components/Select/index.tsx index 9f514954..7098d128 100644 --- a/src/future-hopr-lib-components/Select/index.tsx +++ b/src/future-hopr-lib-components/Select/index.tsx @@ -8,6 +8,7 @@ import FormControl from '@mui/material/FormControl'; import SelectMui, { SelectProps as SelectMuiProps } from '@mui/material/Select'; import { Tooltip, IconButton } from '@mui/material'; import DeleteIcon from '@mui/icons-material/Delete'; +import { generateBase64Jazz } from '../../utils/functions'; const SFormControl = styled(FormControl)` margin-bottom: 16px; @@ -26,14 +27,25 @@ const SFormControl = styled(FormControl)` display: none; } } + + .select-menu-item-text { + margin-left: 30px; + } + + img.node-jazz-icon{ + position: fixed; + } + `; interface Props extends SelectMuiProps { removeValue?: (value: number) => void; removeValueTooltip?: string; + showJazzIcon?: boolean; values?: { value: string | number; name: string | number | null; + apiEndpoint: string | null; disabled?: boolean; }[]; native?: boolean; @@ -55,14 +67,23 @@ const Select: React.FC = (props) => { MenuProps={{ disableScrollLock: true }} > {props.values && - props.values.map((elem, index) => ( - { + const icon = elem.apiEndpoint && generateBase64Jazz(elem.apiEndpoint); + return ( - {elem.name} + { + props.showJazzIcon && + + } + {elem.name} {props.removeValue && ( = (props) => { )} - ))} + )})} ); diff --git a/src/index.css b/src/index.css index 38c28071..c4e5e7b8 100644 --- a/src/index.css +++ b/src/index.css @@ -110,3 +110,15 @@ li.selected-safe { .inline { display: inline; } + +img.node-jazz-icon { + margin-right: 10px; + border-radius: 30px; + background: rgb(3, 94, 91); + height: 22px; + width: 22px; +} + +span.select-menu-item-text{ + flex-grow: 1; +} \ No newline at end of file diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 17c76eee..09f8612e 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -1,3 +1,6 @@ +// @ts-ignore +import jazzicon from "@metamask/jazzicon"; + export function bubbleSortObject(arr: any[], key: string | number) { for (let i = 0; i < arr.length; i++) { // Last i elements are already in place @@ -135,3 +138,28 @@ function unround(value: string) { return ''; } } + +export function toHex(str:String) { + var result = ''; + for (var i=0; i(d:String){var r = M(V(Y(X(d),8*d.length)));return r.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_} + + +export function generateBase64Jazz(string: String){ + try { + const md5 = toHexMD5(string); + const jazzSvg = jazzicon(16, parseInt(md5.slice(2, 10), 16)); + const html = jazzSvg.children[0].outerHTML.replace(' Date: Mon, 18 Nov 2024 16:04:06 +0100 Subject: [PATCH 05/11] make jazzicon apply styles in select only if its is turned on --- src/future-hopr-lib-components/Select/index.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/future-hopr-lib-components/Select/index.tsx b/src/future-hopr-lib-components/Select/index.tsx index 7098d128..433b4167 100644 --- a/src/future-hopr-lib-components/Select/index.tsx +++ b/src/future-hopr-lib-components/Select/index.tsx @@ -28,12 +28,14 @@ const SFormControl = styled(FormControl)` } } - .select-menu-item-text { + &.showJazzIcon{ + .select-menu-item-text { margin-left: 30px; } - img.node-jazz-icon{ - position: fixed; + img.node-jazz-icon{ + position: fixed; + } } `; @@ -53,7 +55,10 @@ interface Props extends SelectMuiProps { const Select: React.FC = (props) => { return ( - + {props.label} Date: Mon, 18 Nov 2024 16:26:23 +0100 Subject: [PATCH 06/11] cleanup --- src/components/ConnectNode/index.tsx | 3 +-- src/components/ConnectNode/modal.tsx | 7 ------- src/pages/node/configuration.tsx | 2 -- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/components/ConnectNode/index.tsx b/src/components/ConnectNode/index.tsx index 57f6a93a..9df8a7d9 100644 --- a/src/components/ConnectNode/index.tsx +++ b/src/components/ConnectNode/index.tsx @@ -93,7 +93,6 @@ const Overlay = styled.div` export default function ConnectNode() { const dispatch = useAppDispatch(); const navigate = useNavigate(); - const ref = useRef(null); const [modalVisible, set_modalVisible] = useState(false); const connected = useAppSelector((store) => store.auth.status.connected); const connecting = useAppSelector((store) => store.auth.status.connecting); @@ -183,7 +182,7 @@ export default function ConnectNode() { onClick={handleContainerClick} ref={containerRef} > -
+
diff --git a/src/components/ConnectNode/modal.tsx b/src/components/ConnectNode/modal.tsx index 23ad35f2..bf9e46a5 100644 --- a/src/components/ConnectNode/modal.tsx +++ b/src/components/ConnectNode/modal.tsx @@ -4,7 +4,6 @@ import { useAppDispatch, useAppSelector } from '../../store'; import styled from '@emotion/styled'; import { trackGoal } from 'fathom-client'; import { parseAndFormatUrl } from '../../utils/parseAndFormatUrl'; -import { generateBase64Jazz } from '../../utils/functions'; // Stores import { authActions, authActionsAsync } from '../../store/slices/auth'; @@ -353,12 +352,6 @@ function ConnectNodeModal(props: ConnectNodeModalProps) { set_localName(chosenNode.localName); }; - // useEffect(() => { - // if(!apiEndpoint) return; - // const b64 = generateBase64Jazz(apiEndpoint); - // if(b64) set_nodeAddressIcon(b64); - // }, [apiEndpoint]); - return ( <> Date: Mon, 18 Nov 2024 16:26:37 +0100 Subject: [PATCH 07/11] format --- src/components/ConnectNode/index.tsx | 30 +- .../Select/index.tsx | 72 ++-- src/index.css | 4 +- src/pages/node/configuration.tsx | 69 ++-- src/utils/functions.ts | 391 +++++++++++++++++- 5 files changed, 470 insertions(+), 96 deletions(-) diff --git a/src/components/ConnectNode/index.tsx b/src/components/ConnectNode/index.tsx index 9df8a7d9..1b35d63d 100644 --- a/src/components/ConnectNode/index.tsx +++ b/src/components/ConnectNode/index.tsx @@ -64,7 +64,7 @@ const NodeButton = styled.div` color: #414141; line-height: 12px; } - .node-info-localname{ + .node-info-localname { font-weight: 700; color: #000050; } @@ -100,10 +100,10 @@ export default function ConnectNode() { const openLoginModalToNode = useAppSelector((store) => store.auth.helper.openLoginModalToNode); const peerId = useAppSelector((store) => store.node.addresses.data.hopr); const localName = useAppSelector((store) => store.auth.loginData.localName); - const localNameToDisplay = localName && localName.length > 17 ? - `${localName?.substring(0,5)}…${localName?.substring(localName.length-11,localName.length)}` - : - localName; + const localNameToDisplay = + localName && localName.length > 17 + ? `${localName?.substring(0, 5)}…${localName?.substring(localName.length - 11, localName.length)}` + : localName; const apiEndpoint = useAppSelector((store) => store.auth.loginData.apiEndpoint); const [nodeAddressIcon, set_nodeAddressIcon] = useState(null); const [anchorEl, setAnchorEl] = useState(null); // State variable to hold the anchor element for the menu @@ -125,9 +125,9 @@ export default function ConnectNode() { }, []); useEffect(() => { - if(!apiEndpoint) return; + if (!apiEndpoint) return; const b64 = generateBase64Jazz(apiEndpoint); - if(b64) set_nodeAddressIcon(b64); + if (b64) set_nodeAddressIcon(b64); }, [apiEndpoint]); useEffect(() => { @@ -182,21 +182,17 @@ export default function ConnectNode() { onClick={handleContainerClick} ref={containerRef} > -
- +
+
{connected ? ( <> - { - localNameToDisplay && -

- {localNameToDisplay} -

- } + {localNameToDisplay &&

{localNameToDisplay}

}

{peerId && `${peerId.substring(0, 6)}...${peerId.substring(peerId.length - 8, peerId.length)}`}

diff --git a/src/future-hopr-lib-components/Select/index.tsx b/src/future-hopr-lib-components/Select/index.tsx index 433b4167..8d189e77 100644 --- a/src/future-hopr-lib-components/Select/index.tsx +++ b/src/future-hopr-lib-components/Select/index.tsx @@ -28,16 +28,15 @@ const SFormControl = styled(FormControl)` } } - &.showJazzIcon{ + &.showJazzIcon { .select-menu-item-text { - margin-left: 30px; - } + margin-left: 30px; + } - img.node-jazz-icon{ + img.node-jazz-icon { position: fixed; } } - `; interface Props extends SelectMuiProps { @@ -74,37 +73,38 @@ const Select: React.FC = (props) => { {props.values && props.values.map((elem, index) => { const icon = elem.apiEndpoint && generateBase64Jazz(elem.apiEndpoint); - return ( - { - props.showJazzIcon && - - } - {elem.name} - {props.removeValue && ( - - { - event.stopPropagation(); - props?.removeValue?.(Number(elem.value)); - }} - > - - - - )} - - )})} + return ( + + {props.showJazzIcon && ( + + )} + {elem.name} + {props.removeValue && ( + + { + event.stopPropagation(); + props?.removeValue?.(Number(elem.value)); + }} + > + + + + )} + + ); + })} ); diff --git a/src/index.css b/src/index.css index c4e5e7b8..3e610804 100644 --- a/src/index.css +++ b/src/index.css @@ -119,6 +119,6 @@ img.node-jazz-icon { width: 22px; } -span.select-menu-item-text{ +span.select-menu-item-text { flex-grow: 1; -} \ No newline at end of file +} diff --git a/src/pages/node/configuration.tsx b/src/pages/node/configuration.tsx index a11e06b8..7f34b8ec 100644 --- a/src/pages/node/configuration.tsx +++ b/src/pages/node/configuration.tsx @@ -37,98 +37,103 @@ function SettingsPage() { if (strategies) { let tmp = JSON.stringify(strategies, null, 2); - try{ - if(ticketPrice) { + try { + if (ticketPrice) { // min_stake_threshold - if(strategies?.strategies?.AutoFunding?.min_stake_threshold){ + if (strategies?.strategies?.AutoFunding?.min_stake_threshold) { const key = 'min_stake_threshold'; - const min_stake_threshold = strategies.strategies.AutoFunding.min_stake_threshold.replace(' HOPR',''); - const min_stake_thresholdBigInt = BigInt(min_stake_threshold)*BigInt(1e18); + const min_stake_threshold = strategies.strategies.AutoFunding.min_stake_threshold.replace(' HOPR', ''); + const min_stake_thresholdBigInt = BigInt(min_stake_threshold) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = min_stake_thresholdBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}"`; - if(tmp.includes(stringToReplace+',')) { + if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( - stringToReplace+',', - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}` + stringToReplace + ',', + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}` + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}`, ); } } // funding_amount - if(strategies?.strategies?.AutoFunding?.funding_amount){ + if (strategies?.strategies?.AutoFunding?.funding_amount) { const key = 'funding_amount'; - const funding_amount = strategies.strategies.AutoFunding.funding_amount.replace(' HOPR',''); - const funding_amountBigInt = BigInt(funding_amount)*BigInt(1e18); + const funding_amount = strategies.strategies.AutoFunding.funding_amount.replace(' HOPR', ''); + const funding_amountBigInt = BigInt(funding_amount) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = funding_amountBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding.funding_amount}"`; - if(tmp.includes(stringToReplace+',')) { + if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( - stringToReplace+',', - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}` + stringToReplace + ',', + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}` + `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}`, ); } } // minimum_redeem_ticket_value - if(strategies?.strategies?.AutoRedeeming?.minimum_redeem_ticket_value){ + if (strategies?.strategies?.AutoRedeeming?.minimum_redeem_ticket_value) { const key = 'minimum_redeem_ticket_value'; - const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value.replace(' HOPR',''); - const minimum_redeem_ticket_valueBigInt = BigInt(minimum_redeem_ticket_value)*BigInt(1e18); + const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value.replace( + ' HOPR', + '', + ); + const minimum_redeem_ticket_valueBigInt = BigInt(minimum_redeem_ticket_value) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = minimum_redeem_ticket_valueBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}"`; - if(tmp.includes(stringToReplace+',')) { + if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( - stringToReplace+',', - `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}", // tickets: ${ticketsString}` + stringToReplace + ',', + `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}" // tickets: ${ticketsString}` + `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}" // tickets: ${ticketsString}`, ); } } // on_close_redeem_single_tickets_value_min - if(strategies?.strategies?.AutoRedeeming?.on_close_redeem_single_tickets_value_min){ + if (strategies?.strategies?.AutoRedeeming?.on_close_redeem_single_tickets_value_min) { const key = 'on_close_redeem_single_tickets_value_min'; - const on_close_redeem_single_tickets_value_min = strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min.replace(' HOPR',''); - const on_close_redeem_single_tickets_value_minBigInt = BigInt(on_close_redeem_single_tickets_value_min)*BigInt(1e18); + const on_close_redeem_single_tickets_value_min = + strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min.replace(' HOPR', ''); + const on_close_redeem_single_tickets_value_minBigInt = + BigInt(on_close_redeem_single_tickets_value_min) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = on_close_redeem_single_tickets_value_minBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}"`; - if(tmp.includes(stringToReplace+',')) { + if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( - stringToReplace+',', - `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}", // tickets: ${ticketsString}` + stringToReplace + ',', + `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}" // tickets: ${ticketsString}` + `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}" // tickets: ${ticketsString}`, ); } } } - } catch(e) { - console.warn('Error while counting strategies against current ticket price.', e) + } catch (e) { + console.warn('Error while counting strategies against current ticket price.', e); } set_strategiesString(tmp); diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 09f8612e..2b698eab 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -1,5 +1,5 @@ // @ts-ignore -import jazzicon from "@metamask/jazzicon"; +import jazzicon from '@metamask/jazzicon'; export function bubbleSortObject(arr: any[], key: string | number) { for (let i = 0; i < arr.length; i++) { @@ -139,27 +139,400 @@ function unround(value: string) { } } -export function toHex(str:String) { +export function toHex(str: string) { var result = ''; - for (var i=0; i(d:String){var r = M(V(Y(X(d),8*d.length)));return r.toLowerCase()};function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_} - +export function toHexMD5(d: string) { + var r = M(V(Y(X(d), 8 * d.length))); + return r.toLowerCase(); +} +function M(d) { + for (var _, m = '0123456789ABCDEF', f = '', r = 0; r < d.length; r++) + (_ = d.charCodeAt(r)), (f += m.charAt((_ >>> 4) & 15) + m.charAt(15 & _)); + return f; +} +function X(d) { + for (var _ = Array(d.length >> 2), m = 0; m < _.length; m++) _[m] = 0; + for (m = 0; m < 8 * d.length; m += 8) _[m >> 5] |= (255 & d.charCodeAt(m / 8)) << m % 32; + return _; +} +function V(d) { + for (var _ = '', m = 0; m < 32 * d.length; m += 8) _ += String.fromCharCode((d[m >> 5] >>> m % 32) & 255); + return _; +} +function Y(d, _) { + (d[_ >> 5] |= 128 << _ % 32), (d[14 + (((_ + 64) >>> 9) << 4)] = _); + for (var m = 1732584193, f = -271733879, r = -1732584194, i = 271733878, n = 0; n < d.length; n += 16) { + var h = m, + t = f, + g = r, + e = i; + (f = md5_ii( + (f = md5_ii( + (f = md5_ii( + (f = md5_ii( + (f = md5_hh( + (f = md5_hh( + (f = md5_hh( + (f = md5_hh( + (f = md5_gg( + (f = md5_gg( + (f = md5_gg( + (f = md5_gg( + (f = md5_ff( + (f = md5_ff( + (f = md5_ff( + (f = md5_ff( + f, + (r = md5_ff( + r, + (i = md5_ff( + i, + (m = md5_ff(m, f, r, i, d[n + 0], 7, -680876936)), + f, + r, + d[n + 1], + 12, + -389564586, + )), + m, + f, + d[n + 2], + 17, + 606105819, + )), + i, + m, + d[n + 3], + 22, + -1044525330, + )), + (r = md5_ff( + r, + (i = md5_ff( + i, + (m = md5_ff(m, f, r, i, d[n + 4], 7, -176418897)), + f, + r, + d[n + 5], + 12, + 1200080426, + )), + m, + f, + d[n + 6], + 17, + -1473231341, + )), + i, + m, + d[n + 7], + 22, + -45705983, + )), + (r = md5_ff( + r, + (i = md5_ff( + i, + (m = md5_ff(m, f, r, i, d[n + 8], 7, 1770035416)), + f, + r, + d[n + 9], + 12, + -1958414417, + )), + m, + f, + d[n + 10], + 17, + -42063, + )), + i, + m, + d[n + 11], + 22, + -1990404162, + )), + (r = md5_ff( + r, + (i = md5_ff( + i, + (m = md5_ff(m, f, r, i, d[n + 12], 7, 1804603682)), + f, + r, + d[n + 13], + 12, + -40341101, + )), + m, + f, + d[n + 14], + 17, + -1502002290, + )), + i, + m, + d[n + 15], + 22, + 1236535329, + )), + (r = md5_gg( + r, + (i = md5_gg( + i, + (m = md5_gg(m, f, r, i, d[n + 1], 5, -165796510)), + f, + r, + d[n + 6], + 9, + -1069501632, + )), + m, + f, + d[n + 11], + 14, + 643717713, + )), + i, + m, + d[n + 0], + 20, + -373897302, + )), + (r = md5_gg( + r, + (i = md5_gg( + i, + (m = md5_gg(m, f, r, i, d[n + 5], 5, -701558691)), + f, + r, + d[n + 10], + 9, + 38016083, + )), + m, + f, + d[n + 15], + 14, + -660478335, + )), + i, + m, + d[n + 4], + 20, + -405537848, + )), + (r = md5_gg( + r, + (i = md5_gg( + i, + (m = md5_gg(m, f, r, i, d[n + 9], 5, 568446438)), + f, + r, + d[n + 14], + 9, + -1019803690, + )), + m, + f, + d[n + 3], + 14, + -187363961, + )), + i, + m, + d[n + 8], + 20, + 1163531501, + )), + (r = md5_gg( + r, + (i = md5_gg( + i, + (m = md5_gg(m, f, r, i, d[n + 13], 5, -1444681467)), + f, + r, + d[n + 2], + 9, + -51403784, + )), + m, + f, + d[n + 7], + 14, + 1735328473, + )), + i, + m, + d[n + 12], + 20, + -1926607734, + )), + (r = md5_hh( + r, + (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 5], 4, -378558)), f, r, d[n + 8], 11, -2022574463)), + m, + f, + d[n + 11], + 16, + 1839030562, + )), + i, + m, + d[n + 14], + 23, + -35309556, + )), + (r = md5_hh( + r, + (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 1], 4, -1530992060)), f, r, d[n + 4], 11, 1272893353)), + m, + f, + d[n + 7], + 16, + -155497632, + )), + i, + m, + d[n + 10], + 23, + -1094730640, + )), + (r = md5_hh( + r, + (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 13], 4, 681279174)), f, r, d[n + 0], 11, -358537222)), + m, + f, + d[n + 3], + 16, + -722521979, + )), + i, + m, + d[n + 6], + 23, + 76029189, + )), + (r = md5_hh( + r, + (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 9], 4, -640364487)), f, r, d[n + 12], 11, -421815835)), + m, + f, + d[n + 15], + 16, + 530742520, + )), + i, + m, + d[n + 2], + 23, + -995338651, + )), + (r = md5_ii( + r, + (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 0], 6, -198630844)), f, r, d[n + 7], 10, 1126891415)), + m, + f, + d[n + 14], + 15, + -1416354905, + )), + i, + m, + d[n + 5], + 21, + -57434055, + )), + (r = md5_ii( + r, + (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 12], 6, 1700485571)), f, r, d[n + 3], 10, -1894986606)), + m, + f, + d[n + 10], + 15, + -1051523, + )), + i, + m, + d[n + 1], + 21, + -2054922799, + )), + (r = md5_ii( + r, + (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 8], 6, 1873313359)), f, r, d[n + 15], 10, -30611744)), + m, + f, + d[n + 6], + 15, + -1560198380, + )), + i, + m, + d[n + 13], + 21, + 1309151649, + )), + (r = md5_ii( + r, + (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 4], 6, -145523070)), f, r, d[n + 11], 10, -1120210379)), + m, + f, + d[n + 2], + 15, + 718787259, + )), + i, + m, + d[n + 9], + 21, + -343485551, + )), + (m = safe_add(m, h)), + (f = safe_add(f, t)), + (r = safe_add(r, g)), + (i = safe_add(i, e)); + } + return [m, f, r, i]; +} +function md5_cmn(d, _, m, f, r, i) { + return safe_add(bit_rol(safe_add(safe_add(_, d), safe_add(f, i)), r), m); +} +function md5_ff(d, _, m, f, r, i, n) { + return md5_cmn((_ & m) | (~_ & f), d, _, r, i, n); +} +function md5_gg(d, _, m, f, r, i, n) { + return md5_cmn((_ & f) | (m & ~f), d, _, r, i, n); +} +function md5_hh(d, _, m, f, r, i, n) { + return md5_cmn(_ ^ m ^ f, d, _, r, i, n); +} +function md5_ii(d, _, m, f, r, i, n) { + return md5_cmn(m ^ (_ | ~f), d, _, r, i, n); +} +function safe_add(d, _) { + var m = (65535 & d) + (65535 & _); + return (((d >> 16) + (_ >> 16) + (m >> 16)) << 16) | (65535 & m); +} +function bit_rol(d, _) { + return (d << _) | (d >>> (32 - _)); +} -export function generateBase64Jazz(string: String){ +export function generateBase64Jazz(string: string) { try { const md5 = toHexMD5(string); const jazzSvg = jazzicon(16, parseInt(md5.slice(2, 10), 16)); - const html = jazzSvg.children[0].outerHTML.replace(' Date: Mon, 18 Nov 2024 16:56:39 +0100 Subject: [PATCH 08/11] formatg --- .prettierignore | 4 +- src/utils/functions.ts | 390 +---------------------------------------- 2 files changed, 11 insertions(+), 383 deletions(-) diff --git a/.prettierignore b/.prettierignore index 2cdfed29..397acbd4 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,4 +6,6 @@ public/ src/index.tsx # Created by github pipeline -gha-creds-*.json \ No newline at end of file +gha-creds-*.json + +src/utils/functions.ts \ No newline at end of file diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 2b698eab..0919d089 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -1,5 +1,5 @@ // @ts-ignore -import jazzicon from '@metamask/jazzicon'; +import jazzicon from "@metamask/jazzicon"; export function bubbleSortObject(arr: any[], key: string | number) { for (let i = 0; i < arr.length; i++) { @@ -139,400 +139,26 @@ function unround(value: string) { } } -export function toHex(str: string) { +export function toHex(str:string) { var result = ''; - for (var i = 0; i < str.length; i++) { + for (var i=0; i(d: string) { - var r = M(V(Y(X(d), 8 * d.length))); - return r.toLowerCase(); -} -function M(d) { - for (var _, m = '0123456789ABCDEF', f = '', r = 0; r < d.length; r++) - (_ = d.charCodeAt(r)), (f += m.charAt((_ >>> 4) & 15) + m.charAt(15 & _)); - return f; -} -function X(d) { - for (var _ = Array(d.length >> 2), m = 0; m < _.length; m++) _[m] = 0; - for (m = 0; m < 8 * d.length; m += 8) _[m >> 5] |= (255 & d.charCodeAt(m / 8)) << m % 32; - return _; -} -function V(d) { - for (var _ = '', m = 0; m < 32 * d.length; m += 8) _ += String.fromCharCode((d[m >> 5] >>> m % 32) & 255); - return _; -} -function Y(d, _) { - (d[_ >> 5] |= 128 << _ % 32), (d[14 + (((_ + 64) >>> 9) << 4)] = _); - for (var m = 1732584193, f = -271733879, r = -1732584194, i = 271733878, n = 0; n < d.length; n += 16) { - var h = m, - t = f, - g = r, - e = i; - (f = md5_ii( - (f = md5_ii( - (f = md5_ii( - (f = md5_ii( - (f = md5_hh( - (f = md5_hh( - (f = md5_hh( - (f = md5_hh( - (f = md5_gg( - (f = md5_gg( - (f = md5_gg( - (f = md5_gg( - (f = md5_ff( - (f = md5_ff( - (f = md5_ff( - (f = md5_ff( - f, - (r = md5_ff( - r, - (i = md5_ff( - i, - (m = md5_ff(m, f, r, i, d[n + 0], 7, -680876936)), - f, - r, - d[n + 1], - 12, - -389564586, - )), - m, - f, - d[n + 2], - 17, - 606105819, - )), - i, - m, - d[n + 3], - 22, - -1044525330, - )), - (r = md5_ff( - r, - (i = md5_ff( - i, - (m = md5_ff(m, f, r, i, d[n + 4], 7, -176418897)), - f, - r, - d[n + 5], - 12, - 1200080426, - )), - m, - f, - d[n + 6], - 17, - -1473231341, - )), - i, - m, - d[n + 7], - 22, - -45705983, - )), - (r = md5_ff( - r, - (i = md5_ff( - i, - (m = md5_ff(m, f, r, i, d[n + 8], 7, 1770035416)), - f, - r, - d[n + 9], - 12, - -1958414417, - )), - m, - f, - d[n + 10], - 17, - -42063, - )), - i, - m, - d[n + 11], - 22, - -1990404162, - )), - (r = md5_ff( - r, - (i = md5_ff( - i, - (m = md5_ff(m, f, r, i, d[n + 12], 7, 1804603682)), - f, - r, - d[n + 13], - 12, - -40341101, - )), - m, - f, - d[n + 14], - 17, - -1502002290, - )), - i, - m, - d[n + 15], - 22, - 1236535329, - )), - (r = md5_gg( - r, - (i = md5_gg( - i, - (m = md5_gg(m, f, r, i, d[n + 1], 5, -165796510)), - f, - r, - d[n + 6], - 9, - -1069501632, - )), - m, - f, - d[n + 11], - 14, - 643717713, - )), - i, - m, - d[n + 0], - 20, - -373897302, - )), - (r = md5_gg( - r, - (i = md5_gg( - i, - (m = md5_gg(m, f, r, i, d[n + 5], 5, -701558691)), - f, - r, - d[n + 10], - 9, - 38016083, - )), - m, - f, - d[n + 15], - 14, - -660478335, - )), - i, - m, - d[n + 4], - 20, - -405537848, - )), - (r = md5_gg( - r, - (i = md5_gg( - i, - (m = md5_gg(m, f, r, i, d[n + 9], 5, 568446438)), - f, - r, - d[n + 14], - 9, - -1019803690, - )), - m, - f, - d[n + 3], - 14, - -187363961, - )), - i, - m, - d[n + 8], - 20, - 1163531501, - )), - (r = md5_gg( - r, - (i = md5_gg( - i, - (m = md5_gg(m, f, r, i, d[n + 13], 5, -1444681467)), - f, - r, - d[n + 2], - 9, - -51403784, - )), - m, - f, - d[n + 7], - 14, - 1735328473, - )), - i, - m, - d[n + 12], - 20, - -1926607734, - )), - (r = md5_hh( - r, - (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 5], 4, -378558)), f, r, d[n + 8], 11, -2022574463)), - m, - f, - d[n + 11], - 16, - 1839030562, - )), - i, - m, - d[n + 14], - 23, - -35309556, - )), - (r = md5_hh( - r, - (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 1], 4, -1530992060)), f, r, d[n + 4], 11, 1272893353)), - m, - f, - d[n + 7], - 16, - -155497632, - )), - i, - m, - d[n + 10], - 23, - -1094730640, - )), - (r = md5_hh( - r, - (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 13], 4, 681279174)), f, r, d[n + 0], 11, -358537222)), - m, - f, - d[n + 3], - 16, - -722521979, - )), - i, - m, - d[n + 6], - 23, - 76029189, - )), - (r = md5_hh( - r, - (i = md5_hh(i, (m = md5_hh(m, f, r, i, d[n + 9], 4, -640364487)), f, r, d[n + 12], 11, -421815835)), - m, - f, - d[n + 15], - 16, - 530742520, - )), - i, - m, - d[n + 2], - 23, - -995338651, - )), - (r = md5_ii( - r, - (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 0], 6, -198630844)), f, r, d[n + 7], 10, 1126891415)), - m, - f, - d[n + 14], - 15, - -1416354905, - )), - i, - m, - d[n + 5], - 21, - -57434055, - )), - (r = md5_ii( - r, - (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 12], 6, 1700485571)), f, r, d[n + 3], 10, -1894986606)), - m, - f, - d[n + 10], - 15, - -1051523, - )), - i, - m, - d[n + 1], - 21, - -2054922799, - )), - (r = md5_ii( - r, - (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 8], 6, 1873313359)), f, r, d[n + 15], 10, -30611744)), - m, - f, - d[n + 6], - 15, - -1560198380, - )), - i, - m, - d[n + 13], - 21, - 1309151649, - )), - (r = md5_ii( - r, - (i = md5_ii(i, (m = md5_ii(m, f, r, i, d[n + 4], 6, -145523070)), f, r, d[n + 11], 10, -1120210379)), - m, - f, - d[n + 2], - 15, - 718787259, - )), - i, - m, - d[n + 9], - 21, - -343485551, - )), - (m = safe_add(m, h)), - (f = safe_add(f, t)), - (r = safe_add(r, g)), - (i = safe_add(i, e)); - } - return [m, f, r, i]; -} -function md5_cmn(d, _, m, f, r, i) { - return safe_add(bit_rol(safe_add(safe_add(_, d), safe_add(f, i)), r), m); -} -function md5_ff(d, _, m, f, r, i, n) { - return md5_cmn((_ & m) | (~_ & f), d, _, r, i, n); -} -function md5_gg(d, _, m, f, r, i, n) { - return md5_cmn((_ & f) | (m & ~f), d, _, r, i, n); -} -function md5_hh(d, _, m, f, r, i, n) { - return md5_cmn(_ ^ m ^ f, d, _, r, i, n); -} -function md5_ii(d, _, m, f, r, i, n) { - return md5_cmn(m ^ (_ | ~f), d, _, r, i, n); -} -function safe_add(d, _) { - var m = (65535 & d) + (65535 & _); - return (((d >> 16) + (_ >> 16) + (m >> 16)) << 16) | (65535 & m); -} -function bit_rol(d, _) { - return (d << _) | (d >>> (32 - _)); -} +export function toHexMD5(d:string){var r = M(V(Y(X(d),8*d.length)));return r.toLowerCase()}function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_} -export function generateBase64Jazz(string: string) { +export function generateBase64Jazz(string: string){ try { const md5 = toHexMD5(string); const jazzSvg = jazzicon(16, parseInt(md5.slice(2, 10), 16)); - const html = jazzSvg.children[0].outerHTML.replace(' Date: Tue, 19 Nov 2024 10:10:53 +0100 Subject: [PATCH 09/11] make icon generation better --- src/components/ConnectNode/index.tsx | 6 ++-- .../Select/index.tsx | 9 ++++-- src/index.css | 5 ++- src/pages/node/configuration.tsx | 32 +++++++++---------- src/utils/functions.ts | 8 +++-- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/components/ConnectNode/index.tsx b/src/components/ConnectNode/index.tsx index 1b35d63d..bd3b7e01 100644 --- a/src/components/ConnectNode/index.tsx +++ b/src/components/ConnectNode/index.tsx @@ -42,7 +42,6 @@ const Container = styled(Button)` height: 38px; width: 38px; border-radius: 50px; - background: rgb(3, 94, 91); } } `; @@ -186,7 +185,10 @@ export default function ConnectNode() { className="image-container" id="jazz-icon-node" > - +
{connected ? ( <> diff --git a/src/future-hopr-lib-components/Select/index.tsx b/src/future-hopr-lib-components/Select/index.tsx index 8d189e77..211d5395 100644 --- a/src/future-hopr-lib-components/Select/index.tsx +++ b/src/future-hopr-lib-components/Select/index.tsx @@ -30,11 +30,14 @@ const SFormControl = styled(FormControl)` &.showJazzIcon { .select-menu-item-text { - margin-left: 30px; + margin-left: 27px; } img.node-jazz-icon { - position: fixed; + position: absolute; + left: 12px; + top: 50%; + transform: translateY(-50%); } } `; @@ -83,7 +86,7 @@ const Select: React.FC = (props) => { > {props.showJazzIcon && ( )} diff --git a/src/index.css b/src/index.css index 3e610804..e3c6fdf4 100644 --- a/src/index.css +++ b/src/index.css @@ -114,11 +114,14 @@ li.selected-safe { img.node-jazz-icon { margin-right: 10px; border-radius: 30px; - background: rgb(3, 94, 91); height: 22px; width: 22px; } +img.node-jazz-icon-present { + background: rgb(3, 94, 91); +} + span.select-menu-item-text { flex-grow: 1; } diff --git a/src/pages/node/configuration.tsx b/src/pages/node/configuration.tsx index 7f34b8ec..2a41c5ce 100644 --- a/src/pages/node/configuration.tsx +++ b/src/pages/node/configuration.tsx @@ -42,21 +42,21 @@ function SettingsPage() { // min_stake_threshold if (strategies?.strategies?.AutoFunding?.min_stake_threshold) { const key = 'min_stake_threshold'; - const min_stake_threshold = strategies.strategies.AutoFunding.min_stake_threshold.replace(' HOPR', ''); + const min_stake_threshold = strategies.strategies.AutoFunding[key].replace(' HOPR', ''); const min_stake_thresholdBigInt = BigInt(min_stake_threshold) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = min_stake_thresholdBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); - const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}"`; + const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding[key]}"`; if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( stringToReplace + ',', - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoFunding[key]}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoFunding[key]}" // tickets: ${ticketsString}`, ); } } @@ -64,21 +64,21 @@ function SettingsPage() { // funding_amount if (strategies?.strategies?.AutoFunding?.funding_amount) { const key = 'funding_amount'; - const funding_amount = strategies.strategies.AutoFunding.funding_amount.replace(' HOPR', ''); + const funding_amount = strategies.strategies.AutoFunding[key].replace(' HOPR', ''); const funding_amountBigInt = BigInt(funding_amount) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = funding_amountBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); - const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding.funding_amount}"`; + const stringToReplace = `"${key}": "${strategies.strategies.AutoFunding[key]}"`; if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( stringToReplace + ',', - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}", // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoFunding[key]}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoFunding.min_stake_threshold}" // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoFunding[key]}" // tickets: ${ticketsString}`, ); } } @@ -86,7 +86,7 @@ function SettingsPage() { // minimum_redeem_ticket_value if (strategies?.strategies?.AutoRedeeming?.minimum_redeem_ticket_value) { const key = 'minimum_redeem_ticket_value'; - const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value.replace( + const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming[key].replace( ' HOPR', '', ); @@ -94,16 +94,16 @@ function SettingsPage() { const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = minimum_redeem_ticket_valueBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); - const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}"`; + const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming[key]}"`; if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( stringToReplace + ',', - `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}", // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoRedeeming[key]}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoRedeeming.minimum_redeem_ticket_value}" // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoRedeeming[key]}" // tickets: ${ticketsString}`, ); } } @@ -112,22 +112,22 @@ function SettingsPage() { if (strategies?.strategies?.AutoRedeeming?.on_close_redeem_single_tickets_value_min) { const key = 'on_close_redeem_single_tickets_value_min'; const on_close_redeem_single_tickets_value_min = - strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min.replace(' HOPR', ''); + strategies.strategies.AutoRedeeming[key].replace(' HOPR', ''); const on_close_redeem_single_tickets_value_minBigInt = BigInt(on_close_redeem_single_tickets_value_min) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = on_close_redeem_single_tickets_value_minBigInt / ticketBigInt; const ticketsString = ticketsBigInt.toString(); - const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}"`; + const stringToReplace = `"${key}": "${strategies.strategies.AutoRedeeming[key]}"`; if (tmp.includes(stringToReplace + ',')) { tmp = tmp.replace( stringToReplace + ',', - `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}", // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoRedeeming[key]}", // tickets: ${ticketsString}`, ); } else { tmp = tmp.replace( stringToReplace, - `"${key}": "${strategies.strategies.AutoRedeeming.on_close_redeem_single_tickets_value_min}" // tickets: ${ticketsString}`, + `"${key}": "${strategies.strategies.AutoRedeeming[key]}" // tickets: ${ticketsString}`, ); } } diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 0919d089..72e285ac 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -1,5 +1,6 @@ // @ts-ignore import jazzicon from "@metamask/jazzicon"; +import { createHash } from 'crypto'; export function bubbleSortObject(arr: any[], key: string | number) { for (let i = 0; i < arr.length; i++) { @@ -147,8 +148,9 @@ export function toHex(str:string) { return result; } -//@ts-ignore -export function toHexMD5(d:string){var r = M(V(Y(X(d),8*d.length)));return r.toLowerCase()}function M(d){for(var _,m="0123456789ABCDEF",f="",r=0;r>>4&15)+m.charAt(15&_);return f}function X(d){for(var _=Array(d.length>>2),m=0;m<_.length;m++)_[m]=0;for(m=0;m<8*d.length;m+=8)_[m>>5]|=(255&d.charCodeAt(m/8))<>5]>>>m%32&255);return _}function Y(d,_){d[_>>5]|=128<<_%32,d[14+(_+64>>>9<<4)]=_;for(var m=1732584193,f=-271733879,r=-1732584194,i=271733878,n=0;n>16)+(_>>16)+(m>>16)<<16|65535&m}function bit_rol(d,_){return d<<_|d>>>32-_} +export function toHexMD5(d: string) { + return createHash('md5').update(d).digest('hex'); +} export function generateBase64Jazz(string: string){ try { @@ -158,7 +160,7 @@ export function generateBase64Jazz(string: string){ const b64 = 'data:image/svg+xml;base64,' + btoa(html); return b64; } catch(e) { - console.log("Did not manage to create a jazzicon/") + console.log("Did not manage to create a jazzicon/", e) return null; } } From 9b96855b2bd12217c50c319f90bb70b0cfcc00fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Tue, 19 Nov 2024 10:11:21 +0100 Subject: [PATCH 10/11] format --- src/pages/node/configuration.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/node/configuration.tsx b/src/pages/node/configuration.tsx index 2a41c5ce..93a24558 100644 --- a/src/pages/node/configuration.tsx +++ b/src/pages/node/configuration.tsx @@ -86,10 +86,7 @@ function SettingsPage() { // minimum_redeem_ticket_value if (strategies?.strategies?.AutoRedeeming?.minimum_redeem_ticket_value) { const key = 'minimum_redeem_ticket_value'; - const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming[key].replace( - ' HOPR', - '', - ); + const minimum_redeem_ticket_value = strategies.strategies.AutoRedeeming[key].replace(' HOPR', ''); const minimum_redeem_ticket_valueBigInt = BigInt(minimum_redeem_ticket_value) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); const ticketsBigInt = minimum_redeem_ticket_valueBigInt / ticketBigInt; @@ -111,8 +108,10 @@ function SettingsPage() { // on_close_redeem_single_tickets_value_min if (strategies?.strategies?.AutoRedeeming?.on_close_redeem_single_tickets_value_min) { const key = 'on_close_redeem_single_tickets_value_min'; - const on_close_redeem_single_tickets_value_min = - strategies.strategies.AutoRedeeming[key].replace(' HOPR', ''); + const on_close_redeem_single_tickets_value_min = strategies.strategies.AutoRedeeming[key].replace( + ' HOPR', + '', + ); const on_close_redeem_single_tickets_value_minBigInt = BigInt(on_close_redeem_single_tickets_value_min) * BigInt(1e18); const ticketBigInt = BigInt(ticketPrice); From 3fb14330a6518ff653d9acb65ca826ae55cc7190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Jadach?= Date: Wed, 27 Nov 2024 11:39:26 +0100 Subject: [PATCH 11/11] format --- .prettierignore | 4 +--- src/utils/functions.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.prettierignore b/.prettierignore index 397acbd4..2cdfed29 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,4 @@ public/ src/index.tsx # Created by github pipeline -gha-creds-*.json - -src/utils/functions.ts \ No newline at end of file +gha-creds-*.json \ No newline at end of file diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 72e285ac..c6b1680d 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -1,5 +1,5 @@ // @ts-ignore -import jazzicon from "@metamask/jazzicon"; +import jazzicon from '@metamask/jazzicon'; import { createHash } from 'crypto'; export function bubbleSortObject(arr: any[], key: string | number) { @@ -140,9 +140,9 @@ function unround(value: string) { } } -export function toHex(str:string) { +export function toHex(str: string) { var result = ''; - for (var i=0; i