From 2706703382bcbdc2a074b3a75a5dfa94feb5ecff Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 31 Oct 2022 11:03:34 -0700 Subject: [PATCH] Add small fixes --- frontend/src/basic/BookPage/index.tsx | 2 + frontend/src/basic/Main.tsx | 38 +++++---- frontend/src/basic/MainDialogs/index.tsx | 21 +---- frontend/src/basic/SettingsPage/index.tsx | 2 +- frontend/src/basic/UserGenPage.js | 4 +- .../components/Charts/DepthChart/index.tsx | 4 +- .../components/Dialogs/CoordinatorSummary.tsx | 47 ++++------- frontend/src/components/Dialogs/Profile.tsx | 4 + frontend/src/components/Dialogs/Stats.tsx | 81 +++++++------------ .../src/components/SettingsForm/index.tsx | 6 +- frontend/src/models/Info.model.ts | 2 + frontend/src/models/Robot.model.ts | 8 +- 12 files changed, 94 insertions(+), 125 deletions(-) diff --git a/frontend/src/basic/BookPage/index.tsx b/frontend/src/basic/BookPage/index.tsx index a4c216455..23099d058 100644 --- a/frontend/src/basic/BookPage/index.tsx +++ b/frontend/src/basic/BookPage/index.tsx @@ -163,6 +163,7 @@ const BookPage = ({ limits={limits.list} maxWidth={chartWidthEm} // EM units maxHeight={windowSize.height * 0.825 - 5} // EM units + onOrderClicked={onOrderClicked} /> @@ -174,6 +175,7 @@ const BookPage = ({ limits={limits.list} maxWidth={windowSize.width * 0.8} // EM units maxHeight={windowSize.height * 0.825 - 5} // EM units + onOrderClicked={onOrderClicked} /> ) : ( { const basename = window.NativeRobosats === undefined ? '' : window.location.pathname; const entryPage: Page | '' = window.NativeRobosats === undefined ? window.location.pathname.split('/')[1] : ''; - const [page, setPage] = useState(entryPage == '' ? 'offers' : entryPage); + const [page, setPage] = useState(entryPage == '' ? 'robot' : entryPage); const [slideDirection, setSlideDirection] = useState({ in: undefined, out: undefined, @@ -134,6 +134,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { }; const fetchInfo = function () { + setInfo({ ...info, loading: true }); apiClient.get('/api/info/').then((data: Info) => { const versionInfo: any = checkVer(data.version.major, data.version.minor, data.version.patch); setInfo({ @@ -141,23 +142,27 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { openUpdateClient: versionInfo.updateAvailable, coordinatorVersion: versionInfo.coordinatorVersion, clientVersion: versionInfo.clientVersion, - }); - setSettings({ - ...settings, - network: data.network, + loading: false, }); }); }; useEffect(() => { - fetchInfo(); + if (open.stats || open.coordinator) { + fetchInfo(); + } }, [open.stats, open.coordinator]); - const fetchRobot = function () { + const fetchRobot = function ({ keys = false }) { const requestBody = { token_sha256: sha256(robot.token), }; + if (keys) { + requestBody.pub_key = robot.pubKey; + requestBody.enc_priv_key = robot.encPrivKey; + } + setRobot({ ...robot, loading: true }); apiClient.post('/api/user/', requestBody).then((data: any) => { setOrder( data.active_order_id @@ -171,7 +176,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { nickname: data.nickname, token: robot.token, loading: false, - avatarLoaded: false, + avatarLoaded: robot.nickname === data.nickname ? true : false, activeOrderId: data.active_order_id ? data.active_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null, referralCode: data.referral_code, @@ -182,18 +187,20 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { tgToken: data.tg_token, bitsEntropy: data.token_bits_entropy, shannonEntropy: data.token_shannon_entropy, - pub_key: data.public_key, - enc_priv_key: data.encrypted_private_key, + pubKey: data.public_key, + encPrivKey: data.encrypted_private_key, copiedToken: data.found ? true : robot.copiedToken, }); }); }; useEffect(() => { - if (robot.token && robot.nickname === null) { - fetchRobot(); + if (open.profile || (robot.token && robot.nickname === null)) { + fetchRobot({ keys: false }); // fetch existing robot + } else if (robot.token && robot.encPrivKey && robot.pubKey) { + fetchRobot({ keys: true }); // create new robot with existing token and keys (on network and coordinator change) } - }, []); + }, [open.profile, settings.network, settings.coordinator]); return ( @@ -213,7 +220,8 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => { > ( { )} /> - + setOpen({ ...open, coordinator: false })} - numPublicBuyOrders={info.num_public_buy_orders} - numPublicSellOrders={info.num_public_sell_orders} - bookLiquidity={info.book_liquidity} - activeRobotsToday={info.active_robots_today} - lastDayNonkycBtcPremium={info.last_day_nonkyc_btc_premium} - makerFee={info.maker_fee} - takerFee={info.taker_fee} - swapFeeRate={info.current_swap_fee_rate} + info={info} /> setOpen({ ...open, stats: false })} - coordinatorVersion={info.coordinatorVersion} - clientVersion={info.clientVersion} - lndVersion={info.lnd_version} - network={info.network} - nodeAlias={info.node_alias} - nodeId={info.node_id} - alternativeName={info.alternative_name} - alternativeSite={info.alternative_site} - commitHash={info.robosats_running_commit_hash} - lastDayVolume={info.last_day_volume} - lifetimeVolume={info.lifetime_volume} + info={info} /> diff --git a/frontend/src/basic/UserGenPage.js b/frontend/src/basic/UserGenPage.js index 964189694..15e7d0a9e 100644 --- a/frontend/src/basic/UserGenPage.js +++ b/frontend/src/basic/UserGenPage.js @@ -111,8 +111,8 @@ class UserGenPage extends Component { tgToken: data.tg_token, bitsEntropy: data.token_bits_entropy, shannonEntropy: data.token_shannon_entropy, - pub_key: data.public_key, - enc_priv_key: data.encrypted_private_key, + pubKey: data.public_key, + encPrivKey: data.encrypted_private_key, copiedToken: data.found ? true : this.props.robot.copiedToken, }) & systemClient.setCookie('robot_token', token) & diff --git a/frontend/src/components/Charts/DepthChart/index.tsx b/frontend/src/components/Charts/DepthChart/index.tsx index 796233ec9..438b98e2b 100644 --- a/frontend/src/components/Charts/DepthChart/index.tsx +++ b/frontend/src/components/Charts/DepthChart/index.tsx @@ -37,6 +37,7 @@ interface DepthChartProps { maxHeight: number; fillContainer?: boolean; elevation?: number; + onOrderClicked?: (id: number) => void; } const DepthChart: React.FC = ({ @@ -48,6 +49,7 @@ const DepthChart: React.FC = ({ maxHeight, fillContainer = false, elevation = 6, + onOrderClicked = () => null, }) => { const { t } = useTranslation(); const history = useHistory(); @@ -278,7 +280,7 @@ const DepthChart: React.FC = ({ }; const formatAxisY = (value: number): string => `${value}BTC`; const handleOnClick: PointMouseHandler = (point: Point) => { - history.push('/order/' + point.data?.order?.id); + onOrderClicked(point.data?.order?.id); }; const em = theme.typography.fontSize; diff --git a/frontend/src/components/Dialogs/CoordinatorSummary.tsx b/frontend/src/components/Dialogs/CoordinatorSummary.tsx index a6aea45e4..9194d80ee 100644 --- a/frontend/src/components/Dialogs/CoordinatorSummary.tsx +++ b/frontend/src/components/Dialogs/CoordinatorSummary.tsx @@ -11,6 +11,7 @@ import { ListItem, ListItemIcon, Typography, + LinearProgress, } from '@mui/material'; import InventoryIcon from '@mui/icons-material/Inventory'; @@ -22,39 +23,25 @@ import BookIcon from '@mui/icons-material/Book'; import LinkIcon from '@mui/icons-material/Link'; import { pn } from '../../utils'; +import { Info } from '../../models'; interface Props { open: boolean; onClose: () => void; - numPublicBuyOrders: number; - numPublicSellOrders: number; - bookLiquidity: number; - activeRobotsToday: number; - lastDayNonkycBtcPremium: number; - makerFee: number; - takerFee: number; - swapFeeRate: number; + info: Info; } -const CoordinatorSummaryDialog = ({ - open = false, - onClose, - numPublicBuyOrders, - numPublicSellOrders, - bookLiquidity, - activeRobotsToday, - lastDayNonkycBtcPremium, - makerFee, - takerFee, - swapFeeRate, -}: Props): JSX.Element => { +const CoordinatorSummaryDialog = ({ open = false, onClose, info }: Props): JSX.Element => { const { t } = useTranslation(); - if (swapFeeRate === null || swapFeeRate === undefined) { - swapFeeRate = 0; + if (info.current_swap_fee_rate === null || info.current_swap_fee_rate === undefined) { + info.current_swap_fee_rate = 0; } return ( +
+ +
{t('Coordinator Summary')} @@ -69,7 +56,7 @@ const CoordinatorSummaryDialog = ({ @@ -84,7 +71,7 @@ const CoordinatorSummaryDialog = ({ @@ -99,7 +86,7 @@ const CoordinatorSummaryDialog = ({ @@ -114,7 +101,7 @@ const CoordinatorSummaryDialog = ({ @@ -129,7 +116,7 @@ const CoordinatorSummaryDialog = ({ @@ -148,7 +135,7 @@ const CoordinatorSummaryDialog = ({ secondaryTypographyProps={{ fontSize: '12px' }} secondary={t('Maker fee')} > - {(makerFee * 100).toFixed(3)}% + {(info.maker_fee * 100).toFixed(3)}% @@ -158,7 +145,7 @@ const CoordinatorSummaryDialog = ({ secondaryTypographyProps={{ fontSize: '12px' }} secondary={t('Taker fee')} > - {(takerFee * 100).toFixed(3)}% + {(info.taker_fee * 100).toFixed(3)}% @@ -174,7 +161,7 @@ const CoordinatorSummaryDialog = ({ diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx index 2fef3e4a4..7250a5eaf 100644 --- a/frontend/src/components/Dialogs/Profile.tsx +++ b/frontend/src/components/Dialogs/Profile.tsx @@ -23,6 +23,7 @@ import { TextField, Tooltip, Typography, + LinearProgress, } from '@mui/material'; import { EnableTelegramDialog } from '.'; @@ -129,6 +130,9 @@ const ProfileDialog = ({ open = false, onClose, robot, setRobot }: Props): JSX.E aria-labelledby='profile-title' aria-describedby='profile-description' > +
+ +
{t('Your Profile')} diff --git a/frontend/src/components/Dialogs/Stats.tsx b/frontend/src/components/Dialogs/Stats.tsx index 10db9ef1d..8312c7552 100644 --- a/frontend/src/components/Dialogs/Stats.tsx +++ b/frontend/src/components/Dialogs/Stats.tsx @@ -11,6 +11,7 @@ import { ListItem, ListItemIcon, Typography, + LinearProgress, } from '@mui/material'; import BoltIcon from '@mui/icons-material/Bolt'; @@ -24,47 +25,23 @@ import EqualizerIcon from '@mui/icons-material/Equalizer'; import { AmbossIcon, BitcoinSignIcon, RoboSatsNoTextIcon } from '../Icons'; import { pn } from '../../utils'; +import { Info } from '../../models'; interface Props { open: boolean; onClose: () => void; - lndVersion: string; - coordinatorVersion: string; - clientVersion: string; - network: string | undefined; - nodeAlias: string; - nodeId: string; - alternativeName: string; - alternativeSite: string; - commitHash: string; - lastDayVolume: number; - lifetimeVolume: number; + info: Info; } -const StatsDialog = ({ - open = false, - onClose, - lndVersion, - coordinatorVersion, - clientVersion, - network, - nodeAlias, - nodeId, - alternativeName, - alternativeSite, - commitHash, - lastDayVolume, - lifetimeVolume, -}: Props): JSX.Element => { +const StatsDialog = ({ open = false, onClose, info }: Props): JSX.Element => { const { t } = useTranslation(); return ( - + +
+ +
+ {t('Stats For Nerds')} @@ -80,9 +57,9 @@ const StatsDialog = ({ /> @@ -93,23 +70,23 @@ const StatsDialog = ({ - + - {network === 'testnet' ? ( + {info.network === 'testnet' ? ( - + - {`${nodeId.slice(0, 12)}... (1ML)`} + {`${info.node_id.slice(0, 12)}... (1ML)`} @@ -118,9 +95,13 @@ const StatsDialog = ({ - - - {`${nodeId.slice(0, 12)}... (AMBOSS)`} + + + {`${info.node_id.slice(0, 12)}... (AMBOSS)`} @@ -132,9 +113,9 @@ const StatsDialog = ({ - - - {`${alternativeSite.slice(0, 12)}...onion`} + + + {`${info.alternative_site.slice(0, 12)}...onion`} @@ -148,10 +129,10 @@ const StatsDialog = ({ - {`${commitHash.slice(0, 12)}...`} + {`${info.robosats_running_commit_hash.slice(0, 12)}...`} @@ -171,7 +152,7 @@ const StatsDialog = ({ flexWrap: 'wrap', }} > - {pn(lastDayVolume)} + {pn(info.last_day_volume)} @@ -192,7 +173,7 @@ const StatsDialog = ({ flexWrap: 'wrap', }} > - {pn(lifetimeVolume)} + {pn(info.lifetime_volume)} diff --git a/frontend/src/components/SettingsForm/index.tsx b/frontend/src/components/SettingsForm/index.tsx index b7ed48dad..e25941baf 100644 --- a/frontend/src/components/SettingsForm/index.tsx +++ b/frontend/src/components/SettingsForm/index.tsx @@ -29,14 +29,14 @@ interface SettingsFormProps { dense?: boolean; settings: Settings; setSettings: (state: Settings) => void; - network?: boolean; + showNetwork?: boolean; } const SettingsForm = ({ dense = false, settings, setSettings, - network = false, + showNetwork = false, }: SettingsFormProps): JSX.Element => { const theme = useTheme(); const { t } = useTranslation(); @@ -129,7 +129,7 @@ const SettingsForm = ({ track={false} /> - {network ? ( + {showNetwork ? ( diff --git a/frontend/src/models/Info.model.ts b/frontend/src/models/Info.model.ts index 0f21400e5..edae3a6f6 100644 --- a/frontend/src/models/Info.model.ts +++ b/frontend/src/models/Info.model.ts @@ -21,6 +21,7 @@ export interface Info { coordinatorVersion: string; clientVersion: string; openUpdateClient: boolean; + loading: boolean; } import packageJson from '../../package.json'; @@ -49,6 +50,7 @@ export const defaultInfo: Info = { coordinatorVersion: 'v?.?.?', clientVersion: `v${semver[0]}.${semver[1]}.${semver[2]}`, openUpdateClient: false, + loading: true, }; export default Info; diff --git a/frontend/src/models/Robot.model.ts b/frontend/src/models/Robot.model.ts index 16c2889bb..b1df80080 100644 --- a/frontend/src/models/Robot.model.ts +++ b/frontend/src/models/Robot.model.ts @@ -3,8 +3,8 @@ import { systemClient } from '../services/System'; export interface Robot { nickname: string | null; token: string | null; - pub_key: string | null; - enc_priv_key: string | null; + pubKey: string | null; + encPrivKey: string | null; bitsEntropy: number | null; shannonEntropy: number | null; stealthInvoices: boolean; @@ -26,8 +26,8 @@ const privKeyCookie = systemClient.getCookie('enc_priv_key'); export const defaultRobot: Robot = { nickname: null, token: systemClient.getCookie('robot_token') ?? null, - pub_key: pubKeyCookie ? pubKeyCookie.split('\\').join('\n') : null, - enc_priv_key: privKeyCookie ? privKeyCookie.split('\\').join('\n') : null, + pubKey: pubKeyCookie ? pubKeyCookie.split('\\').join('\n') : null, + encPrivKey: privKeyCookie ? privKeyCookie.split('\\').join('\n') : null, bitsEntropy: null, shannonEntropy: null, stealthInvoices: true,