-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ca0641
commit f06725d
Showing
16 changed files
with
234 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
apps/wallet-mobile/src/features/Notifications/useCases/common/notification-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 21 additions & 6 deletions
27
apps/wallet-mobile/src/features/Notifications/useCases/common/notifications.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,33 @@ | ||
import {Notification, Notifications} from '@jamsinclair/react-native-notifications' | ||
import {Notifications as NotificationTypes} from '@yoroi/types' | ||
|
||
export const generateNotificationId = (): number => { | ||
return generateRandomInteger(0, Number.MAX_SAFE_INTEGER) | ||
} | ||
|
||
export const parseNotificationId = (id: string): number => { | ||
return parseInt(id, 10) | ||
} | ||
|
||
const generateRandomInteger = (min: number, max: number): number => { | ||
return Math.floor(Math.random() * (max - min + 1)) + min | ||
} | ||
|
||
export const displayNotificationEvent = (notificationEvent: NotificationTypes.Event) => { | ||
if (notificationEvent.trigger === NotificationTypes.Trigger.TransactionReceived) { | ||
console.log('Transaction received', notificationEvent.metadata) | ||
sendNotification('Transaction received', 'You have received a new transaction') | ||
sendNotification({ | ||
title: 'Transaction received', | ||
body: 'You have received a new transaction', | ||
id: notificationEvent.id, | ||
}) | ||
} | ||
} | ||
|
||
const sendNotification = (title: string, body: string) => { | ||
const sendNotification = (options: {title: string; body: string; id: number}) => { | ||
const notification = new Notification({ | ||
title, | ||
body, | ||
title: options.title, | ||
body: options.body, | ||
sound: 'default', | ||
}) | ||
Notifications.postLocalNotification(notification.payload) | ||
Notifications.postLocalNotification(notification.payload, options.id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.