diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 465180d58..96c0c4802 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -17,7 +17,10 @@ - + + + + @@ -41,7 +44,7 @@ - + diff --git a/ios/Podfile b/ios/Podfile index 253391bc6..28ad5cedd 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -1,4 +1,16 @@ -require_relative '../node_modules/react-native/scripts/react_native_pods' +def node_require(script) + # Resolve script with node to allow for hoisting + require Pod::Executable.execute_command('node', ['-p', + "require.resolve( + '#{script}', + {paths: [process.argv[1]]}, + )", __dir__]).strip +end + +# Use it to require both react-native's and this package's scripts: +node_require('react-native/scripts/react_native_pods.rb') +node_require('react-native-permissions/scripts/setup.rb') + require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' ####### @@ -13,6 +25,16 @@ min_ios_version_supported = project.build_configurations.first.build_settings['I platform :ios, min_ios_version_supported prepare_react_native_project! +# Setup permissions you need +setup_permissions([ +'AppTrackingTransparency', +'Bluetooth', +'Camera', +'FaceID', +'LocationWhenInUse', +'Notifications', +]) + # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded # @@ -34,8 +56,6 @@ end $VCEnableLocation=false target 'BitPayApp' do - permissions_path = '../node_modules/react-native-permissions/ios' - pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications/Permission-Notifications.podspec" pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text', :modular_headers => true config = use_native_modules! diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 57648d2e5..ef332abb5 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -114,8 +114,6 @@ PODS: - MMKVCore (1.3.9) - MultiplatformBleAdapter (0.1.9) - OpenSSL-Universal (1.1.1100) - - Permission-Notifications (3.7.2): - - RNPermissions - RCT-Folly (2021.07.22.00): - boost - DoubleConversion @@ -616,7 +614,7 @@ PODS: - React-Core - RNOS (1.2.6): - React - - RNPermissions (3.7.2): + - RNPermissions (5.1.0): - React-Core - RNQuickAction (0.3.13): - React @@ -686,7 +684,6 @@ DEPENDENCIES: - libevent (~> 2.1.12) - MixpanelReactNative (from `../node_modules/mixpanel-react-native`) - OpenSSL-Universal (= 1.1.1100) - - Permission-Notifications (from `../node_modules/react-native-permissions/ios/Notifications/Permission-Notifications.podspec`) - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`) - RCTTypeSafety (from `../node_modules/react-native/Libraries/TypeSafety`) @@ -818,8 +815,6 @@ EXTERNAL SOURCES: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" MixpanelReactNative: :path: "../node_modules/mixpanel-react-native" - Permission-Notifications: - :path: "../node_modules/react-native-permissions/ios/Notifications/Permission-Notifications.podspec" RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTRequired: @@ -983,7 +978,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: AppsFlyerFramework: 9f304d91cc80b6579b1206a59220383056b58b47 - boost: 7dcd2de282d72e344012f7d6564d024930a6a440 + boost: 57d2868c099736d80fcd648bf211b4431e51a558 braze-react-native-sdk: 7ec46f6d33f60946797e75fb06998c03861328d8 BrazeKit: 4afa5f9a89384d06515719b5d246b4676870f030 BrazeLocation: 8f8a54c4170d9ee6035495364f493614401acad0 @@ -1013,7 +1008,6 @@ SPEC CHECKSUMS: MMKVCore: af055b00e27d88cd92fad301c5fecd1ff9b26dd9 MultiplatformBleAdapter: 5a6a897b006764392f9cef785e4360f54fb9477d OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c - Permission-Notifications: dbc8cb572cdfbc3c2941feecce4c7900bbdccea1 RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1 RCTRequired: 01c639ec840ee03928b2d65f5cd5297d737b3834 RCTTypeSafety: 9623592521a1576363baf3d6ab8d164cfe9062bf @@ -1083,7 +1077,7 @@ SPEC CHECKSUMS: RNInAppBrowser: e36d6935517101ccba0e875bac8ad7b0cb655364 RNLocalize: 0df7970cfc60389f00eb62fd7c097dc75af3fb4f RNOS: 6f2f9a70895bbbfbdad7196abd952e7b01d45027 - RNPermissions: 2fbbcb7244357507f958d626d58eb15fb0013d85 + RNPermissions: 5642e6521a29e7aed5049d00230ee0fa80a352e0 RNQuickAction: 6d404a869dc872cde841ad3147416a670d13fa93 RNRate: ef3bcff84f39bb1d1e41c5593d3eea4aab2bd73a RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c @@ -1099,6 +1093,6 @@ SPEC CHECKSUMS: Yoga: ef534101bb891fb09bae657417f34d399c1efe38 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: d45587e182ed77c86769f50ab49373ff403ea395 +PODFILE CHECKSUM: 49cdbbd02c0126946dd274f37d0abe09128f8378 COCOAPODS: 1.15.2 diff --git a/package.json b/package.json index eea5418ae..f9f8b6003 100644 --- a/package.json +++ b/package.json @@ -133,7 +133,7 @@ "react-native-modal": "13.0.1", "react-native-os": "1.2.6", "react-native-pager-view": "6.1.4", - "react-native-permissions": "3.7.2", + "react-native-permissions": "5.1.0", "react-native-print": "0.11.0", "react-native-progress": "5.0.0", "react-native-prompt-android": "1.1.0", diff --git a/src/navigation/onboarding/screens/Notifications.tsx b/src/navigation/onboarding/screens/Notifications.tsx index 494252f0c..a7e44d03c 100644 --- a/src/navigation/onboarding/screens/Notifications.tsx +++ b/src/navigation/onboarding/screens/Notifications.tsx @@ -1,7 +1,6 @@ import {NativeStackScreenProps} from '@react-navigation/native-stack'; import React, {useLayoutEffect, useRef} from 'react'; -import {Platform, ScrollView} from 'react-native'; -import {requestNotifications, RESULTS} from 'react-native-permissions'; +import {ScrollView} from 'react-native'; import {useAndroidBackHandler} from 'react-navigation-backhandler'; import styled from 'styled-components/native'; import Button from '../../../components/button/Button'; @@ -86,15 +85,12 @@ const NotificationsScreen = ({ }, [navigation, t]); const onSetNotificationsPress = async (notificationsAccepted: boolean) => { - const setAndNavigate = async (accepted: boolean) => { + const setAndNavigate = (accepted: boolean) => { haptic('impactLight'); - const systemEnabled = await AppEffects.checkNotificationsPermissions(); - if (systemEnabled) { - dispatch(AppEffects.setNotifications(accepted)); - dispatch(AppEffects.setConfirmTxNotifications(accepted)); - dispatch(AppEffects.setAnnouncementsNotifications(accepted)); - } - await askForTrackingThenNavigate(() => navigation.navigate('Pin')); + dispatch(AppEffects.setNotifications(accepted)); + dispatch(AppEffects.setConfirmTxNotifications(accepted)); + dispatch(AppEffects.setAnnouncementsNotifications(accepted)); + askForTrackingThenNavigate(() => navigation.navigate('Pin')); }; if (!notificationsAccepted) { @@ -102,21 +98,8 @@ const NotificationsScreen = ({ return; } - if (Platform.OS === 'ios') { - try { - const {status: updatedStatus} = await requestNotifications([ - 'alert', - 'badge', - 'sound', - ]); - setAndNavigate(updatedStatus === RESULTS.GRANTED); - return; - } catch (err) { - console.error(err); - } - } - - setAndNavigate(true); + const accepted = await AppEffects.requestNotificationsPermissions(); + setAndNavigate(accepted); }; return ( diff --git a/src/navigation/tabs/settings/components/Notifications.tsx b/src/navigation/tabs/settings/components/Notifications.tsx index c8eade3d0..0c179aabc 100644 --- a/src/navigation/tabs/settings/components/Notifications.tsx +++ b/src/navigation/tabs/settings/components/Notifications.tsx @@ -51,27 +51,23 @@ const Notifications = () => { const setNotificationValue = useCallback( async (accepted: boolean) => { + dispatch(AppEffects.setNotifications(accepted)); + dispatch(AppEffects.setConfirmTxNotifications(accepted)); + dispatch(AppEffects.setAnnouncementsNotifications(accepted)); const systemEnabled = await AppEffects.checkNotificationsPermissions(); - if (systemEnabled) { - dispatch(AppEffects.setNotifications(accepted)); - dispatch(AppEffects.setConfirmTxNotifications(accepted)); - dispatch(AppEffects.setAnnouncementsNotifications(accepted)); - } else { - if (accepted && Platform.OS === 'ios') { - const requestPermissions = - await AppEffects.requestNotificationsPermissions(); - if (requestPermissions) { - dispatch(AppEffects.setNotifications(accepted)); - } else { - openSettings(); - dispatch(AppEffects.setNotifications(false)); - dispatch(AppEffects.setConfirmTxNotifications(false)); - dispatch(AppEffects.setAnnouncementsNotifications(false)); + if (!systemEnabled) { + if (accepted) { + if (Platform.OS === 'ios') { + const requestPermissions = + await AppEffects.requestNotificationsPermissions(); + if (requestPermissions) { + return; + } } - } else { dispatch(AppEffects.setNotifications(false)); dispatch(AppEffects.setConfirmTxNotifications(false)); dispatch(AppEffects.setAnnouncementsNotifications(false)); + openSettings(); } } }, diff --git a/src/navigation/tabs/settings/notifications/screens/PushNotifications.tsx b/src/navigation/tabs/settings/notifications/screens/PushNotifications.tsx index ea5b78e06..05aa532a1 100644 --- a/src/navigation/tabs/settings/notifications/screens/PushNotifications.tsx +++ b/src/navigation/tabs/settings/notifications/screens/PushNotifications.tsx @@ -1,4 +1,4 @@ -import React, {useState} from 'react'; +import React, {useState, useEffect} from 'react'; import {useTranslation} from 'react-i18next'; import {selectSettingsNotificationState} from '../../../../../store/app/app.selectors'; import {View, DeviceEventEmitter} from 'react-native'; @@ -89,6 +89,12 @@ const PushNotifications = () => { }, ]; + useEffect(() => { + setPushNotifications(notificationsState.pushNotifications); + setAnnouncements(notificationsState.announcements); + setConfirmedTx(notificationsState.confirmedTx); + }, [notificationsState]); + return ( diff --git a/src/store/app/app.effects.ts b/src/store/app/app.effects.ts index 352885e8f..4553f18c0 100644 --- a/src/store/app/app.effects.ts +++ b/src/store/app/app.effects.ts @@ -846,8 +846,10 @@ export const unSubscribeEmailNotifications = }; export const checkNotificationsPermissions = async (): Promise => { + if (Platform.OS === 'android') { + return requestNotificationsPermissions(); + } const {status} = await checkNotifications().catch(() => ({status: null})); - return status === RESULTS.GRANTED; }; diff --git a/yarn.lock b/yarn.lock index 5e7b7ba46..ff0a2cd84 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4200,11 +4200,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== -"@types/normalize-package-data@^2.4.0": - version "2.4.1" - resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" - integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw== - "@types/papaparse@5.3.7": version "5.3.7" resolved "https://registry.yarnpkg.com/@types/papaparse/-/papaparse-5.3.7.tgz#8d3bf9e62ac2897df596f49d9ca59a15451aa247" @@ -9236,11 +9231,6 @@ hoist-non-react-statics@^3.0.0, hoist-non-react-statics@^3.3.0, hoist-non-react- dependencies: react-is "^16.7.0" -hosted-git-info@^2.1.4: - version "2.8.9" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" - integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== - html-escaper@^2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453" @@ -12418,16 +12408,6 @@ nopt@^6.0.0: dependencies: abbrev "^1.0.0" -normalize-package-data@^2.5.0: - version "2.5.0" - resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8" - integrity sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA== - dependencies: - hosted-git-info "^2.1.4" - resolve "^1.10.0" - semver "2 || 3 || 4 || 5" - validate-npm-package-license "^3.0.1" - normalize-path@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" @@ -13952,13 +13932,10 @@ react-native-pager-view@6.1.4: resolved "https://registry.yarnpkg.com/react-native-pager-view/-/react-native-pager-view-6.1.4.tgz#3a63ebd1b72f81991157ea552bb9c887e529bc8c" integrity sha512-fmTwgGwPxGCBusKAq7gHzm+s1Yp0qh5rKPoQszaCuxrb+76KgK4Qe82jJNPUp2xTZOKSw+FbJU2QahF8ncTl+w== -react-native-permissions@3.7.2: - version "3.7.2" - resolved "https://registry.yarnpkg.com/react-native-permissions/-/react-native-permissions-3.7.2.tgz#445b3329d66d074fa88f5319b38717e5831b8fee" - integrity sha512-hoiygypCvN2KgDexrxX3cEpYb8BZWAv1783dR0ew5CRdLu2LUb4evJmz6enHUqhOutdQOUHMhJhX5M9X8DYYfg== - dependencies: - picocolors "^1.0.0" - read-pkg "^5.2.0" +react-native-permissions@5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/react-native-permissions/-/react-native-permissions-5.1.0.tgz#1f132dc0a07c330e9b746cab4c384f41b05703cd" + integrity sha512-bRV8OHFAbLulElvbJ/BLtrYNV9WXStxknCuI5mTGJNIz6sl8sDUA0OhKpbtb0rqqDdJ2mbR1ZijhGkCDOaT0tA== react-native-print@0.11.0: version "0.11.0" @@ -14358,16 +14335,6 @@ reactcss@^1.2.0: dependencies: lodash "^4.0.1" -read-pkg@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.2.0.tgz#7bf295438ca5a33e56cd30e053b34ee7250c93cc" - integrity sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg== - dependencies: - "@types/normalize-package-data" "^2.4.0" - normalize-package-data "^2.5.0" - parse-json "^5.0.0" - type-fest "^0.6.0" - readable-stream@1.0.33: version "1.0.33" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.33.tgz#3a360dd66c1b1d7fd4705389860eda1d0f61126c" @@ -14736,7 +14703,7 @@ resolve.exports@^2.0.0: resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-2.0.1.tgz#cee884cd4e3f355660e501fa3276b27d7ffe5a20" integrity sha512-OEJWVeimw8mgQuj3HfkNl4KqRevH7lzeQNaWRPfx0PPse7Jk6ozcsG4FKVgtzDsC1KUF+YlTHh17NcgHOPykLw== -resolve@^1.10.0, resolve@^1.12.0, resolve@^1.14.2, resolve@^1.20.0: +resolve@^1.12.0, resolve@^1.14.2, resolve@^1.20.0: version "1.22.1" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177" integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw== @@ -15051,7 +15018,7 @@ select@^1.1.2: resolved "https://registry.yarnpkg.com/select/-/select-1.1.2.tgz#0e7350acdec80b1108528786ec1d4418d11b396d" integrity sha512-OwpTSOfy6xSs1+pwcNrv0RBMOzI39Lp3qQKUTPVVPRjCdNa5JH/oPRiqsesIskK8TVgmRiHwO4KXlV2Li9dANA== -"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.5.0, semver@^5.6.0: +semver@^5.0.1, semver@^5.5.0, semver@^5.6.0: version "5.7.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== @@ -15435,32 +15402,6 @@ space-separated-tokens@^1.0.0: resolved "https://registry.yarnpkg.com/space-separated-tokens/-/space-separated-tokens-1.1.5.tgz#85f32c3d10d9682007e917414ddc5c26d1aa6899" integrity sha512-q/JSVd1Lptzhf5bkYm4ob4iWPjx0KiRe3sRFBNrVqbJkFaBm5vbbowy1mymoPNLRa52+oadOhJ+K49wsSeSjTA== -spdx-correct@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-3.2.0.tgz#4f5ab0668f0059e34f9c00dce331784a12de4e9c" - integrity sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA== - dependencies: - spdx-expression-parse "^3.0.0" - spdx-license-ids "^3.0.0" - -spdx-exceptions@^2.1.0: - version "2.3.0" - resolved "https://registry.yarnpkg.com/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz#3f28ce1a77a00372683eade4a433183527a2163d" - integrity sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A== - -spdx-expression-parse@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz#cf70f50482eefdc98e3ce0a6833e4a53ceeba679" - integrity sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q== - dependencies: - spdx-exceptions "^2.1.0" - spdx-license-ids "^3.0.0" - -spdx-license-ids@^3.0.0: - version "3.0.12" - resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.12.tgz#69077835abe2710b65f03969898b6637b505a779" - integrity sha512-rr+VVSXtRhO4OHbXUiAF7xW3Bo9DuuF6C5jH+q/x15j2jniycgKbxU09Hr0WqlSLUs4i4ltHGXqTe7VHclYWyA== - split-on-first@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f" @@ -16191,11 +16132,6 @@ type-fest@^0.21.3: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.21.3.tgz#d260a24b0198436e133fa26a524a6d65fa3b2e37" integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== -type-fest@^0.6.0: - version "0.6.0" - resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" - integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== - type-fest@^0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.7.1.tgz#8dda65feaf03ed78f0a3f9678f1869147f7c5c48" @@ -16604,14 +16540,6 @@ v8-to-istanbul@^9.0.1: "@types/istanbul-lib-coverage" "^2.0.1" convert-source-map "^1.6.0" -validate-npm-package-license@^3.0.1: - version "3.0.4" - resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a" - integrity sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew== - dependencies: - spdx-correct "^3.0.0" - spdx-expression-parse "^3.0.0" - value-or-function@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/value-or-function/-/value-or-function-3.0.0.tgz#1c243a50b595c1be54a754bfece8563b9ff8d813"