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: opt-in modal render time #424

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
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/components/AskForPushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ export default function AskForPushNotification(props) {
dispatch(pushDismissOptInQuestion());
};

if (!showOptIn) {
return null;
}
return (
const putDismissOptInQuestion = () => {
dispatch(pushDismissOptInQuestion());
};

const pushNotificationOptInModal = () => (
<ActionModal
title={t`Do you want to enable push notifications for this wallet?`}
text={t`You can always change this later in the settings menu`}
button={t`Yes, enable`}
onAction={() => onEnablePushNotifications()}
onDismiss={() => dispatch(pushDismissOptInQuestion())}
onAction={onEnablePushNotifications}
onDismiss={putDismissOptInQuestion}
/>
);

if (showOptIn) {
return pushNotificationOptInModal();
}

return null;
}
28 changes: 22 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,
spawn,
delay,
} from 'redux-saga/effects';
import messaging from '@react-native-firebase/messaging';
Expand Down Expand Up @@ -315,12 +316,27 @@ export function* init() {
}
}

// If the user has not been asked yet, we should ask him if he wants to enable push notifications
// We should appear only once, so we should save the fact that the user has dismissed the question
const optInDismissed = STORE.getItem(pushNotificationKey.optInDismissed);
if (optInDismissed === null || !optInDismissed) {
yield put(pushAskOptInQuestion());
}
// Gives users the option to opt-in the Push Notification
// after its initialization, but only opens the opt-in
// modal after wallet become ready.
// Spwan creates a detached thread from this current thread.
yield spawn(function* handleOptIn() {
const { ready } = yield race({
ready: take(types.WALLET_STATE_READY),
// Do nothing with error, only terminates the thread.
error: take(types.WALLET_STATE_ERROR),
});

if (ready) {
// Ask user for push notification opt-in if it has not
// been asked previously. It appears only once because
// we persist the dismiss action on store.
const optInDismissed = STORE.getItem(pushNotificationKey.optInDismissed);
if (optInDismissed === null || !optInDismissed) {
yield put(pushAskOptInQuestion());
}
}
});
}

/**
Expand Down
Loading