Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: push notification registration latency on PinScreen #423

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if you use delay(0)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will test.


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
Loading