diff --git a/app/package.json b/app/package.json index d71018d8a..852f8a399 100644 --- a/app/package.json +++ b/app/package.json @@ -96,7 +96,7 @@ "react-native-inappbrowser-reborn": "^3.7.0", "react-native-keychain": "^7.0.0", "react-native-localize": "^2.2.4", - "react-native-permissions": "3.6.1", + "react-native-permissions": "^3.6.1", "react-native-qrcode-svg": "6.1.1", "react-native-reanimated": "2.2.4", "react-native-safe-area-context": "3.3.2", diff --git a/app/src/components/PushNotifications.tsx b/app/src/components/PushNotifications.tsx index e0068c641..5855748f4 100644 --- a/app/src/components/PushNotifications.tsx +++ b/app/src/components/PushNotifications.tsx @@ -2,7 +2,7 @@ import { useAgent } from '@aries-framework/react-hooks' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' -import { isMediatorCapable, registered, setup, userDenied } from '../helpers/PushNotificationsHelper' +import { isMediatorCapable, isRegistered, setup, isUserDenied } from '../helpers/PushNotificationsHelper' import PushNotificationsModal from '../modals/PushNotificationsModal' const PushNotifications = () => { @@ -12,12 +12,12 @@ const PushNotifications = () => { const setupPushNotifications = async () => { setInfoModalVisible(false) - if (!agent || (await userDenied())) return + if (!agent || (await isUserDenied())) return setup(agent) } const initializeCapabilityRequest = async () => { - if (!agent || !(await isMediatorCapable(agent)) || (await registered())) return + if (!agent || !(await isMediatorCapable(agent)) || (await isRegistered())) return setInfoModalVisible(true) } diff --git a/app/src/helpers/PushNotificationsHelper.ts b/app/src/helpers/PushNotificationsHelper.ts index d26cde91e..6b91d76c9 100644 --- a/app/src/helpers/PushNotificationsHelper.ts +++ b/app/src/helpers/PushNotificationsHelper.ts @@ -74,7 +74,7 @@ const _getMediatorConnection = async (agent: Agent): Promise} */ -const userDenied = async (): Promise => { +const isUserDenied = async (): Promise => { return (await AsyncStorage.getItem('userDeniedPushNotifications')) === 'true' } @@ -109,7 +109,7 @@ const isMediatorCapable = async (agent: Agent): Promise} */ -const registered = async (token?: string): Promise => { +const isRegistered = async (token?: string): Promise => { const authorized = (await messaging().hasPermission()) === messaging.AuthorizationStatus.AUTHORIZED // Need to register for push notification capability on iOS @@ -132,7 +132,7 @@ const setDeviceInfo = async (agent: Agent, blankDeviceToken = false): Promi if (blankDeviceToken) token = '' else token = await messaging().getToken() - if ((await registered(token)) && !blankDeviceToken) return + if ((await isRegistered(token)) && !blankDeviceToken) return const mediator = await _getMediatorConnection(agent) if (!mediator) return @@ -155,10 +155,11 @@ const setDeviceInfo = async (agent: Agent, blankDeviceToken = false): Promi * @returns {Promise} */ const setup = async (agent: Agent): Promise => { - setDeviceInfo(agent) + // FIXME: Currently set the token to blank (disabled) on initialization. + setDeviceInfo(agent, true) _backgroundHandler() _foregroundHandler() _requestPermission(agent) } -export { registered, isMediatorCapable, userDenied, setDeviceInfo, setup } +export { isRegistered, isMediatorCapable, isUserDenied, setDeviceInfo, setup } diff --git a/app/src/screens/Developer.tsx b/app/src/screens/Developer.tsx index fa0c0a657..f44e3cdca 100644 --- a/app/src/screens/Developer.tsx +++ b/app/src/screens/Developer.tsx @@ -6,12 +6,7 @@ import { Modal, StyleSheet, Switch, Text, Pressable, View, ScrollView } from 're import { SafeAreaView } from 'react-native-safe-area-context' import Icon from 'react-native-vector-icons/MaterialIcons' -import { - isMediatorCapable as isMediatorPushNotificationCapable, - registered as pushNotificationsRegistered, - setDeviceInfo as setPushNotificationDeviceInfo, - setup as setupPushNotifications, -} from '../helpers/PushNotificationsHelper' +import * as PushNotificationHelper from '../helpers/PushNotificationsHelper' import { BCState } from '../store' import IASEnvironment from './IASEnvironment' @@ -178,18 +173,18 @@ const Settings: React.FC = () => { const getPushNotificationCapable = async () => { if (!agent) return - if ((await isMediatorPushNotificationCapable(agent)) === true) setPushNotificationCapable(true) + if ((await PushNotificationHelper.isMediatorCapable(agent)) === true) setPushNotificationCapable(true) else setPushNotificationCapable(false) } const initializePushNotificationsToggle = async () => { - setEnablePushNotifications(await pushNotificationsRegistered()) + setEnablePushNotifications(await PushNotificationHelper.isRegistered()) } const toggleDevPushNotificationsSwitch = () => { if (!pushNotificationCapable || !agent) return - if (enablePushNotifications) setPushNotificationDeviceInfo(agent, true) - else setupPushNotifications(agent) + if (enablePushNotifications) PushNotificationHelper.setDeviceInfo(agent, true) + else PushNotificationHelper.setup(agent) setEnablePushNotifications(!enablePushNotifications) } diff --git a/yarn.lock b/yarn.lock index d88b170af..e1d1be2c2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7461,7 +7461,7 @@ __metadata: react-native-inappbrowser-reborn: ^3.7.0 react-native-keychain: ^7.0.0 react-native-localize: ^2.2.4 - react-native-permissions: 3.6.1 + react-native-permissions: ^3.6.1 react-native-qrcode-svg: 6.1.1 react-native-reanimated: 2.2.4 react-native-safe-area-context: 3.3.2 @@ -18719,20 +18719,6 @@ __metadata: languageName: node linkType: hard -"react-native-permissions@npm:3.6.1": - version: 3.6.1 - resolution: "react-native-permissions@npm:3.6.1" - peerDependencies: - react: ">=16.13.1" - react-native: ">=0.63.3" - react-native-windows: ">=0.62.0" - peerDependenciesMeta: - react-native-windows: - optional: true - checksum: 41920565e1a850c5bdcda94ee2415be0277ab64ea86ea4daf9f0b90eb7857e3a7a336d159495785d14d3de89dd09bb198f4d1afef6811773b5c2b0148f99d583 - languageName: node - linkType: hard - "react-native-permissions@npm:^3.6.1": version: 3.8.0 resolution: "react-native-permissions@npm:3.8.0"