Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const checkNotificationPermissions = () => {
// Check if the user has enabled push notifications
return PushNotification.checkPermissions(permissions => {
if (!permissions.alert) {
setModals([...modals, { type: 'enableNotifications' }])
}
})
}
popInitialNotification: false,
requestPermissions: true,
});
PushNotification.unregister();
PushNotification.localNotification = (details) => {};
PushNotification.localNotificationSchedule = (details) => {};
PushNotification.requestPermissions();
PushNotification.presentLocalNotification = (details) => {};
PushNotification.scheduleLocalNotification = (details) => {};
PushNotification.cancelLocalNotifications = (details) => {};
PushNotification.cancelAllLocalNotifications();
PushNotification.setApplicationIconBadgeNumber(1);
PushNotification.getApplicationIconBadgeNumber((badgeCount) => {});
PushNotification.popInitialNotification((notification) => {});
PushNotification.checkPermissions((checkPermissions) => {});
PushNotification.abandonPermissions();
PushNotification.registerNotificationActions(['Accept', 'Reject', 'Yes', 'No']);
PushNotification.clearAllNotifications();
async register() {
const activeAddress = get(this.props, 'wallet.activeAccount.address')
if (!activeAddress) {
console.debug(
'Could not register with notifications server, no active address'
)
return
}
console.debug(`Adding ${activeAddress} to mobile registry`)
PushNotification.checkPermissions(async permissions => {
const data = {
eth_address: activeAddress,
device_type: this.getNotificationType(),
permissions: permissions
}
if (this.props.settings.deviceToken) {
data['device_token'] = this.props.settings.deviceToken
}
fetch(this.getNotificationServerUrl(), {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${await this.getAuthToken()}`
export const requestNotificationPermissions = () => new Promise((resolve, reject) => {
if (Platform.OS === 'ios') {
PushNotification.checkPermissions(({ alert, badge, sound }) => {
if (!alert || !badge || !sound) {
PushNotification.requestPermissions()
.then((target) => {
if (target.alert || target.badge || target.sound) {
resolve();
} else {
reject();
}
});
} else {
resolve();
}
});
} else {
resolve();
}
new Promise((resolve, reject) => PushNotifications.checkPermissions(resolve))
const monsterStorageKey = 'shownMonsterPushPrompt'
requestPushNotificationsPermission = async () => {
const promptCount = await AsyncStorage.getItem('@MetaMask:pushNotificationsPromptCount');
if (!promptCount || Number(promptCount) < AppConstants.MAX_PUSH_NOTIFICATION_PROMPT_TIMES) {
PushNotification.checkPermissions(permissions => {
if (!permissions || !permissions.alert) {
Alert.alert(
strings('notifications.prompt_title'),
strings('notifications.prompt_desc'),
[
{
text: strings('notifications.prompt_cancel'),
onPress: () => false,
style: 'default'
},
{
text: strings('notifications.prompt_ok'),
onPress: () => PushNotification.requestPermissions()
}
],
{ cancelable: false }
return new Promise((resolve, reject) => PushNotifications.checkPermissions(resolve))
}
checkPermission(cbk) {
return PushNotification.checkPermissions(cbk);
}