-
Notifications
You must be signed in to change notification settings - Fork 10
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
Added Don't Show Again On Deposit Dialog #1122
base: dev
Are you sure you want to change the base?
Changes from all commits
7334b7d
008004d
4357978
fda1c47
5ea8db9
c320715
be25eff
3b4d5c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,9 @@ import { useState, useEffect } from 'react' | |
import type { Address } from 'viem' | ||
import { IconCopy } from 'app/components/icons' | ||
import { useQRCode } from 'app/utils/useQRCode' | ||
import AsyncStorage from '@react-native-async-storage/async-storage' | ||
|
||
function CopyAddressDialog({ isOpen, onClose, onConfirm }) { | ||
function CopyAddressDialog({ isOpen, onClose, onConfirm }) { const [dontShowAgain, setDontShowAgain] = useState(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we won't need this local state if we are using the checkbox form and the async storage |
||
return ( | ||
<Dialog open={isOpen} onOpenChange={onClose}> | ||
<Dialog.Adapt when="sm" platform="touch"> | ||
|
@@ -61,14 +62,33 @@ function CopyAddressDialog({ isOpen, onClose, onConfirm }) { | |
3. I understand that if I make any mistakes, there is no way to recover the funds. | ||
</Paragraph> | ||
|
||
<XStack justifyContent="flex-end" marginTop="$4" gap="$4"> | ||
<Dialog.Close asChild> | ||
<Button br={'$2'}>Cancel</Button> | ||
</Dialog.Close> | ||
<Button theme="yellow_active" onPress={onConfirm} br={'$2'}> | ||
<Button.Text col={'$color12'}>I Agree & Proceed</Button.Text> | ||
</Button> | ||
</XStack> | ||
<XStack justifyContent="flex-end" marginTop="$4" gap="$4" ai="center"> | ||
{/* Checkbox on the left */} | ||
<XStack ai="center" gap="$2"> | ||
<input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a checkbox form component that has some helpful defaults. lets use that here |
||
type="checkbox" | ||
checked={dontShowAgain} | ||
onChange={async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't do this inline. Pop this out into a new function |
||
const newValue = !dontShowAgain; | ||
setDontShowAgain(newValue); | ||
try { | ||
await AsyncStorage.setItem('dontShowAgain', JSON.stringify(newValue)); | ||
} catch (error) { | ||
console.error('Failed to save checkbox state:', error); | ||
} | ||
}} | ||
/> | ||
<Text fontSize="$3">Don't show again</Text> | ||
</XStack> | ||
|
||
{/* Buttons on the right */} | ||
<Dialog.Close asChild> | ||
<Button br={'$2'}>Cancel</Button> | ||
</Dialog.Close> | ||
<Button theme="yellow_active" onPress={onConfirm} br={'$2'}> | ||
<Button.Text col={'$color12'}>I Agree & Proceed</Button.Text> | ||
</Button> | ||
</XStack> | ||
</YStack> | ||
</Dialog.Content> | ||
</Dialog.Portal> | ||
|
@@ -81,6 +101,23 @@ export function DepositAddress({ address, ...props }: { address?: Address } & Bu | |
const [hasCopied, setHasCopied] = useState(false) | ||
const [isConfirmed, setIsConfirmed] = useState(false) | ||
const [copyAddressDialogIsOpen, setCopyAddressDialogIsOpen] = useState(false) | ||
const [dontShowAgain, setDontShowAgain] = useState(false); | ||
|
||
useEffect(() => { | ||
const loadDontShowAgain = async () => { | ||
try { | ||
const savedValue = await AsyncStorage.getItem('dontShowAgain'); | ||
if (savedValue !== null) { | ||
setDontShowAgain(JSON.parse(savedValue)); | ||
setIsConfirmed(JSON.parse(savedValue)); // Auto-confirm if "Don't show again" was checked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't the right way to do this. Instead we should load this state from storage in the screen component and pass it as props to skip over the dialog entirely |
||
} | ||
} catch (error) { | ||
console.error('Failed to load dontShowAgain:', error); | ||
} | ||
}; | ||
|
||
loadDontShowAgain(); | ||
}, []); | ||
|
||
const { data: qrData, error } = useQRCode(address, { | ||
width: 240, | ||
|
@@ -104,12 +141,36 @@ export function DepositAddress({ address, ...props }: { address?: Address } & Bu | |
if (!address) return null | ||
|
||
const copyOnPress = async () => { | ||
if (!isConfirmed) { | ||
if (dontShowAgain) { | ||
try { | ||
await AsyncStorage.setItem('dontShowAgain', 'true') | ||
} catch (error) { | ||
console.error('Failed to save dontShowAgain:', error) | ||
} | ||
} | ||
if (!dontShowAgain) { | ||
setCopyAddressDialogIsOpen(true); | ||
} | ||
return | ||
} | ||
|
||
await Clipboard.setString(address).catch(() => | ||
toast.show('Something went wrong', { | ||
message: 'We were unable to copy your address to the clipboard', | ||
customData: { | ||
theme: 'red', | ||
}, | ||
}) | ||
) | ||
setHasCopied(true) | ||
} | ||
if (!isConfirmed) { | ||
setCopyAddressDialogIsOpen(true) | ||
return | ||
} | ||
|
||
await Clipboard.setStringAsync(address).catch(() => | ||
await Clipboard.setString(address).catch(() => | ||
toast.show('Something went wrong', { | ||
message: 'We were unable to copy your address to the clipboard', | ||
customData: { | ||
|
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.
can you please use our biome integration to format these changes