Skip to content

Commit

Permalink
chore: make coin-framework not dealing with AccountUserData type
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>
  • Loading branch information
sprohaszka-ledger authored and gre committed May 3, 2024
1 parent 927afc0 commit 7389559
Show file tree
Hide file tree
Showing 32 changed files with 28 additions and 223 deletions.
27 changes: 2 additions & 25 deletions libs/coin-framework/src/serialization/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BigNumber } from "bignumber.js";
import type {
AccountUserData,
Account,
AccountBridge,
AccountRaw,
Expand Down Expand Up @@ -136,11 +135,7 @@ export type ToFamiliyRaw = {
toOperationExtraRaw?: AccountBridge<TransactionCommon>["toOperationExtraRaw"];
};

export function toAccountRaw(
account: Account,
toFamilyRaw?: ToFamiliyRaw,
userData?: AccountUserData,
): AccountRaw {
export function toAccountRaw(account: Account, toFamilyRaw?: ToFamiliyRaw): AccountRaw {
const {
id,
seedIdentifier,
Expand All @@ -167,21 +162,12 @@ export function toAccountRaw(
nfts,
} = account;

let name = "";
let starred;
if (userData) {
name = userData.name;
starred = userData.starredIds.includes(id);
}

const convertOperation = (op: Operation) =>
toOperationRaw(op, undefined, toFamilyRaw?.toOperationExtraRaw);

const res: AccountRaw = {
id,
seedIdentifier,
name,
starred,
used,
derivationMode,
index,
Expand Down Expand Up @@ -213,9 +199,7 @@ export function toAccountRaw(
}

if (subAccounts) {
res.subAccounts = subAccounts.map(a =>
toTokenAccountRaw(a, toFamilyRaw?.toOperationExtraRaw, userData),
);
res.subAccounts = subAccounts.map(a => toTokenAccountRaw(a, toFamilyRaw?.toOperationExtraRaw));
}

if (toFamilyRaw?.assignToAccountRaw) {
Expand Down Expand Up @@ -276,7 +260,6 @@ function fromTokenAccountRaw(
function toTokenAccountRaw(
ta: TokenAccount,
toOperationExtraRaw?: AccountBridge<TransactionCommon>["toOperationExtraRaw"],
userData?: AccountUserData,
): TokenAccountRaw {
const {
id,
Expand All @@ -292,18 +275,12 @@ function toTokenAccountRaw(
approvals,
} = ta;

let starred;
if (userData) {
starred = userData.starredIds.includes(id);
}

const convertOperation = (op: Operation) => toOperationRaw(op, undefined, toOperationExtraRaw);

return {
type: "TokenAccountRaw",
id,
parentId,
starred,
tokenId: token.id,
balance: balance.toString(),
spendableBalance: spendableBalance.toString(),
Expand Down
24 changes: 16 additions & 8 deletions libs/ledger-live-common/src/account/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {

export function toAccountRaw(account: Account, userData?: AccountUserData): AccountRaw {
const bridge = getAccountBridge(account);
return commonToAccountRaw(
account,
{
assignToAccountRaw: bridge.assignToAccountRaw,
toOperationExtraRaw: bridge.toOperationExtraRaw,
},
userData,
);

const commonAccountRaw = commonToAccountRaw(account, {
assignToAccountRaw: bridge.assignToAccountRaw,
toOperationExtraRaw: bridge.toOperationExtraRaw,
});

// extend with user data fields
if (userData) {
commonAccountRaw.name = userData.name;
commonAccountRaw.starred = userData.starredIds.includes(commonAccountRaw.id);
for (const tokenAccount of commonAccountRaw.subAccounts || []) {
tokenAccount.starred = userData.starredIds.includes(tokenAccount.id);
}
}

return commonAccountRaw;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 133,
"pendingOperations": [],
"seedIdentifier": "c8b672d16c497bb097a48f09a9cccf0c4c7d6391acb7a4e7cd3f236fadbef9c4",
"starred": undefined,
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
Expand All @@ -30,7 +29,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 11,
"parentId": "js:2:algorand:ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/312769",
"type": "TokenAccountRaw",
Expand All @@ -41,7 +39,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 0,
"parentId": "js:2:algorand:ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/438828",
"type": "TokenAccountRaw",
Expand All @@ -52,7 +49,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 0,
"parentId": "js:2:algorand:ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/438837",
"type": "TokenAccountRaw",
Expand All @@ -63,7 +59,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 0,
"parentId": "js:2:algorand:ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/2757561",
"type": "TokenAccountRaw",
Expand All @@ -74,7 +69,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 0,
"parentId": "js:2:algorand:ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/27165954",
"type": "TokenAccountRaw",
Expand All @@ -85,7 +79,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 0,
"parentId": "js:2:algorand:ZC3HFULMJF53BF5ER4E2TTGPBRGH2Y4RVS32JZ6NH4RW7LN67HCE6UBS3Q:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/137594422",
"type": "TokenAccountRaw",
Expand All @@ -105,7 +98,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 8,
"pendingOperations": [],
"seedIdentifier": "c8b672d16c497bb097a48f09a9cccf0c4c7d6391acb7a4e7cd3f236fadbef9c4",
"starred": undefined,
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
Expand All @@ -127,7 +119,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 1,
"pendingOperations": [],
"seedIdentifier": "c8b672d16c497bb097a48f09a9cccf0c4c7d6391acb7a4e7cd3f236fadbef9c4",
"starred": undefined,
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
Expand All @@ -149,7 +140,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 44,
"pendingOperations": [],
"seedIdentifier": "c8b672d16c497bb097a48f09a9cccf0c4c7d6391acb7a4e7cd3f236fadbef9c4",
"starred": undefined,
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
Expand All @@ -162,7 +152,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 8,
"parentId": "js:2:algorand:MECOWMKPKH2NWVZTS5V5RQDGFFYBT25KNLOPHG2KUMMNKU6FOHGJT24WBI:",
"pendingOperations": [],
"starred": undefined,
"swapHistory": [],
"tokenId": "algorand/asa/312769",
"type": "TokenAccountRaw",
Expand All @@ -182,7 +171,6 @@ exports[`algorand currency bridge scanAccounts algorand seed 1 1`] = `
"operationsCount": 0,
"pendingOperations": [],
"seedIdentifier": "c8b672d16c497bb097a48f09a9cccf0c4c7d6391acb7a4e7cd3f236fadbef9c4",
"starred": undefined,
"subAccounts": [],
"swapHistory": [],
"syncHash": undefined,
Expand Down

0 comments on commit 7389559

Please sign in to comment.