Small fixes

This commit is contained in:
Reckless_Satoshi 2022-10-18 11:43:37 -07:00
parent fa3e60208f
commit ef73c980a8
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
8 changed files with 83 additions and 95 deletions

View File

@ -44,54 +44,74 @@ import {
class BottomBar extends Component { class BottomBar extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = {
profileShown: false,
openStatsForNerds: false,
openCommunity: false,
openExchangeSummary: false,
openClaimRewards: false,
openProfile: false,
showRewards: false,
rewardInvoice: null,
badInvoice: false,
showRewardsSpinner: false,
withdrawn: false,
};
} }
handleClickOpenStatsForNerds = () => { handleClickOpenStatsForNerds = () => {
this.props.setInfo({ ...this.props.info, openStatsForNerds: true }); this.setState({ openStatsForNerds: true });
}; };
handleClickCloseStatsForNerds = () => { handleClickCloseStatsForNerds = () => {
this.props.setInfo({ ...this.props.info, openStatsForNerds: false }); this.setState({ openStatsForNerds: false });
}; };
handleClickOpenCommunity = () => { handleClickOpenCommunity = () => {
this.props.setInfo({ ...this.props.info, openCommunity: true }); this.setState({ openCommunity: true });
}; };
handleClickCloseCommunity = () => { handleClickCloseCommunity = () => {
this.props.setInfo({ ...this.props.info, openCommunity: false }); this.setState({ openCommunity: false });
}; };
handleClickOpenProfile = () => { handleClickOpenProfile = () => {
this.props.fetchInfo(); this.setState({ openProfile: true, profileShown: true });
this.props.setInfo({ ...this.props.info, openProfile: true, profileShown: true });
}; };
handleClickCloseProfile = () => { handleClickCloseProfile = () => {
this.props.setInfo({ ...this.props.info, openProfile: false }); this.setState({ openProfile: false });
};
handleClickOpenExchangeSummary = () => {
this.setState({ openExchangeSummary: true });
};
handleClickCloseExchangeSummary = () => {
this.setState({ openExchangeSummary: false });
}; };
handleSubmitInvoiceClicked = (e, rewardInvoice) => { handleSubmitInvoiceClicked = (e, rewardInvoice) => {
this.props.setInfo({ ...this.props.info, badInvoice: false, showRewardsSpinner: true }); this.setState({ badInvoice: false, showRewardsSpinner: true });
apiClient apiClient
.post('/api/reward/', { .post('/api/reward/', {
invoice: rewardInvoice, invoice: rewardInvoice,
}) })
.then( .then((data) => {
(data) => this.setState({ badInvoice: data.bad_invoice, showRewardsSpinner: false });
this.props.setInfo({ this.props.setInfo({
...this.props.info, ...this.props.info,
badInvoice: data.bad_invoice, badInvoice: data.bad_invoice,
openClaimRewards: !data.successful_withdrawal, openClaimRewards: !data.successful_withdrawal,
withdrawn: !!data.successful_withdrawal, withdrawn: !!data.successful_withdrawal,
showRewardsSpinner: false, showRewardsSpinner: false,
}) & });
this.props.setRobot({ this.props.setRobot({
...this.props.robot, ...this.props.robot,
earnedRewards: data.successful_withdrawal ? 0 : this.props.robot.earnedRewards, earnedRewards: data.successful_withdrawal ? 0 : this.props.robot.earnedRewards,
}), });
); });
e.preventDefault(); e.preventDefault();
}; };
@ -136,7 +156,10 @@ class BottomBar extends Component {
secondaryTypographyProps: { fontSize: (fontSize * 12) / 14 }, secondaryTypographyProps: { fontSize: (fontSize * 12) / 14 },
}; };
return ( return (
<Paper elevation={6} style={{ height: '2.85em', width: '100%' }}> <Paper
elevation={6}
style={{ height: '2.5em', width: `${(this.props.windowSize.width / 16) * 14}em` }}
>
<Grid container> <Grid container>
<Grid item xs={1.9}> <Grid item xs={1.9}>
<div style={{ display: this.showProfileButton() ? '' : 'none' }}> <div style={{ display: this.showProfileButton() ? '' : 'none' }}>
@ -407,20 +430,12 @@ class BottomBar extends Component {
); );
}; };
handleClickOpenExchangeSummary = () => {
this.props.setInfo({ ...this.props.info, openExchangeSummary: true });
};
handleClickCloseExchangeSummary = () => {
this.props.setInfo({ ...this.props.info, openExchangeSummary: false });
};
bottomBarPhone = () => { bottomBarPhone = () => {
const { t } = this.props; const { t } = this.props;
const hasRewards = this.props.robot.earnedRewards > 0; const hasRewards = this.props.robot.earnedRewards > 0;
const hasOrder = !!( const hasOrder = !!(
(this.props.info.active_order_id > 0) & (this.props.info.active_order_id > 0) &
!this.props.info.profileShown & !this.state.profileShown &
this.props.robot.avatarLoaded this.props.robot.avatarLoaded
); );
return ( return (
@ -558,7 +573,7 @@ class BottomBar extends Component {
return ( return (
<div> <div>
<CommunityDialog <CommunityDialog
open={this.props.info.openCommunity} open={this.state.openCommunity}
handleClickCloseCommunity={this.handleClickCloseCommunity} handleClickCloseCommunity={this.handleClickCloseCommunity}
/> />
@ -566,11 +581,13 @@ class BottomBar extends Component {
open={this.props.info.openUpdateClient} open={this.props.info.openUpdateClient}
coordinatorVersion={this.props.info.coordinatorVersion} coordinatorVersion={this.props.info.coordinatorVersion}
clientVersion={this.props.info.clientVersion} clientVersion={this.props.info.clientVersion}
handleClickClose={() => this.setState({ openUpdateClient: false })} handleClickClose={() =>
this.props.setInfo({ ...this.props.info, openUpdateClient: false })
}
/> />
<ExchangeSummaryDialog <ExchangeSummaryDialog
open={this.props.info.openExchangeSummary} open={this.state.openExchangeSummary}
handleClickCloseExchangeSummary={this.handleClickCloseExchangeSummary} handleClickCloseExchangeSummary={this.handleClickCloseExchangeSummary}
numPublicBuyOrders={this.props.info.num_public_buy_orders} numPublicBuyOrders={this.props.info.num_public_buy_orders}
numPublicSellOrders={this.props.info.num_public_sell_orders} numPublicSellOrders={this.props.info.num_public_sell_orders}
@ -583,7 +600,7 @@ class BottomBar extends Component {
/> />
<ProfileDialog <ProfileDialog
open={this.props.info.openProfile} open={this.state.openProfile}
handleClickCloseProfile={this.handleClickCloseProfile} handleClickCloseProfile={this.handleClickCloseProfile}
nickname={this.props.robot.nickname} nickname={this.props.robot.nickname}
activeOrderId={this.props.robot.activeOrderId} activeOrderId={this.props.robot.activeOrderId}
@ -594,17 +611,17 @@ class BottomBar extends Component {
tgToken={this.props.robot.tgToken} tgToken={this.props.robot.tgToken}
handleSubmitInvoiceClicked={this.handleSubmitInvoiceClicked} handleSubmitInvoiceClicked={this.handleSubmitInvoiceClicked}
host={this.getHost()} host={this.getHost()}
showRewardsSpinner={this.props.info.showRewardsSpinner} showRewardsSpinner={this.state.showRewardsSpinner}
withdrawn={this.props.info.withdrawn} withdrawn={this.props.info.withdrawn}
badInvoice={this.props.info.badInvoice} badInvoice={this.props.info.badInvoice}
earnedRewards={this.props.robot.earnedRewards} earnedRewards={this.props.robot.earnedRewards}
updateRobot={(newParams) => this.props.setRobot({ ...robot, ...newParams })} updateRobot={(newParam) => this.props.setRobot({ ...robot, ...newParam })}
stealthInvoices={this.props.stealthInvoices} stealthInvoices={this.props.robot.stealthInvoices}
handleSetStealthInvoice={this.handleSetStealthInvoice} handleSetStealthInvoice={this.handleSetStealthInvoice}
/> />
<StatsDialog <StatsDialog
open={this.props.info.openStatsForNerds} open={this.state.openStatsForNerds}
handleClickCloseStatsForNerds={this.handleClickCloseStatsForNerds} handleClickCloseStatsForNerds={this.handleClickCloseStatsForNerds}
coordinatorVersion={this.props.info.coordinatorVersion} coordinatorVersion={this.props.info.coordinatorVersion}
clientVersion={this.props.info.clientVersion} clientVersion={this.props.info.clientVersion}

View File

@ -57,7 +57,7 @@ interface Props {
badInvoice: boolean | string; badInvoice: boolean | string;
earnedRewards: number; earnedRewards: number;
stealthInvoices: boolean; stealthInvoices: boolean;
handleSetStealthInvoice: (stealth: boolean) => void; handleSetStealthInvoice: (wantsStealth: boolean) => void;
updateRobot: (state: any) => void; // TODO: move to a ContextProvider updateRobot: (state: any) => void; // TODO: move to a ContextProvider
} }

View File

@ -27,7 +27,7 @@ interface Props {
} }
const UpdateClientDialog = ({ const UpdateClientDialog = ({
open, open = false,
clientVersion, clientVersion,
coordinatorVersion, coordinatorVersion,
handleClickClose, handleClickClose,

View File

@ -86,7 +86,7 @@ const Main = (): JSX.Element => {
const fetchLimits = async () => { const fetchLimits = async () => {
setLimits({ ...limits, loading: true }); setLimits({ ...limits, loading: true });
const data = apiClient.get('/api/limits/').then((data) => { const data = apiClient.get('/api/limits/').then((data) => {
setLimits({ list: data, loading: false }); setLimits({ list: data ?? [], loading: false });
return data; return data;
}); });
return await data; return await data;
@ -105,13 +105,13 @@ const Main = (): JSX.Element => {
...robot, ...robot,
nickname: data.nickname, nickname: data.nickname,
loading: false, loading: false,
activeOrderId: data.active_order_id ? data.active_order_id : null, activeOrderId: data.active_order_id ?? null,
lastOrderId: data.last_order_id ? data.last_order_id : null, lastOrderId: data.last_order_id ?? null,
referralCode: data.referral_code, referralCode: data.referral_code,
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,
earnedRewards: data.earned_rewards, earnedRewards: data.earned_rewards ?? 0,
stealthInvoices: data.wants_stealth, stealthInvoices: data.wants_stealth,
}); });
}); });
@ -168,20 +168,20 @@ const Main = (): JSX.Element => {
/> />
<Route <Route
path='/order/:orderId' path='/order/:orderId'
render={(props) => <OrderPage theme={theme} history={history} {...props} />} render={(props: any) => <OrderPage theme={theme} history={history} {...props} />}
/> />
</Switch> </Switch>
</div> </div>
<div <div
style={{ style={{
height: '2.857em', height: '2.5em',
width: `${(windowSize.width / 16) * 14}em`,
position: 'fixed', position: 'fixed',
bottom: 0, bottom: 0,
}} }}
> >
<BottomBar <BottomBar
theme={theme} theme={theme}
windowSize={windowSize}
redirectTo={(location: string) => history.push(location)} redirectTo={(location: string) => history.push(location)}
robot={robot} robot={robot}
setRobot={setRobot} setRobot={setRobot}

View File

@ -38,7 +38,7 @@ const MakerPage = ({
const matches = filterOrders({ const matches = filterOrders({
orders, orders,
baseFilter: { currency: fav.currency == 0 ? 1 : fav.currency, type: fav.type }, baseFilter: { currency: fav.currency === 0 ? 1 : fav.currency, type: fav.type },
paymentMethods: maker.paymentMethods, paymentMethods: maker.paymentMethods,
amountFilter: { amountFilter: {
amount: maker.amount, amount: maker.amount,

View File

@ -34,7 +34,7 @@ class UserGenPage extends Component {
this.state = { this.state = {
openInfo: false, openInfo: false,
tokenHasChanged: false, tokenHasChanged: false,
token: '', inputToken: '',
}; };
this.refCode = this.props.match.params.refCode; this.refCode = this.props.match.params.refCode;
@ -94,7 +94,7 @@ class UserGenPage extends Component {
avatarLoaded: false, avatarLoaded: false,
activeOrderId: data.active_order_id ? data.active_order_id : null, activeOrderId: data.active_order_id ? data.active_order_id : null,
referralCode: data.referral_code, referralCode: data.referral_code,
earnedRewards: data.earned_rewards, earnedRewards: data.earned_rewards ?? 0,
lastOrderId: data.last_order_id ? data.last_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null,
stealthInvoices: data.wants_stealth, stealthInvoices: data.wants_stealth,
}) })
@ -106,7 +106,7 @@ class UserGenPage extends Component {
activeOrderId: data.active_order_id ? data.active_order_id : null, activeOrderId: data.active_order_id ? data.active_order_id : null,
lastOrderId: data.last_order_id ? data.last_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null,
referralCode: data.referral_code, referralCode: data.referral_code,
earnedRewards: data.earned_rewards, earnedRewards: data.earned_rewards ?? 0,
stealthInvoices: data.wants_stealth, stealthInvoices: data.wants_stealth,
tgEnabled: data.tg_enabled, tgEnabled: data.tg_enabled,
tgBotName: data.tg_bot_name, tgBotName: data.tg_bot_name,
@ -183,10 +183,6 @@ class UserGenPage extends Component {
}; };
render() { render() {
console.log(systemClient.getCookie('robot_token'));
console.log(this.props.robot.token);
console.log(systemClient.getCookie('robot_token') === this.props.robot.token);
const { t, i18n } = this.props; const { t, i18n } = this.props;
const fontSize = this.props.theme.typography.fontSize; const fontSize = this.props.theme.typography.fontSize;
const fontSizeFactor = fontSize / 14; // to scale sizes, default fontSize is 14 const fontSizeFactor = fontSize / 14; // to scale sizes, default fontSize is 14
@ -433,7 +429,7 @@ class UserGenPage extends Component {
</Typography> </Typography>
</Grid> </Grid>
<Grid item xs={2.5} align='left'> <Grid item xs={2.5} align='left'>
<RoboSatsNoTextIcon color='primary' sx={{ height: '5.143em', width: '5.143em' }} /> <RoboSatsNoTextIcon color='primary' sx={{ height: '3.143em', width: '3.143em' }} />
</Grid> </Grid>
</Grid> </Grid>
</div> </div>

View File

@ -20,19 +20,6 @@ export interface Info {
coordinatorVersion: string; coordinatorVersion: string;
clientVersion: string; clientVersion: string;
openUpdateClient: boolean; openUpdateClient: boolean;
// Other keys that do not belong here. TODO on NavBar PR.
profileShown: boolean;
openStatsForNerds: boolean;
openCommunity: boolean;
openExchangeSummary: boolean;
openClaimRewards: boolean;
openProfile: boolean;
showRewards: boolean;
rewardInvoice: string | null;
badInvoice: boolean;
showRewardsSpinner: boolean;
withdrawn: boolean;
} }
export const defaultInfo: Info = { export const defaultInfo: Info = {
@ -57,19 +44,6 @@ export const defaultInfo: Info = {
coordinatorVersion: 'v?.?.?', coordinatorVersion: 'v?.?.?',
clientVersion: 'v?.?.?', clientVersion: 'v?.?.?',
openUpdateClient: false, openUpdateClient: false,
// Other keys that do not belong here. TODO on NavBar PR.
profileShown: false,
openStatsForNerds: false,
openCommunity: false,
openExchangeSummary: false,
openClaimRewards: false,
openProfile: false,
showRewards: false,
rewardInvoice: null,
badInvoice: false,
showRewardsSpinner: false,
withdrawn: false,
}; };
export default Info; export default Info;

View File

@ -14,7 +14,7 @@ interface FilterOrders {
paymentMethods?: string[]; paymentMethods?: string[];
} }
const filterByPayment = function (order: Order, paymentMethods: string[]) { const filterByPayment = function (order: Order, paymentMethods: any[]) {
if (paymentMethods.length === 0) { if (paymentMethods.length === 0) {
return true; return true;
} else { } else {
@ -27,17 +27,19 @@ const filterByPayment = function (order: Order, paymentMethods: string[]) {
}; };
const filterByAmount = function (order: Order, filter: AmountFilter) { const filterByAmount = function (order: Order, filter: AmountFilter) {
const filterMaxAmount = filter.amount != '' ? filter.amount : filter.maxAmount; const filterMaxAmount =
const filterMinAmount = filter.amount != '' ? filter.amount : filter.minAmount; Number(filter.amount != '' ? filter.amount : filter.maxAmount) * (1 + filter.threshold);
const orderMinAmount = const filterMinAmount =
order.amount === '' || order.amount === null ? order.min_amount : order.amount; Number(filter.amount != '' ? filter.amount : filter.minAmount) * (1 - filter.threshold);
const orderMaxAmount =
order.amount === '' || order.amount === null ? order.max_amount : order.amount;
return ( const orderMinAmount = Number(
orderMaxAmount < filterMaxAmount * (1 + filter.threshold) && order.amount === '' || order.amount === null ? order.min_amount : order.amount,
orderMinAmount > filterMinAmount * (1 - filter.threshold)
); );
const orderMaxAmount = Number(
order.amount === '' || order.amount === null ? order.max_amount : order.amount,
);
return Math.max(filterMinAmount, orderMinAmount) <= Math.min(filterMaxAmount, orderMaxAmount);
}; };
const filterOrders = function ({ const filterOrders = function ({
@ -55,7 +57,6 @@ const filterOrders = function ({
return typeChecks && currencyChecks && paymentMethodChecks && amountChecks; return typeChecks && currencyChecks && paymentMethodChecks && amountChecks;
}); });
return filteredOrders; return filteredOrders;
}; };