-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new logic for backup prompt (#6388)
- Loading branch information
Showing
12 changed files
with
430 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Bleed, Box, Inline, Inset, Separator, Stack, Text } from '@/design-system'; | ||
import * as lang from '@/languages'; | ||
import { ImgixImage } from '../images'; | ||
import WalletsAndBackupIcon from '@/assets/WalletsAndBackup.png'; | ||
import { Source } from 'react-native-fast-image'; | ||
import { cloudPlatform } from '@/utils/platform'; | ||
import { ButtonPressAnimation } from '../animations'; | ||
import Routes from '@/navigation/routesNames'; | ||
import { useNavigation } from '@/navigation'; | ||
import { useWallets } from '@/hooks'; | ||
import { format } from 'date-fns'; | ||
import { useCreateBackup } from './useCreateBackup'; | ||
import { executeFnIfCloudBackupAvailable } from '@/model/backup'; | ||
import { backupsStore } from '@/state/backups/backups'; | ||
|
||
const imageSize = 72; | ||
|
||
export default function CloudBackupPrompt() { | ||
const { navigate, goBack } = useNavigation(); | ||
const { mostRecentBackup } = backupsStore(state => ({ | ||
mostRecentBackup: state.mostRecentBackup, | ||
})); | ||
const { selectedWallet } = useWallets(); | ||
const createBackup = useCreateBackup(); | ||
|
||
const onCloudBackup = useCallback(() => { | ||
// pop the bottom sheet, and navigate to the backup section inside settings sheet | ||
goBack(); | ||
navigate(Routes.SETTINGS_SHEET, { | ||
screen: Routes.SETTINGS_SECTION_BACKUP, | ||
initial: false, | ||
}); | ||
|
||
executeFnIfCloudBackupAvailable({ | ||
fn: () => | ||
createBackup({ | ||
walletId: selectedWallet.id, | ||
}), | ||
logout: true, | ||
}); | ||
}, [createBackup, goBack, navigate, selectedWallet.id]); | ||
|
||
const onMaybeLater = useCallback(() => goBack(), [goBack]); | ||
|
||
return ( | ||
<Inset horizontal={'24px'} vertical={'44px'}> | ||
<Inset bottom={'44px'} horizontal={'24px'}> | ||
<Stack alignHorizontal="center"> | ||
<Box | ||
as={ImgixImage} | ||
borderRadius={imageSize / 2} | ||
height={{ custom: imageSize }} | ||
marginLeft={{ custom: -12 }} | ||
marginRight={{ custom: -12 }} | ||
marginTop={{ custom: 0 }} | ||
marginBottom={{ custom: 8 }} | ||
source={WalletsAndBackupIcon as Source} | ||
width={{ custom: imageSize }} | ||
size={imageSize} | ||
/> | ||
<Text align="center" size="26pt" weight="bold" color="label"> | ||
{lang.t(lang.l.back_up.cloud.add_wallet_to_cloud_backups)} | ||
</Text> | ||
</Stack> | ||
</Inset> | ||
|
||
<Bleed horizontal="24px"> | ||
<Separator color="separatorSecondary" thickness={1} /> | ||
</Bleed> | ||
|
||
<ButtonPressAnimation scaleTo={0.95} onPress={onCloudBackup}> | ||
<Box alignItems="center" justifyContent="center" paddingTop={'24px'} paddingBottom={'24px'}> | ||
<Box alignItems="center" justifyContent="center" width="full"> | ||
<Inline alignHorizontal="justify" alignVertical="center" wrap={false}> | ||
<Text color={'action (Deprecated)'} size="20pt" weight="bold"> | ||
{' '} | ||
{lang.t(lang.l.back_up.cloud.back_to_cloud_platform_now, { | ||
cloudPlatform, | ||
})} | ||
</Text> | ||
</Inline> | ||
</Box> | ||
</Box> | ||
</ButtonPressAnimation> | ||
|
||
<Bleed horizontal="24px"> | ||
<Separator color="separatorSecondary" thickness={1} /> | ||
</Bleed> | ||
|
||
<ButtonPressAnimation scaleTo={0.95} onPress={onMaybeLater}> | ||
<Box alignItems="center" justifyContent="center" paddingTop={'24px'} paddingBottom={'24px'}> | ||
<Box alignItems="center" justifyContent="center" width="full"> | ||
<Inline alignHorizontal="justify" alignVertical="center" wrap={false}> | ||
<Text color={'labelSecondary'} size="20pt" weight="bold"> | ||
{lang.t(lang.l.back_up.cloud.mayber_later)} | ||
</Text> | ||
</Inline> | ||
</Box> | ||
</Box> | ||
</ButtonPressAnimation> | ||
|
||
<Bleed horizontal="24px"> | ||
<Separator color="separatorSecondary" thickness={1} /> | ||
</Bleed> | ||
|
||
{mostRecentBackup && ( | ||
<Box alignItems="center" justifyContent="center" paddingTop={'24px'} paddingBottom={'24px'}> | ||
<Box alignItems="center" justifyContent="center" width="full"> | ||
<Inline alignHorizontal="justify" alignVertical="center" wrap={false}> | ||
<Text color={'labelTertiary'} size="15pt" weight="medium"> | ||
{lang.t(lang.l.back_up.cloud.latest_backup, { | ||
date: format(new Date(mostRecentBackup.lastModified), "M/d/yy 'at' h:mm a"), | ||
})} | ||
</Text> | ||
</Inline> | ||
</Box> | ||
</Box> | ||
)} | ||
</Inset> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { Bleed, Box, Inline, Inset, Separator, Stack, Text } from '@/design-system'; | ||
import * as lang from '@/languages'; | ||
import { ImgixImage } from '../images'; | ||
import ManuallyBackedUpIcon from '@/assets/ManuallyBackedUp.png'; | ||
import { Source } from 'react-native-fast-image'; | ||
import { ButtonPressAnimation } from '../animations'; | ||
import { useNavigation } from '@/navigation'; | ||
import Routes from '@/navigation/routesNames'; | ||
import { useWallets } from '@/hooks'; | ||
import walletTypes from '@/helpers/walletTypes'; | ||
import { SETTINGS_BACKUP_ROUTES } from '@/screens/SettingsSheet/components/Backups/routes'; | ||
import walletBackupTypes from '@/helpers/walletBackupTypes'; | ||
import { backupsStore } from '@/state/backups/backups'; | ||
|
||
const imageSize = 72; | ||
|
||
export default function ManualBackupPrompt() { | ||
const { navigate, goBack } = useNavigation(); | ||
const { selectedWallet } = useWallets(); | ||
|
||
const onManualBackup = async () => { | ||
const title = | ||
selectedWallet?.imported && selectedWallet.type === walletTypes.privateKey | ||
? (selectedWallet.addresses || [])[0].label | ||
: selectedWallet.name; | ||
|
||
goBack(); | ||
navigate(Routes.SETTINGS_SHEET, { | ||
screen: SETTINGS_BACKUP_ROUTES.SECRET_WARNING, | ||
params: { | ||
isBackingUp: true, | ||
title, | ||
backupType: walletBackupTypes.manual, | ||
walletId: selectedWallet.id, | ||
}, | ||
}); | ||
}; | ||
|
||
const onMaybeLater = useCallback(() => goBack(), [goBack]); | ||
|
||
return ( | ||
<Inset horizontal={'24px'} vertical={'44px'}> | ||
<Inset bottom={'44px'} horizontal={'24px'}> | ||
<Stack alignHorizontal="center"> | ||
<Box | ||
as={ImgixImage} | ||
borderRadius={imageSize / 2} | ||
height={{ custom: imageSize }} | ||
marginLeft={{ custom: -12 }} | ||
marginRight={{ custom: -12 }} | ||
marginTop={{ custom: 0 }} | ||
marginBottom={{ custom: 8 }} | ||
source={ManuallyBackedUpIcon as Source} | ||
width={{ custom: imageSize }} | ||
size={imageSize} | ||
/> | ||
<Text align="center" size="26pt" weight="bold" color="label"> | ||
{lang.t(lang.l.back_up.manual.backup_manually_now)} | ||
</Text> | ||
</Stack> | ||
</Inset> | ||
|
||
<Bleed horizontal="24px"> | ||
<Separator color="separatorSecondary" thickness={1} /> | ||
</Bleed> | ||
|
||
<ButtonPressAnimation scaleTo={0.95} onPress={onManualBackup}> | ||
<Box alignItems="center" justifyContent="center" paddingTop={'24px'} paddingBottom={'24px'}> | ||
<Box alignItems="center" justifyContent="center" width="full"> | ||
<Inline alignHorizontal="justify" alignVertical="center" wrap={false}> | ||
<Text color={'action (Deprecated)'} size="20pt" weight="bold"> | ||
{lang.t(lang.l.back_up.manual.back_up_now)} | ||
</Text> | ||
</Inline> | ||
</Box> | ||
</Box> | ||
</ButtonPressAnimation> | ||
|
||
<Bleed horizontal="24px"> | ||
<Separator color="separatorSecondary" thickness={1} /> | ||
</Bleed> | ||
|
||
<ButtonPressAnimation scaleTo={0.95} onPress={onMaybeLater}> | ||
<Box alignItems="center" justifyContent="center" paddingTop={'24px'} paddingBottom={'24px'}> | ||
<Box alignItems="center" justifyContent="center" width="full"> | ||
<Inline alignHorizontal="justify" alignVertical="center" wrap={false}> | ||
<Text color={'labelSecondary'} size="20pt" weight="bold"> | ||
{lang.t(lang.l.back_up.manual.already_backed_up)} | ||
</Text> | ||
</Inline> | ||
</Box> | ||
</Box> | ||
</ButtonPressAnimation> | ||
|
||
<Bleed horizontal="24px"> | ||
<Separator color="separatorSecondary" thickness={1} /> | ||
</Bleed> | ||
</Inset> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
export default { | ||
backup_prompt: 'backup_prompt', | ||
backup_manual: 'backup_manual', | ||
backup_cloud: 'backup_cloud', | ||
backup_prompt_manual: 'backup_prompt_manual', | ||
backup_prompt_cloud: 'backup_prompt_cloud', | ||
restore_from_backup: 'restore_from_backup', | ||
backup_now_to_cloud: 'cloud', | ||
backup_now_manually: 'manual', | ||
create_cloud_backup: 'create_cloud_backup', | ||
check_identifier: 'check_identifier', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.