From 1c6deb2336a8b76517cc4d367f76dca24f9228dc Mon Sep 17 00:00:00 2001 From: Hakim <59644786+haammar-ledger@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:22:50 +0200 Subject: [PATCH] [bugfix] Fix regression when serializing cosmos operation extra (#4528) * 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> --- .changeset/olive-oranges-know.md | 5 ++++ .../src/account/serialization.ts | 28 +++++++++++++------ .../src/families/cosmos/account.ts | 16 +++++------ .../coreum.integration.test.ts.snap | 3 -- 4 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 .changeset/olive-oranges-know.md diff --git a/.changeset/olive-oranges-know.md b/.changeset/olive-oranges-know.md new file mode 100644 index 000000000000..b8e2075a2116 --- /dev/null +++ b/.changeset/olive-oranges-know.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/live-common": patch +--- + +Fix regression when serializing cosmos operation extra diff --git a/libs/coin-framework/src/account/serialization.ts b/libs/coin-framework/src/account/serialization.ts index bc8c8161477b..d75ed92a30bf 100644 --- a/libs/coin-framework/src/account/serialization.ts +++ b/libs/coin-framework/src/account/serialization.ts @@ -140,10 +140,6 @@ export const fromOperationRaw = ( value: new BigNumber(value), fee: new BigNumber(fee), extra, - contract, - operator, - standard, - tokenId, }; if (transactionSequenceNumber !== undefined) { @@ -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) { @@ -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; }; diff --git a/libs/ledger-live-common/src/families/cosmos/account.ts b/libs/ledger-live-common/src/families/cosmos/account.ts index 7a0f2dc26592..70bdb73a64b4 100644 --- a/libs/ledger-live-common/src/families/cosmos/account.ts +++ b/libs/ledger-live-common/src/families/cosmos/account.ts @@ -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), @@ -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; diff --git a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap index 2ca38210f0c0..659b4545d4d4 100644 --- a/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap +++ b/libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/coreum.integration.test.ts.snap @@ -119,7 +119,6 @@ Array [ "contract": undefined, "extra": Object { "memo": "lb", - "validators": Array [], }, "fee": "8880", "hash": "0B17FF19A1E8DC703A3AEC457B414DE88845DD76BB4D95F8F6368F68D59248DF", @@ -144,7 +143,6 @@ Array [ "contract": undefined, "extra": Object { "memo": "Lc", - "validators": Array [], }, "fee": "10000", "hash": "B128DC8C3D820F0832BEBD81045FA65ABFDC88FB83246B37E3F1298AF3DE778A", @@ -171,7 +169,6 @@ Array [ "contract": undefined, "extra": Object { "memo": "lb", - "validators": Array [], }, "fee": "8880", "hash": "0B17FF19A1E8DC703A3AEC457B414DE88845DD76BB4D95F8F6368F68D59248DF",