* Singleton class responsible for managing all the * related notifications, which could be in-app or push * depending on the state of the app
| 83 | * depending on the state of the app |
| 84 | */ |
| 85 | class NotificationManager { |
| 86 | /** |
| 87 | * Navigation object from react-navigation |
| 88 | */ |
| 89 | _navigation; |
| 90 | /** |
| 91 | * Array containing the id of the transaction that should be |
| 92 | * displayed while interacting with a notification |
| 93 | */ |
| 94 | _transactionToView; |
| 95 | /** |
| 96 | * Boolean based on the current state of the app |
| 97 | */ |
| 98 | _backgroundMode; |
| 99 | |
| 100 | /** |
| 101 | * Object containing watched transaction ids list by transaction nonce |
| 102 | */ |
| 103 | _transactionsWatchTable = {}; |
| 104 | |
| 105 | _handleAppStateChange = (appState) => { |
| 106 | this._backgroundMode = appState === 'background'; |
| 107 | }; |
| 108 | |
| 109 | _viewTransaction = (id) => { |
| 110 | this._transactionToView.push(id); |
| 111 | this.goTo('TransactionsHome'); |
| 112 | }; |
| 113 | |
| 114 | _removeListeners = (transactionId) => { |
| 115 | const { TransactionController } = Engine.context; |
| 116 | TransactionController.hub.removeAllListeners(`${transactionId}:confirmed`); |
| 117 | TransactionController.hub.removeAllListeners(`${transactionId}:finished`); |
| 118 | }; |
| 119 | |
| 120 | // TODO: Refactor this method to use notifee's channels in combination with MM auth |
| 121 | _showNotification(data, channelId = 'default') { |
| 122 | if (this._backgroundMode) { |
| 123 | const { title, message } = constructTitleAndMessage(data); |
| 124 | const id = data?.transaction?.id || ''; |
| 125 | if (id) { |
| 126 | this._transactionToView.push(id); |
| 127 | } |
| 128 | |
| 129 | const pushData = { |
| 130 | title, |
| 131 | body: message, |
| 132 | android: { |
| 133 | lightUpScreen: false, |
| 134 | channelId, |
| 135 | smallIcon: 'ic_notification_small', |
| 136 | largeIcon: 'ic_notification', |
| 137 | pressAction: { |
| 138 | id: 'default', |
| 139 | launchActivity: 'com.metamask.ui.MainActivity', |
| 140 | }, |
| 141 | }, |
| 142 | ios: { |
nothing calls this directly
no test coverage detected