forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpricing.ts
More file actions
27 lines (24 loc) · 1.27 KB
/
Copy pathpricing.ts
File metadata and controls
27 lines (24 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { getBotConfig } from "../../bindings";
export const calculateBountyPrice = (timeValue: number, priorityValue: number, baseValue?: number): number => {
const botConfig = getBotConfig();
const base = baseValue ?? botConfig.price.baseMultiplier;
const priority = priorityValue / 10; // floats cause bad math
const price = base * timeValue * priority;
return price;
};
export const getTargetPriceLabel = (timeLabel: string | undefined, priorityLabel: string | undefined): string | undefined => {
const botConfig = getBotConfig();
let targetPriceLabel: string | undefined = undefined;
if (!timeLabel && !priorityLabel) return targetPriceLabel;
if (!timeLabel) {
targetPriceLabel = botConfig.price.priorityLabels.find((item) => item.name === priorityLabel)?.target;
} else if (!priorityLabel) {
targetPriceLabel = botConfig.price.timeLabels.find((item) => item.name === timeLabel)?.target;
} else {
const timeWeight = botConfig.price.timeLabels.find((item) => item.name === timeLabel)!.weight;
const priorityWeight = botConfig.price.priorityLabels.find((item) => item.name === priorityLabel)!.weight;
const bountyPrice = calculateBountyPrice(timeWeight, priorityWeight);
targetPriceLabel = `Price: ${bountyPrice} USD`;
}
return targetPriceLabel;
};