From e0c3f6604064b9f4ed267f25be671ce104764965 Mon Sep 17 00:00:00 2001 From: Jeremy Wharton Date: Thu, 16 Mar 2023 22:27:27 -0500 Subject: [PATCH] web/satellite: display correct prices in account upgrade modal The account upgrade modal has been updated to display prices according to the the user's price model. Previously, the modal displayed only the default prices which were incorrect for users with price overrides. Resolves storj/storj-private#187 Change-Id: I58206cc8ea7e7742a37f759a84dbb24ca40dd8eb --- .../UsageAndChargesItem.vue | 20 +++---- .../UsageAndChargesItem2.vue | 20 +++---- .../modals/AddPaymentMethodModal.vue | 58 +++++++++++++++++-- web/satellite/src/utils/strings.ts | 39 +++++++++++++ .../tests/unit/utils/strings.spec.ts | 41 +++++++++++-- 5 files changed, 144 insertions(+), 34 deletions(-) diff --git a/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem.vue b/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem.vue index 0106789de..856f5bfe6 100644 --- a/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem.vue +++ b/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem.vue @@ -22,9 +22,9 @@
-

Storage (${{ storagePrice }} per Gigabyte-Month)

-

Egress (${{ egressPrice }} per GB)

-

Segments (${{ segmentPrice }} per Segment-Month)

+

Storage ({{ storagePrice }} per Gigabyte-Month)

+

Egress ({{ egressPrice }} per GB)

+

Segments ({{ segmentPrice }} per Segment-Month)

{{ period }}

@@ -53,7 +53,7 @@ import { ProjectUsageAndCharges, ProjectUsagePriceModel } from '@/types/payments import { Project } from '@/types/projects'; import { Size } from '@/utils/bytesSize'; import { SHORT_MONTHS_NAMES } from '@/utils/constants/date'; -import { decimalShift } from '@/utils/strings'; +import { decimalShift, formatPrice, CENTS_MB_TO_DOLLARS_GB_SHIFT } from '@/utils/strings'; import { AnalyticsHttpApi } from '@/api/analytics'; import { AnalyticsEvent } from '@/utils/constants/analyticsEventNames'; import { useStore } from '@/utils/hooks'; @@ -68,12 +68,6 @@ const analytics: AnalyticsHttpApi = new AnalyticsHttpApi(); */ const HOURS_IN_MONTH = 720; -/** - * CENTS_MB_TO_DOLLARS_GB_SHIFT constant represents how many places to the left - * a decimal point must be shifted to convert from cents/MB to dollars/GB. - */ -const CENTS_MB_TO_DOLLARS_GB_SHIFT = -1; - const props = withDefaults(defineProps<{ /** * item represents usage and charges of current project by period. @@ -144,21 +138,21 @@ const segmentCountFormatted = computed((): string => { * Returns storage price per GB. */ const storagePrice = computed((): string => { - return decimalShift(priceModel.value.storageMBMonthCents, CENTS_MB_TO_DOLLARS_GB_SHIFT); + return formatPrice(decimalShift(priceModel.value.storageMBMonthCents, CENTS_MB_TO_DOLLARS_GB_SHIFT)); }); /** * Returns egress price per GB. */ const egressPrice = computed((): string => { - return decimalShift(priceModel.value.egressMBCents, CENTS_MB_TO_DOLLARS_GB_SHIFT); + return formatPrice(decimalShift(priceModel.value.egressMBCents, CENTS_MB_TO_DOLLARS_GB_SHIFT)); }); /** * Returns segment price. */ const segmentPrice = computed((): string => { - return decimalShift(priceModel.value.segmentMonthCents, 2); + return formatPrice(decimalShift(priceModel.value.segmentMonthCents, 2)); }); /** diff --git a/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem2.vue b/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem2.vue index a16ec7b71..b0c5ea3ee 100644 --- a/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem2.vue +++ b/web/satellite/src/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem2.vue @@ -26,9 +26,9 @@
-

Storage (${{ storagePrice }} per Gigabyte-Month)

-

Egress (${{ egressPrice }} per GB)

-

Segments (${{ segmentPrice }} per Segment-Month)

+

Storage ({{ storagePrice }} per Gigabyte-Month)

+

Egress ({{ egressPrice }} per GB)

+

Segments ({{ segmentPrice }} per Segment-Month)

{{ period }}

@@ -58,7 +58,7 @@ import { ProjectUsageAndCharges, ProjectUsagePriceModel } from '@/types/payments import { Project } from '@/types/projects'; import { Size } from '@/utils/bytesSize'; import { SHORT_MONTHS_NAMES } from '@/utils/constants/date'; -import { decimalShift } from '@/utils/strings'; +import { decimalShift, formatPrice, CENTS_MB_TO_DOLLARS_GB_SHIFT } from '@/utils/strings'; import { useStore } from '@/utils/hooks'; import GreyChevron from '@/../static/images/common/greyChevron.svg'; @@ -68,12 +68,6 @@ import GreyChevron from '@/../static/images/common/greyChevron.svg'; */ const HOURS_IN_MONTH = 720; -/** - * CENTS_MB_TO_DOLLARS_GB_SHIFT constant represents how many places to the left - * a decimal point must be shifted to convert from cents/MB to dollars/GB. - */ -const CENTS_MB_TO_DOLLARS_GB_SHIFT = -1; - const props = withDefaults(defineProps<{ /** * item represents usage and charges of current project by period. @@ -144,21 +138,21 @@ const segmentCountFormatted = computed((): string => { * Returns storage price per GB. */ const storagePrice = computed((): string => { - return decimalShift(priceModel.value.storageMBMonthCents, CENTS_MB_TO_DOLLARS_GB_SHIFT); + return formatPrice(decimalShift(priceModel.value.storageMBMonthCents, CENTS_MB_TO_DOLLARS_GB_SHIFT)); }); /** * Returns egress price per GB. */ const egressPrice = computed((): string => { - return decimalShift(priceModel.value.egressMBCents, CENTS_MB_TO_DOLLARS_GB_SHIFT); + return formatPrice(decimalShift(priceModel.value.egressMBCents, CENTS_MB_TO_DOLLARS_GB_SHIFT)); }); /** * Returns segment price. */ const segmentPrice = computed((): string => { - return decimalShift(priceModel.value.segmentMonthCents, 2); + return formatPrice(decimalShift(priceModel.value.segmentMonthCents, 2)); }); /** diff --git a/web/satellite/src/components/modals/AddPaymentMethodModal.vue b/web/satellite/src/components/modals/AddPaymentMethodModal.vue index 96fcb890c..32b5d7486 100644 --- a/web/satellite/src/components/modals/AddPaymentMethodModal.vue +++ b/web/satellite/src/components/modals/AddPaymentMethodModal.vue @@ -64,15 +64,16 @@

100 request per second rate limit

-
+ +

Storage price:

-

$4

+

{{ storagePrice }}

TB / month

Bandwidth price:

-

$7

+

{{ bandwidthPrice }}

TB

@@ -125,7 +126,7 @@