mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
refactor(Tx): record rate and use Math.ceil instead of Math.floor
This commit is contained in:
parent
599d70f1de
commit
09c03b9df0
2 changed files with 5 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ const { isEnabled } = require('../server/utils/handleText');
|
||||||
const transactionSchema = require('./schema/transaction');
|
const transactionSchema = require('./schema/transaction');
|
||||||
const { getMultiplier } = require('./tx');
|
const { getMultiplier } = require('./tx');
|
||||||
const Balance = require('./Balance');
|
const Balance = require('./Balance');
|
||||||
|
const cancelRate = 1.15;
|
||||||
|
|
||||||
// Method to calculate and set the tokenValue for a transaction
|
// Method to calculate and set the tokenValue for a transaction
|
||||||
transactionSchema.methods.calculateTokenValue = function () {
|
transactionSchema.methods.calculateTokenValue = function () {
|
||||||
|
|
@ -11,9 +12,11 @@ transactionSchema.methods.calculateTokenValue = function () {
|
||||||
}
|
}
|
||||||
const { valueKey, tokenType, model } = this;
|
const { valueKey, tokenType, model } = this;
|
||||||
const multiplier = getMultiplier({ valueKey, tokenType, model });
|
const multiplier = getMultiplier({ valueKey, tokenType, model });
|
||||||
|
this.rate = multiplier;
|
||||||
this.tokenValue = this.rawAmount * multiplier;
|
this.tokenValue = this.rawAmount * multiplier;
|
||||||
if (this.context && this.tokenType === 'completion' && this.context === 'incomplete') {
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ const transactionSchema = mongoose.Schema({
|
||||||
valueKey: {
|
valueKey: {
|
||||||
type: String,
|
type: String,
|
||||||
},
|
},
|
||||||
|
rate: Number,
|
||||||
rawAmount: Number,
|
rawAmount: Number,
|
||||||
tokenValue: Number,
|
tokenValue: Number,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue