Skip to content

Commit

Permalink
feat: update android not img, find recent mediator
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce McMath <[email protected]>
  • Loading branch information
bryce-mcmath committed Nov 17, 2023
1 parent 355cafe commit c064782
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 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
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.
8 changes: 0 additions & 8 deletions app/ios/AriesBifold/DEVELOPMENT.AriesBifold.entitlements

This file was deleted.

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
}
} else {
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 c064782

Please sign in to comment.