|
| 1 | +import { DialogActions } from '#/Dialog/DialogActions'; |
| 2 | +import { DialogModal } from '#/Dialog/DialogModal'; |
| 3 | +import { ListItem, ListItemProps } from '#/list/ListItem'; |
| 4 | +import { Portal } from '@gorhom/portal'; |
| 5 | +import { ExternalLinkIcon, UpdateIcon } from '@theme/icons'; |
| 6 | +import { createStyles, useStyles } from '@theme/styles'; |
| 7 | +import { Link } from 'expo-router'; |
| 8 | +import { PolicyKey, UAddress } from 'lib'; |
| 9 | +import { useState } from 'react'; |
| 10 | +import { View } from 'react-native'; |
| 11 | +import { Button, Checkbox, Dialog, Text } from 'react-native-paper'; |
| 12 | +import { useRemovePolicy } from '~/hooks/mutations/useRemovePolicy'; |
| 13 | +import { CONFIG } from '~/util/config'; |
| 14 | + |
| 15 | +const UPGRADE_POLICY_HREF = CONFIG.docsUrl + '/upgrades'; |
| 16 | + |
| 17 | +export interface UpgradePolicyItemProps extends Partial<ListItemProps> { |
| 18 | + account: UAddress; |
| 19 | + policyKey: PolicyKey; |
| 20 | +} |
| 21 | + |
| 22 | +export function UpgradePolicyItem({ account, policyKey, ...props }: UpgradePolicyItemProps) { |
| 23 | + const { styles } = useStyles(stylesheet); |
| 24 | + const remove = useRemovePolicy(); |
| 25 | + |
| 26 | + const [showDialog, setShowDialog] = useState(false); |
| 27 | + const [risksAccepted, setRisksAccepted] = useState(false); |
| 28 | + |
| 29 | + return ( |
| 30 | + <> |
| 31 | + <Link asChild href={UPGRADE_POLICY_HREF}> |
| 32 | + <ListItem |
| 33 | + leading={UpdateIcon} |
| 34 | + headline="Automatic upgrades" |
| 35 | + supporting="Enabled" |
| 36 | + trailing={ExternalLinkIcon} |
| 37 | + onLongPress={async () => { |
| 38 | + setShowDialog(true); |
| 39 | + }} |
| 40 | + {...props} |
| 41 | + /> |
| 42 | + </Link> |
| 43 | + |
| 44 | + {showDialog && ( |
| 45 | + <Portal> |
| 46 | + <DialogModal> |
| 47 | + <Dialog.Title>Automatic upgrades</Dialog.Title> |
| 48 | + |
| 49 | + <Dialog.Content> |
| 50 | + <Text variant="bodyMedium"> |
| 51 | + Opting-out of the upgrade policy is{' '} |
| 52 | + <Text variant="titleSmall">not recommended</Text> and may lead to compatibility |
| 53 | + issues with the Zallo app |
| 54 | + </Text> |
| 55 | + |
| 56 | + <View style={styles.checkboxContainer}> |
| 57 | + <Checkbox |
| 58 | + status={risksAccepted ? 'checked' : 'unchecked'} |
| 59 | + onPress={() => setRisksAccepted((c) => !c)} |
| 60 | + /> |
| 61 | + |
| 62 | + <Text variant="titleSmall"> |
| 63 | + I have read and understand the implications of opting out of the{' '} |
| 64 | + <Link href={UPGRADE_POLICY_HREF} style={styles.link}> |
| 65 | + Upgrade Policy |
| 66 | + </Link> |
| 67 | + </Text> |
| 68 | + </View> |
| 69 | + </Dialog.Content> |
| 70 | + |
| 71 | + <DialogActions> |
| 72 | + <Button textColor={styles.cancel.color} onPress={() => setShowDialog(false)}> |
| 73 | + Cancel |
| 74 | + </Button> |
| 75 | + |
| 76 | + <Button |
| 77 | + textColor={styles.destructive.color} |
| 78 | + disabled={!risksAccepted} |
| 79 | + onPress={async () => { |
| 80 | + setShowDialog(false); |
| 81 | + await remove(account, policyKey); |
| 82 | + }} |
| 83 | + > |
| 84 | + Opt-out of automatic upgrades |
| 85 | + </Button> |
| 86 | + </DialogActions> |
| 87 | + </DialogModal> |
| 88 | + </Portal> |
| 89 | + )} |
| 90 | + </> |
| 91 | + ); |
| 92 | +} |
| 93 | + |
| 94 | +const stylesheet = createStyles(({ colors }) => ({ |
| 95 | + checkboxContainer: { |
| 96 | + flexDirection: 'row', |
| 97 | + alignItems: 'center', |
| 98 | + gap: 16, |
| 99 | + // marginVertical: 8, |
| 100 | + marginTop: 16, |
| 101 | + }, |
| 102 | + link: { |
| 103 | + color: colors.tertiary, |
| 104 | + }, |
| 105 | + cancel: { |
| 106 | + color: colors.onSurfaceVariant, |
| 107 | + }, |
| 108 | + destructive: { |
| 109 | + color: colors.error, |
| 110 | + }, |
| 111 | +})); |
0 commit comments