Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZEUS-1503: Settings: Display: add ability to hide millisat amounts #2281

Merged
merged 1 commit into from
Jul 10, 2024
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
10 changes: 10 additions & 0 deletions components/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { Row } from './layout/Row';
import { Body } from './text/Body';
import LoadingIndicator from './LoadingIndicator';

import stores from '../stores/Stores';

type Units = 'sats' | 'BTC' | 'fiat';

interface AmountDisplayProps {
Expand Down Expand Up @@ -95,6 +97,14 @@ function AmountDisplay({
// TODO this could probably be made more readable by componentizing the repeat bits
switch (unit) {
case 'sats':
const hideMsats =
!stores.settingsStore?.settings?.display
?.showMillisatoshiAmounts;
if (hideMsats) {
const [wholeSats] = amount.toString().split('.');
amount = wholeSats;
plural = amount === '1' ? false : true;
}
return (
<Row
style={styles.row}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@
"views.Settings.Display.displayNickname": "Display node nickname on main views",
"views.Settings.Display.bigKeypadButtons": "Big keypad buttons",
"views.Settings.Display.showAllDecimalPlaces": "Show all decimal places",
"views.Settings.Display.showMillisatoshiAmounts": "Show millisatoshi amounts",
"views.Settings.Display.selectNodeOnStartup": "Select node on startup",
"views.Settings.privacy": "Privacy",
"views.Settings.payments": "Payments",
Expand Down
15 changes: 14 additions & 1 deletion stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface DisplaySettings {
displayNickname?: boolean;
bigKeypadButtons?: boolean;
showAllDecimalPlaces?: boolean;
showMillisatoshiAmounts?: boolean;
}

export enum PosEnabled {
Expand Down Expand Up @@ -1041,7 +1042,8 @@ export default class SettingsStore {
defaultView: 'Keypad',
displayNickname: false,
bigKeypadButtons: false,
showAllDecimalPlaces: false
showAllDecimalPlaces: false,
showMillisatoshiAmounts: true
},
pos: {
posEnabled: PosEnabled.Disabled,
Expand Down Expand Up @@ -1465,6 +1467,17 @@ export default class SettingsStore {
await EncryptedStorage.setItem(MOD_KEY4, 'true');
}

const MOD_KEY5 = 'millisat_amounts';
const mod5 = await EncryptedStorage.getItem(MOD_KEY5);
if (!mod5) {
if (!newSettings?.display.showMillisatoshiAmounts) {
newSettings.display.showMillisatoshiAmounts = true;
}

this.setSettings(JSON.stringify(newSettings));
await EncryptedStorage.setItem(MOD_KEY5, 'true');
}

// migrate old POS squareEnabled setting to posEnabled
if (newSettings?.pos?.squareEnabled) {
newSettings.pos.posEnabled = PosEnabled.Square;
Expand Down
68 changes: 63 additions & 5 deletions views/Settings/Display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface DisplayState {
displayNickname: boolean;
bigKeypadButtons: boolean;
showAllDecimalPlaces: boolean;
showMillisatoshiAmounts: boolean;
selectNodeOnStartup: boolean;
}

Expand All @@ -43,6 +44,7 @@ export default class Display extends React.Component<
displayNickname: false,
bigKeypadButtons: false,
showAllDecimalPlaces: false,
showMillisatoshiAmounts: false,
selectNodeOnStartup: false
};

Expand All @@ -63,6 +65,10 @@ export default class Display extends React.Component<
showAllDecimalPlaces:
(settings.display && settings.display.showAllDecimalPlaces) ||
false,
showMillisatoshiAmounts:
(settings.display &&
settings.display.showMillisatoshiAmounts) ||
false,
selectNodeOnStartup: settings.selectNodeOnStartup || false
});
}
Expand All @@ -84,6 +90,7 @@ export default class Display extends React.Component<
bigKeypadButtons,
theme,
showAllDecimalPlaces,
showMillisatoshiAmounts,
selectNodeOnStartup
} = this.state;
const { updateSettings }: any = SettingsStore;
Expand Down Expand Up @@ -118,7 +125,8 @@ export default class Display extends React.Component<
displayNickname,
bigKeypadButtons,
defaultView,
showAllDecimalPlaces
showAllDecimalPlaces,
showMillisatoshiAmounts
}
});
SystemNavigationBar.setNavigationColor(
Expand Down Expand Up @@ -147,7 +155,8 @@ export default class Display extends React.Component<
displayNickname,
bigKeypadButtons,
theme,
showAllDecimalPlaces
showAllDecimalPlaces,
showMillisatoshiAmounts
}
});
}}
Expand Down Expand Up @@ -190,7 +199,8 @@ export default class Display extends React.Component<
theme,
bigKeypadButtons,
displayNickname: !displayNickname,
showAllDecimalPlaces
showAllDecimalPlaces,
showMillisatoshiAmounts
}
});
}}
Expand Down Expand Up @@ -234,7 +244,8 @@ export default class Display extends React.Component<
theme,
displayNickname,
bigKeypadButtons: !bigKeypadButtons,
showAllDecimalPlaces
showAllDecimalPlaces,
showMillisatoshiAmounts
}
});
}}
Expand Down Expand Up @@ -280,7 +291,54 @@ export default class Display extends React.Component<
displayNickname,
bigKeypadButtons,
showAllDecimalPlaces:
!showAllDecimalPlaces
!showAllDecimalPlaces,
showMillisatoshiAmounts
}
});
}}
/>
</View>
</ListItem>
<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent'
}}
>
<ListItem.Title
style={{
color: themeColor('secondaryText'),
fontFamily: 'PPNeueMontreal-Book',
left: -10
}}
>
{localeString(
'views.Settings.Display.showMillisatoshiAmounts'
)}
</ListItem.Title>
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end'
}}
>
<Switch
value={showMillisatoshiAmounts}
onValueChange={async () => {
this.setState({
showMillisatoshiAmounts:
!showMillisatoshiAmounts
});
await updateSettings({
display: {
defaultView,
theme,
displayNickname,
bigKeypadButtons,
showAllDecimalPlaces,
showMillisatoshiAmounts:
!showMillisatoshiAmounts
}
});
}}
Expand Down
Loading