Skip to content

Commit

Permalink
Merge pull request #2218 from kaloudis/zeus-2042
Browse files Browse the repository at this point in the history
ZEUS-2042: add feedback to manual SCB recovery process
  • Loading branch information
kaloudis authored May 31, 2024
2 parents b52acf0 + 5d601bf commit 295b7b6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
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

0 comments on commit 295b7b6

Please sign in to comment.