@lyxa.ai/core 1.1.96 → 1.1.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function calculateWalletDeduction(currentMainBalance: number, deductionAmount: number, isDualCurrencyEnabled?:
|
|
1
|
+
export declare function calculateWalletDeduction(currentMainBalance: number, deductionAmount: number, isDualCurrencyEnabled?: boolean): {
|
|
2
2
|
mainWalletChange: number;
|
|
3
3
|
reserveWalletChange: number;
|
|
4
4
|
};
|
package/dist/utilities/wallet.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateWalletDeduction = calculateWalletDeduction;
|
|
4
4
|
const shared_1 = require("./shared");
|
|
5
|
-
function calculateWalletDeduction(currentMainBalance, deductionAmount, isDualCurrencyEnabled) {
|
|
5
|
+
function calculateWalletDeduction(currentMainBalance, deductionAmount, isDualCurrencyEnabled = true) {
|
|
6
6
|
const round = isDualCurrencyEnabled ? shared_1.roundSecondaryCurrency : shared_1.roundBaseCurrency;
|
|
7
7
|
const remainingAfterMain = round(currentMainBalance - deductionAmount);
|
|
8
8
|
if (remainingAfterMain >= 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.js","sourceRoot":"/","sources":["utilities/wallet.ts"],"names":[],"mappings":";;AAOA,4DAkBC;AAzBD,qCAAqE;AAOrE,SAAgB,wBAAwB,CACvC,kBAA0B,EAC1B,eAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"/","sources":["utilities/wallet.ts"],"names":[],"mappings":";;AAOA,4DAkBC;AAzBD,qCAAqE;AAOrE,SAAgB,wBAAwB,CACvC,kBAA0B,EAC1B,eAAuB,EACvB,wBAAiC,IAAI;IAKrC,MAAM,KAAK,GAAG,qBAAqB,CAAC,CAAC,CAAC,+BAAsB,CAAC,CAAC,CAAC,0BAAiB,CAAC;IACjF,MAAM,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,GAAG,eAAe,CAAC,CAAC;IAGvE,IAAI,kBAAkB,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,gBAAgB,EAAE,CAAC,eAAe,EAAE,mBAAmB,EAAE,CAAC,EAAE,CAAC;IACvE,CAAC;IAGD,OAAO,EAAE,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;AAC3F,CAAC","sourcesContent":["import { roundBaseCurrency, roundSecondaryCurrency } from './shared';\n\n/**\n * Calculates how much to deduct from a user's wallets.\n * Deducts from the main wallet first, then from the reserve wallet if needed.\n * Returns negative values (for use with $inc updates in MongoDB).\n */\nexport function calculateWalletDeduction(\n\tcurrentMainBalance: number,\n\tdeductionAmount: number,\n\tisDualCurrencyEnabled: boolean = true\n): {\n\tmainWalletChange: number;\n\treserveWalletChange: number;\n} {\n\tconst round = isDualCurrencyEnabled ? roundSecondaryCurrency : roundBaseCurrency;\n\tconst remainingAfterMain = round(currentMainBalance - deductionAmount);\n\n\t// If main has enough, reserve doesn't change\n\tif (remainingAfterMain >= 0) {\n\t\treturn { mainWalletChange: -deductionAmount, reserveWalletChange: 0 };\n\t}\n\n\t// Otherwise, deduct all from main and the remainder (negative) from reserve\n\treturn { mainWalletChange: -currentMainBalance, reserveWalletChange: remainingAfterMain };\n}\n"]}
|