Skip to content

Commit e41ca28

Browse files
authored
Merge branch 'dev' into contract-pip-size
2 parents 10a184f + 29af92f commit e41ca28

File tree

7 files changed

+86
-20
lines changed

7 files changed

+86
-20
lines changed

src/botPage/bot/Interpreter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ export default class Interpreter {
149149
}
150150
terminateSession() {
151151
this.$scope.api.disconnect();
152-
globalObserver.emit('bot.stop');
153152
this.stopped = true;
153+
154+
globalObserver.emit('bot.stop');
155+
globalObserver.setState({ isRunning: false });
154156
}
155157
stop() {
156158
if (this.bot.tradeEngine.isSold === false && !this.isErrorTriggered) {

src/botPage/bot/TradeEngine/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
9292
}
9393

9494
globalObserver.emit('bot.running');
95+
globalObserver.setState({ isRunning: true });
9596

9697
this.tradeOptions = expectTradeOptions(tradeOptions);
9798

src/botPage/view/View.js

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,19 @@ export default class View {
511511
});
512512

513513
const startBot = limitations => {
514-
const $runButtons = $('#runButton, #summaryRunButton');
515-
const $stopButtons = $('#stopButton, #summaryStopButton');
516-
$stopButtons.show();
517-
$runButtons.hide();
518-
$runButtons.prop('disabled', true);
514+
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
515+
const elStopButtons = document.querySelectorAll('#stopButton, #summaryStopButton');
516+
517+
elRunButtons.forEach(el => {
518+
const elRunButton = el;
519+
elRunButton.style.display = 'none';
520+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
521+
});
522+
elStopButtons.forEach(el => {
523+
const elStopButton = el;
524+
elStopButton.style.display = 'inline-block';
525+
});
526+
519527
globalObserver.emit('summary.disable_clear');
520528
showSummary();
521529
this.blockly.run(limitations);
@@ -627,31 +635,54 @@ export default class View {
627635
this.blockly.stop();
628636
}
629637
addEventHandlers() {
638+
const getRunButtonElements = () => document.querySelectorAll('#runButton, #summaryRunButton');
639+
const getStopButtonElements = () => document.querySelectorAll('#stopButton, #summaryStopButton');
640+
630641
window.addEventListener('storage', e => {
631642
window.onbeforeunload = null;
632643
if (e.key === 'activeToken' && !e.newValue) window.location.reload();
633644
if (e.key === 'realityCheckTime') hideRealityCheck();
634645
});
635646

636647
globalObserver.register('Error', error => {
637-
$('#runButton, #summaryRunButton').prop('disabled', false);
648+
getRunButtonElements().forEach(el => {
649+
const elRunButton = el;
650+
elRunButton.removeAttribute('disabled');
651+
});
652+
638653
if (error.error && error.error.error.code === 'InvalidToken') {
639654
removeAllTokens();
640655
updateTokenList();
641656
this.stop();
642657
}
643658
});
644659

660+
globalObserver.register('bot.running', () => {
661+
getRunButtonElements().forEach(el => {
662+
const elRunButton = el;
663+
elRunButton.style.display = 'none';
664+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
665+
});
666+
getStopButtonElements().forEach(el => {
667+
const elStopButton = el;
668+
elStopButton.style.display = 'inline-block';
669+
elStopButton.removeAttribute('disabled');
670+
});
671+
});
672+
645673
globalObserver.register('bot.stop', () => {
646-
const $runButtons = $('#runButton, #summaryRunButton');
647-
const $stopButtons = $('#stopButton, #summaryStopButton');
648-
if ($runButtons.is(':visible') || $stopButtons.is(':visible')) {
649-
$runButtons.show();
650-
$stopButtons.hide();
651-
652-
$stopButtons.prop('disabled', false);
653-
$runButtons.prop('disabled', false);
654-
}
674+
// Enable run button, this event is emitted after the interpreter
675+
// killed the API connection.
676+
getStopButtonElements().forEach(el => {
677+
const elStopButton = el;
678+
elStopButton.style.display = null;
679+
elStopButton.removeAttribute('disabled');
680+
});
681+
getRunButtonElements().forEach(el => {
682+
const elRunButton = el;
683+
elRunButton.style.display = null;
684+
elRunButton.removeAttribute('disabled');
685+
});
655686
});
656687

657688
globalObserver.register('bot.info', info => {

src/botPage/view/blockly/blocks/shared.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,21 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
410410
return predictionRange;
411411
};
412412

413-
export const disableRunButton = isDisabled => {
414-
$('#runButton, #summaryRunButton').attr('disabled', isDisabled);
413+
export const disableRunButton = shouldDisable => {
414+
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
415+
const isRunning = globalObserver.getState('isRunning');
416+
417+
elRunButtons.forEach(elRunButton => {
418+
if (isRunning) {
419+
if (shouldDisable) {
420+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
421+
} else {
422+
// Do not enable. The bot is running.
423+
}
424+
} else if (shouldDisable) {
425+
elRunButton.setAttributeNode(document.createAttribute('disabled'));
426+
} else {
427+
elRunButton.removeAttribute('disabled');
428+
}
429+
});
415430
};

src/botPage/view/blockly/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,17 @@ while(true) {
440440
}
441441
stop(stopBeforeStart) {
442442
if (!stopBeforeStart) {
443-
$('#stopButton, #summaryStopButton').prop('disabled', true);
443+
const elRunButtons = document.querySelectorAll('#runButton, #summaryRunButton');
444+
const elStopButtons = document.querySelectorAll('#stopButton, #summaryStopButton');
445+
446+
elRunButtons.forEach(el => {
447+
const elRunButton = el;
448+
elRunButton.style.display = 'initial';
449+
});
450+
elStopButtons.forEach(el => {
451+
const elStopButton = el;
452+
elStopButton.style.display = null;
453+
});
444454
}
445455
if (this.interpreter) {
446456
this.interpreter.stop();

src/common/utils/observer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Map, List } from 'immutable';
33
export default class Observer {
44
constructor() {
55
this.eam = new Map(); // event action map
6+
this.state = {};
67
}
78
register(event, _action, once, unregisterIfError, unregisterAllBefore) {
89
if (unregisterAllBefore) {
@@ -53,6 +54,12 @@ export default class Observer {
5354
this.eam.get(event).forEach(action => action.action(data));
5455
}
5556
}
57+
setState(state = {}) {
58+
this.state = Object.assign({}, this.state, state);
59+
}
60+
getState(key) {
61+
return this.state[key];
62+
}
5663
}
5764

5865
export const observer = new Observer();

static/css/bot.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ body {
169169
background: black;
170170
}
171171

172-
#stopButton {
172+
#stopButton, #summaryStopButton {
173173
display: none;
174174
}
175175

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy