Skip to content

Commit

Permalink
Bugfixes/improve monthly cost calculations (#25)
Browse files Browse the repository at this point in the history
* Fix homepage cost calculation

* Improve monthly cost precision
  • Loading branch information
Redm4x authored Oct 5, 2023
1 parent 09af570 commit e0f7f58
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion deploy-web/src/components/deployment/DeploymentListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const DeploymentListRow: React.FunctionComponent<Props> = ({ deployment,
{isActive && !!deploymentCost && (
<Box marginLeft="1rem" display="flex">
<Box sx={{ display: "flex", alignItems: "center" }}>
<PricePerMonth denom={deployment.escrowAccount.balance.denom} perBlockValue={udenomToDenom(deploymentCost, 6)} typoVariant="body1" />
<PricePerMonth denom={deployment.escrowAccount.balance.denom} perBlockValue={udenomToDenom(deploymentCost, 10)} typoVariant="body1" />

<CustomTooltip
arrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const DeploymentSubHeader: React.FunctionComponent<Props> = ({ deployment
value={
!!deploymentCost && (
<Box sx={{ display: "flex", alignItems: "center" }}>
<PricePerMonth denom={deployment.escrowAccount.balance.denom} perBlockValue={udenomToDenom(deploymentCost, 6)} typoVariant="body1" />
<PricePerMonth denom={deployment.escrowAccount.balance.denom} perBlockValue={udenomToDenom(deploymentCost, 10)} typoVariant="body1" />

<CustomTooltip
arrow
Expand Down
2 changes: 1 addition & 1 deletion deploy-web/src/components/deploymentDetail/LeaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const LeaseRow = React.forwardRef<AcceptRefType, Props>(({ lease, setActi
label="Price:"
value={
<Box sx={{ display: "flex", alignItems: "center" }}>
<PricePerMonth denom={lease.price.denom} perBlockValue={udenomToDenom(lease.price.amount, 6)} sx={{ fontSize: "1.25rem" }} />
<PricePerMonth denom={lease.price.denom} perBlockValue={udenomToDenom(lease.price.amount, 10)} sx={{ fontSize: "1.25rem" }} />
<PriceEstimateTooltip denom={lease.price.denom} value={lease.price.amount} />
</Box>
}
Expand Down
10 changes: 5 additions & 5 deletions deploy-web/src/components/home/YourAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
import { ResponsivePie } from "@nivo/pie";
import { makeStyles } from "tss-react/mui";
import { Box, Button, Card, CardContent, CardHeader, Chip, CircularProgress, lighten, Typography, useTheme } from "@mui/material";
import { uaktToAKT } from "@src/utils/priceUtils";
import { getAvgCostPerMonth, uaktToAKT } from "@src/utils/priceUtils";
import { PriceValue } from "../shared/PriceValue";
import { DeploymentDto, LeaseDto } from "@src/types/deployment";
import { StatusPill } from "../shared/StatusPill";
Expand Down Expand Up @@ -147,13 +147,13 @@ export const YourAccount: React.FunctionComponent<Props> = ({ balances, isLoadin
useEffect(() => {
if (leases && providers && price && isLoaded) {
const activeLeases = leases.filter(x => x.state === "active");
const totalCost = activeLeases
const totalCostPerBlock = activeLeases
.map(x => {
switch (x.price.denom) {
case uAktDenom:
return parseFloat(x.price.amount) * price;
return udenomToDenom(x.price.amount, 10) * price;
case usdcIbcDenom:
return parseFloat(x.price.amount);
return udenomToDenom(x.price.amount, 10);

default:
return 0;
Expand All @@ -169,7 +169,7 @@ export const YourAccount: React.FunctionComponent<Props> = ({ balances, isLoadin
return { owner: provider.owner, name: provider.name };
});

setCostPerMonth(totalCost);
setCostPerMonth(getAvgCostPerMonth(totalCostPerBlock));
setUserProviders(_userProviders);
}
}, [leases, providers, price, isLoaded]);
Expand Down
2 changes: 1 addition & 1 deletion deploy-web/src/components/newDeploymentWizard/BidRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const BidRow: React.FunctionComponent<Props> = ({ bid, selectedBid, handl
>
<TableCell align="center">
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "center" }}>
<PricePerMonth denom={bid.price.denom} perBlockValue={udenomToDenom(bid.price.amount, 6)} className={classes.pricePerMonth} />
<PricePerMonth denom={bid.price.denom} perBlockValue={udenomToDenom(bid.price.amount, 10)} className={classes.pricePerMonth} />
<PriceEstimateTooltip denom={bid.price.denom} value={bid.price.amount} />
</Box>
</TableCell>
Expand Down
2 changes: 1 addition & 1 deletion deploy-web/src/components/providers/LeaseRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MemoLeaseRow: React.FunctionComponent<Props> = ({ lease }) => {
</TableCell>
<TableCell>
<div className={classes.flexCenter}>
<PricePerMonth denom={lease.price.denom} perBlockValue={uaktToAKT(parseFloat(lease.price.amount), 6)} />
<PricePerMonth denom={lease.price.denom} perBlockValue={uaktToAKT(parseFloat(lease.price.amount), 10)} />
<PriceEstimateTooltip denom={lease.price.denom} value={lease.price.amount} />
</div>
</TableCell>
Expand Down
7 changes: 2 additions & 5 deletions deploy-web/src/components/sdl/SimpleServiceFormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { PlacementFormModal } from "./PlacementFormModal";
import { udenomToDenom } from "@src/utils/mathHelpers";
import Link from "next/link";
import { PriceValue } from "../shared/PriceValue";
import { averageBlockTime } from "@src/utils/priceUtils";
import { averageBlockTime, getAvgCostPerMonth } from "@src/utils/priceUtils";
import { averageDaysInMonth } from "@src/utils/dateUtils";
import Image from "next/legacy/image";
import { uAktDenom } from "@src/utils/constants";
Expand Down Expand Up @@ -1149,10 +1149,7 @@ export const SimpleServiceFormControl: React.FunctionComponent<Props> = ({
<div>
<strong>
~
<PriceValue
denom={uAktDenom}
value={udenomToDenom(currentService.placement.pricing.amount) * (60 / averageBlockTime) * 60 * 24 * averageDaysInMonth}
/>
<PriceValue denom={uAktDenom} value={udenomToDenom(getAvgCostPerMonth(currentService.placement.pricing.amount))} />
</strong>
&nbsp; per month
</div>
Expand Down
2 changes: 1 addition & 1 deletion deploy-web/src/components/shared/PriceEstimateTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const useStyles = makeStyles()(theme => ({

export const PriceEstimateTooltip: React.FunctionComponent<Props> = ({ value, denom }) => {
const { classes } = useStyles();
const _value = udenomToDenom(typeof value === "string" ? parseFloat(value) : value, 6);
const _value = udenomToDenom(typeof value === "string" ? parseFloat(value) : value, 10);
const perDayValue = _value * (60 / averageBlockTime) * 60 * 24;
const perMonthValue = _value * (60 / averageBlockTime) * 60 * 24 * averageDaysInMonth;
const denomData = useDenomData(denom);
Expand Down

0 comments on commit e0f7f58

Please sign in to comment.