Skip to content

Commit 0e866da

Browse files
committed
Use /job/status to update backup status correctly
1 parent 2753de3 commit 0e866da

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

app/src/components/NavBar/Points.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,35 @@ const Points: React.FC = () => {
7575
}, []),
7676
);
7777

78-
//TODO - uncomment after merging - https://github.com/selfxyz/self/pull/1363/
79-
// useEffect(() => {
80-
// const backupEvent = usePointEventStore
81-
// .getState()
82-
// .events.find(
83-
// event => event.type === 'backup' && event.status === 'completed',
84-
// );
78+
const getBackupState = usePointEventStore(state => {
79+
const backups = state.events.filter(e => e.type === 'backup');
80+
console.log('backups', backups);
81+
const isPending = backups.some(e => e.status === 'pending');
82+
const isCompleted = backups.some(e => e.status === 'completed');
83+
return {
84+
pending: isPending,
85+
completed: isCompleted,
86+
started: isPending || isCompleted,
87+
};
88+
});
8589

86-
// if (backupEvent && !hasCompletedBackupForPoints) {
87-
// setBackupForPointsCompleted();
88-
// }
89-
// }, [setBackupForPointsCompleted, hasCompletedBackupForPoints]);
90+
//we show the backup success message immediately. This flips the flag to false undo the action
91+
//and to show the backup button again.
92+
//Another way is to show success modal here, but this ccan be delayed (as polling can be upto 32 seconds)
93+
useEffect(() => {
94+
if (
95+
!getBackupState.pending &&
96+
!getBackupState.completed &&
97+
hasCompletedBackupForPoints
98+
) {
99+
setBackupForPointsCompleted(false);
100+
}
101+
}, [
102+
getBackupState.completed,
103+
getBackupState.pending,
104+
hasCompletedBackupForPoints,
105+
setBackupForPointsCompleted,
106+
]);
90107

91108
// Track if we should check for backup completion on next focus
92109
const shouldCheckBackupRef = React.useRef(false);

app/src/screens/account/settings/CloudBackupScreen.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ const CloudBackupScreen: React.FC<CloudBackupScreenProps> = ({
129129
trackEvent(BackupEvents.CLOUD_BACKUP_ENABLED_DONE);
130130

131131
if (params?.returnToScreen) {
132-
navigation.navigate(params.returnToScreen);
132+
setTimeout(() => {
133+
navigation.navigate(params.returnToScreen);
134+
}, 500);
133135
}
134136
} catch (error) {
135137
console.error('iCloud backup error', error);
@@ -176,7 +178,9 @@ const CloudBackupScreen: React.FC<CloudBackupScreenProps> = ({
176178
setTurnkeyPending(false);
177179

178180
if (params?.returnToScreen) {
179-
navigation.navigate(params.returnToScreen);
181+
setTimeout(() => {
182+
navigation.navigate(params.returnToScreen);
183+
}, 500);
180184
}
181185
} catch (error) {
182186
if (error instanceof Error && error.message === 'already_exists') {
@@ -188,7 +192,9 @@ const CloudBackupScreen: React.FC<CloudBackupScreenProps> = ({
188192
) {
189193
console.log('Already backed up with Turnkey');
190194
if (params?.returnToScreen) {
191-
navigation.navigate(params.returnToScreen);
195+
setTimeout(() => {
196+
navigation.navigate(params.returnToScreen);
197+
}, 500);
192198
} else if (params?.nextScreen) {
193199
navigation.navigate(params.nextScreen);
194200
} else {

app/src/stores/settingStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ export const useSettingStore = create<SettingsState>()(
107107
setTurnkeyBackupEnabled: (turnkeyBackupEnabled: boolean) =>
108108
set({ turnkeyBackupEnabled }),
109109
hasCompletedBackupForPoints: false,
110-
setBackupForPointsCompleted: () =>
111-
set({ hasCompletedBackupForPoints: true }),
110+
setBackupForPointsCompleted: (value: boolean = true) =>
111+
set({ hasCompletedBackupForPoints: value }),
112112
resetBackupForPoints: () => set({ hasCompletedBackupForPoints: false }),
113113
pointsAddress: null,
114114
setPointsAddress: (address: string | null) =>

app/src/utils/points/jobStatus.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ export async function checkEventProcessingStatus(
3333
// 200 means completed or failed - check the response body
3434
if (response.status === 200) {
3535
const data: JobStatusResponse = await response.json();
36-
if (data.status === 'complete') {
36+
if (data.success === true) {
3737
return 'completed';
3838
}
39-
if (data.status === 'failed') {
39+
if (data.success === false) {
40+
if (data.message && data.message === 'Address already verified') {
41+
return 'completed';
42+
}
4043
return 'failed';
4144
}
4245
}

0 commit comments

Comments
 (0)