Skip to content

Commit

Permalink
fix: push notification registration latency on PinScreen (#423)
Browse files Browse the repository at this point in the history
* fix: PinScreen dismiss response

* This fix doesn't solve the problem of long latency, however it decreases latency perception for users.

* fix: exits script after dispatch failure effect

* fix: replace BLOCKED to DENIED enum value

* fix: push notification authorization logic

* chore: extract delay from race
  • Loading branch information
alexruzenhack committed May 15, 2024
1 parent f9c8a4e commit cdbe0cd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/sagas/pushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
take,
takeLatest,
debounce,
delay,
} from 'redux-saga/effects';
import messaging from '@react-native-firebase/messaging';
import notifee from '@notifee/react-native';
Expand Down Expand Up @@ -358,6 +359,11 @@ export function* loadWallet() {
const network = new Network(networkSettings.network);

const pin = yield call(showPinScreenForResult, dispatch);

// Delay 300ms to resume script execution in the next loop.
// This solution liberates the PinScreen to dismiss.
yield delay(300);

const seed = yield STORE.getWalletWords(pin);
walletService = new HathorWalletServiceWallet({
seed,
Expand All @@ -372,6 +378,7 @@ export function* loadWallet() {
});
} catch (error) {
yield put(pushLoadWalletFailed({ error }));
return;
}
} else {
walletService = yield select((state) => state.wallet);
Expand All @@ -386,19 +393,19 @@ export function* loadWallet() {
*/
const hasPostNotificationAuthorization = async () => {
let status = await messaging().hasPermission();
if (status === messaging.AuthorizationStatus.BLOCKED) {
if (status === messaging.AuthorizationStatus.DENIED) {
log.debug('Device not authorized to send push notification and blocked to ask permission.');
return false;
}

if (status === messaging.AuthorizationStatus.NOT_DETERMINED) {
log.debug('Device clean. Asking for permission to send push notification.');
if (status === messaging.AuthorizationStatus.NOT_DETERMINED
|| status === messaging.AuthorizationStatus.EPHEMERAL
|| status === messaging.AuthorizationStatus.PROVISIONAL) {
log.debug('Asking for permission to send push notification.');
status = await messaging().requestPermission();
}

log.debug('Device permission status: ', status);
return status === messaging.AuthorizationStatus.AUTHORIZED
|| status === messaging.AuthorizationStatus.PROVISIONAL;
return status === messaging.AuthorizationStatus.AUTHORIZED;
};

/**
Expand Down

0 comments on commit cdbe0cd

Please sign in to comment.