Skip to content

Commit

Permalink
refactor(Tx): record rate and use Math.ceil instead of Math.floor
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila committed Oct 6, 2023
1 parent 599d70f commit 09c03b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/models/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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;
}
};

Expand Down
1 change: 1 addition & 0 deletions api/models/schema/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const transactionSchema = mongoose.Schema({
valueKey: {
type: String,
},
rate: Number,
rawAmount: Number,
tokenValue: Number,
});
Expand Down

0 comments on commit 09c03b9

Please sign in to comment.