Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aa6e7dd
Reset stats on summary.clear event
Feb 25, 2019
8850584
Create common showDialog() function
Feb 25, 2019
041b1c3
Move summary-toolbox to TradeInfoPanel, use React.Fragment as contain…
Feb 25, 2019
e398624
Reset account stats on summary.clear
Feb 25, 2019
2563a7d
Reset TradeTable on summary.clear event
Feb 25, 2019
d614e0b
Add ClearButton to TradeInfoPanel, wrap RunButton+ClearButton in summ…
Feb 25, 2019
ce06595
Use common showDialog() for some binds, add rules for (en|dis)abling …
Feb 25, 2019
5fff697
Refactor to use showDialog() function
Feb 25, 2019
88170f8
Clean up template, dialogs are now generated dynamically
Feb 25, 2019
1911958
Add CSS rules for icon-clear
Feb 25, 2019
6ec94b9
Add enabled & disabled clear svgs
Feb 25, 2019
8408cf3
Create ClearButton
Feb 25, 2019
b679100
Position ClearButton
Feb 25, 2019
5a5cc9e
Update message
Feb 26, 2019
5b49086
Restore setTimeout for cleanUp
Feb 26, 2019
06aa3ad
Merge branch 'dev' into summary-clear-button
ashkanx Feb 28, 2019
888512f
Convert to PureComponent
Mar 1, 2019
5db1a5c
Enable/disable clear button
Mar 1, 2019
4030854
Determine state of summaryClearButton in TradeTable
Mar 1, 2019
deb85c1
Update icons
Mar 1, 2019
eb1bf43
Fix eslint errors
Mar 1, 2019
77ad10f
Check if rows are defined
Mar 1, 2019
f90c16d
Rows fix
Mar 4, 2019
8b7439b
Fix positioning cross-browser
Mar 5, 2019
098d596
Fix enable/disable behaviour
Mar 5, 2019
8a487d9
Merge pull request #1274 from aaron-binary/summary-clear-button
ashkanx Mar 5, 2019
618d4a5
fix input floating
cakasuma Mar 6, 2019
7ca284f
PleaseAuthenticate
Mar 6, 2019
579790b
FinancialAssessmentRequired
Mar 6, 2019
3bacf10
Merge pull request #1301 from aaron-binary/please-authenticate
ashkanx Mar 6, 2019
811bcd9
Merge branch 'dev' into amam/fix_input_floating
ashkanx Mar 6, 2019
2fbbe1e
Merge pull request #1299 from cakasuma/amam/fix_input_floating
ashkanx Mar 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/botPage/bot/Interpreter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const unrecoverableErrors = [
'InvalidCurrency',
'ContractBuyValidationError',
'NotDefaultCurrency',
'PleaseAuthenticate',
'FinancialAssessmentRequired',
];
const botInitialized = bot => bot && bot.tradeEngine.options;
const botStarted = bot => botInitialized(bot) && bot.tradeEngine.tradeOptions;
Expand Down
13 changes: 12 additions & 1 deletion src/botPage/bot/TradeEngine/Total.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { translate } from '../../../common/i18n';
import { roundBalance } from '../../common/tools';
import { info, notify } from '../broadcast';
import createError from '../../common/error';
import { observer as globalObserver } from '../../../common/utils/observer';

const skeleton = {
totalProfit: 0,
Expand All @@ -20,6 +21,14 @@ export default Engine =>
super();
this.sessionRuns = 0;
this.sessionProfit = 0;

globalObserver.register('summary.clear', () => {
this.sessionRuns = 0;
this.sessionProfit = 0;

const { loginid: accountID } = this.accountInfo;
globalStat[accountID] = { ...skeleton };
});
}
updateTotals(contract) {
const { sell_price: sellPrice, buy_price: buyPrice, currency } = contract;
Expand Down Expand Up @@ -87,7 +96,9 @@ export default Engine =>
return;
}

const { limitations: { maxLoss, maxTrades } } = tradeOption;
const {
limitations: { maxLoss, maxTrades },
} = tradeOption;

if (maxLoss && maxTrades) {
if (this.sessionRuns >= maxTrades) {
Expand Down
45 changes: 45 additions & 0 deletions src/botPage/bot/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,48 @@ export const createDetails = contract => {
};

export const getUUID = () => `${new Date().getTime() * Math.random()}`;

export const showDialog = options =>
new Promise((resolve, reject) => {
const $dialog = $('<div/>', { class: 'draggable-dialog', title: options.title });
options.text.forEach(text => $dialog.append(`<p style="margin: 0.7em;">${text}</p>`));
const defaultButtons = [
{
text : translate('No'),
class: 'button-secondary',
click() {
$(this).dialog('close');
$(this).remove();
reject();
},
},
{
text : translate('Yes'),
class: 'button-primary',
click() {
$(this).dialog('close');
$(this).remove();
resolve();
},
},
];
const dialogOptions = {
autoOpen : false,
classes : { 'ui-dialog-titlebar-close': 'icon-close' },
closeText: '',
height : 'auto',
width : 600,
modal : true,
resizable: false,
open() {
$(this)
.parent()
.find('.ui-dialog-buttonset > button')
.removeClass('ui-button ui-corner-all ui-widget');
},
};
Object.assign(dialogOptions, { buttons: options.buttons || defaultButtons });

$dialog.dialog(dialogOptions);
$dialog.dialog('open');
});
39 changes: 39 additions & 0 deletions src/botPage/view/TradeInfoPanel/ClearButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import { observer as globalObserver } from '../../../common/utils/observer';
import { showDialog } from '../../bot/tools';
import { translate } from '../../../common/utils/tools';

export default class ClearButton extends React.PureComponent {
constructor() {
super();
this.state = { isButtonDisabled: true };
}
componentDidMount() {
globalObserver.register('summary.enable_clear', () => this.setState({ isButtonDisabled: false }));
globalObserver.register('summary.disable_clear', () => this.setState({ isButtonDisabled: true }));
}
// eslint-disable-next-line class-methods-use-this
confirmClearLog() {
showDialog({
title: translate('Are you sure?'),
text : [
translate(
'This will clear all transactions in the summary panel, and all counters will be reset to zero.'
),
],
})
.then(() => globalObserver.emit('summary.clear'))
.catch(() => {});
}
render() {
return (
<button
title="Clear summary log"
id="summaryClearButton"
className="toolbox-button icon-clear"
onClick={this.confirmClearLog}
disabled={this.state.isButtonDisabled}
/>
);
}
}
4 changes: 2 additions & 2 deletions src/botPage/view/TradeInfoPanel/RunButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React from 'react';
import { translate } from '../../../common/i18n';

const RunButton = () => (
<div className="summary-toolbox">
<React.Fragment>
<button title="Run the bot" id="summaryRunButton" className="toolbox-button icon-run" />
<button
title={translate('Stop the bot')}
id="summaryStopButton"
className="toolbox-button icon-stop"
style={{ display: 'none' }}
/>
</div>
</React.Fragment>
);

export default RunButton;
12 changes: 8 additions & 4 deletions src/botPage/view/TradeInfoPanel/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { translate } from '../../../common/i18n';
import * as style from '../style';

export default class Summary extends Component {
constructor({ accountID }) {
super();
this.state = { [accountID]: {} };
}
componentWillMount() {
globalObserver.register('bot.info', info => {
const { accountID } = info;
this.setState({ [accountID]: { ...this.state[accountID], ...info } });
});
}
constructor({ accountID }) {
super();
this.state = { [accountID]: {} };
globalObserver.register('summary.clear', () => {
const { accountID } = this.props;
this.setState({ [accountID]: {} });
});
}
render() {
const { accountID } = this.props;
Expand Down
17 changes: 14 additions & 3 deletions src/botPage/view/TradeInfoPanel/TradeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@ export default class TradeTable extends Component {
}
componentWillMount() {
globalObserver.register('summary.export', () => {
const { accountID } = this.props;
const { rows } = this.state[accountID];
if (rows.length) this.export();
const accountData = this.state[this.props.accountID];
if (accountData && accountData.rows.length > 0) {
this.export();
}
});
globalObserver.register('summary.clear', () => {
this.setState({ [this.props.accountID]: { ...this.state.initial } });
globalObserver.emit('summary.disable_clear');
});
globalObserver.register('bot.stop', () => {
const accountData = this.state[this.props.accountID];
if (accountData && accountData.rows.length > 0) {
globalObserver.emit('summary.enable_clear');
}
});
globalObserver.register('bot.contract', info => {
if (!info) {
Expand Down
7 changes: 5 additions & 2 deletions src/botPage/view/TradeInfoPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { translate } from '../../../common/i18n';
import Summary from './Summary';
import TradeTable from './TradeTable';
import RunButton from './RunButton';
import ClearButton from './ClearButton';

const resetAnimation = () => {
$('.circle-wrapper')
Expand Down Expand Up @@ -151,7 +152,10 @@ export default class TradeInfoPanel extends Component {
<div>
<div className="content">
<div className="content-row">
<RunButton />
<div className="summary-toolbox">
<RunButton />
<ClearButton />
</div>
</div>
<div className="content-row">
<AnimateTrade />
Expand All @@ -162,7 +166,6 @@ export default class TradeInfoPanel extends Component {
<div className="content-row">
<Summary accountID={accountID} />
</div>

<div>
<p id="sync-warning">
{translate(
Expand Down
Loading