Skip to content

Commit

Permalink
add settings to hide latest transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
KKA11010 committed Aug 26, 2023
1 parent cd3b843 commit 007a228
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 35 deletions.
3 changes: 2 additions & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
"emptyMint": "Kein Guthaben vorhanden",
"zapSoon": "Zaps werden bald hinzugefügt...",
"enutsPub": "eNuts: ",
"seeFullHistory": "Gesamter Transaktionsverlauf"
"seeFullHistory": "Gesamter Transaktionsverlauf",
"hideLatestTxs": "Aktuellste Transaktionen verbergen"
},
"error": {
"addAllMintIdsErr": "Fehler beim Abrufen der Schlüsselsatz-IDs von Mint",
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@
"emptyMint": "Mint has no funds",
"zapSoon": "Zaps will be added soon...",
"enutsPub": "eNuts public key: ",
"seeFullHistory": "See full transaction history"
"seeFullHistory": "See full transaction history",
"hideLatestTxs": "Hide your latest transactions"
},
"error": {
"addAllMintIdsErr": "Error while getting keyset ids from mint",
Expand Down
3 changes: 2 additions & 1 deletion assets/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@
"newMintAddedQuestion": "Voulez-vous recevoir Ecash maintenant ?",
"clearOverHere": "Tout est clair de ce côté-ci!",
"totalDmsReceived": "Vous avez reçu 4 Cashu token.",
"seeFullHistory": "Voir l'historique complet"
"seeFullHistory": "Voir l'historique complet",
"hideLatestTxs": "Masquer vos dernières transactions"
},
"topNav": {
"about": "À propos de nous",
Expand Down
32 changes: 18 additions & 14 deletions src/components/Balance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ export default function Balance({ balance, nav }: IBalanceProps) {
const [formatSats, setFormatSats] = useState(pref?.formatBalance)
const [history, setHistory] = useState<IHistoryEntry[]>([])

const showBalance = () => {
if (hidden) { return '-' }
return formatSats ? formatBalance(balance) : formatInt(balance)
}

const toggleBalanceFormat = () => {
setFormatSats(prev => !prev)
if (!pref || !isBool(formatSats)) { return }
Expand Down Expand Up @@ -67,16 +62,16 @@ export default function Balance({ balance, nav }: IBalanceProps) {
styles.board,
{ borderColor: color.BORDER, backgroundColor: hi[highlight] }
]}>
<Logo size={hidden ? 100 : 60} style={{ marginTop: hidden ? 40 : 0, marginBottom: hidden ? 40 : 20 }} />
<Logo size={hidden.balance ? 100 : 60} style={{ marginTop: hidden.balance ? 40 : 0, marginBottom: hidden.balance ? 40 : 20 }} />
{/* balance */}
{!hidden &&
{!hidden.balance &&
<TouchableOpacity
style={styles.balanceWrap}
onPress={toggleBalanceFormat}
disabled={hidden}
disabled={hidden.balance}
>
<Text style={styles.balAmount}>
{showBalance()}
{formatSats ? formatBalance(balance) : formatInt(balance)}
</Text>
<View style={styles.balAssetNameWrap}>
<Text style={styles.balAssetName}>
Expand All @@ -88,7 +83,7 @@ export default function Balance({ balance, nav }: IBalanceProps) {
}
<Separator style={[styles.separator]} />
{/* latest 3 history entries */}
{history.length ?
{history.length && !hidden.txs ?
history.map(h => (
<HistoryEntry
key={h.timestamp}
Expand All @@ -104,11 +99,20 @@ export default function Balance({ balance, nav }: IBalanceProps) {
/>
))
:
<View style={{ padding: 10 }}>
<Txt txt={t('noTX')} styles={[globals(color).pressTxt, { color: mainColors.WHITE }]} />
</View>
!hidden.txs ?
<View style={{ padding: 10 }}>
<Txt txt={t('noTX')} styles={[globals(color).pressTxt, { color: mainColors.WHITE }]} />
</View>
:
null
}
{hidden.txs &&
<Txt
txt='Latest transactions hidden'
styles={[globals(color).pressTxt, { color: mainColors.WHITE, marginVertical: 50 }]}
/>
}
{history.length === 3 &&
{history.length === 3 && !hidden.txs &&
<TxtButton
txt={t('seeFullHistory')}
onPress={() => nav?.navigate('history')}
Expand Down
17 changes: 13 additions & 4 deletions src/context/Privacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import { STORE_KEYS } from '@store/consts'
import { createContext, useContext, useEffect, useState } from 'react'

const usePrivacy = () => {
const [hidden, setHidden] = useState(false)
const [hidden, setHidden] = useState({
balance: false,
txs: false
})
useEffect(() => {
void (async () => {
// init privacy preferences
const isHidden = await store.get(STORE_KEYS.hiddenBal)
setHidden(!!isHidden)
const [isHiddenBal, isHiddenTxs] = await Promise.all([
store.get(STORE_KEYS.hiddenBal),
store.get(STORE_KEYS.hiddenTxs)
])
setHidden({
balance: !!isHiddenBal,
txs: !!isHiddenTxs
})
})()
}, [])
return {
Expand All @@ -19,7 +28,7 @@ const usePrivacy = () => {
}
type usePrivacyType = ReturnType<typeof usePrivacy>
const PrivacyContext = createContext<usePrivacyType>({
hidden: false,
hidden: { balance: false, txs: false },
setHidden: () => l('')
})

Expand Down
48 changes: 34 additions & 14 deletions src/screens/Settings/Privacy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Screen from '@comps/Screen'
import Separator from '@comps/Separator'
import Txt from '@comps/Txt'
import { isIOS } from '@consts'
import type { TPrivacySettingsPageProps } from '@model/nav'
Expand All @@ -17,16 +18,24 @@ export default function PrivacySettings({ navigation, route }: TPrivacySettingsP
const { color, highlight } = useThemeContext()
const { hidden, setHidden } = usePrivacyContext()

const handleHidden = async () => {
if (hidden) {
setHidden(false)
const handleHiddenBalance = async () => {
setHidden({ balance: !hidden.balance, txs: hidden.txs })
if (hidden.balance) {
await store.delete(STORE_KEYS.hiddenBal)
return
}
setHidden(true)
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')
}

return (
<Screen
screenName={t('privacy')}
Expand All @@ -36,17 +45,29 @@ export default function PrivacySettings({ navigation, route }: TPrivacySettingsP
<Text style={[styles.subHeader, { color: color.TEXT }]}>
{t('general')}
</Text>
<View style={[globals(color).wrapContainer, styles.wrap]}>
<Txt txt={t('hideNuts', { ns: NS.common })} />
<Switch
trackColor={{ false: color.BORDER, true: hi[highlight] }}
thumbColor={color.TEXT}
onValueChange={handleHidden}
value={hidden}
/>
<View style={globals(color).wrapContainer}>
<View style={styles.wrap}>
<Txt txt={t('hideNuts', { ns: NS.common })} />
<Switch
trackColor={{ false: color.BORDER, true: hi[highlight] }}
thumbColor={color.TEXT}
onValueChange={handleHiddenBalance}
value={hidden.balance}
/>
</View>
<Separator />
<View style={styles.wrap}>
<Txt txt={t('hideLatestTxs', { ns: NS.common })} />
<Switch
trackColor={{ false: color.BORDER, true: hi[highlight] }}
thumbColor={color.TEXT}
onValueChange={handleHiddenTxs}
value={hidden.txs}
/>
</View>
</View>
<BottomNav navigation={navigation} route={route} />
</Screen>
</Screen >
)
}

Expand All @@ -61,7 +82,6 @@ const styles = StyleSheet.create({
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 20,
paddingVertical: isIOS ? 18 : 10
},
})
1 change: 1 addition & 0 deletions src/storage/store/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const STORE_KEYS = {
lang: 'settings_lang',
defaultMint: 'MINT_STORE=|:|=default_mint',
hiddenBal: 'privacy_balance',
hiddenTxs: 'privacy_txs',
latestHistory: 'history_latest'
}

Expand Down

0 comments on commit 007a228

Please sign in to comment.