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

Commit b3d6036

Browse files
author
Aaron
authored
Merge pull request #2757 from binary-com/dev
dev to beta
2 parents 7feca07 + 311ccb2 commit b3d6036

File tree

16 files changed

+564
-58
lines changed

16 files changed

+564
-58
lines changed

package-lock.json

Lines changed: 391 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
"@babel/preset-env": "^7.4.4",
4444
"@babel/preset-react": "^7.0.0",
4545
"@babel/register": "^7.4.4",
46-
"@binary-com/binary-indicators": "^1.6.0",
46+
"@binary-com/binary-indicators": "^1.6.3",
4747
"app-module-path": "^2.2.0",
4848
"babel-eslint": "^10.0.1",
4949
"babel-jest": "^24.8.0",
5050
"babel-loader": "^8.0.6",
51-
"binary-live-api": "^29.0.0",
51+
"binary-live-api": "^29.0.1",
5252
"binary-utils": "^4.23.0",
5353
"chai": "^4.1.2",
5454
"coveralls": "^3.0.3",

src/botPage/bot/Interpreter.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ export default class Interpreter {
163163
this.loop();
164164
}
165165
terminateSession() {
166-
this.$scope.api.disconnect();
166+
const { socket } = this.$scope.api;
167+
if (socket.readyState === 0) {
168+
socket.addEventListener('open', () => {
169+
this.$scope.api.disconnect();
170+
});
171+
} else if (socket.readyState === 1) {
172+
this.$scope.api.disconnect();
173+
}
167174
this.stopped = true;
168175

169176
globalObserver.emit('bot.stop');

src/botPage/bot/TradeEngine/Balance.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,8 @@ export default Engine =>
2020
}
2121
// eslint-disable-next-line class-methods-use-this
2222
getBalance(type) {
23-
const { scope } = this.store.getState();
24-
const currency = globalObserver.getState('currency');
25-
let balance = globalObserver.getState('balance');
26-
27-
// Deduct trade `amount` in this scope for correct value in `balance`-block
28-
if (scope === 'BEFORE_PURCHASE') {
29-
balance = roundBalance({
30-
balance: Number(balance) - this.tradeOptions.amount,
31-
currency,
32-
});
33-
}
34-
23+
const balance = globalObserver.getState('balance');
3524
const balanceStr = `${balance}`;
36-
3725
return type === 'STR' ? balanceStr : Number(balance);
3826
}
3927
};

src/botPage/common/const.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ const config = {
235235
quick_strategies: ['martingale', 'dalembert'],
236236
};
237237

238-
export async function updateConfigCurrencies() {
239-
const api = generateLiveApiInstance();
238+
export async function updateConfigCurrencies(api = generateLiveApiInstance()) {
240239
try {
241240
const response = await api.getPayoutCurrencies();
242241
config.lists.CURRENCY = response.payout_currencies.map(c => [c, c]);

src/botPage/view/Dialogs/Chart.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class ChartContent extends PureComponent {
4141
this.state = {
4242
chartType : 'mountain',
4343
granularity: 0,
44-
symbol : 'R_100',
4544
barrierType: undefined,
4645
high : undefined,
4746
low : undefined,

src/botPage/view/View.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
addTokenIfValid,
2929
} from '../../common/appId';
3030
import { translate } from '../../common/i18n';
31+
import { isEuCountry, showHideEuElements, hasEuAccount } from '../../common/footer-checks';
3132
import googleDrive from '../../common/integrations/GoogleDrive';
3233
import { getLanguage } from '../../common/lang';
3334
import { observer as globalObserver } from '../../common/utils/observer';
@@ -43,6 +44,7 @@ import GTM from '../../common/gtm';
4344
import { saveBeforeUnload } from './blockly/utils';
4445

4546
let realityCheckTimeout;
47+
let chart;
4648

4749
const api = generateLiveApiInstance();
4850

@@ -89,8 +91,6 @@ const addBalanceForToken = token => {
8991
});
9092
};
9193

92-
const chart = new Chart(api);
93-
9494
const tradingView = new TradingView();
9595

9696
const showRealityCheck = () => {
@@ -186,6 +186,9 @@ const updateTokenList = () => {
186186
loginButton.show();
187187
accountList.hide();
188188

189+
// If logged out, determine EU based on IP.
190+
isEuCountry(api).then(isEu => showHideEuElements(isEu));
191+
189192
$('.account-id')
190193
.removeAttr('value')
191194
.text('');
@@ -196,13 +199,17 @@ const updateTokenList = () => {
196199
} else {
197200
loginButton.hide();
198201
accountList.show();
202+
199203
const activeToken = getActiveToken(tokenList, getStorage(AppConstants.STORAGE_ACTIVE_TOKEN));
204+
showHideEuElements(hasEuAccount(tokenList));
200205
updateLogo(activeToken.token);
201206
addBalanceForToken(activeToken.token);
207+
202208
if (!('loginInfo' in activeToken)) {
203209
removeAllTokens();
204210
updateTokenList();
205211
}
212+
206213
tokenList.forEach(tokenInfo => {
207214
const prefix = isVirtual(tokenInfo) ? 'Virtual Account' : `${tokenInfo.loginInfo.currency} Account`;
208215
if (tokenInfo === activeToken) {
@@ -212,7 +219,9 @@ const updateTokenList = () => {
212219
$('.account-type').text(`${prefix}`);
213220
} else {
214221
$('.login-id-list').append(
215-
`<a href="#" value="${tokenInfo.token}"><li><span>${prefix}</span><div>${tokenInfo.accountName}</div></li></a><div class="separator-line-thin-gray"></div>`
222+
`<a href="#" value="${tokenInfo.token}"><li><span>${prefix}</span><div>${
223+
tokenInfo.accountName
224+
}</div></li></a><div class="separator-line-thin-gray"></div>`
216225
);
217226
}
218227
});
@@ -231,7 +240,7 @@ export default class View {
231240
constructor() {
232241
logHandler();
233242
this.initPromise = new Promise(resolve => {
234-
updateConfigCurrencies().then(() => {
243+
updateConfigCurrencies(api).then(() => {
235244
symbolPromise.then(() => {
236245
updateTokenList();
237246
this.blockly = new _Blockly();
@@ -419,6 +428,10 @@ export default class View {
419428
});
420429

421430
$('#chartButton').click(() => {
431+
if (!chart) {
432+
chart = new Chart(api);
433+
}
434+
422435
chart.open();
423436
});
424437

src/common/footer-checks.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
/* eslint-disable import/prefer-default-export */
22
import { generateLiveApiInstance } from './appId';
33

4-
export default async function isEuCountry() {
5-
const api = generateLiveApiInstance();
6-
const { website_status: { clients_country: clientsCountry } } = await api.send({ website_status: 1 });
7-
const { landing_company: { financial_company: financialCompany, gaming_company: gamingCompany } } = await api.send({
8-
landing_company: clientsCountry,
4+
export const showHideEuElements = isEu => {
5+
document.querySelectorAll('.eu-hide').forEach(el => {
6+
if (!isEu && el.classList.contains('invisible')) {
7+
// Keep original display type if invisible was specified.
8+
el.classList.remove('invisible');
9+
} else {
10+
// Default to setting display to block.
11+
el.setAttribute('display', `${!isEu ? 'block' : 'none'} !important`);
12+
}
913
});
14+
document.querySelectorAll('.eu-show', '.eu-only').forEach(el => {
15+
if (isEu && el.classList.contains('invisible')) {
16+
el.classList.remove('invisible');
17+
} else {
18+
el.setAttribute('display', `${isEu ? 'block' : 'none'} !important`);
19+
}
20+
});
21+
};
22+
23+
/* eslint-disable camelcase */
24+
export const isEuLandingCompany = landing_company => /^(maltainvest|malta|iom)$/.test(landing_company);
25+
26+
export const hasEuAccount = token_list =>
27+
token_list.some(token_obj => isEuLandingCompany(token_obj.loginInfo.landing_company_name));
28+
29+
export const isEuCountry = async (api = generateLiveApiInstance()) => {
30+
const { website_status } = await api.send({ website_status: 1 });
31+
const { clients_country } = website_status;
32+
const { landing_company } = await api.send({ landing_company: clients_country });
33+
const { financial_company, gaming_company } = landing_company;
1034

11-
const euShortcodeRegex = new RegExp('^(maltainvest|malta|iom)$');
12-
const euExcludedRegex = new RegExp('^mt$');
13-
const financialShortcode = financialCompany ? financialCompany.shortcode : false;
14-
const gamingShortcode = gamingCompany ? gamingCompany.shortcode : false;
35+
const eu_excluded_regexp = /^mt$/;
36+
const financial_shortcode = financial_company ? financial_company.shortcode : false;
37+
const gaming_shortcode = gaming_company ? gaming_company.shortcode : false;
1538

16-
api.disconnect();
39+
if (financial_shortcode || gaming_shortcode) {
40+
return isEuLandingCompany(financial_shortcode) || isEuLandingCompany(gaming_shortcode);
41+
}
1742

18-
return financialShortcode || gamingShortcode
19-
? euShortcodeRegex.test(financialShortcode) || euShortcodeRegex.test(gamingShortcode)
20-
: euExcludedRegex.test(clientsCountry);
21-
}
43+
return eu_excluded_regexp.test(clients_country);
44+
};
45+
/* eslint-enable */

src/indexPage/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@ import endpoint from './endpoint';
44
import Logo from './react-components/logo.jsx';
55
import Footer from './react-components/footer.jsx';
66
import { oauthLogin } from '../common/appId';
7-
import '../common/binary-ui/dropdown';
8-
import isEuCountry from '../common/footer-checks';
7+
import { isEuCountry, showHideEuElements } from '../common/footer-checks';
98
import GTM from '../common/gtm';
109
import { load as loadLang } from '../common/lang';
1110
import { getTokenList } from '../common/utils/storageManager';
1211
import { createUrl } from '../common/utils/tools';
12+
import '../common/binary-ui/dropdown';
1313

1414
const renderElements = () => {
15-
const showHideEuElements = isEu => {
16-
$('.eu-hide').attr('style', `display: ${isEu ? 'none' : 'block'} !important`);
17-
$('.eu-show, .eu-only').attr('style', `display: ${isEu ? 'block' : 'none'} !important`);
18-
};
1915
ReactDOM.render(<Logo />, document.getElementById('binary-logo'));
2016
ReactDOM.render(<Footer />, document.getElementById('footer'));
21-
isEuCountry().then(isEu => {
22-
showHideEuElements(isEu);
23-
});
17+
isEuCountry().then(isEu => showHideEuElements(isEu));
2418
$('#shop-url').attr('href', createUrl({ subdomain: 'shop', path: 'collections/strategies', isNonBotPage: true }));
2519
};
2620

static/css/_dbot-banner.scss

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
.dbot-banner {
2+
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@700&display=swap');
3+
font-family: 'IBM Plex Sans', sans-serif;
4+
-webkit-font-smoothing: antialiased;
5+
-moz-osx-font-smoothing: antialiased;
6+
align-items: center;
7+
align-self: center;
8+
display: flex;
9+
float: left;
10+
height: calc(100% - 20px);
11+
margin: 10px 0;
12+
13+
&__icon {
14+
margin-right: 8px;
15+
margin-left: 32px;
16+
}
17+
&__ad {
18+
color: #fff;
19+
margin-right: 16px;
20+
display: flex;
21+
justify-content: center;
22+
23+
&-text {
24+
font-size: 16px;
25+
font-weight: bold;
26+
line-height: 1.5;
27+
}
28+
}
29+
&__button {
30+
font-size: 14px;
31+
background-color: #ff444f;
32+
font-weight: bold;
33+
vertical-align: middle;
34+
align-items: center;
35+
justify-content: center;
36+
touch-action: manipulation;
37+
cursor: pointer;
38+
white-space: nowrap;
39+
padding: 0 16px;
40+
display: inline-flex;
41+
border: 0;
42+
height: 32px;
43+
border-radius: 4px;
44+
transition: all .2s cubic-bezier(.65,.05,.36,1);
45+
outline: 0;
46+
position: relative;
47+
text-decoration: none;
48+
text-transform: none!important;
49+
50+
&:hover {
51+
background: #eb3e48;
52+
}
53+
54+
&:focus {
55+
outline: none;
56+
}
57+
}
58+
&__separator {
59+
width: 2px;
60+
height: 36px;
61+
background-color: #17212c;
62+
}
63+
}
64+
65+
@media only screen and (max-width: 520px) {
66+
.dbot-banner {
67+
display: none;
68+
}
69+
}
70+
71+
@media only screen and (max-width: 700px) {
72+
.dbot-banner {
73+
&__separator {
74+
display: none;
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)