From 4fa5eef5e394043200f1d0c5dc6eab17831b90b7 Mon Sep 17 00:00:00 2001 From: KKA11010 Date: Mon, 18 Sep 2023 19:47:18 +0200 Subject: [PATCH] hide wallet amounts by pressing on logo #226 --- src/components/Balance.tsx | 8 ++++-- src/context/Privacy.tsx | 49 ++++++++++++++++++++++++++++++-- src/screens/Settings/Privacy.tsx | 22 +------------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/components/Balance.tsx b/src/components/Balance.tsx index b5f5c5e6..4eeb5f3d 100644 --- a/src/components/Balance.tsx +++ b/src/components/Balance.tsx @@ -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([]) @@ -75,7 +75,11 @@ export default function Balance({ balance, nav }: IBalanceProps) { styles.board, { borderColor: color.BORDER, backgroundColor: hi[highlight] } ]}> - + void handleLogoPress()} + > + + {/* balance */} {!hidden.balance && { 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 @@ -21,15 +59,22 @@ const usePrivacy = () => { }) })() }, []) + return { hidden, - setHidden + setHidden, + handleHiddenBalance, + handleHiddenTxs, + handleLogoPress } } type usePrivacyType = ReturnType const PrivacyContext = createContext({ 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) diff --git a/src/screens/Settings/Privacy.tsx b/src/screens/Settings/Privacy.tsx index e898ec30..da4c2667 100644 --- a/src/screens/Settings/Privacy.tsx +++ b/src/screens/Settings/Privacy.tsx @@ -7,8 +7,6 @@ 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' @@ -16,25 +14,7 @@ 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 (