Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/BalanceHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { Caption13Up } from '../styles/text';
import { EyeIcon } from '../styles/icons';
import Money from './Money';
import { useBalance, useSwitchUnit } from '../hooks/wallet';
import { useBalance, useSwitchUnitAnnounced } from '../hooks/wallet';
import { updateSettings } from '../store/slices/settings';
import {
primaryUnitSelector,
Expand All @@ -18,7 +18,7 @@ import {
*/
const BalanceHeader = (): ReactElement => {
const { t } = useTranslation('wallet');
const [_, switchUnit] = useSwitchUnit();
const onSwitchUnit = useSwitchUnitAnnounced();
const { totalBalance, claimableBalance } = useBalance();
const dispatch = useAppDispatch();
const unit = useAppSelector(primaryUnitSelector);
Expand Down Expand Up @@ -57,7 +57,7 @@ const BalanceHeader = (): ReactElement => {
<TouchableOpacity
style={styles.row}
testID="TotalBalance"
onPress={switchUnit}>
onPress={onSwitchUnit}>
<Money
sats={totalBalance}
unit={unit}
Expand Down
39 changes: 39 additions & 0 deletions src/hooks/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import {
selectedNetworkSelector,
selectedWalletSelector,
} from '../store/reselect/wallet';
import { useCurrency } from './displayValues';
import { useTranslation } from 'react-i18next';
import i18n from '../utils/i18n';
import { showToast } from '../utils/notifications';
import { ignoresSwitchUnitToastSelector } from '../store/reselect/user';
import { ignoreSwitchUnitToast } from '../store/slices/user';

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

return [nextUnit, switchUnit];
};

export function useSwitchUnitAnnounced(): () => void {
const dispatch = useAppDispatch();
const [nextUnit, switchUnit] = useSwitchUnit();
const unit = useAppSelector(primaryUnitSelector);
const ignoresSwitchUnitToast = useAppSelector(ignoresSwitchUnitToastSelector);
const { fiatTicker } = useCurrency();
const { t } = useTranslation('wallet');

const toUnitText: (unit: EUnit) => string = (u) => {
if (u === EUnit.BTC) {
return i18n.t('settings:general.unit_bitcoin');
}
if (u === EUnit.satoshi) {
return i18n.t('settings:general.unit_satoshis');
}
return fiatTicker;
};

return (): void => {
switchUnit();
if (!ignoresSwitchUnitToast) {
showToast({
type: 'info',
title: t('balance_unit_switched_title', { unit: toUnitText(nextUnit) }),
description: t('balance_unit_switched_message', {
unit: toUnitText(unit),
}),
});
dispatch(ignoreSwitchUnitToast());
}
};
}
8 changes: 4 additions & 4 deletions src/screens/Wallets/WalletsDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { Title } from '../../../styles/text';
import NavigationHeader from '../../../components/NavigationHeader';
import useColors from '../../../hooks/colors';
import { useAppDispatch, useAppSelector } from '../../../hooks/redux';
import { useBalance, useSwitchUnit } from '../../../hooks/wallet';
import { useBalance, useSwitchUnitAnnounced } from '../../../hooks/wallet';
import ActivityList from '../../Activity/ActivityList';
import BitcoinBreakdown from './BitcoinBreakdown';
import SafeAreaInset from '../../../components/SafeAreaInset';
Expand Down Expand Up @@ -101,7 +101,7 @@ const WalletsDetail = ({
const ignoresHideBalanceToast = useAppSelector(
ignoresHideBalanceToastSelector,
);
const [_, switchUnit] = useSwitchUnit();
const onSwitchUnit = useSwitchUnitAnnounced();
const colors = useColors();
const size = useSharedValue({ width: 0, height: 0 });
const title = capitalize(assetType);
Expand Down Expand Up @@ -217,7 +217,7 @@ const WalletsDetail = ({
style={styles.cell}
entering={FadeIn}
exiting={FadeOut}>
<TouchableOpacity onPress={switchUnit}>
<TouchableOpacity onPress={onSwitchUnit}>
<Money
sats={totalBalance}
enableHide={true}
Expand All @@ -240,7 +240,7 @@ const WalletsDetail = ({
onSwipeLeft={toggleHideBalance}
onSwipeRight={toggleHideBalance}>
<TouchableOpacity
onPress={switchUnit}
onPress={onSwitchUnit}
style={styles.largeValueContainer}>
<Money
sats={totalBalance}
Expand Down
1 change: 1 addition & 0 deletions src/store/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ const migrations = {
user: {
...state.user,
ignoresHideBalanceToast: false,
ignoresSwitchUnitToast: false,
},
};
},
Expand Down
5 changes: 5 additions & 0 deletions src/store/reselect/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ export const ignoresHideBalanceToastSelector = createSelector(
[userState],
(user): boolean => user.ignoresHideBalanceToast,
);

export const ignoresSwitchUnitToastSelector = createSelector(
[userState],
(user): boolean => user.ignoresSwitchUnitToast,
);
6 changes: 6 additions & 0 deletions src/store/slices/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type TUser = {
requiresRemoteRestore: boolean;
startCoopCloseTimestamp: number;
ignoresHideBalanceToast: boolean;
ignoresSwitchUnitToast: boolean;
};

export const initialUserState: TUser = {
Expand All @@ -28,6 +29,7 @@ export const initialUserState: TUser = {
requiresRemoteRestore: false,
startCoopCloseTimestamp: 0,
ignoresHideBalanceToast: false,
ignoresSwitchUnitToast: false,
};

export const userSlice = createSlice({
Expand Down Expand Up @@ -66,6 +68,9 @@ export const userSlice = createSlice({
ignoreHideBalanceToast: (state) => {
state.ignoresHideBalanceToast = true;
},
ignoreSwitchUnitToast: (state) => {
state.ignoresSwitchUnitToast = true;
},
resetUserState: () => initialUserState,
},
});
Expand All @@ -83,6 +88,7 @@ export const {
verifyBackup,
acceptBetaRisk,
ignoreHideBalanceToast,
ignoreSwitchUnitToast,
resetUserState,
} = actions;

Expand Down
4 changes: 3 additions & 1 deletion src/utils/i18n/locales/en/wallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,7 @@
"lnurl_p_title": "Send Bitcoin",
"lnurl_p_max": "Maximum amount",
"balance_hidden_title" : "Wallet Balance Hidden",
"balance_hidden_message" : "Swipe your wallet balance to reveal it again."
"balance_hidden_message" : "Swipe your wallet balance to reveal it again.",
"balance_unit_switched_title" : "Switched to {unit}",
"balance_unit_switched_message" : "Tap your wallet balance to switch it back to {unit}."
}