-
Notifications
You must be signed in to change notification settings - Fork 1
Make deleting an account take more than two taps #2562
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
Open
MusabShakeel576
wants to merge
1
commit into
master
Choose a base branch
from
claude/clever-rubin-tr6ceo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,190 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { | ||
| ActivityIndicator, | ||
| KeyboardAvoidingView, | ||
| Modal, | ||
| Platform, | ||
| Pressable, | ||
| Text, | ||
| View, | ||
| } from 'react-native'; | ||
| import { AlertTriangle, X } from 'lucide-react-native'; | ||
|
|
||
| import Input from '@/components/ui/input'; | ||
| import { useTotalSavingsUSD } from '@/hooks/useTotalSavingsUSD'; | ||
| import { useWalletTokens } from '@/hooks/useWalletTokens'; | ||
| import { cn, formatBalanceUSD } from '@/lib/utils'; | ||
|
|
||
| /** | ||
| * What the user has to type before "Delete Account" does anything. | ||
| * | ||
| * Two taps used to be enough, and a user closed an account holding $28 that way | ||
| * and then could not sign back in to reach it. Typing a word is the one step | ||
| * that cannot happen by accident. | ||
| */ | ||
| export const DELETE_CONFIRMATION_WORD = 'DELETE'; | ||
|
|
||
| /** Whether what was typed confirms the deletion. Case and stray spaces don't count against it. */ | ||
| export const isDeleteConfirmation = (typed: string): boolean => | ||
| typed.trim().toUpperCase() === DELETE_CONFIRMATION_WORD; | ||
|
|
||
| /** | ||
| * Tells the user what they still hold before they delete the account. | ||
| * | ||
| * Deleting does not move any money: it stays in their wallet, and a closed | ||
| * account cannot sign in to reach it. Wallet and savings are the pots that | ||
| * matter for that and are read the same way the home screen reads them; the | ||
| * card is left out because its balance means different things per issuer, so | ||
| * the figure is "at least" rather than the headline. | ||
| * | ||
| * Only mounted while the modal is open, so the balance queries don't run for | ||
| * everyone who merely opens Account details. | ||
| */ | ||
| export function HeldBalanceWarning() { | ||
| const { totalUSDExcludingVaultTokens: walletUsd } = useWalletTokens(); | ||
| const { data: savingsUsd } = useTotalSavingsUSD(); | ||
|
|
||
| const heldUsd = (walletUsd || 0) + (savingsUsd || 0); | ||
| if (heldUsd < 0.01) return null; | ||
|
|
||
| return ( | ||
| <View className="mb-6 flex-row gap-3 rounded-xl border border-red-500/40 bg-red-500/10 p-4"> | ||
| <AlertTriangle size={20} color="#FF7D7D" /> | ||
| <View className="flex-1"> | ||
| <Text className="mb-1 text-base font-bold text-white"> | ||
| You still have at least {formatBalanceUSD(heldUsd)} in Solid | ||
| </Text> | ||
| <Text className="text-sm text-gray-300"> | ||
| Deleting your account doesn't move this money, and you won't be able to sign | ||
| back in to reach it. Withdraw it or send it to another wallet first. | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| type DeleteAccountModalProps = { | ||
| visible: boolean; | ||
| isDeleting: boolean; | ||
| onCancel: () => void; | ||
| onConfirm: () => void; | ||
| }; | ||
|
|
||
| /** | ||
| * The last step before an account is closed. | ||
| * | ||
| * Closing locks the user out — every sign-in is refused afterwards, and only | ||
| * support can reopen the account — so this asks for more than a tap: it shows | ||
| * what the user still holds, and the delete button stays disabled until they | ||
| * type {@link DELETE_CONFIRMATION_WORD}. | ||
| */ | ||
| export default function DeleteAccountModal({ | ||
| visible, | ||
| isDeleting, | ||
| onCancel, | ||
| onConfirm, | ||
| }: DeleteAccountModalProps) { | ||
| const [confirmationText, setConfirmationText] = useState(''); | ||
| const isConfirmed = isDeleteConfirmation(confirmationText); | ||
|
|
||
| // Whatever was typed must not carry over to the next opening — including after a failed | ||
| // attempt, which closes the modal from the parent rather than through `cancel`. | ||
| useEffect(() => { | ||
| if (!visible) setConfirmationText(''); | ||
| }, [visible]); | ||
|
|
||
| const cancel = () => { | ||
| if (isDeleting) return; | ||
| onCancel(); | ||
| }; | ||
|
|
||
| const confirm = () => { | ||
| if (!isConfirmed || isDeleting) return; | ||
| onConfirm(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal animationType="fade" transparent={true} visible={visible} onRequestClose={cancel}> | ||
| <KeyboardAvoidingView | ||
| behavior={Platform.OS === 'ios' ? 'padding' : 'height'} | ||
| enabled={Platform.OS !== 'web'} | ||
| style={{ flex: 1 }} | ||
| > | ||
| <View className="flex-1 items-center justify-center bg-black/70 px-4"> | ||
| <View className="w-full max-w-sm rounded-3xl bg-[#1c1c1c] p-6"> | ||
| <View className="mb-4 flex-row items-center justify-between"> | ||
| <Text className="text-xl font-bold text-white">Delete Account</Text> | ||
| <Pressable onPress={cancel} accessibilityLabel="Close"> | ||
| <X size={24} color="#ffffff" /> | ||
| </Pressable> | ||
| </View> | ||
|
|
||
| {visible && <HeldBalanceWarning />} | ||
|
|
||
| <Text className="mb-6 text-base text-gray-300"> | ||
| Are you sure you want to delete your account? This action cannot be undone and will: | ||
| </Text> | ||
|
|
||
| <View className="mb-6"> | ||
| <Text className="mb-2 text-sm text-gray-300">• Remove all your data</Text> | ||
| <Text className="mb-2 text-sm text-gray-300">• Cancel any active cards</Text> | ||
| <Text className="mb-2 text-sm text-gray-300">• Delete your transaction history</Text> | ||
| <Text className="text-sm text-gray-300">• Remove access to your wallet</Text> | ||
| </View> | ||
|
|
||
| <Text className="mb-2 text-sm text-gray-300"> | ||
| Type <Text className="font-bold text-white">{DELETE_CONFIRMATION_WORD}</Text> to | ||
| confirm | ||
| </Text> | ||
| <Input | ||
| value={confirmationText} | ||
| onChangeText={setConfirmationText} | ||
| placeholder={DELETE_CONFIRMATION_WORD} | ||
| autoCapitalize="characters" | ||
| autoCorrect={false} | ||
| autoComplete="off" | ||
| editable={!isDeleting} | ||
| className="mb-6" | ||
| accessibilityLabel={`Type ${DELETE_CONFIRMATION_WORD} to confirm`} | ||
| /> | ||
|
|
||
| <View className="flex-row justify-between"> | ||
| <Pressable | ||
| onPress={cancel} | ||
| className="mr-2 flex-1 rounded-xl bg-gray-700 py-4" | ||
| disabled={isDeleting} | ||
| > | ||
| <Text className="text-center font-semibold text-white">Cancel</Text> | ||
| </Pressable> | ||
|
|
||
| <Pressable | ||
| onPress={confirm} | ||
| className={cn('ml-2 flex-1 rounded-xl py-4', { | ||
| 'bg-red-400': isDeleting, | ||
| 'bg-red-600': !isDeleting && isConfirmed, | ||
| 'bg-red-600/40': !isDeleting && !isConfirmed, | ||
| })} | ||
| disabled={isDeleting || !isConfirmed} | ||
| accessibilityLabel="Delete Account" | ||
| accessibilityState={{ disabled: isDeleting || !isConfirmed }} | ||
| > | ||
| {isDeleting ? ( | ||
| <ActivityIndicator color="#ffffff" /> | ||
| ) : ( | ||
| <Text | ||
| className={cn('text-center font-semibold', { | ||
| 'text-white': isConfirmed, | ||
| 'text-white/50': !isConfirmed, | ||
| })} | ||
| > | ||
| Delete Account | ||
| </Text> | ||
| )} | ||
| </Pressable> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </KeyboardAvoidingView> | ||
| </Modal> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The
HeldBalanceWarningdoes not handle the loading state from theuseTotalSavingsUSDhook, causing it to briefly not appear for users with funds only in savings.Severity: MEDIUM
Suggested Fix
The
HeldBalanceWarningcomponent should account for the loading state of the balance queries. Either disable the delete button, show a loading skeleton for the balance, or conditionally render the warning only after theisLoadingstate fromuseTotalSavingsUSDisfalse. This ensures the user always sees the correct information or a loading indicator before they can act.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.