Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proration and credit calculated amounts #1878

Merged
merged 29 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
131e3a5
added api
tanmoyAtb Jan 21, 2022
5db2649
Merge branch 'dev' of github.com:ChainSafe/ui-monorepo into feat/pric…
tanmoyAtb Jan 24, 2022
396a40a
currennt and previous balance
tanmoyAtb Jan 24, 2022
65b72a1
Merge branch 'dev' of github.com:ChainSafe/ui-monorepo into feat/pric…
tanmoyAtb Jan 25, 2022
0db07d1
proration amounts
tanmoyAtb Jan 25, 2022
67f542a
lingui extract
actions-user Jan 25, 2022
05dee81
Update packages/files-ui/src/Components/Modules/Settings/Subscription…
tanmoyAtb Jan 27, 2022
9cb857e
Update packages/files-ui/src/Components/Modules/Settings/Subscription…
tanmoyAtb Jan 27, 2022
9c61774
Update packages/files-ui/src/Components/Modules/Settings/Subscription…
tanmoyAtb Jan 27, 2022
deb3906
Update packages/files-ui/src/Components/Modules/Settings/Subscription…
tanmoyAtb Jan 27, 2022
2f279bb
merged
tanmoyAtb Jan 27, 2022
7758f7c
lingui extract
actions-user Jan 27, 2022
61a9991
lint fix
Tbaut Jan 27, 2022
b8f1995
resolved
tanmoyAtb Jan 28, 2022
f14a320
resolved
tanmoyAtb Jan 28, 2022
33b549d
merge changes
tanmoyAtb Jan 31, 2022
598af23
Merge branch 'dev' into feat/price-calculations-1869
Tbaut Feb 1, 2022
067cd88
Merge branch 'dev' into feat/price-calculations-1869
Tbaut Feb 1, 2022
7de7b44
Merge branch 'dev' into feat/price-calculations-1869
tanmoyAtb Feb 3, 2022
9e1babe
Merge branch 'dev' into feat/price-calculations-1869
Tbaut Feb 4, 2022
755a5b8
merged
tanmoyAtb Feb 9, 2022
a46c6d0
client updates
tanmoyAtb Feb 11, 2022
08193b4
client updates
tanmoyAtb Feb 11, 2022
bad33ee
calculation deigns
tanmoyAtb Feb 11, 2022
1523a35
lingui extract
actions-user Feb 11, 2022
4bb154d
terms updated
tanmoyAtb Feb 11, 2022
d07a009
lingui extract
actions-user Feb 11, 2022
2db9360
Merge branch 'dev' into feat/price-calculations-1869
tanmoyAtb Feb 11, 2022
d27e949
Merge branch 'dev' into feat/price-calculations-1869
FSM1 Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PlanSuccess from "./PlanSuccess"
import DowngradeDetails from "./DowngradeDetails"
import { PaymentMethod } from "../../../../../Contexts/BillingContext"
import CryptoPayment from "./CryptoPayment"

const useStyles = makeStyles(({ constants, breakpoints }: CSFTheme) =>
createStyles({
root: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useMemo } from "react"
import React, { useState, useEffect, useMemo } from "react"
import { makeStyles, createStyles } from "@chainsafe/common-theme"
import { CSFTheme } from "../../../../../Themes/types"
import { Product, ProductPrice } from "@chainsafe/files-api-client"
import { CheckSubscriptionUpdate, Product, ProductPrice } from "@chainsafe/files-api-client"
import { Button, CreditCardIcon, Divider, formatBytes, Typography } from "@chainsafe/common-components"
import { t, Trans } from "@lingui/macro"
import dayjs from "dayjs"
import { PaymentMethod, useBilling } from "../../../../../Contexts/BillingContext"
import clsx from "clsx"
import { useFilesApi } from "../../../../../Contexts/FilesApiContext"

const useStyles = makeStyles(({ constants, palette }: CSFTheme) =>
createStyles({
Expand Down Expand Up @@ -114,12 +115,22 @@ const ConfirmPlan = ({
const classes = useStyles()
const { defaultCard } = useBilling()
const { currentSubscription } = useBilling()
const { filesApiClient } = useFilesApi()
const [checkSubscriptionUpdate, setCheckSubscriptionUpdate] = useState<CheckSubscriptionUpdate | undefined>()
const newPlanStorage = formatBytes(Number(planPrice?.metadata?.storage_size_bytes), 2)

const isDowngrade = useMemo(() => {
const currentPrice = currentSubscription?.product?.price?.unit_amount
return currentPrice && currentPrice > planPrice.unit_amount
}, [currentSubscription, planPrice]
)
}, [currentSubscription, planPrice])

useEffect(() => {
if (!currentSubscription) return
filesApiClient.checkSubscriptionUpdate(currentSubscription?.id, {
payment_method: paymentMethod === "creditCard" ? "stripe" : "crypto",
price_id: planPrice.id
}).then(setCheckSubscriptionUpdate).catch(console.error)
tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved
}, [currentSubscription, paymentMethod, filesApiClient, planPrice])

return (
<article className={classes.root}>
Expand Down Expand Up @@ -256,20 +267,17 @@ const ConfirmPlan = ({
</Typography>
</div>
</div>
<Divider className={classes.divider} />
<div className={classes.rowBox}>
<Typography
component="h5"
variant="h5"
className={classes.boldText}
component="p"
variant="body1"
>
<Trans>Total</Trans>
<Trans>Plan price</Trans>
</Typography>
<div className={classes.pushRightBox}>
<Typography
variant="body1"
component="p"
className={classes.boldText}
>
{planPrice.unit_amount ? planPrice.currency : ""} {planPrice.unit_amount}
<span className={classes.normalWeightText}>
Expand All @@ -278,6 +286,36 @@ const ConfirmPlan = ({
</Typography>
</div>
</div>
<Divider className={classes.divider} />
<div className={classes.rowBox}>
<Typography
component="h5"
variant="h5"
className={classes.boldText}
>
<Trans>Payment amount</Trans>
</Typography>
<div className={classes.pushRightBox}>
{checkSubscriptionUpdate && <div className={classes.pushRightBox}>
<Typography
variant="h5"
component="h5"
className={classes.boldText}
>
{planPrice.currency} {checkSubscriptionUpdate.amount_remaining.toFixed(2)}
</Typography>
{checkSubscriptionUpdate.amount_balance > 0 && <Typography
component="p"
variant="body2"
>
(<Trans>Previous balance</Trans> : {planPrice.currency} {checkSubscriptionUpdate.amount_balance.toFixed(2)})
tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved
</Typography>

tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved
}
</div>
}
</div>
</div>
{isSubscriptionError &&
<Typography
component="p"
Expand All @@ -299,7 +337,7 @@ const ConfirmPlan = ({
<Button
variant="primary"
loading={loadingChangeSubscription}
tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved
disabled={loadingChangeSubscription}
disabled={loadingChangeSubscription || !checkSubscriptionUpdate}
onClick={onChangeSubscription}
>
{paymentMethod === "creditCard"
Expand Down
9 changes: 9 additions & 0 deletions packages/files-ui/src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ msgstr ""
msgid "Pay with {0}"
msgstr ""

msgid "Payment amount"
msgstr ""

msgid "Payment and Subscriptions"
msgstr ""

Expand All @@ -667,6 +670,9 @@ msgstr ""
msgid "Plan changed successfully"
msgstr ""

msgid "Plan price"
msgstr ""

msgid "Please enter a file name"
msgstr "Bitte geben Sie einen Dateinamen ein"

Expand All @@ -691,6 +697,9 @@ msgstr "Vorschau"
msgid "Previous"
msgstr "Vorherige"

msgid "Previous balance"
msgstr ""

msgid "Privacy Policy"
msgstr "Datenschutzrichtlinie"

Expand Down
9 changes: 9 additions & 0 deletions packages/files-ui/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ msgstr "Pay with crypto"
msgid "Pay with {0}"
msgstr "Pay with {0}"

msgid "Payment amount"
msgstr "Payment amount"

msgid "Payment and Subscriptions"
msgstr "Payment and Subscriptions"

Expand All @@ -670,6 +673,9 @@ msgstr "Payment method"
msgid "Plan changed successfully"
msgstr "Plan changed successfully"

msgid "Plan price"
msgstr "Plan price"

msgid "Please enter a file name"
msgstr "Please enter a file name"

Expand All @@ -694,6 +700,9 @@ msgstr "Preview"
msgid "Previous"
msgstr "Previous"

msgid "Previous balance"
msgstr "Previous balance"

msgid "Privacy Policy"
msgstr "Privacy Policy"

Expand Down
9 changes: 9 additions & 0 deletions packages/files-ui/src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ msgstr ""
msgid "Pay with {0}"
msgstr ""

msgid "Payment amount"
msgstr ""

msgid "Payment and Subscriptions"
msgstr ""

Expand All @@ -671,6 +674,9 @@ msgstr ""
msgid "Plan changed successfully"
msgstr ""

msgid "Plan price"
msgstr ""

msgid "Please enter a file name"
msgstr "Ingrese un nombre de archivo"

Expand All @@ -695,6 +701,9 @@ msgstr "Avance"
msgid "Previous"
msgstr "Anterior"

msgid "Previous balance"
msgstr ""

msgid "Privacy Policy"
msgstr "Política de privacidad"

Expand Down
9 changes: 9 additions & 0 deletions packages/files-ui/src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ msgstr ""
msgid "Pay with {0}"
msgstr ""

msgid "Payment amount"
msgstr ""

msgid "Payment and Subscriptions"
msgstr "Paiements et souscriptions"

Expand All @@ -671,6 +674,9 @@ msgstr "Méthode de paiement"
msgid "Plan changed successfully"
msgstr "Formule changée"

msgid "Plan price"
msgstr ""

msgid "Please enter a file name"
msgstr "Veuillez entrer un nom de fichier"

Expand All @@ -695,6 +701,9 @@ msgstr "Aperçu"
msgid "Previous"
msgstr "Précédent"

msgid "Previous balance"
msgstr ""

msgid "Privacy Policy"
msgstr "Politique de confidentialité"

Expand Down
9 changes: 9 additions & 0 deletions packages/files-ui/src/locales/no/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ msgstr ""
msgid "Pay with {0}"
msgstr ""

msgid "Payment amount"
msgstr ""

msgid "Payment and Subscriptions"
msgstr ""

Expand All @@ -667,6 +670,9 @@ msgstr ""
msgid "Plan changed successfully"
msgstr ""

msgid "Plan price"
msgstr ""

msgid "Please enter a file name"
msgstr "Skriv inn et filnavn"

Expand All @@ -691,6 +697,9 @@ msgstr "Forhåndsvis"
msgid "Previous"
msgstr "Forrige"

msgid "Previous balance"
msgstr ""

msgid "Privacy Policy"
msgstr "Personvernspraksis"

Expand Down