Skip to content
Open
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
38 changes: 27 additions & 11 deletions app/src/components/NavBar/Points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,34 @@ const Points: React.FC = () => {
}, []),
);

//TODO - uncomment after merging - https://github.com/selfxyz/self/pull/1363/
// useEffect(() => {
// const backupEvent = usePointEventStore
// .getState()
// .events.find(
// event => event.type === 'backup' && event.status === 'completed',
// );
const getBackupState = usePointEventStore(state => {
const backups = state.events.filter(e => e.type === 'backup');
const isPending = backups.some(e => e.status === 'pending');
const isCompleted = backups.some(e => e.status === 'completed');
return {
pending: isPending,
completed: isCompleted,
started: isPending || isCompleted,
};
});

// if (backupEvent && !hasCompletedBackupForPoints) {
// setBackupForPointsCompleted();
// }
// }, [setBackupForPointsCompleted, hasCompletedBackupForPoints]);
//we show the backup success message immediately. This flips the flag to false undo the action
//and to show the backup button again.
//Another way is to show success modal here, but this ccan be delayed (as polling can be upto 32 seconds)
useEffect(() => {
if (
!getBackupState.pending &&
!getBackupState.completed &&
hasCompletedBackupForPoints
) {
setBackupForPointsCompleted(false);
}
}, [
getBackupState.completed,
getBackupState.pending,
hasCompletedBackupForPoints,
setBackupForPointsCompleted,
]);

// Track if we should check for backup completion on next focus
const shouldCheckBackupRef = React.useRef(false);
Expand Down
6 changes: 3 additions & 3 deletions app/src/stores/settingStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface PersistedSettingsState {
addSubscribedTopic: (topic: string) => void;
removeSubscribedTopic: (topic: string) => void;
hasCompletedBackupForPoints: boolean;
setBackupForPointsCompleted: () => void;
setBackupForPointsCompleted: (value?: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

rather than keeping this here and have to derive it from data in the poinEvents store. what about adding a function to pointEvents store hasCompletedBackupForPoints

this would mean less state to worry about

resetBackupForPoints: () => void;
pointsAddress: string | null;
setPointsAddress: (address: string | null) => void;
Expand Down Expand Up @@ -107,8 +107,8 @@ export const useSettingStore = create<SettingsState>()(
setTurnkeyBackupEnabled: (turnkeyBackupEnabled: boolean) =>
set({ turnkeyBackupEnabled }),
hasCompletedBackupForPoints: false,
setBackupForPointsCompleted: () =>
set({ hasCompletedBackupForPoints: true }),
setBackupForPointsCompleted: (value: boolean = true) =>
set({ hasCompletedBackupForPoints: value }),
resetBackupForPoints: () => set({ hasCompletedBackupForPoints: false }),
pointsAddress: null,
setPointsAddress: (address: string | null) =>
Expand Down
10 changes: 7 additions & 3 deletions app/src/utils/points/jobStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { POINTS_API_BASE_URL } from '@/utils/points/constants';

export type JobStatusResponse = {
job_id: string;
status: 'complete' | 'failed';
success: boolean;
message?: string;
};

export async function checkEventProcessingStatus(
Expand All @@ -33,10 +34,13 @@ export async function checkEventProcessingStatus(
// 200 means completed or failed - check the response body
if (response.status === 200) {
const data: JobStatusResponse = await response.json();
if (data.status === 'complete') {
if (data.success === true) {
return 'completed';
}
if (data.status === 'failed') {
if (data.success === false) {
if (data.message && data.message === 'Address already verified') {
return 'completed';
}
return 'failed';
}
}
Expand Down
Loading