From 5e01938ece3dc1ccf7bea6c2805b6558c846db80 Mon Sep 17 00:00:00 2001 From: qperrot Date: Mon, 23 Dec 2024 16:26:23 +0100 Subject: [PATCH 1/3] fix: earn on llm --- .changeset/bright-cooks-breathe.md | 6 ++++++ .../src/families/solana/accountActions.tsx | 3 ++- libs/coin-framework/src/account/helpers.ts | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/bright-cooks-breathe.md diff --git a/.changeset/bright-cooks-breathe.md b/.changeset/bright-cooks-breathe.md new file mode 100644 index 000000000000..051e0ef6262d --- /dev/null +++ b/.changeset/bright-cooks-breathe.md @@ -0,0 +1,6 @@ +--- +"live-mobile": patch +"@ledgerhq/coin-framework": patch +--- + +fix solana earn on LLm diff --git a/apps/ledger-live-mobile/src/families/solana/accountActions.tsx b/apps/ledger-live-mobile/src/families/solana/accountActions.tsx index 05e4d9a8c6d1..133b6ebdfc37 100644 --- a/apps/ledger-live-mobile/src/families/solana/accountActions.tsx +++ b/apps/ledger-live-mobile/src/families/solana/accountActions.tsx @@ -7,6 +7,7 @@ import { SolanaAccount } from "@ledgerhq/live-common/families/solana/types"; import { NavigatorName, ScreenName } from "~/const"; import type { ActionButtonEvent, NavigationParamsType } from "~/components/FabActions"; import { getStakeLabelLocaleBased } from "~/helpers/getStakeLabelLocaleBased"; +import { isAccountEmpty } from "@ledgerhq/live-common/account/index"; const getMainActions = ({ account, @@ -17,7 +18,7 @@ const getMainActions = ({ parentAccount: Account; parentRoute: RouteProp; }): ActionButtonEvent[] => { - const delegationDisabled = account.solanaResources?.stakes.length > 1; + const delegationDisabled = isAccountEmpty(account); const label = getStakeLabelLocaleBased(); const navigationParams: NavigationParamsType = delegationDisabled diff --git a/libs/coin-framework/src/account/helpers.ts b/libs/coin-framework/src/account/helpers.ts index 3ab46a1eb400..00db5eca261f 100644 --- a/libs/coin-framework/src/account/helpers.ts +++ b/libs/coin-framework/src/account/helpers.ts @@ -69,6 +69,13 @@ export const isAccountEmpty = (a: AccountLike): boolean => { (a as any).balance.isZero() ); } + if (a.type === "Account" && a.currency.family === "solana") { + return ( + (a as any).solanaResources && + (a as any).balance.isZero() && + (a as any).spendableBalance.isZero() + ); + } const hasSubAccounts = a.type === "Account" && a.subAccounts && a.subAccounts.length; return a.operationsCount === 0 && a.balance.isZero() && !hasSubAccounts; }; From db24171619f4876e1f0899fb08a1016063778183 Mon Sep 17 00:00:00 2001 From: qperrot Date: Fri, 27 Dec 2024 09:00:39 +0100 Subject: [PATCH 2/3] fix: check balance or spendableBalance and remove solanaResources --- libs/coin-framework/src/account/helpers.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libs/coin-framework/src/account/helpers.ts b/libs/coin-framework/src/account/helpers.ts index 00db5eca261f..dc1eefa9b359 100644 --- a/libs/coin-framework/src/account/helpers.ts +++ b/libs/coin-framework/src/account/helpers.ts @@ -70,11 +70,7 @@ export const isAccountEmpty = (a: AccountLike): boolean => { ); } if (a.type === "Account" && a.currency.family === "solana") { - return ( - (a as any).solanaResources && - (a as any).balance.isZero() && - (a as any).spendableBalance.isZero() - ); + return (a as any).balance.isZero() || (a as any).spendableBalance.isZero(); } const hasSubAccounts = a.type === "Account" && a.subAccounts && a.subAccounts.length; return a.operationsCount === 0 && a.balance.isZero() && !hasSubAccounts; From 59ab13730e08106ca6399be9ca82b71bb2cb17b8 Mon Sep 17 00:00:00 2001 From: qperrot Date: Mon, 13 Jan 2025 14:52:47 +0100 Subject: [PATCH 3/3] fix: add tests --- .../src/account/helpers.test.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libs/coin-framework/src/account/helpers.test.ts b/libs/coin-framework/src/account/helpers.test.ts index 0cec6c7fd07d..f8dc78d97a89 100644 --- a/libs/coin-framework/src/account/helpers.test.ts +++ b/libs/coin-framework/src/account/helpers.test.ts @@ -159,6 +159,36 @@ describe(isAccountEmpty.name, () => { expect(isAccountEmpty(mockAccount)).toEqual(false); }); }); + describe("when account has subaccounts", () => { + beforeEach(() => { + mockAccount.subAccounts = [{} as TokenAccount]; + }); + + it("should return false", () => { + expect(isAccountEmpty(mockAccount)).toEqual(false); + }); + }); + }); + describe("given an solana account", () => { + beforeEach(() => { + mockAccount.type = "Account"; + mockAccount.currency = { family: "solana" } as CryptoCurrency; + }); + it("Account has balance and spendableBalance is zero ", () => { + mockAccount.balance = new BigNumber(10); + mockAccount.spendableBalance = new BigNumber(0); + expect(isAccountEmpty(mockAccount)).toEqual(true); + }); + it("Account has spendableBalance and balance is zero", () => { + mockAccount.balance = new BigNumber(0); + mockAccount.spendableBalance = new BigNumber(10); + expect(isAccountEmpty(mockAccount)).toEqual(true); + }); + it("Account has spendableBalance and has balance", () => { + mockAccount.balance = new BigNumber(10); + mockAccount.spendableBalance = new BigNumber(10); + expect(isAccountEmpty(mockAccount)).toEqual(false); + }); }); });