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

Commit 5f59209

Browse files
mamali-fsMohammadreza Ghorbani
andauthored
mamali/Fix issues with unwanted create account button popping up (#6760)
* Fix issues with unwanted create account button popping up * Fix issue with VRTC trying to upgrade to SVG * Fix for VRTC clients without real account Co-authored-by: Mohammadreza Ghorbani <reza@firstsource.email>
1 parent 36ecf07 commit 5f59209

File tree

1 file changed

+58
-31
lines changed

1 file changed

+58
-31
lines changed

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

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
const moment = require('moment');
2-
const SetCurrency = require('./set_currency');
3-
const BinaryPjax = require('../../base/binary_pjax');
4-
const Client = require('../../base/client');
5-
const BinarySocket = require('../../base/socket');
6-
const showPopup = require('../../common/attach_dom/popup');
7-
const Currency = require('../../common/currency');
8-
const localize = require('../../../_common/localize').localize;
9-
const State = require('../../../_common/storage').State;
10-
const urlFor = require('../../../_common/url').urlFor;
1+
const moment = require('moment');
2+
const SetCurrency = require('./set_currency');
3+
const BinaryPjax = require('../../base/binary_pjax');
4+
const Client = require('../../base/client');
5+
const BinarySocket = require('../../base/socket');
6+
const showPopup = require('../../common/attach_dom/popup');
7+
const Currency = require('../../common/currency');
8+
const localize = require('../../../_common/localize').localize;
9+
const State = require('../../../_common/storage').State;
10+
const urlFor = require('../../../_common/url').urlFor;
1111

1212
const Accounts = (() => {
1313
let landing_company;
14-
const form_id = '#new_accounts';
15-
const has_real_account = Client.hasAccountType('real');
14+
const form_id = '#new_accounts';
1615

1716
const TableHeaders = (() => {
1817
let table_headers;
@@ -44,17 +43,22 @@ const Accounts = (() => {
4443
BinarySocket.wait('landing_company', 'get_settings', 'statement', 'mt5_login_list').then(() => {
4544
landing_company = State.getResponse('landing_company');
4645
const can_change_currency = Client.canChangeCurrency(State.getResponse('statement'), State.getResponse('mt5_login_list'));
47-
46+
const is_virtual = Client.get('is_virtual');
47+
const has_real_account = Client.hasAccountType('real');
4848
populateExistingAccounts();
4949

5050
let element_to_show = '#no_new_accounts_wrapper';
5151
const upgrade_info = Client.getUpgradeInfo();
52-
if (upgrade_info.can_upgrade && !has_real_account) {
53-
populateNewAccounts(upgrade_info);
54-
element_to_show = '#new_accounts_wrapper';
52+
if (upgrade_info.can_upgrade) {
53+
// VRTC SVG has can_upgrade, but they are only allowed to open crypto related
54+
// accounts. This is a check to ignore the account creation form for them
55+
if (upgrade_info.can_open_multi || !upgrade_info.can_upgrade_to.includes('svg') || !has_real_account) {
56+
populateNewAccounts(upgrade_info);
57+
element_to_show = '#new_accounts_wrapper';
58+
}
5559
}
5660

57-
if (upgrade_info.can_open_multi || has_real_account && Client.get('is_virtual')) {
61+
if (upgrade_info.can_open_multi || (upgrade_info.can_upgrade_to.includes('svg') && is_virtual && has_real_account)) {
5862
populateMultiAccount();
5963
} else if (!can_change_currency) {
6064
doneLoading(element_to_show);
@@ -73,7 +77,7 @@ const Accounts = (() => {
7377
const clearPopup = () => {
7478
SetCurrency.cleanupPopup();
7579
};
76-
80+
7781
const doneLoading = (element_to_show) => {
7882
$(element_to_show).setVisibility(1);
7983
$('#accounts_loading').remove();
@@ -87,12 +91,22 @@ const Accounts = (() => {
8791
const populateNewAccounts = (upgrade_info) => {
8892
const table_headers = TableHeaders.get();
8993
upgrade_info.type.forEach((new_account_type, index) => {
94+
const getAccountTitle = () => {
95+
if (new_account_type === 'financial') {
96+
return localize('Financial Account');
97+
}
98+
if (upgrade_info.can_upgrade_to[index] === 'malta') {
99+
return localize('Gaming Account');
100+
}
101+
102+
return localize('Real Account');
103+
};
104+
90105
const account = {
91106
real : new_account_type === 'real',
92107
financial: new_account_type === 'financial',
93108
};
94-
const new_account_title = new_account_type === 'financial' ? localize('Financial Account') :
95-
upgrade_info.can_upgrade_to[index] === 'malta' ? localize('Gaming Account') : localize('Real Account');
109+
const new_account_title = getAccountTitle();
96110
$(form_id).find('tbody')
97111
.append($('<tr/>')
98112
.append($('<td/>', { datath: table_headers.account }).html($('<span/>', {
@@ -129,7 +143,12 @@ const Accounts = (() => {
129143
})))
130144
.append($('<td/>', { text: getAvailableMarkets(loginid), datath: table_headers.available_markets }))
131145
.append($('<td/>', { id: 'change_currency_action' })
132-
.html($('<button/>', { id: 'change_currency_btn', class: 'button no-margin', type: 'button', text: localize('Change currency') }).click(() => showCurrencyPopUp('change')))));
146+
.html($('<button/>', {
147+
id : 'change_currency_btn',
148+
class: 'button no-margin',
149+
type : 'button',
150+
text : localize('Change currency'),
151+
}).on('click', () => showCurrencyPopUp('change')))));
133152

134153
// Replace note to reflect ability to change currency
135154
$('#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.')}`);
@@ -153,9 +172,9 @@ const Accounts = (() => {
153172
url : urlFor('user/set-currency'),
154173
content_id : '#set_currency',
155174
form_id : 'frm_set_currency',
156-
additionalFunction: () => {
175+
additionalFunction: async () => {
157176
localStorage.setItem('popup_action', action_map[action]);
158-
SetCurrency.onLoad(onConfirmSetCurrency);
177+
await SetCurrency.onLoad(onConfirmSetCurrency);
159178
},
160179
});
161180
};
@@ -185,15 +204,15 @@ const Accounts = (() => {
185204
const account_type_prop = { text: Client.getAccountTitle(loginid) };
186205

187206
if (!Client.isAccountOfType('virtual', loginid)) {
188-
const company_name = getCompanyName(loginid);
189-
const company_country = getCompanyCountry(loginid);
190-
account_type_prop['data-balloon'] = `${localize('Counterparty')}: ${company_name}, ${localize('Jurisdiction')}: ${company_country}`;
207+
const company_name = getCompanyName(loginid);
208+
const company_country = getCompanyCountry(loginid);
209+
account_type_prop['data-balloon'] = `${localize('Counterparty')}: ${company_name}, ${localize('Jurisdiction')}: ${company_country}`;
191210
account_type_prop['data-balloon-length'] = 'large';
192211
}
193212

194213
const is_disabled = Client.get('is_disabled', loginid);
195214
const excluded_until = Client.get('excluded_until', loginid);
196-
let txt_markets = '';
215+
let txt_markets;
197216
if (is_disabled) {
198217
txt_markets = localize('This account is disabled');
199218
} else if (excluded_until) {
@@ -202,13 +221,17 @@ const Accounts = (() => {
202221
txt_markets = getAvailableMarkets(loginid);
203222
}
204223

224+
const showSetCurrency = () => showCurrencyPopUp('set');
205225
$('#existing_accounts').find('tbody')
206226
.append($('<tr/>', { id: loginid, class: ((is_disabled || excluded_until) ? 'color-dark-white' : '') })
207227
.append($('<td/>', { text: loginid, datath: table_headers.account }))
208228
.append($('<td/>', { datath: table_headers.type }).html($('<span/>', account_type_prop)))
209229
.append($('<td/>', { text: txt_markets, datath: table_headers.available_markets }))
210230
.append($('<td/>', { datath: table_headers.currency })
211-
.html(!account_currency && loginid === Client.get('loginid') ? $('<button/>', { text: localize('Set currency'), type: 'button' }).click(() => showCurrencyPopUp('set')) : (Currency.getCurrencyFullName(account_currency) || '-'))));
231+
.html(!account_currency && loginid === Client.get('loginid') ? $('<button/>', {
232+
text: localize('Set currency'),
233+
type: 'button',
234+
}).on('click', showSetCurrency) : (Currency.getCurrencyFullName(account_currency) || '-'))));
212235

213236
if (is_disabled || excluded_until) {
214237
$('#note_support').setVisibility(1);
@@ -253,6 +276,7 @@ const Accounts = (() => {
253276
const populateMultiAccount = () => {
254277
const table_headers = TableHeaders.get();
255278
const account = { real: 1 };
279+
const handleClick = () => showCurrencyPopUp('create');
256280
$(form_id).find('tbody')
257281
.append($('<tr/>', { id: 'new_account_opening' })
258282
.append($('<td/>', { datath: table_headers.account }).html($('<span/>', {
@@ -261,17 +285,20 @@ const Accounts = (() => {
261285
'data-balloon-length': 'large',
262286
})))
263287
.append($('<td/>', { text: getAvailableMarkets({ real: 1 }), datath: table_headers.available_markets }))
264-
.append($('<td/>').html($('<button/>', { text: localize('Create account'), type: 'button' }).click(() => showCurrencyPopUp('create')))));
288+
.append($('<td/>').html($('<button/>', {
289+
text: localize('Create account'),
290+
type: 'button',
291+
}).on('click' , handleClick))));
265292

266293
$('#note').setVisibility(1);
267294

268295
doneLoading('#new_accounts_wrapper');
269296
};
270297

271-
const onUnload = () =>{
298+
const onUnload = () => {
272299
clearPopup();
273300
};
274-
301+
275302
return {
276303
onLoad,
277304
onUnload,

0 commit comments

Comments
 (0)