@@ -29,7 +29,7 @@ const Layout = () => {
29
29
Object . values ( checkClientAccount ) . some ( account => account . currency === currency ) ||
30
30
currency === 'demo' ||
31
31
currency === '' ;
32
- const [ clientHasCurrency ] = useState ( ifClientAccountHasCurrency ) ;
32
+ const [ clientHasCurrency , setClientHasCurrency ] = useState ( ifClientAccountHasCurrency ) ;
33
33
34
34
const validCurrencies = [ ...fiat_currencies_display_order , ...crypto_currencies_display_order ] ;
35
35
const query_currency = ( getQueryParams . get ( 'account' ) ?? '' ) ?. toUpperCase ( ) ;
@@ -40,21 +40,21 @@ const Layout = () => {
40
40
const validateApiAccounts = ( { data } : any ) => {
41
41
if ( data . msg_type === 'authorize' ) {
42
42
api_accounts . push ( data . authorize . account_list || [ ] ) ;
43
- console . log ( 'api_accounts' , api_accounts ) ;
44
- console . log ( 'checkClientAccount' , checkClientAccount ) ;
45
- api_accounts ?. flat ( ) . map ( data => {
46
- Object . values ( checkClientAccount ) . map ( key => {
47
- console . log ( 'outside data.currency' , data . currency ) ;
48
- console . log ( 'outside key.currency' , key . currency ) ;
49
- if ( data . currency !== key . currency ) {
50
- console . log ( 'setClientHasCurrency' ) ;
51
- console . log ( 'data.currency' , data . currency ) ;
52
- console . log ( 'key.currency' , key . currency ) ;
53
- //setClientHasCurrency(false);
54
- }
55
- } ) ;
43
+ const allCurrencies = new Set ( Object . values ( checkClientAccount ) . map ( acc => acc . currency ) ) ;
44
+
45
+ const hasMissingCurrency = api_accounts ?. flat ( ) . some ( data => {
46
+ if ( ! allCurrencies . has ( data . currency ) ) {
47
+ return true ;
48
+ }
49
+ return false ;
56
50
} ) ;
57
51
52
+ if ( hasMissingCurrency ) {
53
+ setClientHasCurrency ( false ) ;
54
+ } else {
55
+ console . log ( 'All currencies are present' ) ;
56
+ }
57
+
58
58
if ( subscription ) {
59
59
subscription ?. unsubscribe ( ) ;
60
60
}
@@ -68,11 +68,11 @@ const Layout = () => {
68
68
}
69
69
} , [ ] ) ;
70
70
71
- console . log ( 'clientHasCurrency' , clientHasCurrency ) ;
72
-
73
71
useEffect ( ( ) => {
74
- if ( isLoggedInCookie && ! isClientAccountsPopulated && isOAuth2Enabled && ! isEndpointPage && ! isCallbackPage ) {
75
- console . log ( 'requestOidcAuthentication' ) ;
72
+ if (
73
+ ( isLoggedInCookie && ! isClientAccountsPopulated && isOAuth2Enabled && ! isEndpointPage && ! isCallbackPage ) ||
74
+ ! clientHasCurrency
75
+ ) {
76
76
requestOidcAuthentication ( {
77
77
redirectCallbackUri : `${ window . location . origin } /callback` ,
78
78
} ) ;
0 commit comments