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

fix: notification permission flow #11266

Merged
merged 13 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
import { MetaMetricsEvents } from '../../../../core/Analytics';
import { useEnableNotifications } from '../../../../util/notifications/hooks/useNotifications';
import { useMetrics } from '../../../hooks/useMetrics';
import { AuthorizationStatus } from '@notifee/react-native';

interface Props {
route: {
Expand Down Expand Up @@ -60,7 +61,7 @@ const BasicFunctionalityModal = ({ route }: Props) => {
asyncAlert,
);

if (nativeNotificationStatus) {
if (nativeNotificationStatus?.authorizationStatus === AuthorizationStatus.AUTHORIZED) {
/**
* Although this is an async function, we are dispatching an action (firing & forget)
* to emulate optimistic UI.
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/Notifications/OptIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import AppConstants from '../../../../core/AppConstants';
import { RootState } from '../../../../reducers';
import { useEnableNotifications } from '../../../../util/notifications/hooks/useNotifications';
import SwitchLoadingModal from '../../../../components/UI/Notification/SwitchLoadingModal';
import { AuthorizationStatus } from '@notifee/react-native';

const OptIn = () => {
const theme = useTheme();
Expand Down Expand Up @@ -51,7 +52,7 @@ const OptIn = () => {
asyncAlert,
);

if (nativeNotificationStatus) {
if (nativeNotificationStatus?.authorizationStatus === AuthorizationStatus.AUTHORIZED) {
/**
* Although this is an async function, we are dispatching an action (firing & forget)
* to emulate optimistic UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import AppConstants from '../../../../core/AppConstants';
import { store } from '../../../../store';
import notificationsRows from './notificationsRows';
import { IconName } from '../../../../component-library/components/Icons/Icon';
import { AuthorizationStatus } from '@notifee/react-native';

interface MainNotificationSettingsProps extends Props {
toggleNotificationsEnabled: () => void;
Expand Down Expand Up @@ -168,7 +169,7 @@ const NotificationsSettings = ({ navigation, route }: Props) => {
asyncAlert,
);

if (nativeNotificationStatus) {
if (nativeNotificationStatus?.authorizationStatus === AuthorizationStatus.AUTHORIZED) {
/**
* Although this is an async function, we are dispatching an action (firing & forget)
* to emulate optimistic UI.
Expand Down
5 changes: 3 additions & 2 deletions app/util/notifications/pushPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import notifee, {
NotificationSettings,
} from '@notifee/react-native';
import { Alert as NativeAlert } from 'react-native';

import NotificationSetting from 'react-native-open-notification';
import { strings } from '../../../locales/i18n';
import Device from '../device';
import { mmStorage } from './settings';
import { STORAGE_IDS } from './settings/storage/constants';
import Logger from '../Logger';
import Device from '../device';

interface AlertButton {
text: string;
Expand Down Expand Up @@ -43,6 +43,7 @@ const defaultButtons = (resolve: (value: boolean) => void): AlertButton[] => [
} else {
await notifee.requestPermission();
}
NotificationSetting.open();
resolve(true);
},
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
"react-native-material-textfield": "0.16.1",
"react-native-mmkv": "^2.11.0",
"react-native-modal": "^12.1.0",
"react-native-open-notification": "^0.1.4",
Jonathansoufer marked this conversation as resolved.
Show resolved Hide resolved
"react-native-os": "^1.2.6",
"react-native-permissions": "^3.7.2",
"react-native-progress": "3.5.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25346,6 +25346,11 @@ react-native-modal@^12.1.0:
prop-types "^15.6.2"
react-native-animatable "1.3.3"

react-native-open-notification@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/react-native-open-notification/-/react-native-open-notification-0.1.4.tgz#20b7c03a1543ce36f3f99ff9924c67eef2688aa9"
integrity sha512-TPeFRsao6nDFW5nvBseD6nheRCN1U3poaY90iDzBY1MEEVepClqfEC9Iw0cqj7LYnpDSF8V25fb/SpjEg3HdQQ==

react-native-os@^1.2.6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/react-native-os/-/react-native-os-1.2.6.tgz#1bb16d78ccad1143972183a04f443cf1af9fbefa"
Expand Down
Loading