Skip to content
Draft
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
42 changes: 22 additions & 20 deletions src/components/Backup/BackupHealthCheckList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
setBackupAllFailure,
setBackupAllSuccess,
setSeedConfirmed,
isAutomaticCloudBackupEnabled,
} from 'src/store/reducers/bhr';
import { CommonActions, useIsFocused, useNavigation } from '@react-navigation/native';
import { useQuery } from '@realm/react';
Expand All @@ -41,7 +42,7 @@ const ContentType = {
mismatch: 'mismatch',
healthCheckSuccessful: 'healthCheckSuccessful',
};
function Content({ contentType, asbEnabled }: { contentType: string; asbEnabled: boolean }) {
function Content({ contentType, asbEnabled }: { contentType: string; asbEnabled?: boolean }) {
const { BackupWallet } = useContext(LocalizationContext).translations;
const illustrations = {
[ContentType.verifying]: (
Expand Down Expand Up @@ -74,17 +75,21 @@ function BackupHealthCheckList({ isUaiFlow }) {
const { translations } = useContext(LocalizationContext);
const { BackupWallet, vault: vaultText, common } = translations;
const dispatch = useAppDispatch();
const { primaryMnemonic, backup, id } = useQuery(RealmSchema.KeeperApp).map(
const { primaryMnemonic, id } = useQuery(RealmSchema.KeeperApp).map(
getJSONFromRealmObject
)[0];
)[0] as { primaryMnemonic: string; id: string };
const {
backupMethod,
seedConfirmed,
automaticCloudBackup,
backupAllLoading,
backupAllFailure,
backupAllSuccess,
automaticCloudBackupByAppId,
backupAllLoadingByAppId,
backupAllFailureByAppId,
backupAllSuccessByAppId,
} = useAppSelector((state) => state.bhr);
const automaticCloudBackup = isAutomaticCloudBackupEnabled({ automaticCloudBackupByAppId }, id);
const backupAllLoading = !!backupAllLoadingByAppId?.[id];
const backupAllFailure = !!backupAllFailureByAppId?.[id];
const backupAllSuccess = !!backupAllSuccessByAppId?.[id];
const [healthCheckModal, setHealthCheckModal] = useState(false);
const [showConfirmSeedModal, setShowConfirmSeedModal] = useState(isUaiFlow);
const [verificationModal, setVerificationModal] = useState(false);
Expand All @@ -107,9 +112,9 @@ function BackupHealthCheckList({ isUaiFlow }) {
useEffect(() => {
if (backupAllSuccess) {
if (!automaticCloudBackup) setAsbEnabled(true);
dispatch(setBackupAllSuccess(false));
dispatch(setBackupAllFailure(false));
dispatch(setAutomaticCloudBackup(true));
dispatch(setBackupAllSuccess({ appId: id, status: false }));
dispatch(setBackupAllFailure({ appId: id, status: false }));
dispatch(setAutomaticCloudBackup({ appId: id, enabled: true }));
setHealthCheckModal(true);
}
}, [backupAllSuccess, backupAllFailure]);
Expand All @@ -118,12 +123,9 @@ function BackupHealthCheckList({ isUaiFlow }) {
if (seedConfirmed) {
setShowConfirmSeedModal(false);
dispatch(setRecoveryKeyBackedUp({ appId: id as string, status: true }));
if (!automaticCloudBackup) dispatch(backupAllSignersAndVaults());
else {
setTimeout(() => {
setHealthCheckModal(true);
}, 100);
}
setTimeout(() => {
setHealthCheckModal(true);
}, 100);
}
return () => {
dispatch(setSeedConfirmed(false));
Expand All @@ -133,13 +135,13 @@ function BackupHealthCheckList({ isUaiFlow }) {
useEffect(() => {
if (backupAllFailure && isFocused) {
setFailedVerificationModal(true);
dispatch(setBackupAllFailure(false));
dispatch(setBackupAllFailure({ appId: id, status: false }));
}
}, [backupAllFailure]);

useEffect(() => {
if (backupAllSuccess && isFocused) {
dispatch(setBackupAllSuccess(false));
dispatch(setBackupAllSuccess({ appId: id, status: false }));
dispatch(seedBackedConfirmed(true));
}
}, [backupAllSuccess]);
Expand Down Expand Up @@ -192,7 +194,7 @@ function BackupHealthCheckList({ isUaiFlow }) {
} else {
setBackupMismatchModal(true);
}
})
}, id)
);
} else {
dispatch(seedBackedConfirmed(true));
Expand Down Expand Up @@ -288,7 +290,7 @@ function BackupHealthCheckList({ isUaiFlow }) {
buttonBackground={`${colorMode}.pantoneGreen`}
buttonText={'Backup Now'}
buttonCallback={() => {
dispatch(backupAllSignersAndVaults());
dispatch(backupAllSignersAndVaults(id));
setBackupMismatchModal(false);
}}
secondaryButtonText="Home"
Expand Down
6 changes: 4 additions & 2 deletions src/components/ImportExportLabels/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useRef, useState } from 'react';
import { Box, useColorMode } from '@gluestack-ui/themed-native-base';
import { StyleSheet, TouchableOpacity } from 'react-native';
import { useDispatch } from 'react-redux';
Expand Down Expand Up @@ -28,6 +28,8 @@ const ImportExportLabels: React.FC<ImportExportLabelsProps> = ({
}) => {
const { colorMode } = useColorMode();
const dispatch = useDispatch();
const activeAppId = useAppSelector((state) => state.storage.appId);
const originAppId = useRef(activeAppId).current;
const { vault: vaultText } = translations;
const { syncingUTXOs } = useAppSelector((state) => state.utxos);
const [isSyncingLabels, setIsSyncingLabels] = useState(false);
Expand Down Expand Up @@ -101,7 +103,7 @@ const ImportExportLabels: React.FC<ImportExportLabelsProps> = ({
origin: standardizeDescriptor(label.origin),
}));

dispatch(importLabels({ labels: standardizedLabels }));
dispatch(importLabels({ labels: standardizedLabels }, originAppId));

onSuccess(`Imported ${walletLabels.length} labels successfully`);
} catch (parseError) {
Expand Down
36 changes: 21 additions & 15 deletions src/hooks/useSettingKeeper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
setAutomaticCloudBackup,
setDeleteBackupSuccess,
setDeleteBackupFailure,
isAutomaticCloudBackupEnabled,
} from 'src/store/reducers/bhr';
import useToastMessage from './useToastMessage';
import ToastErrorIcon from 'src/assets/images/toast_error.svg';
Expand Down Expand Up @@ -92,12 +93,17 @@ export const useSettingKeeper = () => {
});
const { id }: KeeperApp = useQuery(RealmSchema.KeeperApp).map(getJSONFromRealmObject)[0];
const {
backupAllFailure,
backupAllSuccess,
automaticCloudBackup,
deleteBackupSuccess,
deleteBackupFailure,
backupAllFailureByAppId,
backupAllSuccessByAppId,
automaticCloudBackupByAppId,
deleteBackupSuccessByAppId,
deleteBackupFailureByAppId,
} = useAppSelector((state) => state.bhr);
const automaticCloudBackup = isAutomaticCloudBackupEnabled({ automaticCloudBackupByAppId }, id);
const backupAllFailure = !!backupAllFailureByAppId?.[id];
const backupAllSuccess = !!backupAllSuccessByAppId?.[id];
const deleteBackupSuccess = !!deleteBackupSuccessByAppId?.[id];
const deleteBackupFailure = !!deleteBackupFailureByAppId?.[id];

useEffect(() => {
if (isOnL4) {
Expand Down Expand Up @@ -142,8 +148,8 @@ export const useSettingKeeper = () => {

useEffect(() => {
if (backupAllSuccess && isFocused) {
dispatch(setBackupAllSuccess(false));
dispatch(setAutomaticCloudBackup(true));
dispatch(setBackupAllSuccess({ appId: id, status: false }));
dispatch(setAutomaticCloudBackup({ appId: id, enabled: true }));
setTimeout(() => {
dispatch(setShowTipModal({ status: true, address: config.ADDRESS.assistServer }));
}, 1000);
Expand All @@ -152,28 +158,28 @@ export const useSettingKeeper = () => {

useEffect(() => {
if (deleteBackupSuccess && isFocused) {
dispatch(setDeleteBackupSuccess(false));
dispatch(setAutomaticCloudBackup(false));
dispatch(setDeleteBackupSuccess({ appId: id, status: false }));
dispatch(setAutomaticCloudBackup({ appId: id, enabled: false }));
}
}, [deleteBackupSuccess]);

useEffect(() => {
if (deleteBackupFailure && isFocused) {
dispatch(setDeleteBackupFailure(false));
dispatch(setDeleteBackupFailure({ appId: id, status: false }));
showToast(errorText.unableToDeleteAssistedServer, <ToastErrorIcon />);
}
}, [deleteBackupFailure]);

useEffect(() => {
if (backupAllFailure && isFocused) {
dispatch(setBackupAllFailure(false));
dispatch(setBackupAllFailure({ appId: id, status: false }));
}
}, [backupAllFailure]);

const toggleAutomaticBackupMode = useCallback(() => {
if (!automaticCloudBackup) dispatch(backupAllSignersAndVaults());
if (!automaticCloudBackup) dispatch(backupAllSignersAndVaults(id));
else setShowDeleteBackup(true);
}, [automaticCloudBackup, dispatch]);
}, [automaticCloudBackup, dispatch, id]);

const debouncedAutomaticBackupToggle = useCallback(() => {
if (backupToggleTimeoutRef.current) {
Expand Down Expand Up @@ -471,11 +477,11 @@ export const useSettingKeeper = () => {
primaryText={settings.assistedServerDeleteBackupModalCTA}
primaryCallback={() => {
setShowDeleteBackup(false);
dispatch(deleteBackup());
dispatch(deleteBackup(id));
}}
secondaryCallback={() => {
setShowDeleteBackup(false);
dispatch(setAutomaticCloudBackup(false));
dispatch(setAutomaticCloudBackup({ appId: id, enabled: false }));
}}
secondaryText={settings.assistedServerDeleteBackupModalSecondaryCTA}
/>
Expand Down
Loading
Loading