Skip to content

Commit 5e61f54

Browse files
committed
🐛 fix(llm) account item wrong balance
1 parent db88f6a commit 5e61f54

File tree

11 files changed

+52
-16
lines changed

11 files changed

+52
-16
lines changed

.changeset/witty-camels-juggle.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"live-mobile": minor
3+
---
4+
5+
Fix accountItem that was using spendableBalance instead of balance

apps/ledger-live-mobile/src/components/SelectableAccountsList.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ const SelectableAccount = ({
319319
padding="8px"
320320
columnGap={8}
321321
>
322-
<AccountItem account={account as Account} balance={account.spendableBalance} />
322+
<AccountItem
323+
account={account as Account}
324+
balance={useFullBalance ? account.balance : account.spendableBalance}
325+
/>
323326
</Flex>
324327
) : (
325328
<Flex flex={1}>

apps/ledger-live-mobile/src/newArch/features/Accounts/__integrations__/accountsListScreen.integration.test.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import AccountsList from "../screens/AccountsList";
66
import { AccountsListNavigator } from "../screens/AccountsList/types";
77
import { ScreenName } from "~/const";
88
import { createStackNavigator } from "@react-navigation/stack";
9+
910
const INITIAL_STATE = {
1011
overrideInitialState: (state: State) => ({
1112
...state,
@@ -33,6 +34,11 @@ const INITIAL_STATE = {
3334
}),
3435
};
3536

37+
jest.mock("@ledgerhq/live-countervalues-react", () => ({
38+
...jest.requireActual("@ledgerhq/live-countervalues-react"),
39+
useCalculate: ({ value }: { value: number }) => value,
40+
}));
41+
3642
describe("AccountsList Screen", () => {
3743
const renderComponent = (params: AccountsListNavigator[ScreenName.AccountsList]) => {
3844
const Stack = createStackNavigator<AccountsListNavigator>();
@@ -78,7 +84,7 @@ describe("AccountsList Screen", () => {
7884
});
7985

8086
it("should render the accounts list", () => {
81-
const { getByText } = renderComponent({
87+
const { getByText, getAllByTestId, getAllByText, queryByText } = renderComponent({
8288
sourceScreenName: ScreenName.AccountsList,
8389
showHeader: true,
8490
canAddAccount: true,
@@ -100,6 +106,14 @@ describe("AccountsList Screen", () => {
100106
].forEach(account => {
101107
expect(account).toBeVisible();
102108
});
109+
110+
// check the rendered balance
111+
// for a proprer check we should find a way to setup live-countervalues-react for jest
112+
expect(getAllByTestId("account-balance").length).toBe(6);
113+
// check that we well display the full balance
114+
expect(getAllByText(/\$8,331,578.60/i).length).toBe(6);
115+
// check that we don't display the spendable balance
116+
expect(queryByText(/\$3.20/i)).toBeNull();
103117
});
104118

105119
it("should render only the Linea account", () => {

apps/ledger-live-mobile/src/newArch/features/Accounts/__integrations__/mockedAccounts.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const MockedAccounts: AccountsState = {
1515
blockHeight: 157668,
1616
creationDate: new Date("2024-11-13T12:20:06.444Z"),
1717
balance: BigNumber("83315786").multipliedBy(10),
18-
spendableBalance: BigNumber("83315786").multipliedBy(10),
18+
spendableBalance: BigNumber("32").multipliedBy(10),
1919
operations: [],
2020
operationsCount: 117,
2121
pendingOperations: [],
@@ -99,7 +99,7 @@ export const MockedAccounts: AccountsState = {
9999
blockHeight: 109869,
100100
creationDate: new Date("2024-11-13T12:20:06.444Z"),
101101
balance: BigNumber("83315786").multipliedBy(10),
102-
spendableBalance: BigNumber("83315786").multipliedBy(10),
102+
spendableBalance: BigNumber("123").multipliedBy(10),
103103
operations: [],
104104
operationsCount: 74,
105105
pendingOperations: [],
@@ -191,7 +191,7 @@ export const MockedAccounts: AccountsState = {
191191
blockHeight: 128411,
192192
creationDate: new Date("2024-11-13T12:20:06.444Z"),
193193
balance: BigNumber("83315786").multipliedBy(10),
194-
spendableBalance: BigNumber("83315786").multipliedBy(10),
194+
spendableBalance: BigNumber("329").multipliedBy(10),
195195
operations: [],
196196
operationsCount: 62,
197197
pendingOperations: [],
@@ -298,7 +298,7 @@ export const MockedAccounts: AccountsState = {
298298
blockHeight: 120593,
299299
creationDate: new Date("2024-11-13T12:20:06.444Z"),
300300
balance: BigNumber("83315786").multipliedBy(10),
301-
spendableBalance: BigNumber("83315786").multipliedBy(10),
301+
spendableBalance: BigNumber("3932").multipliedBy(10),
302302
operations: [],
303303
operationsCount: 95,
304304
pendingOperations: [],
@@ -387,7 +387,7 @@ export const MockedAccounts: AccountsState = {
387387
blockHeight: 132056,
388388
creationDate: new Date("2024-11-13T12:20:06.444Z"),
389389
balance: BigNumber("83315786").multipliedBy(10),
390-
spendableBalance: BigNumber("83315786").multipliedBy(10),
390+
spendableBalance: BigNumber("3223").multipliedBy(10),
391391
operations: [],
392392
operationsCount: 184,
393393
pendingOperations: [],
@@ -528,7 +528,7 @@ export const MockedAccounts: AccountsState = {
528528
blockHeight: 175413,
529529
creationDate: new Date("2024-11-13T12:20:06.444Z"),
530530
balance: BigNumber("83315786").multipliedBy(10),
531-
spendableBalance: BigNumber("83315786").multipliedBy(10),
531+
spendableBalance: BigNumber("877").multipliedBy(10),
532532
operations: [],
533533
operationsCount: 180,
534534
pendingOperations: [],

apps/ledger-live-mobile/src/newArch/features/Accounts/components/AccountListDrawer/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const AccountListDrawer = ({ isOpen, onClose, data, onPressAccount }: AccountLis
3030
return (
3131
<TouchableOpacity key={account.id} onPress={() => onPressAccount(account)}>
3232
<Flex flexDirection="row" alignItems="center" padding={3} width={343}>
33-
<AccountItem account={account} balance={account.spendableBalance} showUnit />
33+
<AccountItem account={account} balance={account.balance} showUnit />
3434
</Flex>
3535
</TouchableOpacity>
3636
);

apps/ledger-live-mobile/src/newArch/features/Accounts/components/AccountQuickActionsDrawer/CustomHeader/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CustomHeader = ({ account, onClose, backgroundColor, iconColor }: Props) =
2020
borderBottom={5}
2121
borderBottomColor={"neutral.c30"}
2222
>
23-
<AccountItem account={account} balance={account.spendableBalance} hideBalanceInfo />
23+
<AccountItem account={account} balance={account.balance} hideBalanceInfo />
2424
<Flex alignItems="flex-end">
2525
<TouchableOpacity onPress={onClose}>
2626
<Flex

apps/ledger-live-mobile/src/newArch/features/Accounts/components/AccountsListView/components/AccountItem/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const View: React.FC<ViewProps> = ({
1717
unit,
1818
showUnit,
1919
hideBalanceInfo,
20+
withPlaceholder,
2021
}) => (
2122
<>
2223
<Flex flex={1} rowGap={2} flexShrink={1} testID={`accountItem-${accountName}`}>
@@ -45,8 +46,13 @@ const View: React.FC<ViewProps> = ({
4546
</Flex>
4647
{!hideBalanceInfo && (
4748
<Flex justifyContent="center" alignItems="flex-end">
48-
<Text variant="large" fontWeight="semiBold" color="neutral.c100" testID="asset-balance">
49-
<CounterValue currency={currency} value={balance} joinFragmentsSeparator="" />
49+
<Text variant="large" fontWeight="semiBold" color="neutral.c100" testID="account-balance">
50+
<CounterValue
51+
currency={currency}
52+
value={balance}
53+
joinFragmentsSeparator=""
54+
withPlaceholder={withPlaceholder}
55+
/>
5056
</Text>
5157
{showUnit && (
5258
<Text variant="body" fontWeight="medium" color="neutral.c70">

apps/ledger-live-mobile/src/newArch/features/Accounts/components/AccountsListView/components/AccountItem/useAccountItemModel.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@ export interface AccountItemProps {
1717
balance: BigNumber;
1818
showUnit?: boolean;
1919
hideBalanceInfo?: boolean;
20+
withPlaceholder?: boolean;
2021
}
2122

22-
const useAccountItemModel = ({ account, balance, showUnit, hideBalanceInfo }: AccountItemProps) => {
23+
const useAccountItemModel = ({
24+
account,
25+
balance,
26+
showUnit,
27+
hideBalanceInfo,
28+
withPlaceholder,
29+
}: AccountItemProps) => {
2330
const allAccount = useSelector(accountsSelector);
2431
const isTokenAccount = isTokenAccountChecker(account);
2532
const currency = getAccountCurrency(account);
@@ -46,6 +53,7 @@ const useAccountItemModel = ({ account, balance, showUnit, hideBalanceInfo }: Ac
4653
unit,
4754
showUnit,
4855
hideBalanceInfo,
56+
withPlaceholder,
4957
};
5058
};
5159

apps/ledger-live-mobile/src/newArch/features/Accounts/components/AccountsListView/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const View: React.FC<ViewProps> = ({
3535
onPress={onAccountPress.bind(null, item)}
3636
>
3737
<Flex height={40} flexDirection="row" columnGap={12}>
38-
<AccountItem account={item} balance={item.spendableBalance} />
38+
<AccountItem account={item} balance={item.balance} withPlaceholder />
3939
</Flex>
4040
</Pressable>
4141
),

apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccountSuccess/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function AddAccountsSuccess({ route }: Props) {
7070
padding="12px"
7171
width={343}
7272
>
73-
<AccountItem account={item as Account} balance={item.spendableBalance} />
73+
<AccountItem account={item as Account} balance={item.balance} />
7474
<Icons.ChevronRight size="M" color={colors.primary.c100} />
7575
</Flex>
7676
</TouchableOpacity>

apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccountWarning/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default function AddAccountsWarning({ route }: Props) {
9393
>
9494
<AccountItem
9595
account={emptyAccount as Account}
96-
balance={emptyAccount?.spendableBalance as BigNumber}
96+
balance={emptyAccount?.balance || BigNumber(0)}
9797
/>
9898
<Icons.ChevronRight size="M" color={colors.primary.c100} />
9999
</Flex>

0 commit comments

Comments
 (0)