Skip to content

Commit

Permalink
Settings: Display: hide decimal commas
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Nov 15, 2024
1 parent 040c898 commit 883a8fa
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,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.removeDecimalSpaces": "Remove decimal spaces from Bitcoin denominated amounts",
"views.Settings.Display.showMillisatoshiAmounts": "Show millisatoshi amounts",
"views.Settings.Display.selectNodeOnStartup": "Select node on startup",
"views.Settings.privacy": "Privacy",
Expand Down
2 changes: 2 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface DisplaySettings {
displayNickname?: boolean;
bigKeypadButtons?: boolean;
showAllDecimalPlaces?: boolean;
removeDecimalSpaces?: boolean;
showMillisatoshiAmounts?: boolean;
}

Expand Down Expand Up @@ -1106,6 +1107,7 @@ export default class SettingsStore {
displayNickname: false,
bigKeypadButtons: false,
showAllDecimalPlaces: false,
removeDecimalSpaces: false,
showMillisatoshiAmounts: true
},
pos: {
Expand Down
10 changes: 10 additions & 0 deletions utils/AddressUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ jest.mock('react-native-encrypted-storage', () => ({
clear: jest.fn(() => Promise.resolve())
}));

jest.mock('../stores/Stores', () => ({
SettingsStore: {
settings: {
display: {
removeDecimalSpaces: false
}
}
}
}));

import AddressUtils from './AddressUtils';
import { walletrpc } from '../proto/lightning';

Expand Down
10 changes: 10 additions & 0 deletions utils/UnitsUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
jest.mock('../stores/Stores', () => ({
SettingsStore: {
settings: {
display: {
removeDecimalSpaces: false
}
}
}
}));

import { getDecimalPlaceholder } from './UnitsUtils';

describe('UnitsUtils', () => {
Expand Down
9 changes: 8 additions & 1 deletion utils/UnitsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import stores from '../stores/Stores';

// 100_000_000
const SATS_PER_BTC = 100000000;

Expand All @@ -16,7 +18,8 @@ const getDecimalPlaceholder = (amount: string, units: string) => {

return {
string: amount.includes('.')
? units === 'BTC'
? units === 'BTC' &&
!stores?.settingsStore?.settings?.display?.removeDecimalSpaces
? '00 000 000'.slice(
occupiedPlaces +
(decimalPart.length > 5
Expand Down Expand Up @@ -52,6 +55,10 @@ const formatBitcoinWithSpaces = (x: string | number) => {
return integerFormatted;
}

if (stores?.settingsStore?.settings?.display?.removeDecimalSpaces) {
return `${integerFormatted}.${decimalPart}`;
}

// Handle the first two characters, then group the rest in threes
const firstTwo = decimalPart.slice(0, 2);
const rest = decimalPart.slice(2).replace(/(\d{3})(?=\d)/g, '$1 ');
Expand Down
61 changes: 61 additions & 0 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;
removeDecimalSpaces: boolean;
showMillisatoshiAmounts: boolean;
selectNodeOnStartup: boolean;
}
Expand All @@ -44,6 +45,7 @@ export default class Display extends React.Component<
displayNickname: false,
bigKeypadButtons: false,
showAllDecimalPlaces: false,
removeDecimalSpaces: false,
showMillisatoshiAmounts: false,
selectNodeOnStartup: false
};
Expand All @@ -65,6 +67,9 @@ export default class Display extends React.Component<
showAllDecimalPlaces:
(settings.display && settings.display.showAllDecimalPlaces) ||
false,
removeDecimalSpaces:
(settings.display && settings.display.removeDecimalSpaces) ||
false,
showMillisatoshiAmounts:
(settings.display &&
settings.display.showMillisatoshiAmounts) ||
Expand All @@ -90,6 +95,7 @@ export default class Display extends React.Component<
bigKeypadButtons,
theme,
showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts,
selectNodeOnStartup
} = this.state;
Expand Down Expand Up @@ -126,6 +132,7 @@ export default class Display extends React.Component<
bigKeypadButtons,
defaultView,
showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts
}
});
Expand Down Expand Up @@ -156,6 +163,7 @@ export default class Display extends React.Component<
bigKeypadButtons,
theme,
showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts
}
});
Expand Down Expand Up @@ -200,6 +208,7 @@ export default class Display extends React.Component<
bigKeypadButtons,
displayNickname: !displayNickname,
showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts
}
});
Expand Down Expand Up @@ -245,6 +254,7 @@ export default class Display extends React.Component<
displayNickname,
bigKeypadButtons: !bigKeypadButtons,
showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts
}
});
Expand Down Expand Up @@ -292,13 +302,63 @@ export default class Display extends React.Component<
bigKeypadButtons,
showAllDecimalPlaces:
!showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts
}
});
}}
/>
</View>
</ListItem>

<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent'
}}
>
<ListItem.Title
style={{
color: themeColor('secondaryText'),
fontFamily: 'PPNeueMontreal-Book',
left: -10
}}
>
{localeString(
'views.Settings.Display.removeDecimalSpaces'
)}
</ListItem.Title>
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end'
}}
>
<Switch
value={removeDecimalSpaces}
onValueChange={async () => {
this.setState({
removeDecimalSpaces:
!removeDecimalSpaces
});
await updateSettings({
display: {
defaultView,
theme,
displayNickname,
bigKeypadButtons,
showAllDecimalPlaces,
removeDecimalSpaces:
!removeDecimalSpaces,
showMillisatoshiAmounts
}
});
}}
/>
</View>
</ListItem>

<ListItem
containerStyle={{
borderBottomWidth: 0,
Expand Down Expand Up @@ -337,6 +397,7 @@ export default class Display extends React.Component<
displayNickname,
bigKeypadButtons,
showAllDecimalPlaces,
removeDecimalSpaces,
showMillisatoshiAmounts:
!showMillisatoshiAmounts
}
Expand Down

0 comments on commit 883a8fa

Please sign in to comment.