From 35d41969e00e15b4817f2be558a7c81200b71cc7 Mon Sep 17 00:00:00 2001 From: Hakim <59644786+haammar-ledger@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:40:19 +0100 Subject: [PATCH] [bugfix][RELEASE] Sanitize Tron account data that may be missing when de/serializing Tron accounts (#6023) * Sanitize account data that may be missing when de/serializing Tron accounts * Add changeset --- .changeset/rotten-cycles-approve.md | 5 ++++ .../src/families/tron/serialization.ts | 28 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 .changeset/rotten-cycles-approve.md diff --git a/.changeset/rotten-cycles-approve.md b/.changeset/rotten-cycles-approve.md new file mode 100644 index 000000000000..b38f0fef5e0c --- /dev/null +++ b/.changeset/rotten-cycles-approve.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/live-common": patch +--- + +Sanitize account data that may be missing when de/serializing Tron accounts diff --git a/libs/ledger-live-common/src/families/tron/serialization.ts b/libs/ledger-live-common/src/families/tron/serialization.ts index fd5dd5da739d..6fbed9420012 100644 --- a/libs/ledger-live-common/src/families/tron/serialization.ts +++ b/libs/ledger-live-common/src/families/tron/serialization.ts @@ -21,8 +21,10 @@ export const toTronResourcesRaw = ({ const delegatedFrozenBandwidth = delegatedFrozen.bandwidth; const delegatedFrozenEnergy = delegatedFrozen.energy; const cacheTransactionInfoById = {}; - const legacyFrozenBandwidth = legacyFrozen.bandwidth; - const legacyFrozenEnergy = legacyFrozen.energy; + const unFrozenBandwidth = unFrozen?.bandwidth; + const unFrozenEnergy = unFrozen?.energy; + const legacyFrozenBandwidth = legacyFrozen?.bandwidth; + const legacyFrozenEnergy = legacyFrozen?.energy; for (const k in cacheTx) { const { fee, blockNumber, withdraw_amount, unfreeze_amount } = cacheTx[k]; @@ -55,13 +57,13 @@ export const toTronResourcesRaw = ({ : undefined, }, unFrozen: { - bandwidth: unFrozen.bandwidth - ? unFrozen.bandwidth.map(entry => { + bandwidth: unFrozenBandwidth + ? unFrozenBandwidth.map(entry => { return { amount: entry.amount.toString(), expireTime: entry.expireTime.toISOString() }; }) : undefined, - energy: unFrozen.energy - ? unFrozen.energy.map(entry => { + energy: unFrozenEnergy + ? unFrozenEnergy.map(entry => { return { amount: entry.amount.toString(), expireTime: entry.expireTime.toISOString() }; }) : undefined, @@ -115,8 +117,10 @@ export const fromTronResourcesRaw = ({ const frozenEnergy = frozen.energy; const delegatedFrozenBandwidth = delegatedFrozen.bandwidth; const delegatedFrozenEnergy = delegatedFrozen.energy; - const legacyFrozenBandwidth = legacyFrozen.bandwidth; - const legacyFrozenEnergy = legacyFrozen.energy; + const unFrozenBandwidth = unFrozen?.bandwidth; + const unFrozenEnergy = unFrozen?.energy; + const legacyFrozenBandwidth = legacyFrozen?.bandwidth; + const legacyFrozenEnergy = legacyFrozen?.energy; const cacheTransactionInfoById = {}; @@ -158,13 +162,13 @@ export const fromTronResourcesRaw = ({ : undefined, }, unFrozen: { - bandwidth: unFrozen.bandwidth - ? unFrozen.bandwidth.map(entry => { + bandwidth: unFrozenBandwidth + ? unFrozenBandwidth.map(entry => { return { amount: new BigNumber(entry.amount), expireTime: new Date(entry.expireTime) }; }) : undefined, - energy: unFrozen.energy - ? unFrozen.energy.map(entry => { + energy: unFrozenEnergy + ? unFrozenEnergy.map(entry => { return { amount: new BigNumber(entry.amount), expireTime: new Date(entry.expireTime) }; }) : undefined,