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

Commit 279cab8

Browse files
authored
feat(wallet): Show info toast when switching balance unit
2 parents 95628a5 + 581b1bf commit 279cab8

7 files changed

Lines changed: 61 additions & 8 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: 4 additions & 4 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';
@@ -101,7 +101,7 @@ const WalletsDetail = ({
101101
const ignoresHideBalanceToast = useAppSelector(
102102
ignoresHideBalanceToastSelector,
103103
);
104-
const [_, switchUnit] = useSwitchUnit();
104+
const onSwitchUnit = useSwitchUnitAnnounced();
105105
const colors = useColors();
106106
const size = useSharedValue({ width: 0, height: 0 });
107107
const title = capitalize(assetType);
@@ -217,7 +217,7 @@ const WalletsDetail = ({
217217
style={styles.cell}
218218
entering={FadeIn}
219219
exiting={FadeOut}>
220-
<TouchableOpacity onPress={switchUnit}>
220+
<TouchableOpacity onPress={onSwitchUnit}>
221221
<Money
222222
sats={totalBalance}
223223
enableHide={true}
@@ -240,7 +240,7 @@ const WalletsDetail = ({
240240
onSwipeLeft={toggleHideBalance}
241241
onSwipeRight={toggleHideBalance}>
242242
<TouchableOpacity
243-
onPress={switchUnit}
243+
onPress={onSwitchUnit}
244244
style={styles.largeValueContainer}>
245245
<Money
246246
sats={totalBalance}

src/store/migrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ const migrations = {
339339
user: {
340340
...state.user,
341341
ignoresHideBalanceToast: false,
342+
ignoresSwitchUnitToast: false,
342343
},
343344
};
344345
},

src/store/reselect/user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ export const ignoresHideBalanceToastSelector = createSelector(
5858
[userState],
5959
(user): boolean => user.ignoresHideBalanceToast,
6060
);
61+
62+
export const ignoresSwitchUnitToastSelector = createSelector(
63+
[userState],
64+
(user): boolean => user.ignoresSwitchUnitToast,
65+
);

src/store/slices/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type TUser = {
1414
requiresRemoteRestore: boolean;
1515
startCoopCloseTimestamp: number;
1616
ignoresHideBalanceToast: boolean;
17+
ignoresSwitchUnitToast: boolean;
1718
};
1819

1920
export const initialUserState: TUser = {
@@ -28,6 +29,7 @@ export const initialUserState: TUser = {
2829
requiresRemoteRestore: false,
2930
startCoopCloseTimestamp: 0,
3031
ignoresHideBalanceToast: false,
32+
ignoresSwitchUnitToast: false,
3133
};
3234

3335
export const userSlice = createSlice({
@@ -66,6 +68,9 @@ export const userSlice = createSlice({
6668
ignoreHideBalanceToast: (state) => {
6769
state.ignoresHideBalanceToast = true;
6870
},
71+
ignoreSwitchUnitToast: (state) => {
72+
state.ignoresSwitchUnitToast = true;
73+
},
6974
resetUserState: () => initialUserState,
7075
},
7176
});
@@ -83,6 +88,7 @@ export const {
8388
verifyBackup,
8489
acceptBetaRisk,
8590
ignoreHideBalanceToast,
91+
ignoreSwitchUnitToast,
8692
resetUserState,
8793
} = actions;
8894

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,7 @@
193193
"lnurl_p_title": "Send Bitcoin",
194194
"lnurl_p_max": "Maximum amount",
195195
"balance_hidden_title" : "Wallet Balance Hidden",
196-
"balance_hidden_message" : "Swipe your wallet balance to reveal it again."
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}."
197199
}

0 commit comments

Comments
 (0)