From b2c21d4a98c49f6168bc3ff6e6a3d7b9f8943a12 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Wed, 19 Oct 2022 07:26:00 -0700 Subject: [PATCH] Small fixes (more) --- frontend/src/components/BottomBar.js | 27 ++++------ frontend/src/components/Main.tsx | 1 + .../src/components/MakerPage/MakerForm.tsx | 53 +++++++++---------- frontend/src/components/UserGenPage.js | 24 ++++----- frontend/src/models/Maker.model.ts | 2 + frontend/src/models/Robot.model.ts | 14 ++++- 6 files changed, 63 insertions(+), 58 deletions(-) diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index 5b510297..fb1ac8dd 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -146,7 +146,7 @@ class BottomBar extends Component { const hasRewards = this.props.robot.earnedRewards > 0; const hasOrder = !!( (this.props.robot.activeOrderId > 0) & - !this.props.infoprofileShown & + !this.state.profileShown & this.props.robot.avatarLoaded ); const fontSize = this.props.theme.typography.fontSize; @@ -175,7 +175,7 @@ class BottomBar extends Component { 0) & !this.props.robot.profileShown + (this.props.robot.activeOrderId > 0) & !this.state.profileShown ? 'primary' : undefined } @@ -439,7 +439,10 @@ class BottomBar extends Component { this.props.robot.avatarLoaded ); return ( - +
@@ -458,12 +461,12 @@ class BottomBar extends Component { style={{ width: 55, height: 55 }} avatarClass='phoneFlippedSmallAvatar' statusColor={ - (this.props.activeOrderId > 0) & !this.props.profileShown + (this.props.activeOrderId > 0) & !this.state.profileShown ? 'primary' : undefined } - nickname={this.props.nickname} - onLoad={() => this.props.setAppState({ avatarLoaded: true })} + nickname={this.props.robot.nickname} + onLoad={() => this.props.setRobot({ ...this.props.robot, avatarLoaded: true })} /> @@ -475,10 +478,6 @@ class BottomBar extends Component { - this.props.setAppState({ buyChecked: false, sellChecked: true, type: 0 }) & - this.getInfo() - } to={`/book/`} component={LinkRouter} > @@ -494,10 +493,6 @@ class BottomBar extends Component { - this.props.setAppState({ buyChecked: true, sellChecked: false, type: 1 }) & - this.getInfo() - } to={`/book/`} component={LinkRouter} > @@ -513,7 +508,7 @@ class BottomBar extends Component { this.getInfo()} + onClick={() => this.props.fetchInfo()} to={`/`} component={LinkRouter} > @@ -578,7 +573,7 @@ class BottomBar extends Component { /> diff --git a/frontend/src/components/Main.tsx b/frontend/src/components/Main.tsx index c2535696..274d04c7 100644 --- a/frontend/src/components/Main.tsx +++ b/frontend/src/components/Main.tsx @@ -117,6 +117,7 @@ const Main = (): JSX.Element => { }); }; + console.log(robot); return (
diff --git a/frontend/src/components/MakerPage/MakerForm.tsx b/frontend/src/components/MakerPage/MakerForm.tsx index 98cd0b40..67f07e70 100644 --- a/frontend/src/components/MakerPage/MakerForm.tsx +++ b/frontend/src/components/MakerPage/MakerForm.tsx @@ -75,7 +75,6 @@ const MakerForm = ({ const theme = useTheme(); const history = useHistory(); const [badRequest, setBadRequest] = useState(null); - const [advancedOptions, setAdvancedOptions] = useState(false); const [amountLimits, setAmountLimits] = useState([1, 1000]); const [satoshisLimits, setSatoshisLimits] = useState([20000, 4000000]); const [currentPrice, setCurrentPrice] = useState('...'); @@ -142,7 +141,7 @@ const MakerForm = ({ }); updateAmountLimits(limits.list, newCurrency, maker.premium); updateCurrentPrice(limits.list, newCurrency, maker.premium); - if (advancedOptions) { + if (maker.advancedOptions) { setMaker({ ...maker, minAmount: parseFloat(Number(limits.list[newCurrency].max_amount * 0.25).toPrecision(2)), @@ -230,7 +229,7 @@ const MakerForm = ({ }; const handleClickExplicit = function () { - if (!advancedOptions) { + if (!maker.advancedOptions) { setMaker({ ...maker, isExplicit: true, @@ -244,10 +243,10 @@ const MakerForm = ({ const body = { type: fav.type == 0 ? 1 : 0, currency: fav.currency == 0 ? 1 : fav.currency, - amount: advancedOptions ? null : maker.amount, - has_range: advancedOptions, - min_amount: advancedOptions ? maker.minAmount : null, - max_amount: advancedOptions ? maker.maxAmount : null, + amount: maker.advancedOptions ? null : maker.amount, + has_range: maker.advancedOptions, + min_amount: maker.advancedOptions ? maker.minAmount : null, + max_amount: maker.advancedOptions ? maker.maxAmount : null, payment_method: maker.paymentMethodsText === '' ? 'not specified' : maker.paymentMethodsText, is_explicit: maker.isExplicit, @@ -295,13 +294,12 @@ const MakerForm = ({ }; const handleClickAdvanced = function () { - if (advancedOptions) { + if (maker.advancedOptions) { handleClickRelative(); + setMaker({ ...maker, advancedOptions: false }); } else { - resetRange(); + resetRange(true); } - - setAdvancedOptions(!advancedOptions); }; 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 minAmount = maker.amount ? parseFloat((maker.amount / 2).toPrecision(2)) @@ -333,6 +331,7 @@ const MakerForm = ({ setMaker({ ...maker, + advancedOptions, minAmount, maxAmount, }); @@ -376,11 +375,11 @@ const MakerForm = ({ return ( fav.type == null || (maker.amount != '' && - !advancedOptions && + !maker.advancedOptions && (maker.amount < amountLimits[0] || maker.amount > amountLimits[1])) || - (maker.amount == null && (!advancedOptions || limits.loading)) || - (advancedOptions && (minAmountError() || maxAmountError())) || - (maker.amount <= 0 && !advancedOptions) || + (maker.amount == null && (!maker.advancedOptions || limits.loading)) || + (maker.advancedOptions && (minAmountError() || maxAmountError())) || + (maker.amount <= 0 && !maker.advancedOptions) || (maker.isExplicit && (maker.badSatoshisText != '' || maker.satoshis == '')) || (!maker.isExplicit && maker.badPremiumText != '') ); @@ -404,7 +403,7 @@ const MakerForm = ({ : fav.type == 1 ? t('Buy order for ') : t('Sell order for ')} - {advancedOptions && maker.minAmount != '' + {maker.advancedOptions && maker.minAmount != '' ? pn(maker.minAmount) + '-' + pn(maker.maxAmount) : pn(maker.amount)} {' ' + currencyCode} @@ -478,7 +477,7 @@ const MakerForm = ({ @@ -498,7 +497,7 @@ const MakerForm = ({
- + diff --git a/frontend/src/components/UserGenPage.js b/frontend/src/components/UserGenPage.js index 2c6874e1..24a3868a 100644 --- a/frontend/src/components/UserGenPage.js +++ b/frontend/src/components/UserGenPage.js @@ -78,14 +78,6 @@ class UserGenPage extends Component { }); requestBody.then((body) => 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) data.bad_request ? this.props.setRobot({ @@ -111,6 +103,10 @@ class UserGenPage extends Component { tgEnabled: data.tg_enabled, tgBotName: data.tg_bot_name, 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('pub_key', data.public_key.split('\n').join('\\')) & @@ -174,11 +170,11 @@ class UserGenPage extends Component { createJsonFile = () => { return { - token: systemClient.getCookie('robot_token'), - token_shannon_entropy: this.state.shannon_entropy, - token_bit_entropy: this.state.bit_entropy, - public_key: systemClient.getCookie('pub_key').split('\\').join('\n'), - encrypted_private_key: systemClient.getCookie('enc_priv_key').split('\\').join('\n'), + token: this.props.robot.token, + token_shannon_entropy: this.props.robot.shannonEntropy, + token_bit_entropy: this.props.robot.bitsEntropy, + public_key: this.props.robot.pub_key, + encrypted_private_key: this.props.robot.enc_priv_key, }; }; @@ -356,7 +352,7 @@ class UserGenPage extends Component { - {this.state.inputTokenHasChanged ? ( + {this.state.tokenHasChanged ? (