Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Commit 247e517

Browse files
authored
Merge branch 'dev' into misc-blocks
2 parents 276e125 + d3b2699 commit 247e517

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

src/botPage/view/View.js

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

513513
const startBot = limitations => {
514-
$('#stopButton, #summaryStopButton').show();
515-
$('#runButton, #summaryRunButton').hide();
516-
$('#runButton, #summaryRunButton').prop('disabled', true);
514+
const $runButtons = $('#runButton, #summaryRunButton');
515+
const $stopButtons = $('#stopButton, #summaryStopButton');
516+
$stopButtons.show();
517+
$runButtons.hide();
518+
$runButtons.prop('disabled', true);
517519
globalObserver.emit('summary.disable_clear');
518520
showSummary();
519521
this.blockly.run(limitations);
@@ -641,7 +643,15 @@ export default class View {
641643
});
642644

643645
globalObserver.register('bot.stop', () => {
644-
$('#runButton, #summaryRunButton').prop('disabled', false);
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+
}
645655
});
646656

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

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,7 @@ export const getPredictionForContracts = (contracts, selectedContractType) => {
409409
}
410410
return predictionRange;
411411
};
412+
413+
export const disableRunButton = isDisabled => {
414+
$('#runButton, #summaryRunButton').attr('disabled', isDisabled);
415+
};

src/botPage/view/blockly/blocks/trade/tradeOptions.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getDurationsForContracts,
66
getBarriersForContracts,
77
getPredictionForContracts,
8+
disableRunButton,
89
} from '../shared';
910
import { insideTrade } from '../../relationChecker';
1011
import { findTopParentBlock, hideInteractionsFromBlockly, getBlocksByType } from '../../utils';
@@ -102,33 +103,40 @@ export default () => {
102103
}
103104
},
104105
pollForContracts(symbol) {
106+
disableRunButton(true);
105107
return new Promise(resolve => {
106108
const contractsForSymbol = haveContractsForSymbol(symbol);
109+
110+
const resolveContracts = resolveObj => {
111+
disableRunButton(false);
112+
resolve(resolveObj);
113+
};
114+
107115
if (!contractsForSymbol) {
108116
// Register an event and use as a lock to avoid spamming API
109117
const event = `contractsLoaded.${symbol}`;
110118
if (!globalObserver.isRegistered(event)) {
111119
globalObserver.register(event, () => {});
112120
getContractsAvailableForSymbol(symbol).then(contracts => {
113121
globalObserver.unregisterAll(event); // Release the lock
114-
resolve(contracts);
122+
resolveContracts(contracts);
115123
});
116124
} else {
117125
// Request in progress, start polling localStorage until contracts are available.
118126
const pollingFn = setInterval(() => {
119127
const contracts = haveContractsForSymbol(symbol);
120128
if (contracts) {
121129
clearInterval(pollingFn);
122-
resolve(contracts.available);
130+
resolveContracts(contracts.available);
123131
}
124132
}, 100);
125133
setTimeout(() => {
126134
clearInterval(pollingFn);
127-
resolve([]);
135+
resolveContracts([]);
128136
}, 10000);
129137
}
130138
} else {
131-
resolve(contractsForSymbol.available);
139+
resolveContracts(contractsForSymbol.available);
132140
}
133141
});
134142
},

src/botPage/view/blockly/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,7 @@ while(true) {
409409
}
410410
stop(stopBeforeStart) {
411411
if (!stopBeforeStart) {
412-
const $runButtons = $('#runButton, #summaryRunButton');
413-
const $stopButtons = $('#stopButton, #summaryStopButton');
414-
if ($runButtons.is(':visible') || $stopButtons.is(':visible')) {
415-
$runButtons.show();
416-
$stopButtons.hide();
417-
}
412+
$('#stopButton, #summaryStopButton').prop('disabled', true);
418413
}
419414
if (this.interpreter) {
420415
this.interpreter.stop();

static/css/_toolbox.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
z-index: 0;
2828
overflow: auto;
2929

30-
#runButton[disabled], #runButton[disabled]:hover {
30+
#runButton[disabled], #runButton[disabled]:hover, #stopButton[disabled], #stopButton[disabled] {
3131
@include toolbox-runButton-disabled;
3232
}
3333

0 commit comments

Comments
 (0)