Skip to content

Commit fd9d900

Browse files
committed
adds balance hiding functionality
1 parent 997b97b commit fd9d900

File tree

7 files changed

+178
-55
lines changed

7 files changed

+178
-55
lines changed

packages/mobile-app/app/(drawer)/account/account-settings/export-account/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function ExportAccount() {
1111
const [modalVisible, setModalVisible] = useState(false);
1212
const [exportType, setExportType] = useState<AccountFormat | null>(null);
1313
const [exportedContent, setExportedContent] = useState<string | null>(null);
14-
const [holdProgress, setHoldProgress] = useState(3);
14+
const [holdProgress, setHoldProgress] = useState(2);
1515
const holdTimerRef = useRef<NodeJS.Timeout | null>(null);
1616
const isHoldingRef = useRef(false);
1717

@@ -33,7 +33,7 @@ export default function ExportAccount() {
3333
const handleExport = async (format: AccountFormat) => {
3434
setExportType(format);
3535
setExportedContent(null);
36-
setHoldProgress(3);
36+
setHoldProgress(2);
3737
setModalVisible(true);
3838
};
3939

@@ -61,7 +61,7 @@ export default function ExportAccount() {
6161
holdTimerRef.current = null;
6262
}
6363
isHoldingRef.current = false;
64-
setHoldProgress(3);
64+
setHoldProgress(2);
6565
};
6666

6767
const handleReveal = async () => {

packages/mobile-app/app/(drawer)/account/account-settings/index.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {
66
Menu,
77
MenuItem,
88
Toggle,
9+
Text,
910
} from "@ui-kitten/components";
10-
import { StyleSheet } from "react-native";
11+
import { StyleSheet, View } from "react-native";
1112
import { Stack, useRouter } from "expo-router";
1213
import { useFacade } from "@/data/facades";
1314
import { CurrencyUtils } from "@ironfish/sdk";
@@ -47,14 +48,16 @@ const ACCOUNT_SETTINGS_ROUTES = {
4748
function getMenuItems({
4849
currentAccountName,
4950
currentAccountBalance,
51+
hideBalances,
5052
}: {
5153
currentAccountName: string;
5254
currentAccountBalance: string;
55+
hideBalances: boolean;
5356
}) {
5457
return Object.entries(ACCOUNT_SETTINGS_ROUTES).map(([key, route]) => {
5558
if (key === "accountSelect") {
5659
return {
57-
title: `${currentAccountName} (${currentAccountBalance} $IRON)`,
60+
title: `${currentAccountName} (${hideBalances ? "•••••" : currentAccountBalance} $IRON)`,
5861
href: route.href,
5962
};
6063
}
@@ -106,6 +109,7 @@ function AccountSettingsContent({ accountName }: { accountName: string }) {
106109
currentAccountBalance: CurrencyUtils.render(
107110
getAccountResult.data?.balances.iron.confirmed ?? "0",
108111
),
112+
hideBalances,
109113
});
110114

111115
const handleSelect = (index: number) => {
@@ -129,12 +133,26 @@ function AccountSettingsContent({ accountName }: { accountName: string }) {
129133
.concat(
130134
<MenuItem
131135
key="hide-balances"
132-
title="Hide Balances"
133-
accessoryRight={() => (
134-
<Toggle
135-
checked={hideBalances}
136-
onChange={onToggleHideBalances}
137-
/>
136+
title={(props) => (
137+
<Layout style={styles.tipContainer}>
138+
<View style={styles.textColumn}>
139+
<Text>Hide Balances</Text>
140+
<Text
141+
category="c1"
142+
appearance="hint"
143+
style={styles.tipText}
144+
>
145+
Tip: Long press on your balance to quickly toggle
146+
visibility
147+
</Text>
148+
</View>
149+
<View style={styles.toggleContainer}>
150+
<Toggle
151+
checked={hideBalances}
152+
onChange={onToggleHideBalances}
153+
/>
154+
</View>
155+
</Layout>
138156
)}
139157
/>,
140158
)}
@@ -172,7 +190,23 @@ const styles = StyleSheet.create({
172190
menu: {
173191
flex: 1,
174192
},
175-
toggle: {
176-
marginRight: 8,
193+
tipContainer: {
194+
flexDirection: "row",
195+
width: "100%",
196+
},
197+
textColumn: {
198+
flex: 1,
199+
paddingLeft: 12,
200+
paddingRight: 8,
201+
},
202+
toggleContainer: {
203+
justifyContent: "center",
204+
alignItems: "flex-end",
205+
paddingRight: 12,
206+
},
207+
tipText: {
208+
marginTop: 4,
209+
width: "80%",
210+
fontStyle: "italic",
177211
},
178212
});

packages/mobile-app/app/(drawer)/account/index.tsx

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StatusBar } from "expo-status-bar";
2-
import { useState } from "react";
2+
import { useState, useRef, useEffect } from "react";
33
import {
44
Layout,
55
Text,
@@ -12,7 +12,7 @@ import {
1212
Spinner,
1313
Modal,
1414
} from "@ui-kitten/components";
15-
import { StyleSheet, View } from "react-native";
15+
import { StyleSheet, View, Pressable } from "react-native";
1616
import { setStringAsync } from "expo-clipboard";
1717
import Animated, {
1818
useAnimatedScrollHandler,
@@ -28,6 +28,8 @@ import { CurrencyUtils } from "@ironfish/sdk";
2828
import { CONFIRMATIONS } from "@/data/constants";
2929
import { AssetRow } from "@/components/account/AssetRow";
3030
import { TransactionRow } from "@/components/account/TransactionRow";
31+
import { useHideBalances } from "@/hooks/useHideBalances";
32+
import { SettingsKey } from "@/data/settings/db";
3133

3234
const ReceiveIcon = (props: IconProps) => (
3335
<Icon {...props} name="download-outline" />
@@ -46,11 +48,14 @@ interface Balance {
4648
}
4749

4850
export default function Balances() {
51+
const hideBalances = useHideBalances();
52+
const longPressTimerRef = useRef<NodeJS.Timeout | null>(null);
4953
const facade = useFacade();
5054
const { account, accountName, isLoading } = useAccount();
5155
const scrollYOffset = useSharedValue(0);
5256
const [selectedIndex, setSelectedIndex] = useState(0);
5357
const [addressModalVisible, setAddressModalVisible] = useState(false);
58+
const { mutate: setAppSetting } = facade.setAppSetting.useMutation();
5459

5560
const scrollHandler = useAnimatedScrollHandler((event) => {
5661
scrollYOffset.value = event.contentOffset.y;
@@ -105,6 +110,30 @@ export default function Balances() {
105110
},
106111
);
107112

113+
const handlePressIn = () => {
114+
longPressTimerRef.current = setTimeout(() => {
115+
setAppSetting({
116+
key: SettingsKey.HideBalances,
117+
value: hideBalances ? "false" : "true",
118+
});
119+
}, 3000);
120+
};
121+
122+
const handlePressOut = () => {
123+
if (longPressTimerRef.current) {
124+
clearTimeout(longPressTimerRef.current);
125+
longPressTimerRef.current = null;
126+
}
127+
};
128+
129+
useEffect(() => {
130+
return () => {
131+
if (longPressTimerRef.current) {
132+
clearTimeout(longPressTimerRef.current);
133+
}
134+
};
135+
}, []);
136+
108137
if (isLoading || !account) {
109138
return (
110139
<SafeAreaView>
@@ -178,44 +207,48 @@ export default function Balances() {
178207
paddingTop: 40,
179208
}}
180209
>
181-
<Layout style={styles.headerBalance}>
182-
<Text category="h1" style={styles.balanceAmount}>
183-
{CurrencyUtils.render(
184-
account?.balances.iron.confirmed ?? "0",
185-
)}
186-
</Text>
187-
<Text category="s1" appearance="hint">
188-
{getIronAsset.data?.verification.status === "verified"
189-
? getIronAsset.data.verification.symbol
190-
: (getIronAsset.data?.name ?? "IRON")}
191-
</Text>
192-
193-
<Layout style={styles.actionButtons}>
194-
<Button
195-
appearance="ghost"
196-
accessoryLeft={ReceiveIcon}
197-
style={styles.actionButton}
198-
onPress={() => setAddressModalVisible(true)}
199-
>
200-
Receive
201-
</Button>
202-
<Button
203-
appearance="ghost"
204-
accessoryLeft={SendIcon}
205-
style={styles.actionButton}
206-
onPress={() => router.push("/(drawer)/account/send")}
207-
>
208-
Send
209-
</Button>
210-
<Button
211-
appearance="ghost"
212-
accessoryLeft={BridgeIcon}
213-
style={styles.actionButton}
214-
onPress={() => router.push("/(drawer)/account/bridge")}
215-
>
216-
Bridge
217-
</Button>
210+
<Pressable onPressIn={handlePressIn} onPressOut={handlePressOut}>
211+
<Layout style={styles.headerBalance}>
212+
<Text category="h1" style={styles.balanceAmount}>
213+
{hideBalances
214+
? "•••••"
215+
: CurrencyUtils.render(
216+
account?.balances.iron.confirmed ?? "0",
217+
)}
218+
</Text>
219+
<Text category="s1" appearance="hint">
220+
{getIronAsset.data?.verification.status === "verified"
221+
? getIronAsset.data.verification.symbol
222+
: (getIronAsset.data?.name ?? "IRON")}
223+
</Text>
218224
</Layout>
225+
</Pressable>
226+
227+
<Layout style={styles.actionButtons}>
228+
<Button
229+
appearance="ghost"
230+
accessoryLeft={ReceiveIcon}
231+
style={styles.actionButton}
232+
onPress={() => setAddressModalVisible(true)}
233+
>
234+
Receive
235+
</Button>
236+
<Button
237+
appearance="ghost"
238+
accessoryLeft={SendIcon}
239+
style={styles.actionButton}
240+
onPress={() => router.push("/(drawer)/account/send")}
241+
>
242+
Send
243+
</Button>
244+
<Button
245+
appearance="ghost"
246+
accessoryLeft={BridgeIcon}
247+
style={styles.actionButton}
248+
onPress={() => router.push("/(drawer)/account/bridge")}
249+
>
250+
Bridge
251+
</Button>
219252
</Layout>
220253
</Animated.View>
221254

@@ -265,6 +298,9 @@ export default function Balances() {
265298
}
266299
amount={CurrencyUtils.render(
267300
account.balances.iron.confirmed,
301+
hideBalances,
302+
account.balances.iron.assetId,
303+
getIronAsset.data?.verification,
268304
)}
269305
verified={
270306
getIronAsset.data?.verification.status === "verified"
@@ -274,6 +310,7 @@ export default function Balances() {
274310
? getIronAsset.data.verification.logoURI
275311
: undefined
276312
}
313+
forceHideBalance={hideBalances}
277314
/>
278315

279316
{/* Custom Assets */}
@@ -289,7 +326,7 @@ export default function Balances() {
289326
}
290327
amount={CurrencyUtils.render(
291328
balance.confirmed,
292-
false,
329+
hideBalances,
293330
balance.assetId,
294331
asset?.verification.status === "verified"
295332
? asset.verification
@@ -301,6 +338,7 @@ export default function Balances() {
301338
? asset.verification.logoURI
302339
: undefined
303340
}
341+
forceHideBalance={hideBalances}
304342
/>
305343
);
306344
})}

packages/mobile-app/components/account/AssetRow.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { Layout, Text, Card } from "@ui-kitten/components";
22
import { Image } from "expo-image";
33
import { StyleSheet } from "react-native";
4+
import { useHideBalances } from "@/hooks/useHideBalances";
45

56
export function AssetRow({
67
name,
78
amount,
89
verified,
910
image,
11+
forceHideBalance,
1012
}: {
1113
name: string;
1214
amount: string;
1315
verified: boolean;
1416
image?: string;
17+
forceHideBalance?: boolean;
1518
}) {
19+
const hideBalancesGlobal = useHideBalances();
20+
const hideBalances =
21+
forceHideBalance !== undefined ? forceHideBalance : hideBalancesGlobal;
22+
1623
return (
1724
<Card style={styles.assetCard}>
1825
<Layout style={styles.assetCardContent}>
@@ -24,7 +31,7 @@ export function AssetRow({
2431
{name} {verified ? "(Verified)" : ""}
2532
</Text>
2633
<Text category="p2" appearance="hint">
27-
{amount}
34+
{hideBalances ? "•••••" : amount}
2835
</Text>
2936
</Layout>
3037
</Layout>

packages/mobile-app/components/account/TransactionRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Image } from "expo-image";
1111
import { ReceiveArrow } from "@/svgs/ReceiveArrow";
1212
import { SendArrow } from "@/svgs/SendArrow";
1313
import * as CurrencyUtils from "@/utils/currency";
14+
import { useHideBalances } from "@/hooks/useHideBalances";
1415

1516
function renderTransactionType(txType: TransactionType): string {
1617
switch (txType) {
@@ -94,6 +95,7 @@ const assetBalanceCompare = (
9495
export function TransactionRow({ transaction }: { transaction: Transaction }) {
9596
const facade = useFacade();
9697
const router = useRouter();
98+
const hideBalances = useHideBalances();
9799

98100
const getAssets = useQueries({
99101
queries:
@@ -196,7 +198,7 @@ export function TransactionRow({ transaction }: { transaction: Transaction }) {
196198
color: delta.delta.startsWith("-") ? "black" : "#5BA54C",
197199
}}
198200
>
199-
{delta.delta}
201+
{hideBalances ? "•••••" : delta.delta}
200202
</Text>
201203
</Layout>
202204
);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useFacade } from "@/data/facades";
2+
import { useEffect, useState } from "react";
3+
4+
/**
5+
* Hook that provides the current hide balances setting
6+
* @returns The current hide balances state
7+
*/
8+
export function useHideBalances(): boolean {
9+
const facade = useFacade();
10+
const [hideBalances, setHideBalances] = useState(false);
11+
const appSettings = facade.getAppSettings.useQuery();
12+
13+
useEffect(() => {
14+
setHideBalances(appSettings.data?.hideBalances === "true");
15+
}, [appSettings.data?.hideBalances]);
16+
17+
return hideBalances;
18+
}

0 commit comments

Comments
 (0)