Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ameerul /Bug 93397 Notification_counter_not_updated_correctly #8262

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/cashier/src/containers/cashier/cashier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
VerticalTab,
Loading,
} from '@deriv/components';
import { useOnrampVisible, useAccountTransferVisible, useSwitchToRealAccount } from '@deriv/hooks';
import {
useOnrampVisible,
useAccountTransferVisible,
useSwitchToRealAccount,
useP2PNotificationCount,
} from '@deriv/hooks';
import { getSelectedRoute, getStaticUrl, isMobile, routes, WS } from '@deriv/shared';
import AccountPromptDialog from '../../components/account-prompt-dialog';
import ErrorDialog from '../../components/error-dialog';
Expand Down Expand Up @@ -59,7 +64,6 @@ const Cashier = observer(({ history, location, routes: routes_config }: TCashier
is_loading,
is_p2p_enabled,
onMountCommon: onMount,
p2p_notification_count,
setAccountSwitchListener,
setCashierTabIndex: setTabIndex,
cashier_route_tab_index: tab_index,
Expand All @@ -74,6 +78,7 @@ const Cashier = observer(({ history, location, routes: routes_config }: TCashier
const is_account_transfer_visible = useAccountTransferVisible();
const is_onramp_visible = useOnrampVisible();
const switchToReal = useSwitchToRealAccount();
const p2p_notification_count = useP2PNotificationCount();

React.useEffect(() => {
switchToReal();
Expand Down
6 changes: 0 additions & 6 deletions packages/cashier/src/stores/__tests__/general-store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,6 @@ describe('GeneralStore', () => {
expect(general_store.cashier_route_tab_index).toBe(1);
});

it('should set notification count', () => {
general_store.setNotificationCount(1);

expect(general_store.p2p_notification_count).toBe(1);
});

it('should set p2p visibility equal to true', () => {
general_store.setIsP2pVisible(true);

Expand Down
31 changes: 0 additions & 31 deletions packages/cashier/src/stores/general-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export default class GeneralStore extends BaseStore {
onMountCashierOnboarding: action.bound,
onMountCommon: action.bound,
onRemount: observable,
p2p_notification_count: observable,
p2p_unseen_notifications: computed,
percentage: observable,
percentageSelectorSelectionStatus: action.bound,
payment_agent: observable,
Expand All @@ -43,7 +41,6 @@ export default class GeneralStore extends BaseStore {
setIsDeposit: action.bound,
setIsP2pVisible: action.bound,
setLoading: action.bound,
setNotificationCount: action.bound,
setOnRemount: action.bound,
setShouldShowAllAvailableCurrencies: action.bound,
should_percentage_reset: observable,
Expand Down Expand Up @@ -86,7 +83,6 @@ export default class GeneralStore extends BaseStore {
is_p2p_visible = false;
is_populating_values = false;
onRemount: VoidFunction = () => this;
p2p_notification_count = 0;
percentage = 0;
payment_agent: PaymentAgentStore | null = null;
should_percentage_reset = false;
Expand All @@ -110,27 +106,6 @@ export default class GeneralStore extends BaseStore {
return this.is_p2p_visible && !is_eu;
}

/**
* Gets the notifications from local storage, within p2p_settings, where it checks which notification has
* been seen. The number of unseen notifications is displayed in vertical tab, notifications count, for P2P.
*
* @returns {number} Notifications that have not been seen by the user.
*/
get p2p_unseen_notifications(): number {
const p2p_settings = JSON.parse(localStorage.getItem('p2p_settings') || '{}');
const local_storage_settings = p2p_settings[this.root_store.client.loginid || ''];

if (isEmptyObject(local_storage_settings)) {
return 0;
}

const unseen_notifications = local_storage_settings.notifications.filter(
(notification: { is_seen: boolean }) => !notification.is_seen
);

return unseen_notifications.length;
}

async showP2pInCashierOnboarding(): Promise<void> {
const { account_list, is_virtual } = this.root_store.client;

Expand Down Expand Up @@ -280,8 +255,6 @@ export default class GeneralStore extends BaseStore {
const { account_transfer, onramp, payment_agent, payment_agent_transfer, transaction_history } =
modules.cashier;

this.setNotificationCount(this.p2p_unseen_notifications);

if (client.is_logged_in) {
// avoid calling this again
if (this.is_populating_values) {
Expand Down Expand Up @@ -331,10 +304,6 @@ export default class GeneralStore extends BaseStore {
this.cashier_route_tab_index = index;
}

setNotificationCount(notification_count: number): void {
this.p2p_notification_count = notification_count;
}

setIsP2pVisible(is_p2p_visible: boolean): void {
this.is_p2p_visible = is_p2p_visible;
if (!is_p2p_visible && window.location.pathname.endsWith(routes.cashier_p2p)) {
Expand Down