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

Commit 9b30cbf

Browse files
Maryia/Allowing currency change if client has no real dmt5/dxtrade accounts (#7048)
* Maryia/fixed check for real dmt5/dxtrade accounts * Maryia/fixed logical expressions * Maryia/shortened condition * Maryia/passing dxtrade accounts to canChangeCurrency everywhere it's used * Maryia/checking if client has no real mt5/derivX accounts in cashier * Maryia/refactoring * Maryia/optimized conditions and updated messages text * Maryia/updated note text on accounts page * Maryia/removed unnecessary function & updated comments * Maryia/aligned an assignment sign * Maryia/changed content as agreed * Maryia/passed a missing loginid param to canChangeCurrency() * Maryia/refactoring * Maryia/showing popup only if a user able to change currency is creating a real account Co-authored-by: Kevin <70131533+kevinw-binary@users.noreply.github.com>
1 parent 60e8ab6 commit 9b30cbf

File tree

5 files changed

+100
-74
lines changed

5 files changed

+100
-74
lines changed

src/javascript/_common/base/client_base.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const moment = require('moment');
2-
const isCryptocurrency = require('./currency_base').isCryptocurrency;
3-
const SocketCache = require('./socket_cache');
4-
const localize = require('../localize').localize;
5-
const LocalStore = require('../storage').LocalStore;
6-
const State = require('../storage').State;
7-
const getPropertyValue = require('../utility').getPropertyValue;
8-
const isEmptyObject = require('../utility').isEmptyObject;
1+
const moment = require('moment');
2+
const isCryptocurrency = require('./currency_base').isCryptocurrency;
3+
const SocketCache = require('./socket_cache');
4+
const localize = require('../localize').localize;
5+
const LocalStore = require('../storage').LocalStore;
6+
const State = require('../storage').State;
7+
const getHasRealMt5OrDxtrade = require('../utility').getHasRealMt5OrDxtrade;
8+
const getPropertyValue = require('../utility').getPropertyValue;
9+
const isEmptyObject = require('../utility').isEmptyObject;
910

1011
const ClientBase = (() => {
1112
const storage_key = 'client.accounts';
@@ -384,15 +385,14 @@ const ClientBase = (() => {
384385

385386
const hasSvgAccount = () => !!(getAllLoginids().find(loginid => /^CR/.test(loginid)));
386387

387-
const canChangeCurrency = (statement, mt5_login_list, loginid, is_current = true) => {
388+
const canChangeCurrency = (statement, mt5_login_list, dxtrade_accounts_list, loginid, is_current = true) => {
388389
const currency = get('currency', loginid);
389-
const has_no_mt5 = !mt5_login_list || !mt5_login_list.length;
390390
const has_no_transaction = (statement.count === 0 && statement.transactions.length === 0);
391-
const has_account_criteria = has_no_transaction && has_no_mt5;
392-
391+
const has_account_criteria = has_no_transaction &&
392+
!getHasRealMt5OrDxtrade(mt5_login_list, dxtrade_accounts_list);
393393
// Current API requirements for currently logged-in user successfully changing their account's currency:
394394
// 1. User must not have made any transactions
395-
// 2. User must not have any MT5 account
395+
// 2. User must not have any real MT5 or Deriv X account
396396
// 3. Not be a crypto account
397397
// 4. Not be a virtual account
398398
return is_current ? currency && !get('is_virtual', loginid) && has_account_criteria && !isCryptocurrency(currency) : has_account_criteria;

src/javascript/_common/utility.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ const getDocumentData = (country_code, document_type) => {
285285
return null;
286286
};
287287

288+
const getHasRealMt5OrDxtrade = (mt5_login_list = [], dxtrade_accounts_list = []) =>
289+
(mt5_login_list.filter(({ account_type }) => account_type !== 'demo').length > 0) ||
290+
(dxtrade_accounts_list.filter(({ account_type }) => account_type !== 'demo').length > 0);
291+
288292
const getImageLocation = image_name => `/images/common/visual_samples/${image_name}`;
289293

290294
// Note: Ensure that the object keys matches BE API's keys. This is simply a mapping for FE templates
@@ -412,6 +416,7 @@ module.exports = {
412416
showLoadingImage,
413417
getDocumentData,
414418
getRegex,
419+
getHasRealMt5OrDxtrade,
415420
getHighestZIndex,
416421
downloadCSV,
417422
template,

src/javascript/app/pages/cashier/cashier.js

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
const getCurrencies = require('../user/get_currency').getCurrencies;
2-
const Client = require('../../base/client');
3-
const BinarySocket = require('../../base/socket');
4-
const Currency = require('../../common/currency');
5-
const elementInnerHtml = require('../../../_common/common_functions').elementInnerHtml;
6-
const getElementById = require('../../../_common/common_functions').getElementById;
7-
const localize = require('../../../_common/localize').localize;
8-
const State = require('../../../_common/storage').State;
9-
const Url = require('../../../_common/url');
10-
const getPropertyValue = require('../../../_common/utility').getPropertyValue;
11-
const Dialog = require('../../common/attach_dom/dialog');
12-
const BinaryPjax = require('../../base/binary_pjax');
13-
const Accounts = require('../user/accounts');
14-
const Header = require('../../base/header');
15-
const isEuCountry = require('../../common/country_base').isEuCountry;
1+
const getCurrencies = require('../user/get_currency').getCurrencies;
2+
const Client = require('../../base/client');
3+
const BinarySocket = require('../../base/socket');
4+
const Currency = require('../../common/currency');
5+
const elementInnerHtml = require('../../../_common/common_functions').elementInnerHtml;
6+
const getElementById = require('../../../_common/common_functions').getElementById;
7+
const localize = require('../../../_common/localize').localize;
8+
const State = require('../../../_common/storage').State;
9+
const Url = require('../../../_common/url');
10+
const getHasRealMt5OrDxtrade = require('../../../_common/utility').getHasRealMt5OrDxtrade;
11+
const getPropertyValue = require('../../../_common/utility').getPropertyValue;
12+
const Dialog = require('../../common/attach_dom/dialog');
13+
const BinaryPjax = require('../../base/binary_pjax');
14+
const Accounts = require('../user/accounts');
15+
const Header = require('../../base/header');
16+
const isEuCountry = require('../../common/country_base').isEuCountry;
1617

1718
const Cashier = (() => {
1819
let href = '';
@@ -84,43 +85,41 @@ const Cashier = (() => {
8485
$(top_up_id).parent().setVisibility(1);
8586
};
8687

87-
const showCurrentCurrency = (currency, statement, mt5_logins) => {
88-
const has_no_mt5 = mt5_logins.length === 0;
89-
const has_no_transaction = (statement.count === 0 && statement.transactions.length === 0);
90-
const el_acc_currency = getElementById('account_currency');
91-
const el_currency_image = getElementById('account_currency_img');
92-
const el_current_currency = getElementById('account_currency_current');
93-
const el_current_hint = getElementById('account_currency_hint');
94-
const upgrade_info = Client.getUpgradeInfo();
95-
const can_change = Client.canChangeCurrency(statement, mt5_logins);
96-
const has_upgrade = upgrade_info.can_upgrade || upgrade_info.can_open_multi
97-
|| can_change;
98-
const account_action_text = has_upgrade ? `<br />${localize('[_1]Manage your accounts[_2]', [`<a href=${Url.urlFor('user/accounts')}>`, '</a>'])}` : '';
99-
const is_iom_client = Client.get('residence') === 'im' || State.getResponse('website_status.clients_country') === 'im';
100-
const change_text_for_iom = is_iom_client ? localize('time') : localize('time or create an MT5 account');
101-
const url_user_account = `<a href=${Url.urlFor('user/accounts')}>`;
102-
103-
const missingCriteria = (has_mt5, has_transaction) => {
104-
const existing_mt5_msg = localize('You can no longer change the currency because you\'ve created an MT5 account.') + account_action_text;
105-
const existing_transaction_msg = localize('You can no longer change the currency because you\'ve made a first-time deposit.') + account_action_text;
106-
107-
return has_mt5 && !has_transaction ? existing_mt5_msg : existing_transaction_msg;
108-
};
88+
const showCurrentCurrency = (currency, statement, mt5_logins, dxtrade_accounts_list) => {
89+
const has_no_real_mt5_or_dxtrade = !getHasRealMt5OrDxtrade(mt5_logins, dxtrade_accounts_list);
90+
const has_no_transaction = (statement.count === 0 && statement.transactions.length === 0);
91+
const el_acc_currency = getElementById('account_currency');
92+
const el_currency_image = getElementById('account_currency_img');
93+
const el_current_currency = getElementById('account_currency_current');
94+
const el_current_hint = getElementById('account_currency_hint');
95+
const upgrade_info = Client.getUpgradeInfo();
96+
const can_change = Client.canChangeCurrency(statement, mt5_logins, dxtrade_accounts_list, Client.get('loginid'));
97+
const has_upgrade = upgrade_info.can_upgrade || upgrade_info.can_open_multi || can_change;
98+
const account_action_text = has_upgrade ? `<br />${localize('[_1]Manage your accounts[_2]', [`<a href=${Url.urlFor('user/accounts')}>`, '</a>'])}` : '';
99+
const is_iom_client = Client.get('residence') === 'im' || State.getResponse('website_status.clients_country') === 'im';
100+
const change_text_for_iom = is_iom_client ? localize('time') : localize('time or create a real MT5 account (or a real Deriv X account at deriv.com)');
101+
const url_user_account = `<a href=${Url.urlFor('user/accounts')}>`;
102+
103+
const criteria_not_met_message = has_no_transaction
104+
? localize('You can no longer change the currency because you\'ve created a real MT5 account (or a real Deriv X account at deriv.com).') + account_action_text
105+
: localize('You can no longer change the currency because you\'ve made a first-time deposit.') + account_action_text;
109106

110107
// Set messages based on currency being crypto or fiat
111108
// If fiat, set message based on if they're allowed to change currency or not
112-
// Condition is to have no MT5 accounts *and* have no transactions
113-
const currency_message = Currency.isCryptocurrency(currency)
109+
// Condition is to have no real MT5 or Deriv X accounts *and* have no transactions
110+
const fiat_currency_is_set_message = has_no_real_mt5_or_dxtrade && has_no_transaction
111+
? localize('Your fiat account\'s currency is currently set to [_1].', `${currency}`)
112+
: localize('Your fiat account\'s currency is set to [_1].', `${currency}`);
113+
const currency_message = Currency.isCryptocurrency(currency)
114114
? localize('This is your [_1] account.', `${Currency.getCurrencyDisplayCode(currency)}`)
115-
: has_no_mt5 && has_no_transaction
116-
? localize('Your fiat account\'s currency is currently set to [_1].', `${currency}`)
117-
: localize('Your fiat account\'s currency is set to [_1].', `${currency}`);
115+
: fiat_currency_is_set_message;
118116

119-
const currency_hint = Currency.isCryptocurrency(currency)
117+
const fiat_currency_change_hint = has_no_real_mt5_or_dxtrade && has_no_transaction
118+
? localize('You can [_1]set a new currency[_2] before you deposit for the first [_3].', [can_change ? url_user_account : '', can_change ? '</a>' : '', change_text_for_iom])
119+
: criteria_not_met_message;
120+
const currency_hint = Currency.isCryptocurrency(currency)
120121
? localize('Don\'t want to trade in [_1]? You can open another cryptocurrency account.', `${Currency.getCurrencyDisplayCode(currency)}`) + account_action_text
121-
: has_no_mt5 && has_no_transaction
122-
? localize('You can [_1]set a new currency[_2] before you deposit for the first [_3].', [can_change ? url_user_account : '', can_change ? '</a>' : '', change_text_for_iom])
123-
: missingCriteria(!has_no_mt5, !has_no_transaction);
122+
: fiat_currency_change_hint;
124123

125124
elementInnerHtml(el_current_currency, currency_message);
126125
elementInnerHtml(el_current_hint, currency_hint);
@@ -263,7 +262,8 @@ const Cashier = (() => {
263262
}
264263
if (Client.isLoggedIn()) {
265264
BinarySocket.send({ statement: 1, limit: 1 });
266-
BinarySocket.wait('authorize', 'mt5_login_list', 'statement', 'get_account_status', 'landing_company').then(() => {
265+
BinarySocket.send({ trading_platform_accounts: 1, platform: 'dxtrade' });
266+
BinarySocket.wait('authorize', 'mt5_login_list', 'statement', 'get_account_status', 'landing_company', 'trading_platform_accounts').then(() => {
267267
if (!is_virtual) checkStatusIsLocked(State.getResponse('get_account_status'));
268268
const residence = Client.get('residence');
269269
const currency = Client.get('currency');
@@ -276,7 +276,8 @@ const Cashier = (() => {
276276
showCurrentCurrency(
277277
currency,
278278
State.getResponse('statement'),
279-
State.getResponse('mt5_login_list')
279+
State.getResponse('mt5_login_list'),
280+
State.getResponse('trading_platform_accounts'),
280281
);
281282
if (is_p2p_allowed_currency && is_show_dp2p) {
282283
setP2PVisibility();

src/javascript/app/pages/user/accounts.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ const Accounts = (() => {
4141
}
4242
clearPopup();
4343
BinarySocket.send({ statement: 1, limit: 1 });
44-
BinarySocket.wait('landing_company', 'get_settings', 'statement', 'mt5_login_list').then(() => {
44+
BinarySocket.send({ trading_platform_accounts: 1, platform: 'dxtrade' });
45+
BinarySocket.wait('landing_company', 'get_settings', 'statement', 'mt5_login_list', 'trading_platform_accounts').then(() => {
4546
landing_company = State.getResponse('landing_company');
46-
const can_change_currency = Client.canChangeCurrency(State.getResponse('statement'), State.getResponse('mt5_login_list'));
47+
const can_change_currency = Client.canChangeCurrency(
48+
State.getResponse('statement'),
49+
State.getResponse('mt5_login_list'),
50+
State.getResponse('trading_platform_accounts'),
51+
Client.get('loginid')
52+
);
4753
const is_virtual = Client.get('is_virtual');
4854
const has_real_account = Client.hasAccountType('real');
4955
populateExistingAccounts();
@@ -160,12 +166,17 @@ const Accounts = (() => {
160166
}).on('click', () => showCurrencyPopUp('change')))));
161167

162168
// Replace note to reflect ability to change currency
163-
$('#note > .hint').text(`${localize('Note: You are limited to one fiat currency account. The currency of your fiat account can be changed before you deposit into your fiat account for the first time or create an MT5 account. You may also open one account for each supported cryptocurrency.')}`);
169+
$('#note > .hint').text(`${localize('Note: You are limited to one fiat currency account. The currency of your fiat account can be changed before you deposit into your fiat account for the first time or create a real MT5 account (or a real Deriv X account at deriv.com). You may also open one account for each supported cryptocurrency.')}`);
164170
$('#note_change_currency').setVisibility(0);
165171
};
166172

167173
const onConfirmSetCurrency = () => {
168-
const can_change_currency = Client.canChangeCurrency(State.getResponse('statement'), State.getResponse('mt5_login_list'));
174+
const can_change_currency = Client.canChangeCurrency(
175+
State.getResponse('statement'),
176+
State.getResponse('mt5_login_list'),
177+
State.getResponse('trading_platform_accounts'),
178+
Client.get('loginid')
179+
);
169180
if (can_change_currency) {
170181
addChangeCurrencyOption();
171182
}
@@ -210,10 +221,12 @@ const Accounts = (() => {
210221
};
211222

212223
const appendExistingAccounts = (loginid) => {
213-
const table_headers = TableHeaders.get();
214-
const account_currency = Client.get('currency', loginid);
215-
const account_type_prop = { text: Client.getAccountTitle(loginid) };
216-
const can_currency_change_id = Client.canChangeCurrency(State.getResponse('statement'), State.getResponse('mt5_login_list'), loginid);
224+
const table_headers = TableHeaders.get();
225+
const account_currency = Client.get('currency', loginid);
226+
const account_type_prop = { text: Client.getAccountTitle(loginid) };
227+
const can_currency_change_id = Client.canChangeCurrency(
228+
State.getResponse('statement'), State.getResponse('mt5_login_list'), State.getResponse('trading_platform_accounts'), loginid
229+
);
217230

218231
if (!Client.isAccountOfType('virtual', loginid)) {
219232
const company_name = getCompanyName(loginid);

src/javascript/app/pages/user/metatrader/metatrader.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const MetaTrader = (() => {
1919

2020
const onLoad = () => {
2121
BinarySocket.send({ statement: 1, limit: 1 });
22-
BinarySocket.wait('landing_company', 'get_account_status', 'statement').then(async () => {
22+
BinarySocket.send({ trading_platform_accounts: 1, platform: 'dxtrade' });
23+
BinarySocket.wait('landing_company', 'get_account_status', 'statement', 'trading_platform_accounts').then(async () => {
2324
await BinarySocket.send({ trading_servers: 1, platform: 'mt5' });
2425

2526
if (isEligible()) {
@@ -221,7 +222,13 @@ const MetaTrader = (() => {
221222

222223
const getAllAccountsInfo = (response) => {
223224
MetaTraderUI.init(submit, sendTopupDemo);
224-
show_new_account_popup = Client.canChangeCurrency(State.getResponse('statement'), (response.mt5_login_list || []), false);
225+
show_new_account_popup = Client.canChangeCurrency(
226+
State.getResponse('statement'),
227+
(response.mt5_login_list || []),
228+
State.getResponse('trading_platform_accounts'),
229+
Client.get('loginid'),
230+
false
231+
);
225232
allAccountsResponseHandler(response);
226233
};
227234

@@ -273,8 +280,10 @@ const MetaTrader = (() => {
273280

274281
const submit = (e) => {
275282
e.preventDefault();
283+
const $btn_submit = $(e.target);
284+
const acc_type = $btn_submit.attr('acc_type');
276285

277-
if (show_new_account_popup) {
286+
if (acc_type.includes('real') && show_new_account_popup) {
278287
MetaTraderUI.showNewAccountConfirmationPopup(
279288
e,
280289
() => show_new_account_popup = false,
@@ -284,8 +293,6 @@ const MetaTrader = (() => {
284293
return;
285294
}
286295

287-
const $btn_submit = $(e.target);
288-
const acc_type = $btn_submit.attr('acc_type');
289296
const action = $btn_submit.attr('action');
290297
MetaTraderUI.hideFormMessage(action);
291298
if (Validation.validate(`#frm_${action}`)) {

0 commit comments

Comments
 (0)