Skip to content

Commit a88edd4

Browse files
authored
feat: add the notifications center (#2001)
1 parent f71de0b commit a88edd4

File tree

11 files changed

+144
-1
lines changed

11 files changed

+144
-1
lines changed

apps/browser-extension-wallet/src/components/NotificationsCenter/NotificationsBellContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, { useState } from 'react';
2+
import { useHistory } from 'react-router';
23
import { Dropdown } from 'antd';
34

45
import { usePostHogClientContext } from '@providers/PostHogClientProvider';
56
import { ExperimentName } from '@lib/scripts/types/feature-flags';
7+
import { walletRoutePaths } from '@routes';
68

79
import { NotificationsBell } from './NotificationsBell';
810
import { NotificationsDropDown } from './NotificationsDropDown';
@@ -13,7 +15,7 @@ export interface NotificationsCenterContainerProps {
1315

1416
export const NotificationsBellContainer = ({ popupView }: NotificationsCenterContainerProps): React.ReactElement => {
1517
const posthog = usePostHogClientContext();
16-
18+
const history = useHistory();
1719
const [isOpen, setIsOpen] = useState(false);
1820

1921
// TODO Connect with notifications center
@@ -38,6 +40,7 @@ export const NotificationsBellContainer = ({ popupView }: NotificationsCenterCon
3840

3941
const handleViewAll = () => {
4042
setIsOpen(false);
43+
history.push(walletRoutePaths.notifications);
4144
};
4245

4346
return (
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import '../../../../../packages/core/src/ui/styles/theme.scss';
2+
@import '../../../../../packages/common/src/ui/styles/theme.scss';
3+
4+
.button {
5+
max-width: size_unit(25);
6+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { Box, Flex } from '@input-output-hk/lace-ui-toolkit';
4+
5+
import { Button, NavigationButton } from '@lace/common';
6+
import { SectionTitle } from '@components/Layout/SectionTitle';
7+
8+
import styles from './NotificationsCenter.module.scss';
9+
10+
export interface NotificationsCenterProps {
11+
onBack: () => void;
12+
onMarkAllAsRead: () => void;
13+
popupView?: boolean;
14+
}
15+
16+
export const NotificationsCenter = ({
17+
onBack,
18+
onMarkAllAsRead,
19+
popupView
20+
}: NotificationsCenterProps): React.ReactElement => {
21+
const { t } = useTranslation();
22+
23+
return (
24+
<Box p="$24">
25+
<Flex justifyContent="space-between" mb={'$44'}>
26+
<Box mb={'$0'}>
27+
<SectionTitle
28+
sideText={`(${1})`}
29+
title={
30+
<Flex alignItems="center" gap="$8">
31+
<NavigationButton icon="arrow" onClick={onBack} />
32+
{t('notificationsCenter.title')}
33+
</Flex>
34+
}
35+
/>
36+
</Box>
37+
{!popupView && (
38+
<Button
39+
className={styles.button}
40+
block
41+
color="gradient"
42+
data-testid="notifications-bell"
43+
onClick={onMarkAllAsRead}
44+
>
45+
{t('notificationsCenter.markAllAsRead')}
46+
</Button>
47+
)}
48+
</Flex>
49+
Notifications Center (Placeholder content)
50+
</Box>
51+
);
52+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { useHistory } from 'react-router';
3+
4+
import { useWalletStore } from '@stores';
5+
import { APP_MODE_POPUP } from '@src/utils/constants';
6+
7+
import { NotificationsCenter } from './NotificationsCenter';
8+
9+
export const NotificationsCenterContainer = (): React.ReactElement => {
10+
const history = useHistory();
11+
const { walletUI } = useWalletStore();
12+
13+
return (
14+
<NotificationsCenter
15+
onBack={() => history.goBack()}
16+
onMarkAllAsRead={() => {
17+
// TODO connect with notifications center
18+
// eslint-disable-next-line no-console
19+
console.log('onMarkAllAsRead');
20+
}}
21+
popupView={walletUI.appMode === APP_MODE_POPUP}
22+
/>
23+
);
24+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import { Layout, SectionLayout } from '@src/views/browser-view/components/Layout';
4+
import { EducationalList } from '@src/views/browser-view/components';
5+
import { useTranslation } from 'react-i18next';
6+
import { getEducationalList } from '@src/views/browser-view/features/assets/components/AssetEducationalList/AssetEducationalList';
7+
8+
import { NotificationsCenterContainer } from './NotificationsCenterContainer';
9+
10+
export const NotificationsCenterLayout = (): React.ReactElement => {
11+
const { t } = useTranslation();
12+
13+
const educationalItems = getEducationalList(t);
14+
15+
return (
16+
<>
17+
<Layout>
18+
<SectionLayout
19+
sidePanelContent={
20+
<EducationalList items={educationalItems} title={t('browserView.sidePanel.aboutYourWallet')} />
21+
}
22+
>
23+
<NotificationsCenterContainer />
24+
</SectionLayout>
25+
</Layout>
26+
</>
27+
);
28+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from './NotificationsBellContainer';
2+
export * from './NotificationsCenterContainer';
3+
export * from './NotificationsCenterLayout';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ExperimentName } from '@lib/scripts/types/feature-flags';
2+
import { usePostHogClientContext } from '@providers/PostHogClientProvider';
3+
4+
export interface NotificationsCenterConfig {
5+
isNotificationsCenterEnabled: boolean;
6+
}
7+
8+
export const useNotificationsCenterConfig = (): NotificationsCenterConfig => {
9+
const posthog = usePostHogClientContext();
10+
11+
return { isNotificationsCenterEnabled: posthog?.isFeatureFlagEnabled(ExperimentName.NOTIFICATIONS_CENTER) ?? false };
12+
};

apps/browser-extension-wallet/src/routes/ExtensionRoutes.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import { NftDetail, Nfts } from '@src/features/nfts';
1515
import { useWalletStore } from '@stores';
1616
import { config } from '@src/config';
1717
import { Voting } from '@src/features/voting-beta/components';
18+
import { NotificationsCenterContainer } from '@src/components/NotificationsCenter';
19+
import { useNotificationsCenterConfig } from '@hooks/useNotificationsCenterConfig';
1820

1921
const { GOV_TOOLS_URLS } = config();
2022

2123
export const ExtensionRoutes = (): React.ReactElement => {
2224
const { isSharedWallet, environmentName } = useWalletStore();
2325
const isVotingCenterEnabled = !!GOV_TOOLS_URLS[environmentName];
26+
const { isNotificationsCenterEnabled } = useNotificationsCenterConfig();
2427

2528
return (
2629
<MainLayout>
@@ -30,6 +33,9 @@ export const ExtensionRoutes = (): React.ReactElement => {
3033
<Route exact path={walletRoutePaths.activity} component={Activity} />
3134
<Route exact path={walletRoutePaths.send} component={Send} />
3235
<Route exact path={walletRoutePaths.nftDetail} component={NftDetail} />
36+
{isNotificationsCenterEnabled && (
37+
<Route exact path={walletRoutePaths.notifications} component={NotificationsCenterContainer} />
38+
)}
3339
{!isSharedWallet && <Route exact path={walletRoutePaths.earn} component={DelegationContainer} />}
3440
<Route exact path={walletRoutePaths.addressBook} component={AddressBook} />
3541
<Route exact path={walletRoutePaths.settings} component={Settings} />

apps/browser-extension-wallet/src/routes/wallet-paths.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const walletRoutePaths = {
55
confirmDelegation: '/delegate/confirm',
66
delegate: '/delegate',
77
earn: '/earn',
8+
notifications: '/notifications',
89
nftDetail: '/nft/:id',
910
nfts: '/nfts',
1011
assets: '/assets',

apps/browser-extension-wallet/src/views/browser-view/routes/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import { catchAndBrandExtensionApiError } from '@utils/catch-and-brand-extension
4747
import { removePreloaderIfExists } from '@utils/remove-reloader-if-exists';
4848
import { ENHANCED_ANALYTICS_OPT_IN_STATUS_LS_KEY } from '@providers/AnalyticsProvider/config';
4949
import { EnhancedAnalyticsOptInStatus } from '@providers/AnalyticsProvider/analyticsTracker';
50+
import { NotificationsCenterLayout } from '@components/NotificationsCenter';
51+
import { useNotificationsCenterConfig } from '@hooks/useNotificationsCenterConfig';
5052

5153
export const defaultRoutes: RouteMap = [
5254
{
@@ -84,6 +86,10 @@ export const defaultRoutes: RouteMap = [
8486
{
8587
path: routes.nfts,
8688
component: NftsLayout
89+
},
90+
{
91+
path: routes.notifications,
92+
component: NotificationsCenterLayout
8793
}
8894
];
8995

@@ -143,10 +149,12 @@ export const BrowserViewRoutes = ({ routesMap = defaultRoutes }: { routesMap?: R
143149
const posthogClientInitialized = useIsPosthogClientInitialized();
144150
const location = useLocation<{ background?: Location<unknown> }>();
145151
const isVotingCenterEnabled = !!GOV_TOOLS_URLS[environmentName];
152+
const { isNotificationsCenterEnabled } = useNotificationsCenterConfig();
146153

147154
const availableRoutes = routesMap.filter((route) => {
148155
if (route.path === routes.staking && isSharedWallet) return false;
149156
if (route.path === routes.voting && !isVotingCenterEnabled) return false;
157+
if (route.path === routes.notifications && !isNotificationsCenterEnabled) return false;
150158
return true;
151159
});
152160

0 commit comments

Comments
 (0)