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

Feat/LIVE-4533 LIVE-4532 - Improve decimal handling to show more digits #2037

Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .changeset/fast-seas-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": minor
---

use new parameter from formatCurrencyUnit, dynamicSignificantDigits, in all related display value components/utils. Increased this value for the display of the account crypto value in Account page so more digits are shown.
5 changes: 5 additions & 0 deletions .changeset/perfect-candles-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

Add dynamicSignificantDigits parameter to formatCurrencyUnit to show more digits of value when needed. Also increased this default parameter value from 4 to 6, so more digits will be displayed throught LLM and LLD.
5 changes: 5 additions & 0 deletions .changeset/shaggy-dogs-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": minor
---

use new parameter from formatCurrencyUnit, dynamicSignificantDigits, in all related display value components/utils. Increased this value for the display of the account crypto value in Account page so more digits are shown.
12 changes: 2 additions & 10 deletions apps/ledger-live-desktop/release-notes.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
[
{
"tag_name": "2.49.2",
"body": "\n### πŸ› Fixes\n\nWe have fixed a critical issue preventing macOS users from accessing their nano device.\n"
},
{
"tag_name": "2.49.1",
"body": "\nWe’ve done few small but important changes behind the curtain.\nDon’t forget to update your Ledger Live app so that you can access these new features.\n"
},
{
"tag_name": "2.49.0",
"body": "\nA few small but mighty improvements have been made to Ledger Live's swapping capabilities πŸ‘‡\n\n### πŸš€ Features\n\n- You can now filter swap quotes based on floating or fixed rates.\n\n### πŸ› Fixes\n\n- Trying to swap some assets with Changelly, such as GALA and MBOX, may have resulted in the app crashing. We've sorted this out and everything is working as it should now.\n"
"tag_name": "2.50.0",
"body": "\n### πŸš€ Features\n\n- **EIP-1559 is here.** Now you can enjoy **more predictable fees and reduced confirmation delays** for Ethereum-based transactions. You can also avoid overpaying feesβ€”specify the max fee you're willing to pay and get reimbursed if the transaction is processed at a lower price.\n- **Don’t trust, verify.** Ledger now supports the **EIP-712** standard that will display data in signing prompts in a readable format instead of complex hexadecimal strings.\n- **Swap crypto with CIC from the US without leaving Ledger Live.** Access to CIC swapping options to grow and diversify your portfolio from the security of your Ledger Nano.\n\n### πŸ› Fixes\n\n- A sneaky bug caused the value of some Cardano tokens to be displayed incorrectly. This has now been fixed.\n"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type BalanceTotalProps = {
showCryptoEvenIfNotAvailable?: boolean,
account?: AccountLike,
withTransactionsPendingConfirmationWarning?: boolean,
dynamicSignificantDigits?: number,
};

type Props = {
Expand Down Expand Up @@ -78,6 +79,7 @@ export function BalanceTotal({
children = null,
withTransactionsPendingConfirmationWarning,
account,
dynamicSignificantDigits,
...boxProps
}: BalanceTotalProps) {
return (
Expand All @@ -95,6 +97,7 @@ export function BalanceTotal({
fontSize={8}
showCode
val={totalBalance}
dynamicSignificantDigits={dynamicSignificantDigits}
data-test-id="total-balance"
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type OwnProps = {
suffix?: string,
showAllDigits?: boolean,
alwaysShowValue?: boolean, // overrides discreet mode
dynamicSignificantDigits?: number,
};

const mapStateToProps = createStructuredSelector({
Expand Down Expand Up @@ -94,6 +95,7 @@ function FormattedVal(props: Props) {
showAllDigits,
alwaysShowValue,
discreet,
dynamicSignificantDigits,
...p
} = props;
const valProp = props.val;
Expand Down Expand Up @@ -127,6 +129,7 @@ function FormattedVal(props: Props) {
subMagnitude,
discreet: alwaysShowValue ? false : discreet,
showAllDigits,
dynamicSignificantDigits,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function AccountBalanceSummaryHeader({
const unit = getAccountUnit(account);
const cvUnit = counterValue.units[0];
const data = [
{ valueChange: cryptoChange, balance: last.value, unit },
{ valueChange: cryptoChange, balance: last.value, unit, dynamicSignificantDigits: 8 },
{ valueChange: countervalueChange, balance: last.countervalue, unit: cvUnit },
nparigi-ledger marked this conversation as resolved.
Show resolved Hide resolved
];
if (countervalueFirst) {
Expand Down Expand Up @@ -75,6 +75,7 @@ export default function AccountBalanceSummaryHeader({
isAvailable={isAvailable}
totalBalance={data[0].balance}
unit={data[0].unit}
dynamicSignificantDigits={data[0].dynamicSignificantDigits}
>
<Wrapper style={{ marginTop: 4 }}>
<div style={{ width: "auto", marginRight: 20 }}>
Expand All @@ -88,6 +89,7 @@ export default function AccountBalanceSummaryHeader({
fontSize={6}
showCode
val={data[1].balance}
dynamicSignificantDigits={data[1].dynamicSignificantDigits}
/>
) : (
<NoCountervaluePlaceholder style={{}} />
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/src/analytics/TrackScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function TrackScreen({
screen(category, name, props);
}
}
}, [category, name, props, isFocused]);
}, [category, name, props, isFocused, refreshSource]);

return null;
}
10 changes: 4 additions & 6 deletions apps/ledger-live-mobile/src/components/AccountGraphCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { QrCodeMedium } from "@ledgerhq/native-ui/assets/icons";
import { useNavigation } from "@react-navigation/native";
import { useTimeRange } from "../actions/settings";
import Delta from "./Delta";
import CurrencyUnitValue from "./CurrencyUnitValue";
import CurrencyUnitValue, { CurrencyUnitValueProps } from "./CurrencyUnitValue";
import { Item } from "./Graph/types";
import getWindowDimensions from "../logic/getWindowDimensions";
import Graph from "./Graph";
Expand Down Expand Up @@ -235,10 +235,11 @@ const GraphCardHeader = ({
parentAccount,
currency,
}: HeaderTitleProps) => {
const items = [
const items: CurrencyUnitValueProps[] = [
{
unit: cryptoCurrencyUnit,
value: item.value,
dynamicSignificantDigits: 8,
},
{
unit: counterValueUnit,
Expand Down Expand Up @@ -309,10 +310,7 @@ const GraphCardHeader = ({
numberOfLines={1}
adjustsFontSizeToFit
>
<CurrencyUnitValue
disableRounding={shouldUseCounterValue}
{...items[0]}
/>
<CurrencyUnitValue {...items[0]} />
</Text>
<Flex flexDirection="row" alignItems="center">
<Delta percent show0Delta valueChange={valueChange} />
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/src/components/CounterValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
addExtraSessionTrackingPair,
} from "../actions/general";
import CurrencyUnitValue from "./CurrencyUnitValue";
import type { Props as CurrencyUnitValueProps } from "./CurrencyUnitValue";
import type { CurrencyUnitValueProps } from "./CurrencyUnitValue";
import LText from "./LText";
import Circle from "./Circle";
import IconHelp from "../icons/Info";
Expand Down
19 changes: 6 additions & 13 deletions apps/ledger-live-mobile/src/components/CurrencyUnitValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,28 @@ import { formatCurrencyUnit } from "@ledgerhq/live-common/currencies/index";
import { Unit } from "@ledgerhq/types-cryptoassets";
import { useSelector } from "react-redux";
import { BigNumber } from "bignumber.js";
import { formatCurrencyUnitOptions } from "@ledgerhq/live-common/currencies/formatCurrencyUnit";
import { useLocale } from "../context/Locale";
import DiscreetModeContext from "../context/DiscreetModeContext";
import { discreetModeSelector } from "../reducers/settings";

export type Props = {
export type CurrencyUnitValueProps = {
unit: Unit;
value?: BigNumber | number | null;
showCode?: boolean;
alwaysShowSign?: boolean;
alwaysShowValue?: boolean;
before?: string;
after?: string;
disableRounding?: boolean;
joinFragmentsSeparator?: string;
};
} & formatCurrencyUnitOptions;

const CurrencyUnitValue = ({
unit,
value: valueProp,
showCode = true,
alwaysShowSign,
alwaysShowValue,
before = "",
after = "",
disableRounding = false,
joinFragmentsSeparator = "",
}: Props): JSX.Element => {
...otherFormatCurrencyUnitOptions
}: CurrencyUnitValueProps): JSX.Element => {
const { locale } = useLocale();
const discreet = useSelector(discreetModeSelector);
const shouldApplyDiscreetMode = useContext(DiscreetModeContext);
Expand All @@ -51,11 +46,9 @@ const CurrencyUnitValue = ({
(value
? formatCurrencyUnit(unit, value, {
showCode,
alwaysShowSign,
locale: loc,
disableRounding,
discreet: !alwaysShowValue && shouldApplyDiscreetMode && discreet,
joinFragmentsSeparator,
...otherFormatCurrencyUnitOptions,
})
: "") +
after}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { useCalculate } from "@ledgerhq/live-common/countervalues/react";
import { useTheme } from "@react-navigation/native";
import { Trans } from "react-i18next";
import { counterValueCurrencySelector } from "../reducers/settings";
import CurrencyUnitValue, {
Props as CurrencyUnitValueProps,
} from "./CurrencyUnitValue";
import CurrencyUnitValue, { CurrencyUnitValueProps } from "./CurrencyUnitValue";
import LText from "./LText";
import InfoIcon from "../icons/Info";
import BottomModal from "./BottomModal";
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-mobile/src/components/GraphCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function GraphCard({
</Text>
) : (
<>
<Flex>
<Flex mx={6}>
{!balanceHistory ? (
<BigPlaceholder mt="8px" />
) : (
Expand Down
13 changes: 10 additions & 3 deletions libs/ledger-live-common/src/currencies/formatCurrencyUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const defaultFormatOptions = {
// discrete mode will hide amounts
discreet: false,
joinFragmentsSeparator: "",
// Increase the significant digits. Ex: For a value of 1.121212 BTC, dynamicSignificantDigits of 4 => 1.121 / dynamicSignificantDigits of 6 => 1.12121
dynamicSignificantDigits: 6,
};

export type formatCurrencyUnitOptions = Partial<typeof defaultFormatOptions>;

type FormatFragment =
| {
kind: "value";
Expand All @@ -47,7 +52,7 @@ type FormatFragmentTypes = "value" | "sign" | "code" | "separator";
export function formatCurrencyUnitFragment(
unit: Unit,
value: BigNumber,
_options?: Partial<typeof defaultFormatOptions>
_options?: formatCurrencyUnitOptions
): FormatFragment[] {
if (!BigNumber.isBigNumber(value)) {
console.warn("formatCurrencyUnit called with value=", value);
Expand Down Expand Up @@ -82,6 +87,7 @@ export function formatCurrencyUnitFragment(
useGrouping,
subMagnitude,
discreet,
dynamicSignificantDigits,
} = { ...defaultFormatOptions, ...unit, ...options };
const { magnitude, code } = unit;
const floatValue = value.div(new BigNumber(10).pow(magnitude));
Expand All @@ -94,7 +100,8 @@ export function formatCurrencyUnitFragment(
Math.max(
0, // dynamic max number of digits based on the value itself. to only show significant part
Math.min(
4 - Math.round(Math.log10(floatValueAbs.toNumber())),
dynamicSignificantDigits -
Math.round(Math.log10(floatValueAbs.toNumber())),
magnitude + subMagnitude,
8
)
Expand Down Expand Up @@ -140,7 +147,7 @@ export function formatCurrencyUnitFragment(
export function formatCurrencyUnit(
unit: Unit,
value: BigNumber,
options?: Partial<typeof defaultFormatOptions>
options?: formatCurrencyUnitOptions
): string {
const joinFragmentsSeparator =
(options && options.joinFragmentsSeparator) ||
Expand Down