Skip to content
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

Hide wallet amounts by pressing on logo #227

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Balance({ balance, nav }: IBalanceProps) {
const { pref, color, highlight } = useThemeContext()
// State to indicate token claim from clipboard after app comes to the foreground, to re-render total balance
const { claimed } = useFocusClaimContext()
const { hidden } = usePrivacyContext()
const { hidden, handleLogoPress } = usePrivacyContext()
const [formatSats, setFormatSats] = useState(pref?.formatBalance)
const [history, setHistory] = useState<IHistoryEntry[]>([])

Expand Down Expand Up @@ -75,7 +75,11 @@ export default function Balance({ balance, nav }: IBalanceProps) {
styles.board,
{ borderColor: color.BORDER, backgroundColor: hi[highlight] }
]}>
<Logo size={hidden.balance ? 100 : 40} style={{ marginTop: hidden.balance ? 40 : 0, marginBottom: hidden.balance ? 40 : 10 }} />
<TouchableOpacity
onPress={() => void handleLogoPress()}
>
<Logo size={hidden.balance ? 100 : 40} style={{ marginTop: hidden.balance ? 40 : 0, marginBottom: hidden.balance ? 40 : 10 }} />
</TouchableOpacity>
{/* balance */}
{!hidden.balance &&
<TouchableOpacity
Expand Down
49 changes: 47 additions & 2 deletions src/context/Privacy.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-return-await */
/* eslint-disable @typescript-eslint/await-thenable */
import { l } from '@log'
import { store } from '@store'
import { STORE_KEYS } from '@store/consts'
Expand All @@ -8,6 +10,42 @@ const usePrivacy = () => {
balance: false,
txs: false
})

const handleHiddenBalance = async () => {
setHidden({ balance: !hidden.balance, txs: hidden.txs })
if (hidden.balance) {
await store.delete(STORE_KEYS.hiddenBal)
return
}
await store.set(STORE_KEYS.hiddenBal, '1')
}

const handleHiddenTxs = async () => {
setHidden({ balance: hidden.balance, txs: !hidden.txs })
if (hidden.txs) {
await store.delete(STORE_KEYS.hiddenTxs)
return
}
await store.set(STORE_KEYS.hiddenTxs, '1')
}

const handleLogoPress = async () => {
// both hidden, show both
if (hidden.balance && hidden.txs) {
setHidden({ balance: false, txs: false })
await Promise.all([
store.delete(STORE_KEYS.hiddenTxs),
store.delete(STORE_KEYS.hiddenBal)
])
return
}
setHidden({ balance: true, txs: true })
await Promise.all([
store.set(STORE_KEYS.hiddenTxs, '1'),
store.set(STORE_KEYS.hiddenBal, '1')
])
}

useEffect(() => {
void (async () => {
// init privacy preferences
Expand All @@ -21,15 +59,22 @@ const usePrivacy = () => {
})
})()
}, [])

return {
hidden,
setHidden
setHidden,
handleHiddenBalance,
handleHiddenTxs,
handleLogoPress
}
}
type usePrivacyType = ReturnType<typeof usePrivacy>
const PrivacyContext = createContext<usePrivacyType>({
hidden: { balance: false, txs: false },
setHidden: () => l('')
setHidden: () => l(''),
handleHiddenBalance: async () => await l(''),
handleHiddenTxs: async () => await l(''),
handleLogoPress: async () => await l('')
})

export const usePrivacyContext = () => useContext(PrivacyContext)
Expand Down
22 changes: 1 addition & 21 deletions src/screens/Settings/Privacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,14 @@ import BottomNav from '@nav/BottomNav'
import { usePrivacyContext } from '@src/context/Privacy'
import { useThemeContext } from '@src/context/Theme'
import { NS } from '@src/i18n'
import { store } from '@store'
import { STORE_KEYS } from '@store/consts'
import { globals, highlight as hi } from '@styles'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Switch, Text, View } from 'react-native'

export default function PrivacySettings({ navigation, route }: TPrivacySettingsPageProps) {
const { t } = useTranslation([NS.topNav])
const { color, highlight } = useThemeContext()
const { hidden, setHidden } = usePrivacyContext()

const handleHiddenBalance = async () => {
setHidden({ balance: !hidden.balance, txs: hidden.txs })
if (hidden.balance) {
await store.delete(STORE_KEYS.hiddenBal)
return
}
await store.set(STORE_KEYS.hiddenBal, '1')
}

const handleHiddenTxs = async () => {
setHidden({ balance: hidden.balance, txs: !hidden.txs })
if (hidden.txs) {
await store.delete(STORE_KEYS.hiddenTxs)
return
}
await store.set(STORE_KEYS.hiddenTxs, '1')
}
const { hidden, handleHiddenBalance, handleHiddenTxs } = usePrivacyContext()

return (
<Screen
Expand Down
Loading