From ef73c980a8cfc4ae760e720e3bca99acc30b7270 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Tue, 18 Oct 2022 11:43:37 -0700 Subject: [PATCH] Small fixes --- frontend/src/components/BottomBar.js | 97 +++++++++++-------- frontend/src/components/Dialogs/Profile.tsx | 2 +- .../src/components/Dialogs/UpdateClient.tsx | 2 +- frontend/src/components/Main.tsx | 14 +-- .../src/components/MakerPage/MakerPage.tsx | 2 +- frontend/src/components/UserGenPage.js | 12 +-- frontend/src/models/Info.model.ts | 26 ----- frontend/src/utils/filterOrders.ts | 23 ++--- 8 files changed, 83 insertions(+), 95 deletions(-) diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index 23011215..5b510297 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -44,54 +44,74 @@ import { class BottomBar extends Component { constructor(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 = () => { - this.props.setInfo({ ...this.props.info, openStatsForNerds: true }); + this.setState({ openStatsForNerds: true }); }; handleClickCloseStatsForNerds = () => { - this.props.setInfo({ ...this.props.info, openStatsForNerds: false }); + this.setState({ openStatsForNerds: false }); }; handleClickOpenCommunity = () => { - this.props.setInfo({ ...this.props.info, openCommunity: true }); + this.setState({ openCommunity: true }); }; handleClickCloseCommunity = () => { - this.props.setInfo({ ...this.props.info, openCommunity: false }); + this.setState({ openCommunity: false }); }; handleClickOpenProfile = () => { - this.props.fetchInfo(); - this.props.setInfo({ ...this.props.info, openProfile: true, profileShown: true }); + this.setState({ openProfile: true, profileShown: true }); }; 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) => { - this.props.setInfo({ ...this.props.info, badInvoice: false, showRewardsSpinner: true }); + this.setState({ badInvoice: false, showRewardsSpinner: true }); apiClient .post('/api/reward/', { invoice: rewardInvoice, }) - .then( - (data) => - this.props.setInfo({ - ...this.props.info, - badInvoice: data.bad_invoice, - openClaimRewards: !data.successful_withdrawal, - withdrawn: !!data.successful_withdrawal, - showRewardsSpinner: false, - }) & - this.props.setRobot({ - ...this.props.robot, - earnedRewards: data.successful_withdrawal ? 0 : this.props.robot.earnedRewards, - }), - ); + .then((data) => { + this.setState({ badInvoice: data.bad_invoice, showRewardsSpinner: false }); + this.props.setInfo({ + ...this.props.info, + badInvoice: data.bad_invoice, + openClaimRewards: !data.successful_withdrawal, + withdrawn: !!data.successful_withdrawal, + showRewardsSpinner: false, + }); + this.props.setRobot({ + ...this.props.robot, + earnedRewards: data.successful_withdrawal ? 0 : this.props.robot.earnedRewards, + }); + }); e.preventDefault(); }; @@ -136,7 +156,10 @@ class BottomBar extends Component { secondaryTypographyProps: { fontSize: (fontSize * 12) / 14 }, }; return ( - +
@@ -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 = () => { const { t } = this.props; const hasRewards = this.props.robot.earnedRewards > 0; const hasOrder = !!( (this.props.info.active_order_id > 0) & - !this.props.info.profileShown & + !this.state.profileShown & this.props.robot.avatarLoaded ); return ( @@ -558,7 +573,7 @@ class BottomBar extends Component { return (
@@ -566,11 +581,13 @@ class BottomBar extends Component { open={this.props.info.openUpdateClient} coordinatorVersion={this.props.info.coordinatorVersion} clientVersion={this.props.info.clientVersion} - handleClickClose={() => this.setState({ openUpdateClient: false })} + handleClickClose={() => + this.props.setInfo({ ...this.props.info, openUpdateClient: false }) + } /> this.props.setRobot({ ...robot, ...newParams })} - stealthInvoices={this.props.stealthInvoices} + updateRobot={(newParam) => this.props.setRobot({ ...robot, ...newParam })} + stealthInvoices={this.props.robot.stealthInvoices} handleSetStealthInvoice={this.handleSetStealthInvoice} /> void; + handleSetStealthInvoice: (wantsStealth: boolean) => void; updateRobot: (state: any) => void; // TODO: move to a ContextProvider } diff --git a/frontend/src/components/Dialogs/UpdateClient.tsx b/frontend/src/components/Dialogs/UpdateClient.tsx index 548f7cee..802b1934 100644 --- a/frontend/src/components/Dialogs/UpdateClient.tsx +++ b/frontend/src/components/Dialogs/UpdateClient.tsx @@ -27,7 +27,7 @@ interface Props { } const UpdateClientDialog = ({ - open, + open = false, clientVersion, coordinatorVersion, handleClickClose, diff --git a/frontend/src/components/Main.tsx b/frontend/src/components/Main.tsx index 21836dee..c2535696 100644 --- a/frontend/src/components/Main.tsx +++ b/frontend/src/components/Main.tsx @@ -86,7 +86,7 @@ const Main = (): JSX.Element => { const fetchLimits = async () => { setLimits({ ...limits, loading: true }); const data = apiClient.get('/api/limits/').then((data) => { - setLimits({ list: data, loading: false }); + setLimits({ list: data ?? [], loading: false }); return data; }); return await data; @@ -105,13 +105,13 @@ const Main = (): JSX.Element => { ...robot, nickname: data.nickname, loading: false, - activeOrderId: data.active_order_id ? data.active_order_id : null, - lastOrderId: data.last_order_id ? data.last_order_id : null, + activeOrderId: data.active_order_id ?? null, + lastOrderId: data.last_order_id ?? null, referralCode: data.referral_code, tgEnabled: data.tg_enabled, tgBotName: data.tg_bot_name, tgToken: data.tg_token, - earnedRewards: data.earned_rewards, + earnedRewards: data.earned_rewards ?? 0, stealthInvoices: data.wants_stealth, }); }); @@ -168,20 +168,20 @@ const Main = (): JSX.Element => { /> } + render={(props: any) => } />
history.push(location)} robot={robot} setRobot={setRobot} diff --git a/frontend/src/components/MakerPage/MakerPage.tsx b/frontend/src/components/MakerPage/MakerPage.tsx index 2a91f9c7..7d0bd890 100644 --- a/frontend/src/components/MakerPage/MakerPage.tsx +++ b/frontend/src/components/MakerPage/MakerPage.tsx @@ -38,7 +38,7 @@ const MakerPage = ({ const matches = filterOrders({ 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, amountFilter: { amount: maker.amount, diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js index 391c1c6d..2c6874e1 100644 --- a/frontend/src/components/UserGenPage.js +++ b/frontend/src/components/UserGenPage.js @@ -34,7 +34,7 @@ class UserGenPage extends Component { this.state = { openInfo: false, tokenHasChanged: false, - token: '', + inputToken: '', }; this.refCode = this.props.match.params.refCode; @@ -94,7 +94,7 @@ class UserGenPage extends Component { avatarLoaded: false, activeOrderId: data.active_order_id ? data.active_order_id : null, referralCode: data.referral_code, - earnedRewards: data.earned_rewards, + earnedRewards: data.earned_rewards ?? 0, lastOrderId: data.last_order_id ? data.last_order_id : null, stealthInvoices: data.wants_stealth, }) @@ -106,7 +106,7 @@ class UserGenPage extends Component { activeOrderId: data.active_order_id ? data.active_order_id : null, lastOrderId: data.last_order_id ? data.last_order_id : null, referralCode: data.referral_code, - earnedRewards: data.earned_rewards, + earnedRewards: data.earned_rewards ?? 0, stealthInvoices: data.wants_stealth, tgEnabled: data.tg_enabled, tgBotName: data.tg_bot_name, @@ -183,10 +183,6 @@ class UserGenPage extends Component { }; 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 fontSize = this.props.theme.typography.fontSize; const fontSizeFactor = fontSize / 14; // to scale sizes, default fontSize is 14 @@ -433,7 +429,7 @@ class UserGenPage extends Component { - +
diff --git a/frontend/src/models/Info.model.ts b/frontend/src/models/Info.model.ts index 3fcf2b7b..0b5d145e 100644 --- a/frontend/src/models/Info.model.ts +++ b/frontend/src/models/Info.model.ts @@ -20,19 +20,6 @@ export interface Info { coordinatorVersion: string; clientVersion: string; 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 = { @@ -57,19 +44,6 @@ export const defaultInfo: Info = { coordinatorVersion: 'v?.?.?', clientVersion: 'v?.?.?', 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; diff --git a/frontend/src/utils/filterOrders.ts b/frontend/src/utils/filterOrders.ts index 1b423dcb..ba31ef1d 100644 --- a/frontend/src/utils/filterOrders.ts +++ b/frontend/src/utils/filterOrders.ts @@ -14,7 +14,7 @@ interface FilterOrders { paymentMethods?: string[]; } -const filterByPayment = function (order: Order, paymentMethods: string[]) { +const filterByPayment = function (order: Order, paymentMethods: any[]) { if (paymentMethods.length === 0) { return true; } else { @@ -27,17 +27,19 @@ const filterByPayment = function (order: Order, paymentMethods: string[]) { }; const filterByAmount = function (order: Order, filter: AmountFilter) { - const filterMaxAmount = filter.amount != '' ? filter.amount : filter.maxAmount; - const filterMinAmount = filter.amount != '' ? filter.amount : filter.minAmount; - const orderMinAmount = - order.amount === '' || order.amount === null ? order.min_amount : order.amount; - const orderMaxAmount = - order.amount === '' || order.amount === null ? order.max_amount : order.amount; + const filterMaxAmount = + Number(filter.amount != '' ? filter.amount : filter.maxAmount) * (1 + filter.threshold); + const filterMinAmount = + Number(filter.amount != '' ? filter.amount : filter.minAmount) * (1 - filter.threshold); - return ( - orderMaxAmount < filterMaxAmount * (1 + filter.threshold) && - orderMinAmount > filterMinAmount * (1 - filter.threshold) + const orderMinAmount = Number( + order.amount === '' || order.amount === null ? order.min_amount : order.amount, ); + 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 ({ @@ -55,7 +57,6 @@ const filterOrders = function ({ return typeChecks && currencyChecks && paymentMethodChecks && amountChecks; }); - return filteredOrders; };