Skip to content

Commit

Permalink
[bugfix] Fix regression when serializing cosmos operation extra (#4528)
Browse files Browse the repository at this point in the history
* Fix regression when serialiazing cosmos operation extra

* Add changeset

* [WIP]fix: cosmos unit tests (#4532)

fix: cosmos unit tests

---------

Co-authored-by: hzheng-ledger <71653044+hzheng-ledger@users.noreply.github.com>
  • Loading branch information
Hakim and hzheng-ledger authored Aug 30, 2023
1 parent 3dc9ba1 commit 1c6deb2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-oranges-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Fix regression when serializing cosmos operation extra
28 changes: 20 additions & 8 deletions libs/coin-framework/src/account/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ export const fromOperationRaw = (
value: new BigNumber(value),
fee: new BigNumber(fee),
extra,
contract,
operator,
standard,
tokenId,
};

if (transactionSequenceNumber !== undefined) {
Expand All @@ -154,6 +150,26 @@ export const fromOperationRaw = (
res.hasFailed = hasFailed;
}

if (transactionRaw !== undefined) {
res.transactionRaw = transactionRaw;
}

if (contract !== undefined) {
res.contract = contract;
}

if (operator !== undefined) {
res.operator = operator;
}

if (standard !== undefined) {
res.standard = standard;
}

if (tokenId !== undefined) {
res.tokenId = tokenId;
}

if (subAccounts) {
res.subOperations = inferSubOperations(hash, subAccounts);
} else if (subOperations) {
Expand All @@ -170,9 +186,5 @@ export const fromOperationRaw = (
res.nftOperations = nftOperations.map((o: OperationRaw) => fromOperationRaw(o, o.accountId));
}

if (transactionRaw !== undefined) {
res.transactionRaw = transactionRaw;
}

return res;
};
16 changes: 8 additions & 8 deletions libs/ledger-live-common/src/families/cosmos/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function fromOperationExtraRaw(extraRaw: CosmosOperationExtraRaw): Cosmos
};
}

if (extraRaw.validators) {
if (extraRaw.validators && extraRaw.validators.length > 0) {
extra.validators = extraRaw.validators.map(validator => ({
address: validator.address,
amount: new BigNumber(validator.amount),
Expand Down Expand Up @@ -159,23 +159,23 @@ export function toOperationExtraRaw(extra: CosmosOperationExtra): CosmosOperatio
};
}

if (extra.validators) {
if (extra.validators && extra.validators.length > 0) {
extraRaw.validators = extra.validators.map(validator => ({
address: validator.address,
amount: validator.amount.toString(),
}));
}

if (extraRaw.sourceValidator) {
extra.sourceValidator = extraRaw.sourceValidator;
if (extra.sourceValidator) {
extraRaw.sourceValidator = extra.sourceValidator;
}

if (extraRaw.autoClaimedRewards) {
extra.autoClaimedRewards = extraRaw.autoClaimedRewards;
if (extra.autoClaimedRewards) {
extraRaw.autoClaimedRewards = extra.autoClaimedRewards;
}

if (extraRaw.memo) {
extra.memo = extraRaw.memo;
if (extra.memo) {
extraRaw.memo = extra.memo;
}

return extraRaw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Array [
"contract": undefined,
"extra": Object {
"memo": "lb",
"validators": Array [],
},
"fee": "8880",
"hash": "0B17FF19A1E8DC703A3AEC457B414DE88845DD76BB4D95F8F6368F68D59248DF",
Expand All @@ -144,7 +143,6 @@ Array [
"contract": undefined,
"extra": Object {
"memo": "Lc",
"validators": Array [],
},
"fee": "10000",
"hash": "B128DC8C3D820F0832BEBD81045FA65ABFDC88FB83246B37E3F1298AF3DE778A",
Expand All @@ -171,7 +169,6 @@ Array [
"contract": undefined,
"extra": Object {
"memo": "lb",
"validators": Array [],
},
"fee": "8880",
"hash": "0B17FF19A1E8DC703A3AEC457B414DE88845DD76BB4D95F8F6368F68D59248DF",
Expand Down

1 comment on commit 1c6deb2

@vercel
Copy link

@vercel vercel bot commented on 1c6deb2 Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.