fix: unit functions

This commit is contained in:
Arman committed 2023-12-15 12:03:03 +01:00
1 parent 502cb3fcbd
commit 8686628ea2
2 files changed
+13 -6

No files matched your search

+10 -3
View File
@@ -44,11 +44,18 @@ export function createValueUnitPair<T = string>(initialValue = 0, units: Unit<T>
unit.subscribe((newValue, prev) => {
value.update((v) => {
const unitInBase = v * units.find((u) => u.name === prev).value;
return unitInBase / units.find((u) => u.name === newValue).value;
const prevUnit = units.find((u) => u.name === prev);
const newUnit = units.find((u) => u.name === newValue);
// If either unit is not found, just return the current value
if (!prevUnit || !newUnit) {
return v;
}
const unitInBase = v * prevUnit.value;
return unitInBase / newUnit.value;
});
});
return {
value,
unit,
+3 -3
View File
@@ -70,9 +70,9 @@ export type PlanServices =
export function getServiceLimit(serviceId: PlanServices, tier: Tier = null): number {
if (!isCloud) return 0;
if (!serviceId) return 0;
const plan = get(plansInfo).plans.find(
(p) => p.$id === (tier ?? get(organization)?.billingPlan)
);
const info = get(plansInfo);
if (!info?.plans) return 0;
const plan = info.plans.find((p) => p.$id === (tier ?? get(organization)?.billingPlan));
return plan?.[serviceId];
}