diff --git a/backend/src/graphql/model/Balance.ts b/backend/src/graphql/model/Balance.ts index 619d9b242..f04b235ee 100644 --- a/backend/src/graphql/model/Balance.ts +++ b/backend/src/graphql/model/Balance.ts @@ -5,33 +5,20 @@ import Decimal from 'decimal.js-light' export class Balance { constructor(data: { balance: Decimal - decay: Decimal - lastBookedBalance: Decimal balanceGDT: number | null count: number linkCount: number - lastBookedDate?: Date | null }) { this.balance = data.balance - this.decay = data.decay - this.lastBookedBalance = data.lastBookedBalance this.balanceGDT = data.balanceGDT || null this.count = data.count this.linkCount = data.linkCount - this.lastBookedDate = data.lastBookedDate || null } // the actual balance, decay included @Field(() => Decimal) balance: Decimal - // the decay since the last booked balance - @Field(() => Decimal) - decay: Decimal - - @Field(() => Decimal) - lastBookedBalance: Decimal - @Field(() => Number, { nullable: true }) balanceGDT: number | null @@ -42,8 +29,4 @@ export class Balance { // the count of transaction links @Field(() => Number) linkCount: number - - // may be null as there may be no transaction - @Field(() => Date, { nullable: true }) - lastBookedDate: Date | null } diff --git a/backend/src/graphql/model/Decay.ts b/backend/src/graphql/model/Decay.ts index f1204e730..f59a21249 100644 --- a/backend/src/graphql/model/Decay.ts +++ b/backend/src/graphql/model/Decay.ts @@ -1,17 +1,21 @@ import { ObjectType, Field, Int } from 'type-graphql' import Decimal from 'decimal.js-light' +interface DecayInterface { + balance: Decimal + decay: Decimal + roundedDecay: Decimal + start: Date | null + end: Date | null + duration: number | null +} + @ObjectType() export class Decay { - constructor( - balance: Decimal, - decay: Decimal, - start: Date | null, - end: Date | null, - duration: number | null, - ) { + constructor({ balance, decay, roundedDecay, start, end, duration }: DecayInterface) { this.balance = balance this.decay = decay + this.roundedDecay = roundedDecay this.start = start this.end = end this.duration = duration @@ -23,6 +27,9 @@ export class Decay { @Field(() => Decimal) decay: Decimal + @Field(() => Decimal) + roundedDecay: Decimal + @Field(() => Date, { nullable: true }) start: Date | null diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 3c3a684ef..24c66ac67 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -17,21 +17,26 @@ export class Transaction { this.balanceDate = transaction.balanceDate if (!transaction.decayStart) { // 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, - ) + this.decay = new Decay({ + balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + decay: new Decimal(0), + roundedDecay: new Decimal(0), + start: null, + end: null, + duration: null, + }) } else { - this.decay = new 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), - ) + this.decay = new Decay({ + balance: transaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), + decay: transaction.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), + // TODO: add correct value when decay must be rounded in transaction context + roundedDecay: new Decimal(0), + start: transaction.decayStart, + end: transaction.balanceDate, + duration: Math.round( + (transaction.balanceDate.getTime() - transaction.decayStart.getTime()) / 1000, + ), + }) } this.memo = transaction.memo this.creationDate = transaction.creationDate diff --git a/backend/src/graphql/resolver/BalanceResolver.ts b/backend/src/graphql/resolver/BalanceResolver.ts index 7cbd455cb..909a22144 100644 --- a/backend/src/graphql/resolver/BalanceResolver.ts +++ b/backend/src/graphql/resolver/BalanceResolver.ts @@ -29,8 +29,6 @@ export class BalanceResolver { if (!lastTransaction) { return new Balance({ balance: new Decimal(0), - decay: new Decimal(0), - lastBookedBalance: new Decimal(0), balanceGDT, count: 0, linkCount: 0, @@ -69,12 +67,9 @@ export class BalanceResolver { balance: calculatedDecay.balance .minus(sumHoldAvailableAmount.toString()) .toDecimalPlaces(2, Decimal.ROUND_DOWN), // round towards zero - decay: calculatedDecay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR), // round towards - infinity - lastBookedBalance: lastTransaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN), balanceGDT, count, linkCount, - lastBookedDate: lastTransaction.balanceDate, }) } } diff --git a/backend/src/util/decay.ts b/backend/src/util/decay.ts index 36f83f23f..48674dc50 100644 --- a/backend/src/util/decay.ts +++ b/backend/src/util/decay.ts @@ -29,6 +29,7 @@ function calculateDecay( const decay: Decay = { balance: amount, decay: new Decimal(0), + roundedDecay: new Decimal(0), start: null, end: null, duration: null, @@ -52,6 +53,10 @@ function calculateDecay( decay.end = to decay.balance = decayFormula(amount, decay.duration) decay.decay = decay.balance.minus(amount) + decay.roundedDecay = amount + .toDecimalPlaces(2, Decimal.ROUND_DOWN) + .minus(decay.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN).toString()) + .mul(-1) return decay } diff --git a/backend/src/util/virtualTransactions.ts b/backend/src/util/virtualTransactions.ts index 920fc4201..8c1aec65b 100644 --- a/backend/src/util/virtualTransactions.ts +++ b/backend/src/util/virtualTransactions.ts @@ -68,12 +68,12 @@ const virtualDecayTransaction = ( userId: -1, previous: -1, typeId: TransactionTypeId.DECAY, - amount: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0), // new Decimal(0), // this kinda is wrong, but helps with the frontend query + amount: decay.decay ? decay.roundedDecay : new Decimal(0), balance: decay.balance .minus(holdAvailabeAmount.toString()) .toDecimalPlaces(2, Decimal.ROUND_DOWN), balanceDate: time, - decay: decay.decay ? decay.decay.toDecimalPlaces(2, Decimal.ROUND_FLOOR) : new Decimal(0), + decay: decay.decay ? decay.roundedDecay : new Decimal(0), decayStart: decay.start, memo: '', creationDate: null, diff --git a/database/README.md b/database/README.md index af9f3242c..d6cf84518 100644 --- a/database/README.md +++ b/database/README.md @@ -30,10 +30,3 @@ yarn dev_down yarn dev_reset ``` Runs all down migrations and after this all up migrations. - - -## Reset DB -``` -yarn dev_reset -``` - diff --git a/frontend/src/components/DecayInformations/DecayInformation-Decay.vue b/frontend/src/components/DecayInformations/DecayInformation-Decay.vue index 67847f6cf..96ffc9153 100644 --- a/frontend/src/components/DecayInformations/DecayInformation-Decay.vue +++ b/frontend/src/components/DecayInformations/DecayInformation-Decay.vue @@ -17,6 +17,7 @@
{{ previousBookedBalance | GDD }} + {{ decay === '0' ? $t('math.minus') : '' }} {{ decay | GDD }} {{ $t('math.equal') }} {{ balance | GDD }}
diff --git a/frontend/src/config/index.js b/frontend/src/config/index.js index d29c4dc09..a11b5d924 100644 --- a/frontend/src/config/index.js +++ b/frontend/src/config/index.js @@ -5,7 +5,7 @@ const pkg = require('../../package') const constants = { - DECAY_START_TIME: new Date('2021-05-13 17:46:31'), // GMT+0 + DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 CONFIG_VERSION: { DEFAULT: 'DEFAULT', EXPECTED: 'v1.2022-03-18', diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index dce22fbd9..6a27a8052 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -47,12 +47,9 @@ export const transactionsQuery = gql` transactionList(currentPage: $currentPage, pageSize: $pageSize, order: $order) { balance { balance - decay - lastBookedBalance balanceGDT count linkCount - lastBookedDate } transactions { id diff --git a/frontend/src/layouts/DashboardLayout_gdd.vue b/frontend/src/layouts/DashboardLayout_gdd.vue index 8b84ac10d..f65329470 100755 --- a/frontend/src/layouts/DashboardLayout_gdd.vue +++ b/frontend/src/layouts/DashboardLayout_gdd.vue @@ -53,11 +53,9 @@ export default { }, data() { return { - logo: 'img/brand/green.png', balance: 0, GdtBalance: 0, transactions: [], - bookedBalance: 0, transactionCount: 0, transactionLinkCount: 0, pending: true, diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 899ff85dc..20ce055d4 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -147,6 +147,7 @@ "aprox": "~", "equal": "=", "exclaim": "!", + "minus": "−", "pipe": "|" }, "navigation": { diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 0431e6209..201c44d93 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -147,6 +147,7 @@ "aprox": "~", "equal": "=", "exclaim": "!", + "minus": "−", "pipe": "|" }, "navigation": {