refactor(Tx): record rate and use Math.ceil instead of Math.floor

This commit is contained in:
Danny Avila 2023-10-06 13:39:30 -04:00 committed by Danny Avila
parent 599d70f1de
commit 09c03b9df0
2 changed files with 5 additions and 1 deletions

View file

@ -3,6 +3,7 @@ const { isEnabled } = require('../server/utils/handleText');
const transactionSchema = require('./schema/transaction');
const { getMultiplier } = require('./tx');
const Balance = require('./Balance');
const cancelRate = 1.15;
// Method to calculate and set the tokenValue for a transaction
transactionSchema.methods.calculateTokenValue = function () {
@ -11,9 +12,11 @@ transactionSchema.methods.calculateTokenValue = function () {
}
const { valueKey, tokenType, model } = this;
const multiplier = getMultiplier({ valueKey, tokenType, model });
this.rate = multiplier;
this.tokenValue = this.rawAmount * multiplier;
if (this.context && this.tokenType === 'completion' && this.context === 'incomplete') {
this.tokenValue = Math.floor(this.tokenValue * 1.15);
this.tokenValue = Math.ceil(this.tokenValue * cancelRate);
this.rate *= cancelRate;
}
};

View file

@ -26,6 +26,7 @@ const transactionSchema = mongoose.Schema({
valueKey: {
type: String,
},
rate: Number,
rawAmount: Number,
tokenValue: Number,
});