Skip to content

Commit

Permalink
Add small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Oct 31, 2022
1 parent c9749bd commit 2706703
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 125 deletions.
2 changes: 2 additions & 0 deletions frontend/src/basic/BookPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const BookPage = ({
limits={limits.list}
maxWidth={chartWidthEm} // EM units
maxHeight={windowSize.height * 0.825 - 5} // EM units
onOrderClicked={onOrderClicked}
/>
</Grid>
</Grid>
Expand All @@ -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}
/>
) : (
<BookTable
Expand Down
38 changes: 23 additions & 15 deletions frontend/src/basic/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
const basename = window.NativeRobosats === undefined ? '' : window.location.pathname;
const entryPage: Page | '' =
window.NativeRobosats === undefined ? window.location.pathname.split('/')[1] : '';
const [page, setPage] = useState<Page>(entryPage == '' ? 'offers' : entryPage);
const [page, setPage] = useState<Page>(entryPage == '' ? 'robot' : entryPage);
const [slideDirection, setSlideDirection] = useState<SlideDirection>({
in: undefined,
out: undefined,
Expand Down Expand Up @@ -134,30 +134,35 @@ 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({
...data,
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
Expand All @@ -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,
Expand All @@ -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 (
<Router basename={basename}>
Expand All @@ -213,7 +220,8 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
>
<Switch>
<Route
path='/robot/:refCode?'
path={['/robot/:refCode?', '/']}
exact
render={(props: any) => (
<Slide
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
Expand All @@ -235,7 +243,7 @@ const Main = ({ settings, setSettings }: MainProps): JSX.Element => {
)}
/>

<Route exact path={['/offers', '/']}>
<Route path={'/offers'}>
<Slide
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
in={page === 'offers'}
Expand Down
21 changes: 2 additions & 19 deletions frontend/src/basic/MainDialogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,12 @@ const MainDialogs = ({
<CoordinatorSummaryDialog
open={open.coordinator}
onClose={() => 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}
/>
<StatsDialog
open={open.stats}
onClose={() => 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}
/>
<ProfileDialog
open={open.profile}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/basic/SettingsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SettingsPage = ({ settings, setSettings, windowSize }: SettingsPageProps):
<SettingsForm
settings={settings}
setSettings={setSettings}
networt={window.NativeRobosats}
showNetwork={!(window.NativeRobosats === undefined)}
/>
</Grid>
</Grid>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/basic/UserGenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) &
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Charts/DepthChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface DepthChartProps {
maxHeight: number;
fillContainer?: boolean;
elevation?: number;
onOrderClicked?: (id: number) => void;
}

const DepthChart: React.FC<DepthChartProps> = ({
Expand All @@ -48,6 +49,7 @@ const DepthChart: React.FC<DepthChartProps> = ({
maxHeight,
fillContainer = false,
elevation = 6,
onOrderClicked = () => null,
}) => {
const { t } = useTranslation();
const history = useHistory();
Expand Down Expand Up @@ -278,7 +280,7 @@ const DepthChart: React.FC<DepthChartProps> = ({
};
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;
Expand Down
47 changes: 17 additions & 30 deletions frontend/src/components/Dialogs/CoordinatorSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ListItem,
ListItemIcon,
Typography,
LinearProgress,
} from '@mui/material';

import InventoryIcon from '@mui/icons-material/Inventory';
Expand All @@ -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 (
<Dialog open={open} onClose={onClose}>
<div style={info.loading ? {} : { display: 'none' }}>
<LinearProgress />
</div>
<DialogContent>
<Typography component='h5' variant='h5'>
{t('Coordinator Summary')}
Expand All @@ -69,7 +56,7 @@ const CoordinatorSummaryDialog = ({
<ListItemText
primaryTypographyProps={{ fontSize: '14px' }}
secondaryTypographyProps={{ fontSize: '12px' }}
primary={numPublicBuyOrders}
primary={info.num_public_buy_orders}
secondary={t('Public buy orders')}
/>
</ListItem>
Expand All @@ -84,7 +71,7 @@ const CoordinatorSummaryDialog = ({
<ListItemText
primaryTypographyProps={{ fontSize: '14px' }}
secondaryTypographyProps={{ fontSize: '12px' }}
primary={numPublicSellOrders}
primary={info.num_public_sell_orders}
secondary={t('Public sell orders')}
/>
</ListItem>
Expand All @@ -99,7 +86,7 @@ const CoordinatorSummaryDialog = ({
<ListItemText
primaryTypographyProps={{ fontSize: '14px' }}
secondaryTypographyProps={{ fontSize: '12px' }}
primary={`${pn(bookLiquidity)} Sats`}
primary={`${pn(info.book_liquidity)} Sats`}
secondary={t('Book liquidity')}
/>
</ListItem>
Expand All @@ -114,7 +101,7 @@ const CoordinatorSummaryDialog = ({
<ListItemText
primaryTypographyProps={{ fontSize: '14px' }}
secondaryTypographyProps={{ fontSize: '12px' }}
primary={activeRobotsToday}
primary={info.active_robots_today}
secondary={t('Today active robots')}
/>
</ListItem>
Expand All @@ -129,7 +116,7 @@ const CoordinatorSummaryDialog = ({
<ListItemText
primaryTypographyProps={{ fontSize: '14px' }}
secondaryTypographyProps={{ fontSize: '12px' }}
primary={`${lastDayNonkycBtcPremium}%`}
primary={`${info.last_day_nonkyc_btc_premium}%`}
secondary={t('24h non-KYC bitcoin premium')}
/>
</ListItem>
Expand All @@ -148,7 +135,7 @@ const CoordinatorSummaryDialog = ({
secondaryTypographyProps={{ fontSize: '12px' }}
secondary={t('Maker fee')}
>
{(makerFee * 100).toFixed(3)}%
{(info.maker_fee * 100).toFixed(3)}%
</ListItemText>
</Grid>

Expand All @@ -158,7 +145,7 @@ const CoordinatorSummaryDialog = ({
secondaryTypographyProps={{ fontSize: '12px' }}
secondary={t('Taker fee')}
>
{(takerFee * 100).toFixed(3)}%
{(info.taker_fee * 100).toFixed(3)}%
</ListItemText>
</Grid>
</Grid>
Expand All @@ -174,7 +161,7 @@ const CoordinatorSummaryDialog = ({
<ListItemText
primaryTypographyProps={{ fontSize: '14px' }}
secondaryTypographyProps={{ fontSize: '12px' }}
primary={`${swapFeeRate.toPrecision(3)}%`}
primary={`${info.current_swap_fee_rate.toPrecision(3)}%`}
secondary={t('Current onchain payout fee')}
/>
</ListItem>
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/Dialogs/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TextField,
Tooltip,
Typography,
LinearProgress,
} from '@mui/material';

import { EnableTelegramDialog } from '.';
Expand Down Expand Up @@ -129,6 +130,9 @@ const ProfileDialog = ({ open = false, onClose, robot, setRobot }: Props): JSX.E
aria-labelledby='profile-title'
aria-describedby='profile-description'
>
<div style={robot.loading ? {} : { display: 'none' }}>
<LinearProgress />
</div>
<DialogContent>
<Typography component='h5' variant='h5'>
{t('Your Profile')}
Expand Down
Loading

0 comments on commit 2706703

Please sign in to comment.