Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

Commit 29fa2bf

Browse files
Merge pull request #1498 from synonymdev/feat/wallet-balance-hide-toast
feat(wallet): Show info toast when hiding balance
2 parents c3cc276 + 279cab8 commit 29fa2bf

9 files changed

Lines changed: 120 additions & 11 deletions

File tree

src/components/BalanceHeader.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Trans, useTranslation } from 'react-i18next';
66
import { Caption13Up } from '../styles/text';
77
import { EyeIcon } from '../styles/icons';
88
import Money from './Money';
9-
import { useBalance, useSwitchUnit } from '../hooks/wallet';
9+
import { useBalance, useSwitchUnitAnnounced } from '../hooks/wallet';
1010
import { updateSettings } from '../store/slices/settings';
1111
import {
1212
primaryUnitSelector,
@@ -18,7 +18,7 @@ import {
1818
*/
1919
const BalanceHeader = (): ReactElement => {
2020
const { t } = useTranslation('wallet');
21-
const [_, switchUnit] = useSwitchUnit();
21+
const onSwitchUnit = useSwitchUnitAnnounced();
2222
const { totalBalance, claimableBalance } = useBalance();
2323
const dispatch = useAppDispatch();
2424
const unit = useAppSelector(primaryUnitSelector);
@@ -57,7 +57,7 @@ const BalanceHeader = (): ReactElement => {
5757
<TouchableOpacity
5858
style={styles.row}
5959
testID="TotalBalance"
60-
onPress={switchUnit}>
60+
onPress={onSwitchUnit}>
6161
<Money
6262
sats={totalBalance}
6363
unit={unit}

src/hooks/wallet.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {
1313
selectedNetworkSelector,
1414
selectedWalletSelector,
1515
} from '../store/reselect/wallet';
16+
import { useCurrency } from './displayValues';
17+
import { useTranslation } from 'react-i18next';
18+
import i18n from '../utils/i18n';
19+
import { showToast } from '../utils/notifications';
20+
import { ignoresSwitchUnitToastSelector } from '../store/reselect/user';
21+
import { ignoreSwitchUnitToast } from '../store/slices/user';
1622

1723
/**
1824
* Retrieves wallet balances for the currently selected wallet and network.
@@ -102,3 +108,36 @@ export const useSwitchUnit = (): [EUnit, () => void] => {
102108

103109
return [nextUnit, switchUnit];
104110
};
111+
112+
export function useSwitchUnitAnnounced(): () => void {
113+
const dispatch = useAppDispatch();
114+
const [nextUnit, switchUnit] = useSwitchUnit();
115+
const unit = useAppSelector(primaryUnitSelector);
116+
const ignoresSwitchUnitToast = useAppSelector(ignoresSwitchUnitToastSelector);
117+
const { fiatTicker } = useCurrency();
118+
const { t } = useTranslation('wallet');
119+
120+
const toUnitText: (unit: EUnit) => string = (u) => {
121+
if (u === EUnit.BTC) {
122+
return i18n.t('settings:general.unit_bitcoin');
123+
}
124+
if (u === EUnit.satoshi) {
125+
return i18n.t('settings:general.unit_satoshis');
126+
}
127+
return fiatTicker;
128+
};
129+
130+
return (): void => {
131+
switchUnit();
132+
if (!ignoresSwitchUnitToast) {
133+
showToast({
134+
type: 'info',
135+
title: t('balance_unit_switched_title', { unit: toUnitText(nextUnit) }),
136+
description: t('balance_unit_switched_message', {
137+
unit: toUnitText(unit),
138+
}),
139+
});
140+
dispatch(ignoreSwitchUnitToast());
141+
}
142+
};
143+
}

src/screens/Wallets/WalletsDetail/index.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { Title } from '../../../styles/text';
3737
import NavigationHeader from '../../../components/NavigationHeader';
3838
import useColors from '../../../hooks/colors';
3939
import { useAppDispatch, useAppSelector } from '../../../hooks/redux';
40-
import { useBalance, useSwitchUnit } from '../../../hooks/wallet';
40+
import { useBalance, useSwitchUnitAnnounced } from '../../../hooks/wallet';
4141
import ActivityList from '../../Activity/ActivityList';
4242
import BitcoinBreakdown from './BitcoinBreakdown';
4343
import SafeAreaInset from '../../../components/SafeAreaInset';
@@ -51,6 +51,10 @@ import {
5151
import { capitalize } from '../../../utils/helpers';
5252
import DetectSwipe from '../../../components/DetectSwipe';
5353
import type { WalletScreenProps } from '../../../navigation/types';
54+
import { showToast } from '../../../utils/notifications';
55+
import { useTranslation } from 'react-i18next';
56+
import { ignoresHideBalanceToastSelector } from '../../../store/reselect/user';
57+
import { ignoreHideBalanceToast } from '../../../store/slices/user';
5458

5559
const updateHeight = ({ height, toValue = 0, duration = 250 }): void => {
5660
try {
@@ -94,14 +98,18 @@ const WalletsDetail = ({
9498
enableSwipeToHideBalanceSelector,
9599
);
96100
const hideBalance = useAppSelector(hideBalanceSelector);
97-
const [_, switchUnit] = useSwitchUnit();
101+
const ignoresHideBalanceToast = useAppSelector(
102+
ignoresHideBalanceToastSelector,
103+
);
104+
const onSwitchUnit = useSwitchUnitAnnounced();
98105
const colors = useColors();
99106
const size = useSharedValue({ width: 0, height: 0 });
100107
const title = capitalize(assetType);
101108
const [showDetails, setShowDetails] = useState(true);
102109
const [radiusContainerHeight, setRadiusContainerHeight] = useState(400);
103110
const [headerHeight, setHeaderHeight] = useState(0);
104111
const height = useSharedValue(0);
112+
const { t } = useTranslation('wallet');
105113

106114
const activityPadding = useMemo(
107115
() => ({ paddingTop: radiusContainerHeight, paddingBottom: 230 }),
@@ -113,7 +121,16 @@ const WalletsDetail = ({
113121
}, [height, headerHeight]);
114122

115123
const toggleHideBalance = (): void => {
116-
dispatch(updateSettings({ hideBalance: !hideBalance }));
124+
const enabled = !hideBalance;
125+
dispatch(updateSettings({ hideBalance: enabled }));
126+
if (!ignoresHideBalanceToast && enabled) {
127+
showToast({
128+
type: 'info',
129+
title: t('balance_hidden_title'),
130+
description: t('balance_hidden_message'),
131+
});
132+
dispatch(ignoreHideBalanceToast());
133+
}
117134
};
118135

119136
const onScroll = useCallback(
@@ -200,7 +217,7 @@ const WalletsDetail = ({
200217
style={styles.cell}
201218
entering={FadeIn}
202219
exiting={FadeOut}>
203-
<TouchableOpacity onPress={switchUnit}>
220+
<TouchableOpacity onPress={onSwitchUnit}>
204221
<Money
205222
sats={totalBalance}
206223
enableHide={true}
@@ -223,7 +240,7 @@ const WalletsDetail = ({
223240
onSwipeLeft={toggleHideBalance}
224241
onSwipeRight={toggleHideBalance}>
225242
<TouchableOpacity
226-
onPress={switchUnit}
243+
onPress={onSwitchUnit}
227244
style={styles.largeValueContainer}>
228245
<Money
229246
sats={totalBalance}

src/screens/Wallets/index.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import {
3434
hideOnboardingMessageSelector,
3535
showWidgetsSelector,
3636
} from '../../store/reselect/settings';
37+
import { showToast } from '../../utils/notifications';
38+
import { useTranslation } from 'react-i18next';
39+
import { ignoresHideBalanceToastSelector } from '../../store/reselect/user';
40+
import { ignoreHideBalanceToast } from '../../store/slices/user';
3741

3842
// Workaround for crash on Android
3943
// https://github.com/software-mansion/react-native-reanimated/issues/4306#issuecomment-1538184321
@@ -51,6 +55,9 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
5155
enableSwipeToHideBalanceSelector,
5256
);
5357
const hideBalance = useAppSelector(hideBalanceSelector);
58+
const ignoresHideBalanceToast = useAppSelector(
59+
ignoresHideBalanceToastSelector,
60+
);
5461
const hideOnboardingSetting = useAppSelector(hideOnboardingMessageSelector);
5562
const showWidgets = useAppSelector(showWidgetsSelector);
5663
const widgets = useAppSelector(widgetsSelector);
@@ -59,6 +66,7 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
5966
const empty = useMemo(() => {
6067
return noTransactions && Object.values(widgets).length === 0;
6168
}, [noTransactions, widgets]);
69+
const { t } = useTranslation('wallet');
6270

6371
// tell WalletNavigator that this screen is focused
6472
useFocusEffect(
@@ -69,7 +77,16 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
6977
);
7078

7179
const toggleHideBalance = (): void => {
72-
dispatch(updateSettings({ hideBalance: !hideBalance }));
80+
const enabled = !hideBalance;
81+
dispatch(updateSettings({ hideBalance: enabled }));
82+
if (!ignoresHideBalanceToast && enabled) {
83+
showToast({
84+
type: 'info',
85+
title: t('balance_hidden_title'),
86+
description: t('balance_hidden_message'),
87+
});
88+
dispatch(ignoreHideBalanceToast());
89+
}
7390
};
7491

7592
const navigateToScanner = (): void => {

src/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const persistConfig = {
4040
key: 'root',
4141
storage: mmkvStorage,
4242
// increase version after store shape changes
43-
version: 31,
43+
version: 32,
4444
stateReconciler: autoMergeLevel2,
4545
blacklist: ['receive', 'ui'],
4646
migrate: createMigrate(migrations, { debug: __ENABLE_MIGRATION_DEBUG__ }),

src/store/migrations/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ const migrations = {
333333
},
334334
};
335335
},
336+
32: (state): PersistedState => {
337+
return {
338+
...state,
339+
user: {
340+
...state.user,
341+
ignoresHideBalanceToast: false,
342+
ignoresSwitchUnitToast: false,
343+
},
344+
};
345+
},
336346
};
337347

338348
export default migrations;

src/store/reselect/user.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,13 @@ export const betaRiskAcceptedSelector = createSelector(
5353
[userState],
5454
(user): boolean => user.betaRiskAccepted,
5555
);
56+
57+
export const ignoresHideBalanceToastSelector = createSelector(
58+
[userState],
59+
(user): boolean => user.ignoresHideBalanceToast,
60+
);
61+
62+
export const ignoresSwitchUnitToastSelector = createSelector(
63+
[userState],
64+
(user): boolean => user.ignoresSwitchUnitToast,
65+
);

src/store/slices/user.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export type TUser = {
1313
lightningSettingUpStep: number;
1414
requiresRemoteRestore: boolean;
1515
startCoopCloseTimestamp: number;
16+
ignoresHideBalanceToast: boolean;
17+
ignoresSwitchUnitToast: boolean;
1618
};
1719

1820
export const initialUserState: TUser = {
@@ -26,6 +28,8 @@ export const initialUserState: TUser = {
2628
lightningSettingUpStep: 0,
2729
requiresRemoteRestore: false,
2830
startCoopCloseTimestamp: 0,
31+
ignoresHideBalanceToast: false,
32+
ignoresSwitchUnitToast: false,
2933
};
3034

3135
export const userSlice = createSlice({
@@ -61,6 +65,12 @@ export const userSlice = createSlice({
6165
acceptBetaRisk: (state) => {
6266
state.betaRiskAccepted = true;
6367
},
68+
ignoreHideBalanceToast: (state) => {
69+
state.ignoresHideBalanceToast = true;
70+
},
71+
ignoreSwitchUnitToast: (state) => {
72+
state.ignoresSwitchUnitToast = true;
73+
},
6474
resetUserState: () => initialUserState,
6575
},
6676
});
@@ -77,6 +87,8 @@ export const {
7787
clearCoopCloseTimer,
7888
verifyBackup,
7989
acceptBetaRisk,
90+
ignoreHideBalanceToast,
91+
ignoreSwitchUnitToast,
8092
resetUserState,
8193
} = actions;
8294

src/utils/i18n/locales/en/wallet.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,9 @@
191191
"lnurl_w_success_title": "Success",
192192
"lnurl_w_success_description": "Withdraw Requested Successful",
193193
"lnurl_p_title": "Send Bitcoin",
194-
"lnurl_p_max": "Maximum amount"
194+
"lnurl_p_max": "Maximum amount",
195+
"balance_hidden_title" : "Wallet Balance Hidden",
196+
"balance_hidden_message" : "Swipe your wallet balance to reveal it again.",
197+
"balance_unit_switched_title" : "Switched to {unit}",
198+
"balance_unit_switched_message" : "Tap your wallet balance to switch it back to {unit}."
195199
}

0 commit comments

Comments
 (0)