Skip to content

Commit

Permalink
Merge pull request #304 from rupato-deriv/Rupato/Fix--for-disabled-ac…
Browse files Browse the repository at this point in the history
…counts

Rupato/fix  for disabled accounts
  • Loading branch information
rupato-deriv authored Mar 6, 2025
2 parents 1c27abc + 5eb0bd5 commit 976da1a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
19 changes: 17 additions & 2 deletions src/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const Layout = () => {

const validateApiAccounts = ({ data }: any) => {

Check warning on line 40 in src/components/layout/index.tsx

View workflow job for this annotation

GitHub Actions / build_to_cloudflare_pages

Unexpected any. Specify a different type
if (data.msg_type === 'authorize') {
api_accounts.push(data.authorize.account_list || []);
const enabled_accounts = (data?.authorize?.account_list || []).filter((acc: any) => !acc.is_disabled);

Check warning on line 42 in src/components/layout/index.tsx

View workflow job for this annotation

GitHub Actions / build_to_cloudflare_pages

Unexpected any. Specify a different type
api_accounts.push(enabled_accounts || []);

const allCurrencies = new Set(Object.values(checkClientAccount).map(acc => acc.currency));
let currency = 'USD';
const hasMissingCurrency = api_accounts?.flat().some(data => {
Expand All @@ -54,8 +56,22 @@ const Layout = () => {
if (hasMissingCurrency) {
setClientHasCurrency(false);
} else {
const enabled_account_currency =
enabled_accounts?.find(acc => acc.currency === currency)?.currency || 'USD';

let session_storage_currency = sessionStorage.getItem('query_param_currency');

if (session_storage_currency) {
session_storage_currency = `account=${session_storage_currency}`;
} else {
session_storage_currency = `account=${enabled_account_currency}`;
}

window.history.pushState({}, '', `${window.location.pathname}?${session_storage_currency}`);

sessionStorage.removeItem('query_param_currency');
setClientHasCurrency(true);
console.log('All accounts present');
}

if (subscription) {
Expand All @@ -77,7 +93,6 @@ const Layout = () => {
!clientHasCurrency
) {
const query_param_currency = sessionStorage.getItem('query_param_currency') || currency || 'USD';
console.log('query_param_currency', query_param_currency);
sessionStorage.setItem('query_param_currency', currency);
requestOidcAuthentication({
redirectCallbackUri: `${window.location.origin}/callback`,
Expand Down
3 changes: 2 additions & 1 deletion src/external/bot-skeleton/services/api/api-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ class APIBase {
this.active_symbols_promise = this.getActiveSymbols();
}
this.account_info = authorize;
setAccountList(authorize.account_list);
const filtered_accounts = (authorize?.account_list || []).filter(acc => !acc?.is_disabled);
setAccountList(filtered_accounts);
setAuthData(authorize);
setIsAuthorized(true);
this.is_authorized = true;
Expand Down
6 changes: 0 additions & 6 deletions src/pages/callback/callback-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ const CallbackPage = () => {
: null;
const selected_currency =
(is_valid_currency ? state?.account?.currency || currency : currency) || firstAccountCurrency;
console.log('selected_currency', {
firstAccountCurrency,
stateAccountCurrency: state?.account?.currency,
currency,
selected_currency,
});
window.location.assign(`/?account=${selected_currency}`);
}}
renderReturnButton={() => {
Expand Down

0 comments on commit 976da1a

Please sign in to comment.