mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-07-22 07:48:28 +00:00
102 lines
3.5 KiB
JavaScript
102 lines
3.5 KiB
JavaScript
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 } from './src/models'
|
|
import {
|
|
WalletTask,
|
|
NotificationService,
|
|
SWAP_ALL_TASK,
|
|
SWAP_DENOMINATION_TASK,
|
|
TEST_TASK,
|
|
SYNC_STATE_WITH_ALL_MINTS_TASK,
|
|
} from './src/services'
|
|
import {
|
|
LISTEN_FOR_NWC_EVENTS
|
|
} from './src/models/NwcStore'
|
|
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 starting for task:', notification.data.task)
|
|
|
|
try {
|
|
|
|
// Listen for NWC commands over ws (started by the push handler AFTER it has
|
|
// processed the pushed command directly; this catches any follow-ups that
|
|
// arrive in the window without their own push).
|
|
if(notification.data.task === LISTEN_FOR_NWC_EVENTS) {
|
|
const {nwcStore} = rootStoreInstance
|
|
nwcStore.listenForNwcEvents()
|
|
}
|
|
|
|
if(notification.data.task === SYNC_STATE_WITH_ALL_MINTS_TASK) {
|
|
log.debug(`[registerForegroundService] Submitting task ${SYNC_STATE_WITH_ALL_MINTS_TASK} to the queue.`)
|
|
|
|
await WalletTask.syncStateWithAllMintsQueueAwaitable({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 === SWAP_DENOMINATION_TASK) {
|
|
log.debug(`[registerForegroundService] Submitting task ${SWAP_DENOMINATION_TASK} to the queue.`)
|
|
|
|
const payload = notification.data.data || {}
|
|
WalletTask.swapByDenominationQueue(payload.denomination, payload.mintUrl)
|
|
}
|
|
|
|
|
|
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.onForegroundEvent(async ({ type, detail }) => {
|
|
//log.trace('[onForegroundEvent]', {type, detail})
|
|
|
|
if (detail.pressAction && detail.pressAction.id === 'stop') {
|
|
log.trace('[onForegroundEvent] Stopping foreground service')
|
|
// Route through closeNwcListener (not raw stopForegroundService) so pressing
|
|
// Stop also tears down the adaptive poll and releases any in-flight NWC
|
|
// pay_invoice immediately. It's a superset of stopping the service, and is
|
|
// harmless for non-NWC task foreground services (which share the one service).
|
|
await NotificationService.closeNwcListener()
|
|
}
|
|
})
|
|
|
|
notifee.onBackgroundEvent(async ({ type, detail }) => {
|
|
return true
|
|
})
|
|
|
|
globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true
|
|
messaging().onMessage(NotificationService.onForegroundNotification)
|
|
messaging().setBackgroundMessageHandler(NotificationService.onBackgroundNotification)
|
|
NotificationService.initNotifications()
|
|
|
|
AppRegistry.registerComponent(appName, () => BootstrapApp)
|