Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
feat(SyncOnboarding): handle disconnected device
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandremgo committed May 13, 2022
1 parent 917e6dd commit 939e7c2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/screens/SyncOnboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const initialOnboardingState: OnboardingState = {
currentSeedWordIndex: 0,
};

const pollingFrequencyMs = 1000;

type Props = StackScreenProps<
SyncOnboardingStackParamList,
"SyncOnboardingWelcome"
Expand Down Expand Up @@ -88,7 +90,7 @@ export const SyncOnboarding = ({ navigation, route }: Props): ReactElement => {
`SyncOnboarding: 🧑‍💻 new device: ${JSON.stringify(device)}`,
);

onboardingStatePollingSubscription = timer(0, 1000)
onboardingStatePollingSubscription = timer(0, pollingFrequencyMs)
.pipe(
tap(i => {
console.log(`SyncOnboarding: ▶️ Polling ${i}`);
Expand All @@ -99,6 +101,7 @@ export const SyncOnboarding = ({ navigation, route }: Props): ReactElement => {
retryWhen(errors =>
errors.pipe(
mergeMap(error => {
// Transport error: retry polling
if (
error &&
error instanceof TransportStatusError &&
Expand All @@ -110,6 +113,20 @@ export const SyncOnboarding = ({ navigation, route }: Props): ReactElement => {
);
return of(error);
}
// Disconnection error: retry polling
if (
error &&
error instanceof Error &&
error.name === "DisconnectedDevice"
) {
console.log(
`SyncOnboarding: disconnection error 🔌 ${JSON.stringify(
error,
)}`,
);
return of(error);
}

console.log(
`SyncOnboarding: 💥 Error ${error} -> ${JSON.stringify(
error,
Expand All @@ -118,7 +135,7 @@ export const SyncOnboarding = ({ navigation, route }: Props): ReactElement => {
return throwError(error);
}),
tap(() => console.log("Going to retry in 🕐️ ...")),
delayWhen(() => timer(2000)),
delayWhen(() => timer(pollingFrequencyMs)),
tap(() => console.log("Retrying 🏃️ !")),
),
),
Expand Down

0 comments on commit 939e7c2

Please sign in to comment.