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

ZEUS-2042: add feedback to manual SCB recovery process #2218

Merged
merged 1 commit into from
May 31, 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
38 changes: 30 additions & 8 deletions stores/ChannelBackupStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import BackendUtils from '../utils/BackendUtils';
import { LndMobileEventEmitter } from '../utils/LndMobileUtils';
import Base64Utils from '../utils/Base64Utils';
import { errorToUserFriendly } from '../utils/ErrorUtils';

const BACKUPS_HOST = 'https://backups.lnolymp.us';

Expand All @@ -24,6 +25,7 @@ export default class ChannelBackupStore {
@observable public backups: Array<any> = [];
@observable public loading: boolean = false;
@observable public error: boolean = false;
@observable public error_msg: string;

nodeInfoStore: NodeInfoStore;
settingsStore: SettingsStore;
Expand All @@ -36,6 +38,9 @@ export default class ChannelBackupStore {
@action
public reset = () => {
this.channelEventsSubscription = null;
this.error_msg = '';
this.error = false;
this.loading = false;
};

logBackupStatus = async (status: string) => {
Expand Down Expand Up @@ -195,16 +200,33 @@ export default class ChannelBackupStore {
};

@action
public triggerRecovery = async (backup: string) => {
const decryptedBytes = CryptoJS.AES.decrypt(
backup,
this.settingsStore.seedPhrase.toString()
);
const decryptedString = decryptedBytes.toString(CryptoJS.enc.Utf8);
public triggerRecovery = async (backup: string): Promise<void> => {
this.error_msg = '';
this.loading = true;

return await new Promise(async (resolve, reject) => {
try {
const decryptedBytes = CryptoJS.AES.decrypt(
backup,
this.settingsStore.seedPhrase.toString()
);
const decryptedString = decryptedBytes.toString(
CryptoJS.enc.Utf8
);

await restoreChannelBackups(decryptedString);
await restoreChannelBackups(decryptedString);

return;
this.error_msg = '';
this.loading = false;

resolve();
} catch (e: any) {
this.error_msg = errorToUserFriendly(e);
this.loading = false;

reject(new Error(this.error_msg));
}
});
};

@action
Expand Down
25 changes: 17 additions & 8 deletions views/Settings/EmbeddedNode/DisasterRecoveryAdvanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import moment from 'moment';
import { StackNavigationProp } from '@react-navigation/stack';

import Button from '../../../components/Button';
import Screen from '../../../components/Screen';
import Header from '../../../components/Header';
import LoadingIndicator from '../../../components/LoadingIndicator';
import Screen from '../../../components/Screen';
import { ErrorMessage } from '../../../components/SuccessErrorMessage';

import ChannelBackupStore from '../../../stores/ChannelBackupStore';

import { localeString } from '../../../utils/LocaleUtils';
import { themeColor } from '../../../utils/ThemeUtils';
import LoadingIndicator from '../../../components/LoadingIndicator';

interface DisasterRecoveryAdvancedProps {
navigation: StackNavigationProp<any, any>;
Expand All @@ -35,7 +36,9 @@ export default class DisasterRecoveryAdvanced extends React.Component<
};

UNSAFE_componentWillMount(): void {
this.props.ChannelBackupStore.advancedRecoveryList();
const { ChannelBackupStore } = this.props;
ChannelBackupStore.reset();
ChannelBackupStore.advancedRecoveryList();
}

render() {
Expand All @@ -46,7 +49,8 @@ export default class DisasterRecoveryAdvanced extends React.Component<
triggerRecovery,
backups,
loading,
error
error,
error_msg
} = ChannelBackupStore;

const noneSelected = Object.keys(selected).length === 0;
Expand Down Expand Up @@ -110,15 +114,20 @@ export default class DisasterRecoveryAdvanced extends React.Component<
disabled={noneSelected}
onPress={async () => {
if (selected.backup) {
await triggerRecovery(
selected.backup
);
navigation.popTo('Wallet');
try {
await triggerRecovery(
selected.backup
);
navigation.popTo('Wallet');
} catch (e) {}
}
}}
/>
</View>
)}
{!loading && error_msg && (
<ErrorMessage message={error_msg} />
)}
{!loading && backups.length > 0 && (
<FlatList
data={backups}
Expand Down
Loading