From 15e3aeb7e6fce4a968c65806f8b1c1e0fc9b0cb9 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 1 Apr 2022 13:57:25 +0200 Subject: [PATCH 1/5] round virtual transaction link transaction --- backend/src/util/virtualTransactions.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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, From a32e0a9d434e75ab5c93f4e93bcdc88bd6d6fc70 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 1 Apr 2022 14:04:01 +0200 Subject: [PATCH 2/5] round down decay amount and balance --- backend/src/graphql/model/Decay.ts | 2 +- backend/src/graphql/model/Transaction.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index f1204e730..ba09702fa 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -11,7 +11,7 @@ export class Decay { duration: number | null, ) { this.balance = balance - this.decay = decay + this.decay = decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) this.start = start this.end = end this.duration = duration diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 684224175..d641e038e 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -12,8 +12,8 @@ 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.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) From ff04cf0cb5b911238badc61efe73cbf248cf1a30 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 1 Apr 2022 14:08:55 +0200 Subject: [PATCH 3/5] do not round in decay model as it is used in utils on creation --- backend/src/graphql/model/Decay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index ba09702fa..f1204e730 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -11,7 +11,7 @@ export class Decay { duration: number | null, ) { this.balance = balance - this.decay = decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) + this.decay = decay this.start = start this.end = end this.duration = duration From cc86a81117cc51b4906642912fad27a190aa9f29 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 1 Apr 2022 14:13:49 +0200 Subject: [PATCH 4/5] round decay values in transaction graphql model --- backend/src/graphql/model/Transaction.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index d641e038e..0ffb4c0bd 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -16,11 +16,18 @@ export class Transaction { this.balance = transaction.balance.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), From 8923cda341ae59d92ab06167fea6091bd540657f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 1 Apr 2022 14:35:42 +0200 Subject: [PATCH 5/5] fix copy and paste mess --- backend/src/graphql/model/Transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 0ffb4c0bd..3c3a684ef 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -13,7 +13,7 @@ export class Transaction { this.previous = transaction.previous this.typeId = transaction.typeId this.amount = transaction.amount.toDecimalPlaces(2, Decimal.ROUND_DOWN) - this.balance = transaction.balance.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN) + this.balance = transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN) this.balanceDate = transaction.balanceDate if (!transaction.decayStart) { // TODO: hot fix, we should separate decay calculation from decay graphql model