Skip to content

Commit

Permalink
Add the ability to hide amounts on overview screen
Browse files Browse the repository at this point in the history
Long-press on the balance to activate. There is also a setting
for it.
  • Loading branch information
hsjoberg committed Feb 16, 2024
1 parent 6b41fd4 commit a57c3dd
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 155 deletions.
3 changes: 3 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@
},
"mapTheme": {
"title": "Set Map theme"
},
"hideAmountsEnabled": {
"title": "Hide amounts"
}
},
"wallet": {
Expand Down
34 changes: 31 additions & 3 deletions src/components/TransactionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import { ITransaction } from "../storage/database/transaction";
import { blixtTheme } from ".././native-base-theme/variables/commonColor";
import { capitalize, formatISO, isLong } from "../utils";
import { extractDescription } from "../utils/NameDesc";
import { IBitcoinUnits, formatBitcoin, convertBitcoinToFiat } from "../utils/bitcoin-units";
import {
IBitcoinUnits,
formatBitcoin,
convertBitcoinToFiat,
getUnitNice,
} from "../utils/bitcoin-units";
import { useStoreState } from "../state/store";
import { getLightningService } from "../utils/lightning-services";
import { fontFactor, fontFactorSubtle, zoomed } from "../utils/scale";
import BigNumber from "bignumber.js";

interface IProps {
onPress: (id: string) => void;
Expand All @@ -26,6 +32,8 @@ export default function TransactionCard({ onPress, transaction, unit }: IProps)
const fiatUnit = useStoreState((store) => store.settings.fiatUnit);
const currentRate = useStoreState((store) => store.fiat.currentRate);
const preferFiat = useStoreState((store) => store.settings.preferFiat);
const hideAmountsEnabled = useStoreState((store) => store.settings.hideAmountsEnabled);
const bitcoinUnit = useStoreState((store) => store.settings.bitcoinUnit);

let transactionValue: Long;
if (isLong(amtPaidSat) && amtPaidSat.greaterThan(0)) {
Expand Down Expand Up @@ -108,8 +116,28 @@ export default function TransactionCard({ onPress, transaction, unit }: IProps)
{transactionValue.notEquals(0) && (
<>
{positive ? "+" : ""}
{!preferFiat && formatBitcoin(transactionValue, unit)}
{preferFiat && convertBitcoinToFiat(transactionValue, currentRate, fiatUnit)}

{!hideAmountsEnabled && (
<>
{!preferFiat && formatBitcoin(transactionValue, unit)}
{preferFiat &&
convertBitcoinToFiat(transactionValue, currentRate, fiatUnit)}
</>
)}
{hideAmountsEnabled && (
<>
{!preferFiat && (
<>
{!positive ? "-" : ""}●●● {getUnitNice(new BigNumber(2), bitcoinUnit)}
</>
)}
{preferFiat && (
<>
{!positive ? "-" : ""}●●● {fiatUnit}
</>
)}
</>
)}
</>
)}
</Text>
Expand Down
13 changes: 13 additions & 0 deletions src/state/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface ISettingsModel {
changeLightningBoxServer: Thunk<ISettingsModel, string>;
changeLightningBoxAddress: Thunk<ISettingsModel, string>;
changeLightningBoxLnurlPayDesc: Thunk<ISettingsModel, string>;
changeHideAmountsEnabled: Thunk<ISettingsModel, boolean>;

setBitcoinUnit: Action<ISettingsModel, keyof IBitcoinUnits>;
setFiatUnit: Action<ISettingsModel, keyof IFiatRates>;
Expand Down Expand Up @@ -141,6 +142,7 @@ export interface ISettingsModel {
setLightningBoxServer: Action<ISettingsModel, string>;
setLightningBoxAddress: Action<ISettingsModel, string>;
SetLightningBoxLnurlPayDesc: Action<ISettingsModel, string>;
setHideAmountsEnabled: Action<ISettingsModel, boolean>;

bitcoinUnit: keyof IBitcoinUnits;
fiatUnit: keyof IFiatRates;
Expand Down Expand Up @@ -189,6 +191,7 @@ export interface ISettingsModel {
lightningBoxServer: string;
lightningBoxAddress: string;
lightningBoxLnurlPayDesc: string;
hideAmountsEnabled: boolean;
}

export const settings: ISettingsModel = {
Expand Down Expand Up @@ -283,6 +286,7 @@ export const settings: ISettingsModel = {
actions.SetLightningBoxLnurlPayDesc(
(await getItem(StorageItem.lightningBoxLnurlPayDesc)) ?? DEFAULT_LIGHTNINGBOX_LNURLPDESC,
);
actions.setHideAmountsEnabled((await getItemObject(StorageItem.hideAmountsEnabled)) ?? false);

log.d("Done");
}),
Expand Down Expand Up @@ -526,6 +530,11 @@ export const settings: ISettingsModel = {
actions.SetLightningBoxLnurlPayDesc(payload);
}),

changeHideAmountsEnabled: thunk(async (actions, payload) => {
await setItemObject(StorageItem.hideAmountsEnabled, payload);
actions.setHideAmountsEnabled(payload);
}),

setBitcoinUnit: action((state, payload) => {
state.bitcoinUnit = payload;
}),
Expand Down Expand Up @@ -667,6 +676,9 @@ export const settings: ISettingsModel = {
SetLightningBoxLnurlPayDesc: action((state, payload) => {
state.lightningBoxLnurlPayDesc = payload;
}),
setHideAmountsEnabled: action((state, payload) => {
state.hideAmountsEnabled = payload;
}),

bitcoinUnit: "bitcoin",
fiatUnit: "USD",
Expand Down Expand Up @@ -715,4 +727,5 @@ export const settings: ISettingsModel = {
lightningBoxServer: DEFAULT_LIGHTNINGBOX_SERVER,
lightningBoxAddress: "",
lightningBoxLnurlPayDesc: DEFAULT_LIGHTNINGBOX_LNURLPDESC,
hideAmountsEnabled: false,
};
3 changes: 3 additions & 0 deletions src/storage/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export enum StorageItem { // const enums not supported in Babel 7...
lightningBoxServer = "lightningBoxServer",
lightningBoxAddress = "lightningBoxAddress",
lightningBoxLnurlPayDesc = "lightningBoxLnurlPayDesc",
hideAmountsEnabled = "hideAmountsEnabled",
}

export const setItem = async (key: StorageItem, value: string) =>
Expand Down Expand Up @@ -192,6 +193,7 @@ export const clearApp = async () => {
removeItem(StorageItem.lightningBoxServer),
removeItem(StorageItem.lightningBoxAddress),
removeItem(StorageItem.lightningBoxLnurlPayDesc),
removeItem(StorageItem.hideAmountsEnabled),
]);
};

Expand Down Expand Up @@ -283,5 +285,6 @@ export const setupApp = async () => {
setItem(StorageItem.lightningBoxServer, DEFAULT_LIGHTNINGBOX_SERVER),
// setItem(StorageItem.lightningBoxAddress, ""),
setItem(StorageItem.lightningBoxLnurlPayDesc, DEFAULT_LIGHTNINGBOX_LNURLPDESC),
setItemObject<boolean>(StorageItem.hideAmountsEnabled, false),
]);
};
Loading

0 comments on commit a57c3dd

Please sign in to comment.