Skip to content

Commit

Permalink
[bugfix][RELEASE] Sanitize Tron account data that may be missing when…
Browse files Browse the repository at this point in the history
… de/serializing Tron accounts (#6023)

* Sanitize account data that may be missing when de/serializing Tron accounts

* Add changeset
  • Loading branch information
Hakim authored Jan 26, 2024
1 parent 795f707 commit 35d4196
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-cycles-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Sanitize account data that may be missing when de/serializing Tron accounts
28 changes: 16 additions & 12 deletions libs/ledger-live-common/src/families/tron/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 35d4196

Please sign in to comment.