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

Commit e65728b

Browse files
hubert-derivHubert Koster
andauthored
fixing creation of real sibling accounts when on virtual account. (#6734)
Co-authored-by: Hubert Koster <hubertkoster@Huberts-MacBook-Pro.local>
1 parent 86edd38 commit e65728b

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const urlFor = require('../../../_common/url').urlFor;
1111

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

1617
const TableHeaders = (() => {
1718
let table_headers;
@@ -48,12 +49,12 @@ const Accounts = (() => {
4849

4950
let element_to_show = '#no_new_accounts_wrapper';
5051
const upgrade_info = Client.getUpgradeInfo();
51-
if (upgrade_info.can_upgrade) {
52+
if (upgrade_info.can_upgrade && !has_real_account) {
5253
populateNewAccounts(upgrade_info);
5354
element_to_show = '#new_accounts_wrapper';
5455
}
5556

56-
if (upgrade_info.can_open_multi) {
57+
if (upgrade_info.can_open_multi || has_real_account && Client.get('is_virtual')) {
5758
populateMultiAccount();
5859
} else if (!can_change_currency) {
5960
doneLoading(element_to_show);

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ const GetCurrency = (() => {
55
const getCurrenciesOfOtherAccounts = (is_different_company = false) => {
66
const all_loginids = Client.getAllLoginids();
77
const other_currencies = [];
8-
// console.log(Client.get('landing_company_shortcode'))
98
const current_landing_company_shortcode = Client.get('landing_company_shortcode');
10-
// console.log(Client.get('loginid'))
11-
// console.log(all_loginids)
129
all_loginids.forEach((loginid) => {
1310
// if it's not current client or under a different landing company, consider the currency
1411
if (is_different_company) {
@@ -54,34 +51,39 @@ const GetCurrency = (() => {
5451
};
5552

5653
const getCurrencies = (landing_company, all_fiat) => {
57-
const client_currency = Client.get('currency');
58-
const is_crypto = Currency.isCryptocurrency(client_currency);
59-
const currency_values = getCurrencyValues();
54+
let currencies_to_show = [];
55+
const current_client_currency = Client.get('currency');
56+
const is_crypto = Currency.isCryptocurrency(current_client_currency);
57+
const currency_values = getCurrencyValues();
58+
const is_virtual = Client.get('is_virtual');
59+
const has_real_account = Client.hasAccountType('real');
60+
const all_client_accounts = Client.getAllAccountsObject();
61+
const all_client_currencies = Object.values(all_client_accounts).map(account => account.currency);
6062

6163
const allowed_currencies =
6264
Client.getLandingCompanyValue({ real: 1 }, landing_company, 'legal_allowed_currencies');
6365

6466
const available_crypto =
65-
currency_values.cryptocurrencies.filter(c =>
66-
currency_values.other_currencies.concat(is_crypto ? client_currency : []).indexOf(c) < 0 &&
67-
allowed_currencies.indexOf(c) > -1);
68-
const can_open_crypto = available_crypto.length;
67+
currency_values.cryptocurrencies.filter(c =>
68+
currency_values.other_currencies.concat(is_crypto ?
69+
current_client_currency : all_client_currencies).indexOf(c) < 0 &&
70+
allowed_currencies.indexOf(c) > -1);
6971

70-
let currencies_to_show = [];
72+
const can_open_crypto = available_crypto.length;
7173

7274
// only allow client to open more sub accounts if the last currency is not to be reserved for master account
73-
if ((client_currency && (can_open_crypto || !currency_values.has_fiat)) ||
74-
(!client_currency && (available_crypto.length > 1 || (can_open_crypto && !currency_values.has_fiat)))) {
75+
if ((current_client_currency && (can_open_crypto || !currency_values.has_fiat)) ||
76+
(!current_client_currency && (available_crypto.length > 1 ||
77+
(can_open_crypto && !currency_values.has_fiat)))) {
7578
// if have sub account with fiat currency, or master account is fiat currency, only show cryptocurrencies
7679
// else show all
77-
const is_virtual = Client.get('is_virtual');
7880

7981
currencies_to_show =
80-
!all_fiat && (currency_values.has_fiat || (!is_crypto && client_currency && !is_virtual)) ?
82+
!all_fiat && (currency_values.has_fiat || (!is_crypto && current_client_currency && has_real_account)) ?
8183
available_crypto : allowed_currencies;
8284
// remove client's currency and sub account currencies from list of currencies to show
8385
const currencies_to_compare = is_virtual ?
84-
currency_values.other_currencies : currency_values.other_currencies.concat(client_currency);
86+
currency_values.other_currencies : currency_values.other_currencies.concat(current_client_currency);
8587
currencies_to_show = currencies_to_show.filter(c => currencies_to_compare.indexOf(c) < 0);
8688
}
8789

@@ -90,12 +92,12 @@ const GetCurrency = (() => {
9092

9193
const getAllCurrencies = (landing_company) => {
9294
const allowed_currencies =
93-
Client.getLandingCompanyValue({ real: 1 }, landing_company, 'legal_allowed_currencies');
94-
const currency_values = getCurrencyValues();
95-
const client_currency = Client.get('currency');
96-
const is_virtual = Client.get('is_virtual');
97-
const currencies_to_compare = is_virtual ?
98-
currency_values.other_currencies : currency_values.other_currencies.concat(client_currency);
95+
Client.getLandingCompanyValue({ real: 1 }, landing_company, 'legal_allowed_currencies');
96+
const currency_values = getCurrencyValues();
97+
const current_client_currency = Client.get('currency');
98+
const is_virtual = Client.get('is_virtual');
99+
const currencies_to_compare = is_virtual ?
100+
currency_values.other_currencies : currency_values.other_currencies.concat(current_client_currency);
99101

100102
return allowed_currencies.filter(c => currencies_to_compare.indexOf(c) < 0);
101103
};

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ const SetCurrency = (() => {
8181

8282
onSelection($currency_list, $error, true);
8383
};
84-
8584
const getAvailableCurrencies = (landing_company, payout_currencies) =>
86-
Client.get('landing_company_shortcode') === 'svg' ? GetCurrency.getCurrencies(landing_company) : payout_currencies;
85+
Client.hasSvgAccount() ? GetCurrency.getCurrencies(landing_company) : payout_currencies;
8786

8887
const getCurrencyChangeOptions = (landing_company) => {
8988
const allowed_currencies = Client.getLandingCompanyValue(Client.get('loginid'), landing_company, 'legal_allowed_currencies');
@@ -103,7 +102,6 @@ const SetCurrency = (() => {
103102
const $wrapper = $('<div/>', { class: 'gr-2 gr-4-m currency_wrapper', id: c });
104103
const $image = $('<div/>').append($('<img/>', { src: Url.urlForStatic(`images/pages/set_currency/${c.toLowerCase()}.svg`) }));
105104
const $name = $('<div/>', { class: 'currency-name' });
106-
107105
if (Currency.isCryptocurrency(c)) {
108106
const $display_name = $('<span/>', {
109107
text: Currency.getCurrencyName(c) || c,

0 commit comments

Comments
 (0)