-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
81 lines (62 loc) · 2.61 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'react-native-reanimated' // needed for qrcode reader
import { install } from 'react-native-quick-crypto' // needed for secp256k1, conf in babel.config
install()
import 'react-native-url-polyfill/auto' // URL.host etc
import 'text-encoding-polyfill' // cashu-ts
import 'message-port-polyfill' // nostr-tools
import notifee from '@notifee/react-native'
import messaging from '@react-native-firebase/messaging'
import {AppRegistry} from 'react-native'
import { rootStoreInstance, setupRootStore } from './src/models'
import {
WalletTask,
NotificationService,
SWAP_ALL_TASK,
TEST_TASK,
SYNC_STATE_WITH_ALL_MINTS_TASK,
HANDLE_NWC_REQUEST_TASK
} from './src/services'
import { log } from './src/services/logService'
import App from './src/App'
import {name as appName} from './app.json'
function BootstrapApp() {
return <App appName={appName} />
}
// long running tasks
notifee.registerForegroundService(async (notification) => {
return new Promise(async (resolve) => {
log.trace('[registerForegroundService] Foreground service running for task:', notification)
try {
if(notification.data.task === HANDLE_NWC_REQUEST_TASK) {
log.debug(`[registerForegroundService] Submitting task ${HANDLE_NWC_REQUEST_TASK} to the queue.`)
const {nwcStore} = rootStoreInstance
// if an app is in killed state, state is not loaded
if(nwcStore.all.length === 0) {
await setupRootStore(rootStoreInstance)
}
WalletTask.handleNwcRequestQueue({requestEvent: notification.data.data})
}
if(notification.data.task === SYNC_STATE_WITH_ALL_MINTS_TASK) {
log.debug(`[registerForegroundService] Submitting task ${SYNC_STATE_WITH_ALL_MINTS_TASK} to the queue.`)
WalletTask.syncStateWithAllMintsQueue({isPending: false})
}
if(notification.data.task === SWAP_ALL_TASK) {
log.debug(`[registerForegroundService] Submitting task ${SWAP_ALL_TASK} to the queue.`)
WalletTask.swapAllQueue()
}
if(notification.data.task === TEST_TASK) {
log.debug(`[registerForegroundService] Submitting task ${TEST_TASK} to the queue.`)
WalletTask.testQueue()
}
} catch(e) {
log.error('[registerForegroundService]', e.message)
}
})
})
notifee.onBackgroundEvent(async ({ type, detail }) => {
return true
})
// Setup notification listeners and handlers
messaging().onMessage(NotificationService.onForegroundNotification)
messaging().setBackgroundMessageHandler(NotificationService.onBackgroundNotification)
AppRegistry.registerComponent(appName, () => BootstrapApp)