mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
SELF-1177 - Separate button states during backup (#1402)
* AccountRecoveryChoiceScreen: seperate button states * clean up logging * improve analytics --------- Co-authored-by: Justin Hernandez <justin.hernandez@self.xyz>
This commit is contained in:
@@ -50,7 +50,8 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
// const { turnkeyWallets, refreshWallets } = useTurnkeyUtils();
|
||||
// const { getMnemonic } = useTurnkeyUtils();
|
||||
// const { authState } = useTurnkey();
|
||||
const [restoring, setRestoring] = useState(false);
|
||||
const [restoringFromTurnkey, setRestoringFromTurnkey] = useState(false);
|
||||
const [restoringFromCloud, setRestoringFromCloud] = useState(false);
|
||||
const { cloudBackupEnabled, toggleCloudBackupEnabled, biometricsAvailable } =
|
||||
useSettingStore();
|
||||
const { download } = useBackupMnemonic();
|
||||
@@ -73,6 +74,7 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
async (
|
||||
mnemonic: Mnemonic,
|
||||
isCloudRestore: boolean = false,
|
||||
setRestoring: (value: boolean) => void,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const result = await restoreAccountFromMnemonic(mnemonic.phrase);
|
||||
@@ -152,7 +154,10 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
setRestoring(false);
|
||||
return true;
|
||||
} catch (e: unknown) {
|
||||
console.error(e);
|
||||
console.error(
|
||||
'Restore account error:',
|
||||
e instanceof Error ? e.message : 'Unknown error',
|
||||
);
|
||||
trackEvent(BackupEvents.CLOUD_RESTORE_FAILED_UNKNOWN);
|
||||
setRestoring(false);
|
||||
return false;
|
||||
@@ -172,7 +177,7 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
|
||||
// DISABLED FOR NOW: Turnkey functionality
|
||||
// const onRestoreFromTurnkeyPress = useCallback(async () => {
|
||||
// setRestoring(true);
|
||||
// setRestoringFromTurnkey(true);
|
||||
// try {
|
||||
// const mnemonicPhrase = await getMnemonic();
|
||||
// const mnemonic: Mnemonic = {
|
||||
@@ -183,7 +188,11 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
// },
|
||||
// entropy: '',
|
||||
// };
|
||||
// const success = await restoreAccountFlow(mnemonic);
|
||||
// const success = await restoreAccountFlow(
|
||||
// mnemonic,
|
||||
// false,
|
||||
// setRestoringFromTurnkey,
|
||||
// );
|
||||
// if (success) {
|
||||
// setTurnkeyBackupEnabled(true);
|
||||
// }
|
||||
@@ -191,19 +200,22 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
// console.error('Turnkey restore error:', error);
|
||||
// trackEvent(BackupEvents.CLOUD_RESTORE_FAILED_UNKNOWN);
|
||||
// } finally {
|
||||
// setRestoring(false);
|
||||
// setRestoringFromTurnkey(false);
|
||||
// }
|
||||
// }, [getMnemonic, restoreAccountFlow, setTurnkeyBackupEnabled, trackEvent]);
|
||||
|
||||
const onRestoreFromCloudPress = useCallback(async () => {
|
||||
setRestoring(true);
|
||||
setRestoringFromCloud(true);
|
||||
try {
|
||||
const mnemonic = await download();
|
||||
await restoreAccountFlow(mnemonic, true);
|
||||
await restoreAccountFlow(mnemonic, true, setRestoringFromCloud);
|
||||
} catch (error) {
|
||||
console.error('Cloud restore error:', error);
|
||||
console.error(
|
||||
'Cloud restore error:',
|
||||
error instanceof Error ? error.message : 'Unknown error',
|
||||
);
|
||||
trackEvent(BackupEvents.CLOUD_RESTORE_FAILED_UNKNOWN);
|
||||
setRestoring(false);
|
||||
setRestoringFromCloud(false);
|
||||
}
|
||||
}, [download, restoreAccountFlow, trackEvent]);
|
||||
|
||||
@@ -244,23 +256,23 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
onPress={onRestoreFromTurnkeyPress}
|
||||
testID="button-from-turnkey"
|
||||
disabled={
|
||||
restoring ||
|
||||
restoringFromTurnkey ||
|
||||
!biometricsAvailable ||
|
||||
(authState === AuthState.Authenticated &&
|
||||
turnkeyWallets.length === 0)
|
||||
}
|
||||
>
|
||||
{restoring ? 'Restoring' : 'Restore'} from Turnkey
|
||||
{restoring ? '…' : ''}
|
||||
{restoringFromTurnkey ? 'Restoring' : 'Restore'} from Turnkey
|
||||
{restoringFromTurnkey ? '…' : ''}
|
||||
</PrimaryButton> */}
|
||||
<PrimaryButton
|
||||
trackEvent={BackupEvents.CLOUD_BACKUP_STARTED}
|
||||
onPress={onRestoreFromCloudPress}
|
||||
testID="button-from-teststorage"
|
||||
disabled={restoring || !biometricsAvailable}
|
||||
disabled={restoringFromCloud || !biometricsAvailable}
|
||||
>
|
||||
{restoring ? 'Restoring' : 'Restore'} from {STORAGE_NAME}
|
||||
{restoring ? '…' : ''}
|
||||
{restoringFromCloud ? 'Restoring' : 'Restore'} from {STORAGE_NAME}
|
||||
{restoringFromCloud ? '…' : ''}
|
||||
</PrimaryButton>
|
||||
<XStack gap={64} alignItems="center" justifyContent="space-between">
|
||||
<Separator flexGrow={1} />
|
||||
@@ -270,7 +282,6 @@ const AccountRecoveryChoiceScreen: React.FC = () => {
|
||||
<SecondaryButton
|
||||
trackEvent={BackupEvents.MANUAL_RECOVERY_SELECTED}
|
||||
onPress={handleManualRecoveryPress}
|
||||
disabled={restoring}
|
||||
>
|
||||
<XStack alignItems="center" justifyContent="center">
|
||||
<Keyboard height={25} width={40} color={slate500} />
|
||||
|
||||
Reference in New Issue
Block a user