diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 684224175..3c3a684ef 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -12,15 +12,22 @@ export class Transaction { this.user = user this.previous = transaction.previous this.typeId = transaction.typeId - this.amount = transaction.amount - this.balance = transaction.balance + this.amount = transaction.amount.toDecimalPlaces(2, Decimal.ROUND_DOWN) + this.balance = transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN) this.balanceDate = transaction.balanceDate if (!transaction.decayStart) { - this.decay = new Decay(transaction.balance, new Decimal(0), null, null, null) + // TODO: hot fix, we should separate decay calculation from decay graphql model + this.decay = new Decay( + transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + new Decimal(0), + null, + null, + null, + ) } else { this.decay = new Decay( - transaction.balance, - transaction.decay, + transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), transaction.decayStart, transaction.balanceDate, Math.round((transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000), diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index ff1b7548e..920fc4201 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -42,11 +42,11 @@ const virtualLinkTransaction = ( userId: -1, previous: -1, typeId: TransactionTypeId.LINK_SUMMARY, - amount: amount, - balance: balance, + amount: amount.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + balance: balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), balanceDate: validUntil, decayStart: createdAt, - decay: decay, + decay: decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), memo: '', creationDate: null, ...defaultModelFunctions,