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

Commit 9bf3b85

Browse files
authored
Revert "Revert "V20191104_0""
1 parent 8b94ec2 commit 9bf3b85

File tree

23 files changed

+659
-241
lines changed

23 files changed

+659
-241
lines changed

.jest

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000
1+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000
22

33
process.on('unhandledRejection', e => console.log(e))

package-lock.json

+186-119
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"scripts": {
2323
"start": "gulp watch",
24-
"test": "eslint src/ && jest -w 10 --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
24+
"test": "eslint src/ && jest -w 1 --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
2525
"release": "d() { test -z $1 && echo 'Please specify branch.' && exit 1; (git show-branch $1) || exit 1; git stash; git checkout $1; npm i; rm -rf branch/$1; mkdir -p branch/$1 ; gulp build-min; cp -r www/ branch/$1; gulp release-branch --branch $1;}; d",
2626
"release-production": "d() { git stash; git checkout master; npm i;gulp build-min;gulp release-master;}; d",
2727
"build": "webpack --config webpack.config.cli.js"
@@ -53,7 +53,7 @@
5353
"coveralls": "^3.0.3",
5454
"deep-diff": "^1.0.2",
5555
"del": "^4.1.1",
56-
"es6-plato": "^1.1.6",
56+
"es6-plato": "^1.2.2",
5757
"eslint": "^4.14.0",
5858
"eslint-config-airbnb": "^16.1.0",
5959
"eslint-config-binary": "^1.0.2",

src/botPage/bot/Interface/ToolsInterface.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import CandleInterface from './CandleInterface';
22
import MiscInterface from './MiscInterface';
33
import IndicatorsInterface from './IndicatorsInterface';
4+
import WebhookInterface from './WebhookInterface';
45
import { translate } from '../../../common/i18n';
56

67
// prettier-ignore
78
export default Interface => class extends IndicatorsInterface(
8-
MiscInterface(CandleInterface(Interface))) {
9+
MiscInterface(CandleInterface(WebhookInterface(Interface)))) {
910
getToolsInterface() {
1011
return {
1112
getTime : () => parseInt(new Date().getTime() / 1000),
@@ -76,6 +77,7 @@ export default Interface => class extends IndicatorsInterface(
7677
...this.getCandleInterface(),
7778
...this.getMiscInterface(),
7879
...this.getIndicatorsInterface(),
80+
...this.getWebhookInterface(),
7981
};
8082
}
8183
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { notify } from '../broadcast';
2+
import { translate } from '../../../common/i18n';
3+
4+
export default Interface =>
5+
class extends Interface {
6+
// eslint-disable-next-line class-methods-use-this
7+
sendWebhook(url, payload) {
8+
const onError = () => notify('warn', translate('Unable to send webhook'));
9+
const fetchOption = {
10+
method : 'POST',
11+
mode : 'cors',
12+
headers: { 'Content-Type': 'application/json' },
13+
};
14+
15+
if (payload) {
16+
fetchOption.body = JSON.stringify(payload);
17+
}
18+
19+
fetch(url, fetchOption)
20+
.then(response => {
21+
if (!response.ok) {
22+
onError();
23+
}
24+
})
25+
.catch(onError);
26+
}
27+
28+
getWebhookInterface() {
29+
return {
30+
sendWebhook: this.sendWebhook,
31+
};
32+
}
33+
};
+11-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { roundBalance } from '../../common/tools';
22
import { info } from '../broadcast';
3-
4-
let balanceStr = '';
3+
import { observer as globalObserver } from '../../../common/utils/observer';
54

65
export default Engine =>
76
class Balance extends Engine {
@@ -11,26 +10,30 @@ export default Engine =>
1110
balance: { balance: b, currency },
1211
} = r;
1312

14-
this.balance = roundBalance({ currency, balance: b });
15-
balanceStr = `${this.balance} ${currency}`;
13+
const balance = roundBalance({ currency, balance: b });
14+
const balanceStr = `${balance} ${currency}`;
15+
16+
globalObserver.setState({ balance, currency });
1617

1718
info({ accountID: this.accountInfo.loginid, balance: balanceStr });
1819
});
1920
}
2021
// eslint-disable-next-line class-methods-use-this
2122
getBalance(type) {
2223
const { scope } = this.store.getState();
23-
let { balance } = this;
24+
const currency = globalObserver.getState('currency');
25+
let balance = globalObserver.getState('balance');
2426

2527
// Deduct trade `amount` in this scope for correct value in `balance`-block
2628
if (scope === 'BEFORE_PURCHASE') {
2729
balance = roundBalance({
28-
currency: this.tradeOptions.currency,
29-
balance : Number(balance) - this.tradeOptions.amount,
30+
balance: Number(balance) - this.tradeOptions.amount,
31+
currency,
3032
});
31-
balanceStr = `${balance} ${this.tradeOptions.currency}`;
3233
}
3334

35+
const balanceStr = `${balance}`;
36+
3437
return type === 'STR' ? balanceStr : Number(balance);
3538
}
3639
};

src/botPage/bot/TradeEngine/index.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,23 @@ export default class TradeEngine extends Balance(Purchase(Sell(OpenContract(Prop
115115
this.listen('authorize', ({ authorize }) => {
116116
this.accountInfo = authorize;
117117
this.token = token;
118-
this.api.subscribeToBalance().then(r => {
119-
this.balance = Number(r.balance.balance);
118+
119+
// Only subscribe to balance in browser, not for tests.
120+
if (document) {
121+
this.api.subscribeToBalance().then(response => {
122+
const {
123+
balance: { balance, currency },
124+
} = response;
125+
126+
globalObserver.setState({
127+
balance: Number(balance),
128+
currency,
129+
});
130+
resolve();
131+
});
132+
} else {
120133
resolve();
121-
});
134+
}
122135
})
123136
);
124137
}

src/botPage/bot/__tests__/BotApi.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('Interface', () => {
3232
currency : 'USD',
3333
duration : 5,
3434
duration_unit: 't',
35+
basis : 'stake',
3536
});
3637

3738
watch('before').then(c => {

src/botPage/bot/__tests__/UI.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ expectReturnTrue(
3838
prediction: undefined,
3939
barrierOffset: undefined,
4040
secondBarrierOffset: undefined,
41+
basis: 'stake',
4142
});
4243
}
4344

src/botPage/bot/__tests__/tools.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const start = options =>
1515
`
1616
Bot.start({
1717
amount: 1,
18-
currency: 'USD', ${options || ''}
18+
currency: 'USD', ${options || ''},
19+
basis: 'stake',
1920
});
2021
`;
2122

src/botPage/bot/tools.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const tradeOptionToProposal = tradeOption =>
99
tradeOption.contractTypes.map(type => {
1010
const proposal = {
1111
duration_unit: tradeOption.duration_unit,
12-
basis : 'stake',
12+
basis : tradeOption.basis,
1313
currency : tradeOption.currency,
1414
symbol : tradeOption.symbol,
1515
duration : tradeOption.duration,

src/botPage/common/const.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ const CRYPTO_CURRENCIES = ['BTC', 'ETH', 'LTC', 'BCH'];
88

99
const config = {
1010
lists: {
11-
PAYOUTTYPE: [
12-
// [translate('Payout'), 'payout'],
13-
[translate('Stake'), 'stake'],
14-
],
1511
CRYPTO_CURRENCIES,
1612
DETAILS: [
1713
[translate('statement'), '1'],
@@ -232,9 +228,9 @@ const config = {
232228
bbResult : [[translate('upper'), '1'], [translate('middle'), '0'], [translate('lower'), '2']],
233229
macdFields: [[translate('Histogram'), '0'], [translate('MACD'), '1'], [translate('Signal'), '2']],
234230
gd : {
235-
cid: '646610722767-7ivdbunktgtnumj23en9gkecbgtf2ur7.apps.googleusercontent.com',
236-
aid: 'binarybot-237009',
237-
api: 'AIzaSyBieTeLip_lVQZUimIuJypU1kJyqOvQRgc',
231+
cid: '828416594271-qj2dnf4u2omg1iugangbtsrq6p0a55oc.apps.googleusercontent.com',
232+
aid: 'derivbot-248506',
233+
api: 'AIzaSyBDYQ7IIgGxM14IeAV5JrtaJNYjxB4A5jo',
238234
},
239235
};
240236

src/botPage/view/View.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
} from '../../common/utils/storageManager';
4141
import { isProduction } from '../../common/utils/tools';
4242
import GTM from '../../common/gtm';
43+
import { saveBeforeUnload } from './blockly/utils';
4344

4445
let realityCheckTimeout;
4546

@@ -76,6 +77,8 @@ api.events.on('balance', response => {
7677
const element = elTopMenuBalance;
7778
element.textContent = `${balance} ${currency}`;
7879
});
80+
81+
globalObserver.setState({ balance: b, currency });
7982
});
8083

8184
const addBalanceForToken = token => {
@@ -90,14 +93,6 @@ const chart = new Chart(api);
9093

9194
const tradingView = new TradingView();
9295

93-
const setBeforeUnload = off => {
94-
if (off) {
95-
window.onbeforeunload = null;
96-
} else {
97-
window.onbeforeunload = () => 'You have some unsaved blocks, do you want to save them before you exit?';
98-
}
99-
};
100-
10196
const showRealityCheck = () => {
10297
$('.blocker').show();
10398
$('.reality-check').show();
@@ -472,7 +467,7 @@ export default class View {
472467
$('#toggleHeaderButton').click(() => this.showHeader($('#header').is(':hidden')));
473468

474469
$('#logout, #toolbox-logout').click(() => {
475-
setBeforeUnload(true);
470+
saveBeforeUnload();
476471
logout();
477472
hideRealityCheck();
478473
});
@@ -610,7 +605,7 @@ export default class View {
610605

611606
$('#login, #toolbox-login')
612607
.bind('click.login', () => {
613-
setBeforeUnload(true);
608+
saveBeforeUnload();
614609
document.location = getOAuthURL();
615610
})
616611
.text(translate('Log in'));

src/botPage/view/blockly/blocks/tools/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ import './block_holder';
77
import './loader';
88
import './candle';
99
import './time';
10+
import './webhook';
11+
import './key_value_pair';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { translate } from '../../../../../common/i18n';
2+
3+
Blockly.Blocks.key_value_pair = {
4+
init() {
5+
this.jsonInit({
6+
message0: translate('Key: %1 Value: %2'),
7+
args0 : [
8+
{
9+
type: 'field_input',
10+
name: 'KEY',
11+
text: 'default',
12+
},
13+
{
14+
type: 'input_value',
15+
name: 'VALUE',
16+
},
17+
],
18+
colour : '#dedede',
19+
output : null,
20+
tooltip: translate('Returns a string representation of a key value pair'),
21+
});
22+
},
23+
};
24+
25+
Blockly.JavaScript.key_value_pair = block => {
26+
const key = block.getFieldValue('KEY') || '';
27+
const value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_ATOMIC) || null;
28+
29+
if (!key) {
30+
return '';
31+
}
32+
33+
return [`{"${key}":${value}}`, Blockly.JavaScript.ORDER_ATOMIC];
34+
};

0 commit comments

Comments
 (0)