@@ -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 } ;
0 commit comments