Skip to content

Commit

Permalink
feat: enable and configure push notifications (#1594)
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce McMath <[email protected]>
  • Loading branch information
bryce-mcmath authored Nov 17, 2023
1 parent 2ff7a0f commit 7b173be
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 79 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,13 @@ jobs:
IAS_PORTAL_URL: ${{ secrets.IAS_PORTAL_URL }}
IAS_AGENT_INVITE_URL: ${{ secrets.IAS_AGENT_INVITE_URL }}
OCA_URL: ${{ vars.OCA_URL }}
MEDIATOR_USE_PUSH_NOTIFICATIONS: false
run: |
echo "MEDIATOR_URL=${MEDIATOR_URL}" >.env
echo "IAS_PORTAL_URL=${IAS_PORTAL_URL}" >>.env
echo "IAS_AGENT_INVITE_URL=${IAS_AGENT_INVITE_URL}" >>.env
echo "OCA_URL=${OCA_URL}" >>.env
- name: Set Push Notification Capability
working-directory: app/ios/AriesBifold
env:
MEDIATOR_USE_PUSH_NOTIFICATIONS: false
MEDIATOR_LABEL: Mediator
run: |
mv DEVELOPMENT.AriesBifold.entitlements AriesBifold.entitlements
echo "MEDIATOR_USE_PUSH_NOTIFICATIONS=${MEDIATOR_USE_PUSH_NOTIFICATIONS}" >>.env
- name: Archive build
working-directory: app/ios
Expand Down
5 changes: 2 additions & 3 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ In the `./app/` directory copy the .env.sample `cp .env.sample .env`

```
MEDIATOR_URL=<url>
MEDIATOR_USE_PUSH_NOTIFICATIONS=false
MEDIATOR_LABEL=Mediator
```
Push notifications can be used locally on android if the mediator service has the firebase plugin and it's configured correctly.

Push notifications can be used locally if the mediator service has the firebase plugin and it's configured correctly.

### Adding ledger configurations

Expand Down
6 changes: 2 additions & 4 deletions app/.env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
OCA_URL=https://raw.githubusercontent.com/bcgov/aries-oca-bundles/main/
MEDIATOR_URL=https://f326-207-194-65-204.ngrok.io?c_i=eyJAdHlwZSI6ICJodHRwczovL2RpZGNvbW0ub3JnL2Nvbm5lY3Rpb25zLzEuMC9pbnZpdGF0aW9uIiwgIkBpZCI6ICI2MjQ0ZThiNS0wNWYzLTRhYWItYjM1Yy1lYWVlMWNmZTAyM2MiLCAicmVjaXBpZW50S2V5cyI6IFsiQ3lqM1BHRUJzQ3RyUGFtTTQyRngza3BlYmR2QWdNd1lGejlFS3RmNnlUN3giXSwgImxhYmVsIjogIk1lZGlhdG9yIiwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwczovL2YzMjYtMjA3LTE5NC02NS0yMDQubmdyb2suaW8ifQ==

# Push notification variables
MEDIATOR_USE_PUSH_NOTIFICATIONS=false
MEDIATOR_LABEL=Mediator
MEDIATOR_USE_PUSH_NOTIFICATIONS=false
79 changes: 36 additions & 43 deletions app/android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
{
"project_info": {
"project_number": "493003137594",
"project_id": "ca-bc-gov-bcwallet-2d4df",
"storage_bucket": "ca-bc-gov-bcwallet-2d4df.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:493003137594:android:eecbd78be4bc043c890b03",
"android_client_info": {
"package_name": "ca.bc.gov.BCWallet"
}
},
"oauth_client": [
{
"client_id": "493003137594-rgc6pc7cg0nmamc16c5kqs8dpf2gv117.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDIeHtE0Ds_P8LduRhUqDsQqroi-0Ruric"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "493003137594-rgc6pc7cg0nmamc16c5kqs8dpf2gv117.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "493003137594-0cimp1ta4jlq83j63chv1gvi0vgk8sm6.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "ca.bc.gov.BCWallet"
}
}
]
}
"project_info": {
"project_number": "1008044298583",
"project_id": "bc-wallet-mobile",
"storage_bucket": "bc-wallet-mobile.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1008044298583:android:56bf7c25b882152a44ae12",
"android_client_info": {
"package_name": "ca.bc.gov.BCWallet"
}
},
"oauth_client": [
{
"client_id": "1008044298583-12lpkisi403oa5bc5hs0800o48cl4nhj.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyB9TMILh7AQmEGCdwvvmDeN-WG4G345p9I"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1008044298583-12lpkisi403oa5bc5hs0800o48cl4nhj.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
],
"configuration_version": "1"
}
}
],
"configuration_version": "1"
}
21 changes: 21 additions & 0 deletions app/android/app/src/main/java/ca/bc/gov/BCWallet/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,22 @@
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactActivityDelegate;
import androidx.core.app.NotificationManagerCompat;

public class MainActivity extends ReactActivity {

@Override
protected void onStart() {
super.onStart();
removeNotifications();
}

@Override
protected void onRestart() {
super.onRestart();
removeNotifications();
}

/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
Expand All @@ -29,4 +42,12 @@ protected ReactActivityDelegate createReactActivityDelegate() {
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
DefaultNewArchitectureEntryPoint.getFabricEnabled());
}

/**
* Clears notification badges etc. on app open
*/
protected void removeNotifications() {
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.cancelAll();
}
}
Binary file modified app/android/app/src/main/res/drawable/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/ios/AriesBifold/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ - (BOOL)application:(UIApplication *)application
return [RCTLinkingManager application:application openURL:url options:options];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
</plist>
14 changes: 5 additions & 9 deletions app/ios/GoogleService-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>493003137594-0cimp1ta4jlq83j63chv1gvi0vgk8sm6.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.493003137594-0cimp1ta4jlq83j63chv1gvi0vgk8sm6</string>
<key>API_KEY</key>
<string>AIzaSyByvJDrhcSJTy27Qqu9_1SPlt_u7r1bi6o</string>
<string>AIzaSyCL37I5zpWEauPopROBm6d64bGDiimAvZE</string>
<key>GCM_SENDER_ID</key>
<string>493003137594</string>
<string>1008044298583</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>ca.bc.gov.BCWallet</string>
<key>PROJECT_ID</key>
<string>ca-bc-gov-bcwallet-2d4df</string>
<string>bc-wallet-mobile</string>
<key>STORAGE_BUCKET</key>
<string>ca-bc-gov-bcwallet-2d4df.appspot.com</string>
<string>bc-wallet-mobile.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
Expand All @@ -29,6 +25,6 @@
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:493003137594:ios:3ea44407af9632cd890b03</string>
<string>1:1008044298583:ios:76bfc02e8a3c04f844ae12</string>
</dict>
</plist>
35 changes: 26 additions & 9 deletions app/src/helpers/PushNotificationsHelper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Agent, ConnectionRecord } from '@aries-framework/core'
import { Agent, ConnectionRecord, ConnectionType } from '@aries-framework/core'
import AsyncStorage from '@react-native-async-storage/async-storage'
import messaging from '@react-native-firebase/messaging'
import { Platform } from 'react-native'
Expand Down Expand Up @@ -62,14 +62,31 @@ const _requestPermission = async (agent: Agent): Promise<void> => {
*/

const _getMediatorConnection = async (agent: Agent): Promise<ConnectionRecord | undefined> => {
const connections = await agent.connections.getAll()
for (const connection of connections) {
if (connection.theirLabel === Config.MEDIATOR_LABEL) {
return connection
}
const connections: ConnectionRecord[] = await agent.connections.getAll()
const mediators = connections.filter((r) => r.connectionTypes.includes(ConnectionType.Mediator))
if (mediators.length < 1) {
agent.config.logger.warn(`Mediator connection not found`)
return undefined
}
agent.config.logger.warn(`Mediator connection with label [${Config.MEDIATOR_LABEL}] not found`)
return undefined

// get most recent mediator connection
const latestMediator = mediators.reduce((acc, cur) => {
if (!acc.updatedAt) {
if (!cur.updatedAt) {
return acc.createdAt > cur.createdAt ? acc : cur
} else {
return acc.createdAt > cur.updatedAt ? acc : cur
}
}

if (!cur.updatedAt) {
return acc.updatedAt > cur.createdAt ? acc : cur
} else {
return acc.updatedAt > cur.updatedAt ? acc : cur
}
})

return latestMediator
}

/**
Expand All @@ -86,7 +103,7 @@ const isUserDenied = async (): Promise<boolean> => {
* @returns {Promise<boolean>}
*/
const isMediatorCapable = async (agent: Agent): Promise<boolean | undefined> => {
if (!Config.MEDIATOR_LABEL || Config.MEDIATOR_USE_PUSH_NOTIFICATIONS === 'false') {
if (Config.MEDIATOR_USE_PUSH_NOTIFICATIONS !== 'true') {
return false
}

Expand Down

0 comments on commit 7b173be

Please sign in to comment.