From da2b2a51e89e8d917c63b6af0a1459a68af81960 Mon Sep 17 00:00:00 2001
From: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
Date: Fri, 1 Dec 2023 12:29:54 +0530
Subject: [PATCH 1/5] initial support for firebase notifications
Signed-off-by: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
---
android/app/build.gradle | 2 +
android/app/src/main/AndroidManifest.xml | 35 ++++++++
android/build.gradle | 3 +-
index.js | 15 ++--
package.json | 4 +-
src/App.tsx | 18 ++++
src/utils/push-notification.ts | 106 ++++++++++++++++++++++-
yarn.lock | 73 +++++++++++++++-
8 files changed, 242 insertions(+), 14 deletions(-)
diff --git a/android/app/build.gradle b/android/app/build.gradle
index c96bb5dcd..99cf7fc48 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -1,5 +1,6 @@
apply plugin: "com.android.application"
apply plugin: "com.facebook.react"
+apply plugin: "com.google.gms.google-services"
// Blixt:
apply plugin: "com.google.protobuf"
@@ -185,6 +186,7 @@ android {
}
dependencies {
+ implementation platform('com.google.firebase:firebase-bom:32.6.0')
// The version of react-native is set by the React Native Gradle Plugin
implementation("com.facebook.react:react-android")
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 86d8457e9..43f1deb62 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -7,7 +7,10 @@
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode" />
+
+
+
@@ -19,6 +22,10 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/build.gradle b/android/build.gradle
index cd8d4e461..ed6f34b82 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -26,8 +26,7 @@ buildscript {
// Needed for react-native-camera-kit
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("com.google.protobuf:protobuf-gradle-plugin:0.9.3")// 0.8.12")
- // classpath "com.google.gms:google-services:4.3.10" // TODO(hsjoberg): Needed?
-
+ classpath ("com.google.gms:google-services:4.4.0")
}
}
diff --git a/index.js b/index.js
index ab41e3153..a011d4424 100644
--- a/index.js
+++ b/index.js
@@ -1,14 +1,15 @@
import "react-native-gesture-handler";
import React from "react";
import ReactNative, { AppRegistry, LogBox, Platform, UIManager, Text } from "react-native";
+import "@react-native-firebase/messaging";
+import messaging from "@react-native-firebase/messaging";
import App from "./src/App";
-import {name as appName} from "./app.json";
+import { name as appName } from "./app.json";
import Long from "long";
import protobuf from "protobufjs";
import { enableES5 } from "immer";
import "./src/i18n/i18n";
-
protobuf.util.Long = Long;
protobuf.configure();
enableES5();
@@ -29,11 +30,13 @@ LogBox.ignoreLogs([
"i18next::pluralResolver: Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.",
]);
-if (
- Platform.OS === "android" &&
- UIManager.setLayoutAnimationEnabledExperimental
-) {
+if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
+// Register background handler
+messaging().setBackgroundMessageHandler(async (remoteMessage) => {
+ console.log("Message handled in the background!", remoteMessage);
+});
+
AppRegistry.registerComponent(appName, () => App);
diff --git a/package.json b/package.json
index 9dfd927e1..7696c879b 100644
--- a/package.json
+++ b/package.json
@@ -62,6 +62,8 @@
"@react-native-community/netinfo": "^9.4.1",
"@react-native-community/push-notification-ios": "^1.11.0",
"@react-native-community/slider": "^4.4.2",
+ "@react-native-firebase/app": "^18.7.1",
+ "@react-native-firebase/messaging": "^18.7.1",
"@react-native-google-signin/google-signin": "^10.1.1",
"@react-navigation/bottom-tabs": "^6.5.8",
"@react-navigation/drawer": "7.0.0-alpha.5",
@@ -125,7 +127,7 @@
"react-native-modal": "^13.0.1",
"react-native-paper": "^5.11.1",
"react-native-permissions": "^3.10.1",
- "react-native-push-notification": "8.1.1",
+ "react-native-push-notification": "^8.1.1",
"react-native-qrcode-svg": "^6.2.0",
"react-native-reanimated": "3.5.4",
"react-native-safe-area-context": "^4.7.4",
diff --git a/src/App.tsx b/src/App.tsx
index c17e195da..e039b2062 100755
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -14,10 +14,28 @@ import store from "./state/store";
import { clearApp } from "./storage/app";
import { PLATFORM } from "./utils/constants";
import "./i18n/i18n";
+import {
+ getFcmToken,
+ notificationListener,
+ requestUserPermission,
+} from "./utils/push-notification";
export default function App() {
const [debug, setDebug] = useState(__DEV__ ? true : false);
+ useEffect(() => {
+ const fetchToken = async () => {
+ const token = await getFcmToken();
+ if (token) {
+ console.log("Your Firebase Token is:", token);
+ }
+ };
+
+ fetchToken();
+ requestUserPermission();
+ notificationListener();
+ }, []);
+
useEffect(() => {
(async () => {
if (PLATFORM === "web") {
diff --git a/src/utils/push-notification.ts b/src/utils/push-notification.ts
index a3bb45651..0145e5819 100644
--- a/src/utils/push-notification.ts
+++ b/src/utils/push-notification.ts
@@ -1,7 +1,13 @@
import PushNotification, { PushNotificationObject } from "react-native-push-notification";
+import PushNotificationIOS from "@react-native-community/push-notification-ios";
import { ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID } from "./constants";
+import firebase from "@react-native-firebase/app";
+import { Alert } from "./alert";
-export const localNotification = (message: string, importance: PushNotificationObject["importance"] = "default"): void => {
+export const localNotification = (
+ message: string,
+ importance: PushNotificationObject["importance"] = "default",
+): void => {
PushNotification.localNotification({
channelId: ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID,
message,
@@ -12,3 +18,101 @@ export const localNotification = (message: string, importance: PushNotificationO
autoCancel: true,
});
};
+
+// Must be outside of any component LifeCycle (such as `componentDidMount`).
+PushNotification.configure({
+ // (optional) Called when Token is generated (iOS and Android)
+ onRegister: function (token) {
+ console.log("TOKEN:", token);
+ },
+
+ // (required) Called when a remote is received or opened, or local notification is opened
+ onNotification: function (notification) {
+ console.log("NOTIFICATION:", notification);
+
+ // process the notification
+
+ // (required) Called when a remote is received or opened, or local notification is opened
+ notification.finish(PushNotificationIOS.FetchResult.NoData);
+ },
+
+ // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
+ onAction: function (notification) {
+ console.log("ACTION:", notification.action);
+ console.log("NOTIFICATION:", notification);
+
+ // process the action
+ },
+
+ // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
+ onRegistrationError: function (err) {
+ console.error(err.message, err);
+ },
+
+ // IOS ONLY (optional): default: all - Permissions to register.
+ permissions: {
+ alert: true,
+ badge: true,
+ sound: true,
+ },
+
+ // Should the initial notification be popped automatically
+ // default: true
+ popInitialNotification: true,
+
+ /**
+ * (optional) default: true
+ * - Specified if permissions (ios) and token (android and ios) will requested or not,
+ * - if not, you must call PushNotificationsHandler.requestPermissions() later
+ * - if you are not using remote notification or do not have Firebase installed, use this:
+ * requestPermissions: Platform.OS === 'ios'
+ */
+ requestPermissions: true,
+});
+
+export const notificationListener = () => {
+ firebase.messaging().onNotificationOpenedApp((remoteMessage) => {
+ console.log(
+ "Notification caused app to open from background state:",
+ remoteMessage.notification,
+ );
+ });
+
+ // Quiet and Background State -> Check whether an initial notification is available
+ firebase
+ .messaging()
+ .getInitialNotification()
+ .then((remoteMessage) => {
+ if (remoteMessage) {
+ console.log("Notification caused app to open from quit state:", remoteMessage.notification);
+ }
+ })
+ .catch((error) => console.log("failed", error));
+
+ // Foreground State
+ firebase.messaging().onMessage(async (remoteMessage) => {
+ Alert.alert("A new FCM message arrived!", JSON.stringify(remoteMessage));
+ console.log("foreground", remoteMessage);
+ });
+};
+
+export const getFcmToken = async () => {
+ try {
+ const newFcmToken = await firebase.messaging().getToken();
+ return newFcmToken;
+ } catch (error) {
+ console.error("error fetching firebase token", error);
+ return null;
+ }
+};
+
+export const requestUserPermission = async () => {
+ const authStatus = await firebase.messaging().requestPermission();
+ const enabled =
+ authStatus === firebase.messaging.AuthorizationStatus.AUTHORIZED ||
+ authStatus === firebase.messaging.AuthorizationStatus.PROVISIONAL;
+
+ if (enabled) {
+ console.log("Authorization status:", authStatus);
+ }
+};
diff --git a/yarn.lock b/yarn.lock
index 34df1188b..f22ace364 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3017,6 +3017,19 @@
resolved "https://registry.yarnpkg.com/@react-native-community/slider/-/slider-4.4.3.tgz#9b9dc639b88f5bfda72bd72a9dff55cbf9f777ed"
integrity sha512-WdjvGtqJfqcCiLwtbzie53Z/H6w6dIfRHhlW832D89ySAdE5DxLAsqRhDOG0eacuAxxEB+T9sGCkVMD0fa3aBg==
+"@react-native-firebase/app@^18.7.1":
+ version "18.7.1"
+ resolved "https://registry.yarnpkg.com/@react-native-firebase/app/-/app-18.7.1.tgz#89fea18713a0fec9e2a0190a4be6b6c54208a73e"
+ integrity sha512-OcWfOUl47pIXcmD5lDn+b1hJktiU7DawXTqjxzDLfWpPzSQUys4OH9kV2ZEnFNKMuvgPELNtzq/H9+Bylc4PGA==
+ dependencies:
+ opencollective-postinstall "^2.0.3"
+ superstruct "^0.6.2"
+
+"@react-native-firebase/messaging@^18.7.1":
+ version "18.7.1"
+ resolved "https://registry.yarnpkg.com/@react-native-firebase/messaging/-/messaging-18.7.1.tgz#0b5885a40711ad21ae8e1c28c583fa0df0cb1d27"
+ integrity sha512-66aBHF9gmuvYpZwb/jviTRo1t845+Ib7D8xMxNnRKh+aHzTN1eHnjY7M0E4lkG9gpw00t7bP+U05riOAveL1dw==
+
"@react-native-google-signin/google-signin@^10.1.1":
version "10.1.1"
resolved "https://registry.yarnpkg.com/@react-native-google-signin/google-signin/-/google-signin-10.1.1.tgz#1306aac8c32cb5deb994a1bfb05bed8172defed1"
@@ -5430,6 +5443,16 @@ cliui@^8.0.1:
strip-ansi "^6.0.1"
wrap-ansi "^7.0.0"
+clone-deep@^2.0.1:
+ version "2.0.2"
+ resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-2.0.2.tgz#00db3a1e173656730d1188c3d6aced6d7ea97713"
+ integrity sha512-SZegPTKjCgpQH63E+eN6mVEEPdQBOUzjyJm5Pora4lrwWRFS8I0QAxV/KD6vV/i0WuijHZWQC1fMsPEdxfdVCQ==
+ dependencies:
+ for-own "^1.0.0"
+ is-plain-object "^2.0.4"
+ kind-of "^6.0.0"
+ shallow-clone "^1.0.0"
+
clone-deep@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/clone-deep/-/clone-deep-4.0.1.tgz#c19fd9bdbbf85942b4fd979c84dcf7d5f07c2387"
@@ -7330,11 +7353,23 @@ for-each@^0.3.3:
dependencies:
is-callable "^1.1.3"
-for-in@^1.0.2:
+for-in@^0.1.3:
+ version "0.1.8"
+ resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"
+ integrity sha512-F0to7vbBSHP8E3l6dCjxNOLuSFAACIxFy3UehTUlG7svlXi37HHsDkyVcHo0Pq8QwrE+pXvWSVX3ZT1T9wAZ9g==
+
+for-in@^1.0.1, for-in@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
integrity sha512-7EwmXrOjyL+ChxMhmG5lnW9MPt1aIeZEwKhQzoBUdTV0N3zuwWDZYVJatDvZ2OyzPUvdIAZDsCetk3coyMfcnQ==
+for-own@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/for-own/-/for-own-1.0.0.tgz#c63332f415cedc4b04dbfe70cf836494c53cb44b"
+ integrity sha512-0OABksIGrxKK8K4kynWkQ7y1zounQxP+CWnyclVwj81KW3vlLlGUx57DKGcP/LH216GzqnstnPocF16Nxs0Ycg==
+ dependencies:
+ for-in "^1.0.1"
+
forwarded@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
@@ -9346,7 +9381,12 @@ kind-of@^4.0.0:
dependencies:
is-buffer "^1.1.5"
-kind-of@^6.0.2:
+kind-of@^5.0.0:
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d"
+ integrity sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw==
+
+kind-of@^6.0.0, kind-of@^6.0.1, kind-of@^6.0.2:
version "6.0.3"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==
@@ -10675,6 +10715,14 @@ mixin-deep@^1.2.0:
for-in "^1.0.2"
is-extendable "^1.0.1"
+mixin-object@^2.0.1:
+ version "2.0.1"
+ resolved "https://registry.yarnpkg.com/mixin-object/-/mixin-object-2.0.1.tgz#4fb949441dab182540f1fe035ba60e1947a5e57e"
+ integrity sha512-ALGF1Jt9ouehcaXaHhn6t1yGWRqGaHkPFndtFVHfZXOvkIZ/yoGaSi0AHVTafb3ZBGg4dr/bDwnaEKqCXzchMA==
+ dependencies:
+ for-in "^0.1.3"
+ is-extendable "^0.1.1"
+
mkdirp@^0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6"
@@ -11159,7 +11207,7 @@ open@^8.0.9:
is-docker "^2.1.1"
is-wsl "^2.2.0"
-opencollective-postinstall@^2.0.2:
+opencollective-postinstall@^2.0.2, opencollective-postinstall@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==
@@ -12145,7 +12193,7 @@ react-native-permissions@^3.10.1:
resolved "https://registry.yarnpkg.com/react-native-permissions/-/react-native-permissions-3.10.1.tgz#cb0171c8d12113869deaabbdfb979aad1a44752b"
integrity sha512-Gc5BxxpjZn4QNUDiVeHOO0vXh3AH7ToolmwTJozqC6DsxV7NAf3ttap+8BSmzDR8WxuAM3Cror+YNiBhHJx7/w==
-react-native-push-notification@8.1.1:
+react-native-push-notification@^8.1.1:
version "8.1.1"
resolved "https://registry.yarnpkg.com/react-native-push-notification/-/react-native-push-notification-8.1.1.tgz#a41d20c70ea5a7709417e96261b225461f8dc73a"
integrity sha512-XpBtG/w+a6WXTxu6l1dNYyTiHnbgnvjoc3KxPTxYkaIABRmvuJZkFxqruyGvfCw7ELAlZEAJO+dthdTabCe1XA==
@@ -13159,6 +13207,15 @@ sha.js@^2.4.0, sha.js@^2.4.11, sha.js@^2.4.8:
inherits "^2.0.1"
safe-buffer "^5.0.1"
+shallow-clone@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-1.0.0.tgz#4480cd06e882ef68b2ad88a3ea54832e2c48b571"
+ integrity sha512-oeXreoKR/SyNJtRJMAKPDSvd28OqEwG4eR/xc856cRGBII7gX9lvAqDxusPm0846z/w/hWYjI1NpKwJ00NHzRA==
+ dependencies:
+ is-extendable "^0.1.1"
+ kind-of "^5.0.0"
+ mixin-object "^2.0.1"
+
shallow-clone@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/shallow-clone/-/shallow-clone-3.0.1.tgz#8f2981ad92531f55035b01fb230769a40e02efa3"
@@ -13704,6 +13761,14 @@ sumchecker@^3.0.1:
dependencies:
debug "^4.1.0"
+superstruct@^0.6.2:
+ version "0.6.2"
+ resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-0.6.2.tgz#c5eb034806a17ff98d036674169ef85e4c7f6a1c"
+ integrity sha512-lvA97MFAJng3rfjcafT/zGTSWm6Tbpk++DP6It4Qg7oNaeM+2tdJMuVgGje21/bIpBEs6iQql1PJH6dKTjl4Ig==
+ dependencies:
+ clone-deep "^2.0.1"
+ kind-of "^6.0.1"
+
supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
From 92fc5aefced688d740e66a576a0b80fc8be75436 Mon Sep 17 00:00:00 2001
From: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
Date: Fri, 1 Dec 2023 17:44:06 +0530
Subject: [PATCH 2/5] clean up code and add google services file
Signed-off-by: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
---
.../app/src/chainregtest/google-services.json | 207 ++++++++++++------
.../src/chainregtest/google-services.json.bak | 78 +++++++
src/utils/push-notification.ts | 54 +----
3 files changed, 219 insertions(+), 120 deletions(-)
create mode 100644 android/app/src/chainregtest/google-services.json.bak
diff --git a/android/app/src/chainregtest/google-services.json b/android/app/src/chainregtest/google-services.json
index 7f881c5c8..92d161e41 100644
--- a/android/app/src/chainregtest/google-services.json
+++ b/android/app/src/chainregtest/google-services.json
@@ -1,78 +1,151 @@
{
"project_info": {
- "project_number": "123456789",
- "firebase_url": "https://phonyblixt.firebaseio.com",
- "project_id": "phony-blixt-wallet",
- "storage_bucket": "phony-blixt-wallet.appspot.com"
+ "project_number": "349959255310",
+ "firebase_url": "https://blixt-wallet.firebaseio.com",
+ "project_id": "blixt-wallet",
+ "storage_bucket": "blixt-wallet.appspot.com"
},
- "client": [{
- "client_info": {
- "mobilesdk_app_id": "1:123465798:android:123465798123",
- "android_client_info": {
- "package_name": "com.blixtwallet.regtest.debug"
+ "client": [
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:349959255310:android:674d8ca658d8468d59d35f",
+ "android_client_info": {
+ "package_name": "com.blixtwallet"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "349959255310-oa9ogtk6vp969jmbeg1hdodt3cp78a9g.apps.googleusercontent.com",
+ "client_type": 1,
+ "android_info": {
+ "package_name": "com.blixtwallet",
+ "certificate_hash": "b8c178ee58a694507442dbe627f5343addb4c5bb"
+ }
+ },
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyCYJ3myPlN9bsL7PRs6_VrWIqEZAQLE8D4"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
}
},
- "api_key": [{
- "current_key": "abcde123465789"
- }]
- },
- {
- "client_info": {
- "mobilesdk_app_id": "1:123465798:android:123465798123",
- "android_client_info": {
- "package_name": "com.blixtwallet.regtest"
- }
- },
- "api_key": [{
- "current_key": "abcde123465789"
- }]
- },
-
-
- {
- "client_info": {
- "mobilesdk_app_id": "1:123465798:android:123465798123",
- "android_client_info": {
- "package_name": "com.blixtwallet.regtest.experiment1"
- }
- },
- "api_key": [{
- "current_key": "abcde123465789"
- }]
- },
- {
- "client_info": {
- "mobilesdk_app_id": "1:123465798:android:123465798123",
- "android_client_info": {
- "package_name": "com.blixtwallet.regtest.experiment1.debug"
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:349959255310:android:85ac1e39762a39fb59d35f",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.debug"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "349959255310-5nm9kipu9dmap1374fkv3mk4adumbabm.apps.googleusercontent.com",
+ "client_type": 1,
+ "android_info": {
+ "package_name": "com.blixtwallet.debug",
+ "certificate_hash": "076a963bc0168507ca72117b5a9513fe814b6e9d"
+ }
+ },
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyCYJ3myPlN9bsL7PRs6_VrWIqEZAQLE8D4"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
}
},
- "api_key": [{
- "current_key": "abcde123465789"
- }]
- },
- {
- "client_info": {
- "mobilesdk_app_id": "1:123465798:android:123465798123",
- "android_client_info": {
- "package_name": "com.blixtwallet.regtest.fakelnd.debug"
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:349959255310:android:c703af800eb9dff159d35f",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest.debug"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyCYJ3myPlN9bsL7PRs6_VrWIqEZAQLE8D4"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
}
},
- "api_key": [{
- "current_key": "abcde123465789"
- }]
- },
- {
- "client_info": {
- "mobilesdk_app_id": "1:123465798:android:123465798123",
- "android_client_info": {
- "package_name": "com.blixtwallet.regtest.fakelnd"
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:349959255310:android:b3b30a7ca155ace959d35f",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.restore.debug"
+ }
+ },
+ "oauth_client": [
+ {
+ "client_id": "349959255310-m1qakerr8ll92b7nu0vclb3f14qggg7i.apps.googleusercontent.com",
+ "client_type": 1,
+ "android_info": {
+ "package_name": "com.blixtwallet.restore.debug",
+ "certificate_hash": "076a963bc0168507ca72117b5a9513fe814b6e9d"
+ }
+ },
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ],
+ "api_key": [
+ {
+ "current_key": "AIzaSyCYJ3myPlN9bsL7PRs6_VrWIqEZAQLE8D4"
+ }
+ ],
+ "services": {
+ "appinvite_service": {
+ "other_platform_oauth_client": [
+ {
+ "client_id": "349959255310-nlhtlfjlcv4jufk8c659flj8colqm8r4.apps.googleusercontent.com",
+ "client_type": 3
+ }
+ ]
+ }
}
- },
- "api_key": [{
- "current_key": "abcde123465789"
- }]
- }
-],
+ }
+ ],
"configuration_version": "1"
-}
+}
\ No newline at end of file
diff --git a/android/app/src/chainregtest/google-services.json.bak b/android/app/src/chainregtest/google-services.json.bak
new file mode 100644
index 000000000..7f881c5c8
--- /dev/null
+++ b/android/app/src/chainregtest/google-services.json.bak
@@ -0,0 +1,78 @@
+{
+ "project_info": {
+ "project_number": "123456789",
+ "firebase_url": "https://phonyblixt.firebaseio.com",
+ "project_id": "phony-blixt-wallet",
+ "storage_bucket": "phony-blixt-wallet.appspot.com"
+ },
+ "client": [{
+ "client_info": {
+ "mobilesdk_app_id": "1:123465798:android:123465798123",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest.debug"
+ }
+ },
+ "api_key": [{
+ "current_key": "abcde123465789"
+ }]
+ },
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:123465798:android:123465798123",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest"
+ }
+ },
+ "api_key": [{
+ "current_key": "abcde123465789"
+ }]
+ },
+
+
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:123465798:android:123465798123",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest.experiment1"
+ }
+ },
+ "api_key": [{
+ "current_key": "abcde123465789"
+ }]
+ },
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:123465798:android:123465798123",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest.experiment1.debug"
+ }
+ },
+ "api_key": [{
+ "current_key": "abcde123465789"
+ }]
+ },
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:123465798:android:123465798123",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest.fakelnd.debug"
+ }
+ },
+ "api_key": [{
+ "current_key": "abcde123465789"
+ }]
+ },
+ {
+ "client_info": {
+ "mobilesdk_app_id": "1:123465798:android:123465798123",
+ "android_client_info": {
+ "package_name": "com.blixtwallet.regtest.fakelnd"
+ }
+ },
+ "api_key": [{
+ "current_key": "abcde123465789"
+ }]
+ }
+],
+ "configuration_version": "1"
+}
diff --git a/src/utils/push-notification.ts b/src/utils/push-notification.ts
index 0145e5819..4a54733b0 100644
--- a/src/utils/push-notification.ts
+++ b/src/utils/push-notification.ts
@@ -1,5 +1,4 @@
import PushNotification, { PushNotificationObject } from "react-native-push-notification";
-import PushNotificationIOS from "@react-native-community/push-notification-ios";
import { ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID } from "./constants";
import firebase from "@react-native-firebase/app";
import { Alert } from "./alert";
@@ -19,57 +18,6 @@ export const localNotification = (
});
};
-// Must be outside of any component LifeCycle (such as `componentDidMount`).
-PushNotification.configure({
- // (optional) Called when Token is generated (iOS and Android)
- onRegister: function (token) {
- console.log("TOKEN:", token);
- },
-
- // (required) Called when a remote is received or opened, or local notification is opened
- onNotification: function (notification) {
- console.log("NOTIFICATION:", notification);
-
- // process the notification
-
- // (required) Called when a remote is received or opened, or local notification is opened
- notification.finish(PushNotificationIOS.FetchResult.NoData);
- },
-
- // (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
- onAction: function (notification) {
- console.log("ACTION:", notification.action);
- console.log("NOTIFICATION:", notification);
-
- // process the action
- },
-
- // (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
- onRegistrationError: function (err) {
- console.error(err.message, err);
- },
-
- // IOS ONLY (optional): default: all - Permissions to register.
- permissions: {
- alert: true,
- badge: true,
- sound: true,
- },
-
- // Should the initial notification be popped automatically
- // default: true
- popInitialNotification: true,
-
- /**
- * (optional) default: true
- * - Specified if permissions (ios) and token (android and ios) will requested or not,
- * - if not, you must call PushNotificationsHandler.requestPermissions() later
- * - if you are not using remote notification or do not have Firebase installed, use this:
- * requestPermissions: Platform.OS === 'ios'
- */
- requestPermissions: true,
-});
-
export const notificationListener = () => {
firebase.messaging().onNotificationOpenedApp((remoteMessage) => {
console.log(
@@ -87,7 +35,7 @@ export const notificationListener = () => {
console.log("Notification caused app to open from quit state:", remoteMessage.notification);
}
})
- .catch((error) => console.log("failed", error));
+ .catch((error) => console.error("Quiet and background state error: ", error));
// Foreground State
firebase.messaging().onMessage(async (remoteMessage) => {
From 9fcc4ddd2cd20ed546786fb1aab46c8e7edd0547 Mon Sep 17 00:00:00 2001
From: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
Date: Fri, 1 Dec 2023 17:54:40 +0530
Subject: [PATCH 3/5] clean up manifest file
Signed-off-by: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
---
android/app/src/main/AndroidManifest.xml | 27 ------------------------
1 file changed, 27 deletions(-)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 43f1deb62..729d7083f 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -128,32 +128,5 @@
/>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
From f9facbe555ee72e7ccb8f83ec354db9fc6286ea4 Mon Sep 17 00:00:00 2001
From: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
Date: Fri, 1 Dec 2023 22:30:15 +0530
Subject: [PATCH 4/5] move code to notifications manager
Signed-off-by: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
---
src/App.tsx | 18 --------------
src/state/NotificationManager.ts | 40 +++++++++++++++++++-------------
src/storage/app.ts | 3 +++
src/utils/push-notification.ts | 12 +---------
4 files changed, 28 insertions(+), 45 deletions(-)
diff --git a/src/App.tsx b/src/App.tsx
index e039b2062..c17e195da 100755
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -14,28 +14,10 @@ import store from "./state/store";
import { clearApp } from "./storage/app";
import { PLATFORM } from "./utils/constants";
import "./i18n/i18n";
-import {
- getFcmToken,
- notificationListener,
- requestUserPermission,
-} from "./utils/push-notification";
export default function App() {
const [debug, setDebug] = useState(__DEV__ ? true : false);
- useEffect(() => {
- const fetchToken = async () => {
- const token = await getFcmToken();
- if (token) {
- console.log("Your Firebase Token is:", token);
- }
- };
-
- fetchToken();
- requestUserPermission();
- notificationListener();
- }, []);
-
useEffect(() => {
(async () => {
if (PLATFORM === "web") {
diff --git a/src/state/NotificationManager.ts b/src/state/NotificationManager.ts
index fd99a4023..4c2bbe2b2 100644
--- a/src/state/NotificationManager.ts
+++ b/src/state/NotificationManager.ts
@@ -4,8 +4,12 @@ import PushNotification, { PushNotificationObject } from "react-native-push-noti
import { navigate } from "../utils/navigation";
import { IStoreModel } from "./index";
-import { ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID, ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_NAME, PLATFORM } from "../utils/constants";
-import { localNotification } from "../utils/push-notification";
+import {
+ ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID,
+ ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_NAME,
+ PLATFORM,
+} from "../utils/constants";
+import { getFcmToken, localNotification, notificationListener } from "../utils/push-notification";
import { toast } from "../utils";
import logger from "./../utils/log";
@@ -19,8 +23,8 @@ interface ILocalNotificationPayload {
export interface INotificationManagerModel {
initialize: Thunk;
- localNotification: Thunk;
-};
+ localNotification: Thunk;
+}
export const notificationManager: INotificationManagerModel = {
initialize: thunk(async () => {
@@ -35,24 +39,29 @@ export const notificationManager: INotificationManagerModel = {
if (PLATFORM === "ios") {
const permissions = await PushNotification.requestPermissions(["alert", "sound", "badge"]);
- if(!permissions.alert) {
+ if (!permissions.alert) {
log.w("Didn't get permissions to send push notifications.");
return;
}
+
+ await getFcmToken();
+ notificationListener();
} else if (PLATFORM === "android") {
const granted = await PermissionsAndroid.request(
- PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
if (granted === "denied" || granted === "never_ask_again") {
log.w("Post notification permission was denied", [granted]);
} else {
+ await getFcmToken();
+ notificationListener();
return;
}
}
PushNotification.configure({
requestPermissions: false,
- onNotification: ((notification) => {
+ onNotification: (notification) => {
log.i("onNotification", [notification]);
// TODO(hsjoberg): ios notification deeplinking
@@ -60,21 +69,23 @@ export const notificationManager: INotificationManagerModel = {
if (notification.message.toString().includes("on-chain")) {
log.i("Navigating to OnChainTransactionLog");
navigate("OnChain", { screen: "OnChainTransactionLog" });
- }
- else if (notification.message.toString().toLocaleLowerCase().includes("payment channel")) {
+ } else if (
+ notification.message.toString().toLocaleLowerCase().includes("payment channel")
+ ) {
log.i("Navigating to LightningInfo");
navigate("LightningInfo");
}
}
- }),
+ },
});
if (PLATFORM === "android") {
- PushNotification.createChannel({
+ PushNotification.createChannel(
+ {
channelId: ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID,
channelName: ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_NAME,
},
- () => {}
+ () => {},
);
}
} catch (error) {
@@ -90,10 +101,7 @@ export const notificationManager: INotificationManagerModel = {
localNotification: thunk((_, { message, importance }, { getStoreState }) => {
if (getStoreState().settings.pushNotificationsEnabled) {
if (PLATFORM !== "macos") {
- localNotification(
- message,
- importance ?? "default"
- );
+ localNotification(message, importance ?? "default");
} else {
toast(message);
}
diff --git a/src/storage/app.ts b/src/storage/app.ts
index 88d8a0fb8..df05e1e53 100644
--- a/src/storage/app.ts
+++ b/src/storage/app.ts
@@ -89,6 +89,7 @@ export enum StorageItem { // const enums not supported in Babel 7...
lightningBoxServer = "lightningBoxServer",
lightningBoxAddress = "lightningBoxAddress",
lightningBoxLnurlPayDesc = "lightningBoxLnurlPayDesc",
+ firebaseToken = "firebaseToken",
}
export const setItem = async (key: StorageItem, value: string) =>
@@ -192,6 +193,7 @@ export const clearApp = async () => {
removeItem(StorageItem.lightningBoxServer),
removeItem(StorageItem.lightningBoxAddress),
removeItem(StorageItem.lightningBoxLnurlPayDesc),
+ removeItem(StorageItem.firebaseToken),
]);
};
@@ -283,5 +285,6 @@ export const setupApp = async () => {
setItem(StorageItem.lightningBoxServer, DEFAULT_LIGHTNINGBOX_SERVER),
// setItem(StorageItem.lightningBoxAddress, ""),
setItem(StorageItem.lightningBoxLnurlPayDesc, DEFAULT_LIGHTNINGBOX_LNURLPDESC),
+ setItem(StorageItem.firebaseToken, ""),
]);
};
diff --git a/src/utils/push-notification.ts b/src/utils/push-notification.ts
index 4a54733b0..e01321cef 100644
--- a/src/utils/push-notification.ts
+++ b/src/utils/push-notification.ts
@@ -47,20 +47,10 @@ export const notificationListener = () => {
export const getFcmToken = async () => {
try {
const newFcmToken = await firebase.messaging().getToken();
+ console.log("firebase token: ", newFcmToken);
return newFcmToken;
} catch (error) {
console.error("error fetching firebase token", error);
return null;
}
};
-
-export const requestUserPermission = async () => {
- const authStatus = await firebase.messaging().requestPermission();
- const enabled =
- authStatus === firebase.messaging.AuthorizationStatus.AUTHORIZED ||
- authStatus === firebase.messaging.AuthorizationStatus.PROVISIONAL;
-
- if (enabled) {
- console.log("Authorization status:", authStatus);
- }
-};
From cd7967997ee01e276e3a8d7011417b4b95d4c5a5 Mon Sep 17 00:00:00 2001
From: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
Date: Fri, 1 Dec 2023 22:34:10 +0530
Subject: [PATCH 5/5] set firebase token to localstorage
Signed-off-by: Nitesh Balusu <84944042+niteshbalusu11@users.noreply.github.com>
---
src/state/NotificationManager.ts | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/state/NotificationManager.ts b/src/state/NotificationManager.ts
index 4c2bbe2b2..d94bf59eb 100644
--- a/src/state/NotificationManager.ts
+++ b/src/state/NotificationManager.ts
@@ -13,6 +13,7 @@ import { getFcmToken, localNotification, notificationListener } from "../utils/p
import { toast } from "../utils";
import logger from "./../utils/log";
+import { StorageItem, getItem, getItemObject, setItem } from "../storage/app";
const log = logger("NotificationManager");
interface ILocalNotificationPayload {
@@ -44,7 +45,10 @@ export const notificationManager: INotificationManagerModel = {
return;
}
- await getFcmToken();
+ const token = await getFcmToken();
+ if (!!token) {
+ await setItem(StorageItem.firebaseToken, token);
+ }
notificationListener();
} else if (PLATFORM === "android") {
const granted = await PermissionsAndroid.request(
@@ -53,7 +57,10 @@ export const notificationManager: INotificationManagerModel = {
if (granted === "denied" || granted === "never_ask_again") {
log.w("Post notification permission was denied", [granted]);
} else {
- await getFcmToken();
+ const token = await getFcmToken();
+ if (!!token) {
+ await setItem(StorageItem.firebaseToken, token);
+ }
notificationListener();
return;
}