Skip to content

Commit

Permalink
fix: keep previously renamed accounts value
Browse files Browse the repository at this point in the history
  • Loading branch information
KVNLS committed Jun 12, 2024
1 parent 3581d4b commit 9f33fc1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/strong-dingos-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-wallet": minor
---

Keep previously renamed accounts alias
38 changes: 38 additions & 0 deletions libs/live-wallet/src/store.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { handlers, initialState } from "./store";
import type { Account } from "@ledgerhq/types-live";

const ETHEREUM_ACCOUNT = "js:2:ethereum:0x23304541225D9b0BA2368B55ERTYF:";
const POLKADOT_ACCOUNT =
"js:2:polkadot:133vQbgqtsMufsPbhH9uHWLsdfdsfsdfxw2yRjxC56Tcztg6VeLK:polkadotbip44:";

const ETHEREUM_ACCOUNT_NAME = "My name is ethereum";
const POLKADOT_ACCOUNT_NAME = "My name is polkadot";

initialState.accountNames.set(ETHEREUM_ACCOUNT, ETHEREUM_ACCOUNT_NAME);
initialState.accountNames.set(POLKADOT_ACCOUNT, POLKADOT_ACCOUNT_NAME);

initialState.starredAccountIds.add(ETHEREUM_ACCOUNT);

const NEW_POLKADOT_ACCOUNT =
"js:2:polkadot:133vQbgqtsMufsPbhH9uHWLsdfdsfsdfxw2yRjxC5azeazeazezaVeLK:polkadotbip44:";
const NEW_POLKADOT_ACCOUNT_NAME = "My name is new polkadot";

describe("Wallet store", () => {
it("should add an account", (): void => {
const editedNames = new Map();
editedNames.set(NEW_POLKADOT_ACCOUNT, NEW_POLKADOT_ACCOUNT_NAME);
const result = handlers.ADD_ACCOUNTS(initialState, {
payload: {
allAccounts: [
{ id: ETHEREUM_ACCOUNT, type: "Account", currency: { name: "Ethereum" } } as Account,
{ id: POLKADOT_ACCOUNT, type: "Account", currency: { name: "Polkadot" } } as Account,
{ id: NEW_POLKADOT_ACCOUNT, type: "Account", currency: { name: "Polkadot" } } as Account,
],
editedNames,
},
});
expect(result.accountNames.get(ETHEREUM_ACCOUNT)).toBe(ETHEREUM_ACCOUNT_NAME);
expect(result.accountNames.get(POLKADOT_ACCOUNT)).toBe(POLKADOT_ACCOUNT_NAME);
expect(result.accountNames.get(NEW_POLKADOT_ACCOUNT)).toBe(NEW_POLKADOT_ACCOUNT_NAME);
});
});
5 changes: 4 additions & 1 deletion libs/live-wallet/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export const handlers: WalletHandlers = {
ADD_ACCOUNTS: (state, { payload: { allAccounts, editedNames } }) => {
const accountNames = new Map(state.accountNames);
for (const account of allAccounts) {
const name = editedNames.get(account.id) || getDefaultAccountName(account);
const name =
editedNames.get(account.id) ||
accountNames.get(account.id) ||
getDefaultAccountName(account);
accountNames.set(account.id, name);
}
return { ...state, accountNames };
Expand Down

0 comments on commit 9f33fc1

Please sign in to comment.