Skip to content

Commit

Permalink
Merge pull request #9006 from LedgerHQ/bugfix/rename-account-issue
Browse files Browse the repository at this point in the history
🐛  Rename account and starred accounts now fixed on LLM and LLD
  • Loading branch information
cgrellard-ledger authored Jan 28, 2025
2 parents 8409d5c + eb9f1b3 commit bca2b55
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/curly-pants-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"ledger-live-desktop": minor
"@ledgerhq/live-wallet": minor
---

LLD - Fix rename account issue
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ const AccountHeader: React.ComponentType<Props> = React.memo(function AccountHea
disableEllipsis={editingName}
value={name}
id="account-header-name"
data-testid="account-header-name"
/>
{account.type === "Account" && (
<>
Expand Down
7 changes: 7 additions & 0 deletions apps/ledger-live-desktop/tests/page/account.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class AccountPage extends AppPage {
private seeGalleryButton = this.page.getByRole("button", { name: "See Gallery" });
private nftOperation = this.page.getByText("NFT Sent");
private nftList = (collectionName: string) => this.page.getByTestId(`nft-row-${collectionName}`);
private accountHeaderName = this.page.locator("id=account-header-name");

@step("Navigate to token")
async navigateToToken(SubAccount: Account) {
Expand Down Expand Up @@ -106,6 +107,12 @@ export class AccountPage extends AppPage {
await operationList.scrollIntoViewIfNeeded();
}

@step("Rename account")
async renameAccount(newName: string) {
await this.accountHeaderName.fill(newName);
await this.page.keyboard.press("Enter");
}

/**
* Delete account from account itself
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import test from "../../fixtures/common";
import { AccountsPage } from "../../page/accounts.page";
import { Layout } from "../../component/layout.component";
import fsPromises from "fs/promises";
import { expect } from "@playwright/test";

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

test.use({ userdata: "accountCosmos" });

test("Rename account", async ({ app, page, userdataFile, electronApp }) => {
const getUserdata = async () => {
const jsonFile = await fsPromises.readFile(userdataFile, "utf-8");
return JSON.parse(jsonFile);
};
const layout = new Layout(page);
await layout.goToAccounts();
const accountsPage = new AccountsPage(page);
await accountsPage.navigateToAccountByName("Cosmos 1");

const newName = "New account name";
await app.account.expectAccountVisibility("Cosmos 1");
await app.account.renameAccount(newName);
await app.account.expectAccountVisibility(newName);
await sleep(2000);
await electronApp.close();
await sleep(2000);
const userData = await getUserdata();
expect(userData.data.wallet.accountNames[0][1]).toBe(newName);
});
36 changes: 36 additions & 0 deletions libs/live-wallet/src/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ describe("Wallet store", () => {
const exportedState = {
walletSyncState: { data: {}, version: 42 },
nonImportedAccountInfos: [],
accountNames: [],
starredAccountIds: [],
};

it("allows partial wallet state", () => {
Expand All @@ -242,11 +244,45 @@ describe("Wallet store", () => {
expect(walletSyncStateSelector(result)).toEqual({ data: {}, version: 42 });
});

it("can import the wallet state with renamed accounts and starred accounts", () => {
const result = handlers.IMPORT_WALLET_SYNC(
initialState,
importWalletState({
...exportedState,
accountNames: [[ETHEREUM_ACCOUNT, "New name"]],
starredAccountIds: [ETHEREUM_ACCOUNT],
}),
);
expect(walletSyncStateSelector(result)).toEqual({ data: {}, version: 42 });
expect(accountNameSelector(result, { accountId: ETHEREUM_ACCOUNT })).toBe("New name");
expect(isStarredAccountSelector(result, { accountId: ETHEREUM_ACCOUNT })).toBe(true);
});

it("can export the wallet state", () => {
const result = handlers.IMPORT_WALLET_SYNC(initialState, importWalletState(exportedState));
expect(exportWalletState(result)).toEqual(exportedState);
});

it("can export the wallet state with updated values", () => {
const result = handlers.IMPORT_WALLET_SYNC(initialState, importWalletState(exportedState));
//Check that the exported state includes rename of accounts.
const resultRename = handlers.SET_ACCOUNT_NAME(
result,
setAccountName(ETHEREUM_ACCOUNT, "New name"),
);
//Check that the exported state includes starred accounts.
const resultStarred = handlers.SET_ACCOUNT_STARRED(
resultRename,
setAccountStarred(POLKADOT_ACCOUNT, true),
);

expect(exportWalletState(resultStarred)).toEqual({
...exportedState,
accountNames: [[ETHEREUM_ACCOUNT, "New name"]],
starredAccountIds: [POLKADOT_ACCOUNT],
});
});

it("walletStateExportShouldDiffer", () => {
const result = handlers.IMPORT_WALLET_SYNC(initialState, importWalletState(exportedState));
expect(exportWalletState(result)).toEqual(exportedState);
Expand Down
16 changes: 13 additions & 3 deletions libs/live-wallet/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type WalletState = {
export type ExportedWalletState = {
walletSyncState: WSState;
nonImportedAccountInfos: NonImportedAccountInfo[];
accountNames: Array<[string, string]>;
starredAccountIds: string[];
};

export const initialState: WalletState = {
Expand Down Expand Up @@ -61,7 +63,7 @@ export type HandlersPayloads = {
data: DistantState | null;
version: number;
};
IMPORT_WALLET_SYNC: Partial<ExportedWalletState>;
IMPORT_WALLET_SYNC: Partial<WalletState>;
SET_NON_IMPORTED_ACCOUNTS: NonImportedAccountInfo[];
};

Expand Down Expand Up @@ -169,7 +171,11 @@ export const initAccounts = (accounts: Account[], accountsUserData: AccountUserD
*/
export const importWalletState = (payload: Partial<ExportedWalletState>) => ({
type: "IMPORT_WALLET_SYNC",
payload,
payload: {
...payload,
accountNames: new Map(payload.accountNames),
starredAccountIds: new Set(payload.starredAccountIds),
},
});

export const walletSyncUpdate = (data: DistantState | null, version: number) => ({
Expand Down Expand Up @@ -246,12 +252,16 @@ export const accountRawToAccountUserData = (raw: AccountRaw): AccountUserData =>
export const exportWalletState = (state: WalletState): ExportedWalletState => ({
walletSyncState: state.walletSyncState,
nonImportedAccountInfos: state.nonImportedAccountInfos,
accountNames: Array.from(state.accountNames),
starredAccountIds: Array.from(state.starredAccountIds),
});

export const walletStateExportShouldDiffer = (a: WalletState, b: WalletState): boolean => {
return (
a.walletSyncState !== b.walletSyncState ||
a.nonImportedAccountInfos !== b.nonImportedAccountInfos
a.nonImportedAccountInfos !== b.nonImportedAccountInfos ||
a.accountNames !== b.accountNames ||
a.starredAccountIds !== b.starredAccountIds
);
};

Expand Down

0 comments on commit bca2b55

Please sign in to comment.