Small fixes (more)

This commit is contained in:
Reckless_Satoshi 2022-10-19 07:26:00 -07:00
parent 78a8ab799d
commit b2c21d4a98
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
6 changed files with 63 additions and 58 deletions

View File

@ -146,7 +146,7 @@ class BottomBar extends Component {
const hasRewards = this.props.robot.earnedRewards > 0; const hasRewards = this.props.robot.earnedRewards > 0;
const hasOrder = !!( const hasOrder = !!(
(this.props.robot.activeOrderId > 0) & (this.props.robot.activeOrderId > 0) &
!this.props.infoprofileShown & !this.state.profileShown &
this.props.robot.avatarLoaded this.props.robot.avatarLoaded
); );
const fontSize = this.props.theme.typography.fontSize; const fontSize = this.props.theme.typography.fontSize;
@ -175,7 +175,7 @@ class BottomBar extends Component {
<RobotAvatar <RobotAvatar
style={{ marginTop: -13 }} style={{ marginTop: -13 }}
statusColor={ statusColor={
(this.props.robot.activeOrderId > 0) & !this.props.robot.profileShown (this.props.robot.activeOrderId > 0) & !this.state.profileShown
? 'primary' ? 'primary'
: undefined : undefined
} }
@ -439,7 +439,10 @@ class BottomBar extends Component {
this.props.robot.avatarLoaded this.props.robot.avatarLoaded
); );
return ( return (
<Paper elevation={6} style={{ height: '2.85em', width: '100%' }}> <Paper
elevation={6}
style={{ height: '2.85em', width: `${(this.props.windowSize.width / 16) * 14}em` }}
>
<Grid container> <Grid container>
<Grid item xs={1.6}> <Grid item xs={1.6}>
<div style={{ display: this.showProfileButton() ? '' : 'none' }}> <div style={{ display: this.showProfileButton() ? '' : 'none' }}>
@ -458,12 +461,12 @@ class BottomBar extends Component {
style={{ width: 55, height: 55 }} style={{ width: 55, height: 55 }}
avatarClass='phoneFlippedSmallAvatar' avatarClass='phoneFlippedSmallAvatar'
statusColor={ statusColor={
(this.props.activeOrderId > 0) & !this.props.profileShown (this.props.activeOrderId > 0) & !this.state.profileShown
? 'primary' ? 'primary'
: undefined : undefined
} }
nickname={this.props.nickname} nickname={this.props.robot.nickname}
onLoad={() => this.props.setAppState({ avatarLoaded: true })} onLoad={() => this.props.setRobot({ ...this.props.robot, avatarLoaded: true })}
/> />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
@ -475,10 +478,6 @@ class BottomBar extends Component {
<IconButton <IconButton
disabled={!this.showProfileButton()} disabled={!this.showProfileButton()}
color='primary' color='primary'
onClick={() =>
this.props.setAppState({ buyChecked: false, sellChecked: true, type: 0 }) &
this.getInfo()
}
to={`/book/`} to={`/book/`}
component={LinkRouter} component={LinkRouter}
> >
@ -494,10 +493,6 @@ class BottomBar extends Component {
<IconButton <IconButton
disabled={!this.showProfileButton()} disabled={!this.showProfileButton()}
color='primary' color='primary'
onClick={() =>
this.props.setAppState({ buyChecked: true, sellChecked: false, type: 1 }) &
this.getInfo()
}
to={`/book/`} to={`/book/`}
component={LinkRouter} component={LinkRouter}
> >
@ -513,7 +508,7 @@ class BottomBar extends Component {
<IconButton <IconButton
disabled={!this.showProfileButton()} disabled={!this.showProfileButton()}
color='primary' color='primary'
onClick={() => this.getInfo()} onClick={() => this.props.fetchInfo()}
to={`/`} to={`/`}
component={LinkRouter} component={LinkRouter}
> >
@ -578,7 +573,7 @@ class BottomBar extends Component {
/> />
<UpdateClientDialog <UpdateClientDialog
open={this.props.info.openUpdateClient} open={this.state.openUpdateClient}
coordinatorVersion={this.props.info.coordinatorVersion} coordinatorVersion={this.props.info.coordinatorVersion}
clientVersion={this.props.info.clientVersion} clientVersion={this.props.info.clientVersion}
handleClickClose={() => handleClickClose={() =>

View File

@ -117,6 +117,7 @@ const Main = (): JSX.Element => {
}); });
}; };
console.log(robot);
return ( return (
<Router basename={basename}> <Router basename={basename}>
<div className='appCenter'> <div className='appCenter'>

View File

@ -75,7 +75,6 @@ const MakerForm = ({
const theme = useTheme(); const theme = useTheme();
const history = useHistory(); const history = useHistory();
const [badRequest, setBadRequest] = useState<string | null>(null); const [badRequest, setBadRequest] = useState<string | null>(null);
const [advancedOptions, setAdvancedOptions] = useState<boolean>(false);
const [amountLimits, setAmountLimits] = useState<number[]>([1, 1000]); const [amountLimits, setAmountLimits] = useState<number[]>([1, 1000]);
const [satoshisLimits, setSatoshisLimits] = useState<number[]>([20000, 4000000]); const [satoshisLimits, setSatoshisLimits] = useState<number[]>([20000, 4000000]);
const [currentPrice, setCurrentPrice] = useState<number | string>('...'); const [currentPrice, setCurrentPrice] = useState<number | string>('...');
@ -142,7 +141,7 @@ const MakerForm = ({
}); });
updateAmountLimits(limits.list, newCurrency, maker.premium); updateAmountLimits(limits.list, newCurrency, maker.premium);
updateCurrentPrice(limits.list, newCurrency, maker.premium); updateCurrentPrice(limits.list, newCurrency, maker.premium);
if (advancedOptions) { if (maker.advancedOptions) {
setMaker({ setMaker({
...maker, ...maker,
minAmount: parseFloat(Number(limits.list[newCurrency].max_amount * 0.25).toPrecision(2)), minAmount: parseFloat(Number(limits.list[newCurrency].max_amount * 0.25).toPrecision(2)),
@ -230,7 +229,7 @@ const MakerForm = ({
}; };
const handleClickExplicit = function () { const handleClickExplicit = function () {
if (!advancedOptions) { if (!maker.advancedOptions) {
setMaker({ setMaker({
...maker, ...maker,
isExplicit: true, isExplicit: true,
@ -244,10 +243,10 @@ const MakerForm = ({
const body = { const body = {
type: fav.type == 0 ? 1 : 0, type: fav.type == 0 ? 1 : 0,
currency: fav.currency == 0 ? 1 : fav.currency, currency: fav.currency == 0 ? 1 : fav.currency,
amount: advancedOptions ? null : maker.amount, amount: maker.advancedOptions ? null : maker.amount,
has_range: advancedOptions, has_range: maker.advancedOptions,
min_amount: advancedOptions ? maker.minAmount : null, min_amount: maker.advancedOptions ? maker.minAmount : null,
max_amount: advancedOptions ? maker.maxAmount : null, max_amount: maker.advancedOptions ? maker.maxAmount : null,
payment_method: payment_method:
maker.paymentMethodsText === '' ? 'not specified' : maker.paymentMethodsText, maker.paymentMethodsText === '' ? 'not specified' : maker.paymentMethodsText,
is_explicit: maker.isExplicit, is_explicit: maker.isExplicit,
@ -295,13 +294,12 @@ const MakerForm = ({
}; };
const handleClickAdvanced = function () { const handleClickAdvanced = function () {
if (advancedOptions) { if (maker.advancedOptions) {
handleClickRelative(); handleClickRelative();
setMaker({ ...maker, advancedOptions: false });
} else { } else {
resetRange(); resetRange(true);
} }
setAdvancedOptions(!advancedOptions);
}; };
const minAmountError = function () { const minAmountError = function () {
@ -322,7 +320,7 @@ const MakerForm = ({
); );
}; };
const resetRange = function () { const resetRange = function (advancedOptions: boolean) {
const index = fav.currency === 0 ? 1 : fav.currency; const index = fav.currency === 0 ? 1 : fav.currency;
const minAmount = maker.amount const minAmount = maker.amount
? parseFloat((maker.amount / 2).toPrecision(2)) ? parseFloat((maker.amount / 2).toPrecision(2))
@ -333,6 +331,7 @@ const MakerForm = ({
setMaker({ setMaker({
...maker, ...maker,
advancedOptions,
minAmount, minAmount,
maxAmount, maxAmount,
}); });
@ -376,11 +375,11 @@ const MakerForm = ({
return ( return (
fav.type == null || fav.type == null ||
(maker.amount != '' && (maker.amount != '' &&
!advancedOptions && !maker.advancedOptions &&
(maker.amount < amountLimits[0] || maker.amount > amountLimits[1])) || (maker.amount < amountLimits[0] || maker.amount > amountLimits[1])) ||
(maker.amount == null && (!advancedOptions || limits.loading)) || (maker.amount == null && (!maker.advancedOptions || limits.loading)) ||
(advancedOptions && (minAmountError() || maxAmountError())) || (maker.advancedOptions && (minAmountError() || maxAmountError())) ||
(maker.amount <= 0 && !advancedOptions) || (maker.amount <= 0 && !maker.advancedOptions) ||
(maker.isExplicit && (maker.badSatoshisText != '' || maker.satoshis == '')) || (maker.isExplicit && (maker.badSatoshisText != '' || maker.satoshis == '')) ||
(!maker.isExplicit && maker.badPremiumText != '') (!maker.isExplicit && maker.badPremiumText != '')
); );
@ -404,7 +403,7 @@ const MakerForm = ({
: fav.type == 1 : fav.type == 1
? t('Buy order for ') ? t('Buy order for ')
: t('Sell order for ')} : t('Sell order for ')}
{advancedOptions && maker.minAmount != '' {maker.advancedOptions && maker.minAmount != ''
? pn(maker.minAmount) + '-' + pn(maker.maxAmount) ? pn(maker.minAmount) + '-' + pn(maker.maxAmount)
: pn(maker.amount)} : pn(maker.amount)}
{' ' + currencyCode} {' ' + currencyCode}
@ -478,7 +477,7 @@ const MakerForm = ({
<Switch <Switch
size='small' size='small'
disabled={limits.list.length == 0} disabled={limits.list.length == 0}
checked={advancedOptions} checked={maker.advancedOptions}
onChange={handleClickAdvanced} onChange={handleClickAdvanced}
/> />
<SelfImprovement sx={{ color: 'text.secondary' }} /> <SelfImprovement sx={{ color: 'text.secondary' }} />
@ -498,7 +497,7 @@ const MakerForm = ({
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
<ButtonGroup> <ButtonGroup>
<Button <Button
size={advancedOptions ? 'small' : 'large'} size={maker.advancedOptions ? 'small' : 'large'}
variant='contained' variant='contained'
onClick={() => onClick={() =>
setFav({ setFav({
@ -518,7 +517,7 @@ const MakerForm = ({
{t('Buy')} {t('Buy')}
</Button> </Button>
<Button <Button
size={advancedOptions ? 'small' : 'large'} size={maker.advancedOptions ? 'small' : 'large'}
variant='contained' variant='contained'
onClick={() => onClick={() =>
setFav({ setFav({
@ -544,7 +543,7 @@ const MakerForm = ({
</Grid> </Grid>
<Grid item> <Grid item>
<Collapse in={advancedOptions}> <Collapse in={maker.advancedOptions}>
<AmountRange <AmountRange
minAmount={maker.minAmount} minAmount={maker.minAmount}
handleRangeAmountChange={handleRangeAmountChange} handleRangeAmountChange={handleRangeAmountChange}
@ -559,7 +558,7 @@ const MakerForm = ({
handleMaxAmountChange={handleMaxAmountChange} handleMaxAmountChange={handleMaxAmountChange}
/> />
</Collapse> </Collapse>
<Collapse in={!advancedOptions}> <Collapse in={!maker.advancedOptions}>
<Grid item> <Grid item>
<Grid container alignItems='stretch' style={{ display: 'flex' }}> <Grid container alignItems='stretch' style={{ display: 'flex' }}>
<Grid item xs={6}> <Grid item xs={6}>
@ -572,8 +571,8 @@ const MakerForm = ({
> >
<TextField <TextField
fullWidth fullWidth
disabled={advancedOptions} disabled={maker.advancedOptions}
variant={advancedOptions ? 'filled' : 'outlined'} variant={maker.advancedOptions ? 'filled' : 'outlined'}
error={ error={
maker.amount != '' && maker.amount != '' &&
(maker.amount < amountLimits[0] || maker.amount > amountLimits[1]) (maker.amount < amountLimits[0] || maker.amount > amountLimits[1])
@ -650,7 +649,7 @@ const MakerForm = ({
/> />
</Grid> </Grid>
{!advancedOptions && pricingMethods ? ( {!maker.advancedOptions && pricingMethods ? (
<Grid item xs={12}> <Grid item xs={12}>
<Box <Box
sx={{ sx={{
@ -692,7 +691,7 @@ const MakerForm = ({
title={t('Set a fix amount of satoshis')} title={t('Set a fix amount of satoshis')}
> >
<FormControlLabel <FormControlLabel
disabled={advancedOptions} disabled={maker.advancedOptions}
value='explicit' value='explicit'
control={<Radio color='secondary' />} control={<Radio color='secondary' />}
label={t('Exact')} label={t('Exact')}
@ -749,7 +748,7 @@ const MakerForm = ({
</div> </div>
</Grid> </Grid>
<Grid item> <Grid item>
<Collapse in={advancedOptions}> <Collapse in={maker.advancedOptions}>
<Grid container spacing={1}> <Grid container spacing={1}>
<Grid item xs={12}> <Grid item xs={12}>
<LocalizationProvider dateAdapter={DateFnsUtils}> <LocalizationProvider dateAdapter={DateFnsUtils}>

View File

@ -78,14 +78,6 @@ class UserGenPage extends Component {
}); });
requestBody.then((body) => requestBody.then((body) =>
apiClient.post('/api/user/', body).then((data) => { apiClient.post('/api/user/', body).then((data) => {
this.props.setRobot({
bit_entropy: data.token_bits_entropy,
shannon_entropy: data.token_shannon_entropy,
bad_request: data.bad_request,
found: data.found,
loading: false,
stealthInvoices: data.wants_stealth,
});
// Add nick and token to App state (token only if not a bad request) // Add nick and token to App state (token only if not a bad request)
data.bad_request data.bad_request
? this.props.setRobot({ ? this.props.setRobot({
@ -111,6 +103,10 @@ class UserGenPage extends Component {
tgEnabled: data.tg_enabled, tgEnabled: data.tg_enabled,
tgBotName: data.tg_bot_name, tgBotName: data.tg_bot_name,
tgToken: data.tg_token, 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,
}) & }) &
systemClient.setCookie('robot_token', token) & systemClient.setCookie('robot_token', token) &
systemClient.setCookie('pub_key', data.public_key.split('\n').join('\\')) & systemClient.setCookie('pub_key', data.public_key.split('\n').join('\\')) &
@ -174,11 +170,11 @@ class UserGenPage extends Component {
createJsonFile = () => { createJsonFile = () => {
return { return {
token: systemClient.getCookie('robot_token'), token: this.props.robot.token,
token_shannon_entropy: this.state.shannon_entropy, token_shannon_entropy: this.props.robot.shannonEntropy,
token_bit_entropy: this.state.bit_entropy, token_bit_entropy: this.props.robot.bitsEntropy,
public_key: systemClient.getCookie('pub_key').split('\\').join('\n'), public_key: this.props.robot.pub_key,
encrypted_private_key: systemClient.getCookie('enc_priv_key').split('\\').join('\n'), encrypted_private_key: this.props.robot.enc_priv_key,
}; };
}; };
@ -356,7 +352,7 @@ class UserGenPage extends Component {
</Grid> </Grid>
</Grid> </Grid>
<Grid item xs={12} align='center'> <Grid item xs={12} align='center'>
{this.state.inputTokenHasChanged ? ( {this.state.tokenHasChanged ? (
<Button type='submit' size='small' onClick={this.handleClickSubmitToken}> <Button type='submit' size='small' onClick={this.handleClickSubmitToken}>
<SmartToyIcon sx={{ width: 18 * fontSizeFactor, height: 18 * fontSizeFactor }} /> <SmartToyIcon sx={{ width: 18 * fontSizeFactor, height: 18 * fontSizeFactor }} />
<span> {t('Generate Robot')}</span> <span> {t('Generate Robot')}</span>

View File

@ -1,4 +1,5 @@
export interface Maker { export interface Maker {
advancedOptions: boolean;
isExplicit: boolean; isExplicit: boolean;
amount: string; amount: string;
paymentMethods: string[]; paymentMethods: string[];
@ -18,6 +19,7 @@ export interface Maker {
} }
export const defaultMaker: Maker = { export const defaultMaker: Maker = {
advancedOptions: false,
isExplicit: false, isExplicit: false,
amount: '', amount: '',
paymentMethods: [], paymentMethods: [],

View File

@ -1,6 +1,10 @@
import { systemClient } from '../services/System';
export interface Robot { export interface Robot {
nickname: string | null; nickname: string | null;
token: string | null; token: string | null;
pub_key: string | null;
enc_priv_key: string | null;
bitsEntropy: number | null; bitsEntropy: number | null;
shannonEntropy: number | null; shannonEntropy: number | null;
stealthInvoices: boolean; stealthInvoices: boolean;
@ -18,7 +22,15 @@ export interface Robot {
export const defaultRobot: Robot = { export const defaultRobot: Robot = {
nickname: null, nickname: null,
token: null, token: systemClient.getCookie('robot_token') ?? null,
pub_key:
systemClient.getCookie('pub_key') === undefined
? null
: systemClient.getCookie('pub_key').split('\\').join('\n'),
enc_priv_key:
systemClient.getCookie('enc_priv_key') === undefined
? null
: systemClient.getCookie('enc_priv_key').split('\\').join('\n'),
bitsEntropy: null, bitsEntropy: null,
shannonEntropy: null, shannonEntropy: null,
stealthInvoices: true, stealthInvoices: true,