From 6925f87f69741bc77682e51e5965ebca94b29f6c Mon Sep 17 00:00:00 2001 From: Wilfred Asomani Date: Fri, 8 Dec 2023 15:43:10 +0000 Subject: [PATCH] web/satellite/vuetify-poc: add STORJ token from billing This change allows to add STORJ tokens from the billing page. It reuses the token step of the account upgrade dialog. Issue: #6494 Change-Id: Ic521b8ab5113124634b8489f0fb92ab680d9f3df --- .../src/store/modules/billingStore.ts | 2 +- .../components/StorjTokenCardComponent.vue | 35 +++++++- .../components/dialogs/AddTokensDialog.vue | 88 +++++++++++++++++++ .../upgradeAccountFlow/AddTokensStep.vue | 20 ++++- .../UpgradeAccountDialog.vue | 15 +++- .../vuetify-poc/src/views/Billing.vue | 29 +++--- 6 files changed, 171 insertions(+), 18 deletions(-) create mode 100644 web/satellite/vuetify-poc/src/components/dialogs/AddTokensDialog.vue diff --git a/web/satellite/src/store/modules/billingStore.ts b/web/satellite/src/store/modules/billingStore.ts index 38958b5d3305..3c6a30a18c3a 100644 --- a/web/satellite/src/store/modules/billingStore.ts +++ b/web/satellite/src/store/modules/billingStore.ts @@ -16,7 +16,7 @@ import { PaymentStatus, PaymentWithConfirmations, ProjectCharges, - ProjectUsagePriceModel, + ProjectUsagePriceModel, TokenAmount, Wallet, } from '@/types/payments'; import { PaymentsHttpApi } from '@/api/payments'; diff --git a/web/satellite/vuetify-poc/src/components/StorjTokenCardComponent.vue b/web/satellite/vuetify-poc/src/components/StorjTokenCardComponent.vue index 8db6a13eda30..288a2bc4edc2 100644 --- a/web/satellite/vuetify-poc/src/components/StorjTokenCardComponent.vue +++ b/web/satellite/vuetify-poc/src/components/StorjTokenCardComponent.vue @@ -21,27 +21,35 @@

Total Balance

{{ balance || '------' }} - + Add STORJ Tokens + + Add STORJ Tokens Create New Wallet View Transactions + + diff --git a/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/AddTokensStep.vue b/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/AddTokensStep.vue index 64a30c2a6751..db97a3cbda1b 100644 --- a/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/AddTokensStep.vue +++ b/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/AddTokensStep.vue @@ -70,7 +70,7 @@ /> (); const intervalID = ref(); const viewState = ref(ViewState.Default); +const props = defineProps<{ + // whether this step is the first step in a flow + isRoot?: boolean; +}>(); + const emit = defineEmits<{ back: []; + success: []; }>(); /** @@ -167,8 +173,20 @@ watch(() => pendingPayments.value, async () => { } clearInterval(intervalID.value); billingStore.clearPendingPayments(); + + if (usersStore.state.user.paidTier) { + // in case this step was entered in to directly from + // the billing/payment method tab when the user is + // already in paid tier. + return; + } + // fetch User to update their Paid Tier status. await usersStore.getUser(); + + // arbitrary delay to allow for user to read success banner. + await new Promise(resolve => setTimeout(resolve, 2000)); + emit('success'); }, { deep: true }); /** diff --git a/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/UpgradeAccountDialog.vue b/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/UpgradeAccountDialog.vue index 26e9b9759253..c0ce7a44e75f 100644 --- a/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/UpgradeAccountDialog.vue +++ b/web/satellite/vuetify-poc/src/components/dialogs/upgradeAccountFlow/UpgradeAccountDialog.vue @@ -6,7 +6,7 @@ v-model="model" scrollable min-width="460px" - :max-width="step === UpgradeAccountStep.Info || step === UpgradeAccountStep.PricingPlanSelection ? '720px' : '460px'" + :max-width="maxWidth" transition="fade-transition" :persistent="loading" :scrim="scrim" @@ -57,6 +57,7 @@ @@ -151,6 +152,17 @@ const stepTitles = computed(() => { }; }); +const maxWidth = computed(() => { + switch (step.value) { + case UpgradeAccountStep.Info: + case UpgradeAccountStep.PricingPlanSelection: + case UpgradeAccountStep.AddTokens: + return '720px'; + default: + return '460px'; + } +}); + /** * Claims wallet and sets add token step. */ @@ -225,6 +237,7 @@ async function setSecondStep() { watch(content, (value) => { if (!value) { setStep(UpgradeAccountStep.Info); + return; } }); diff --git a/web/satellite/vuetify-poc/src/views/Billing.vue b/web/satellite/vuetify-poc/src/views/Billing.vue index 6c742da4a42f..8bd6792d0281 100644 --- a/web/satellite/vuetify-poc/src/views/Billing.vue +++ b/web/satellite/vuetify-poc/src/views/Billing.vue @@ -5,8 +5,8 @@ @@ -57,7 +57,7 @@ {{ centsToDollars(priceSummary) }} - View Billing History + View Billing History @@ -72,7 +72,7 @@ {{ formattedTokenBalance }} - + Add STORJ Tokens @@ -174,7 +174,7 @@ - + @@ -250,6 +250,10 @@ enum TABS { 'billing-history', } +interface IStorjTokenCardComponent { + onAddTokens(): Promise; +} + const billingStore = useBillingStore(); const projectsStore = useProjectsStore(); const configStore = useConfigStore(); @@ -263,6 +267,8 @@ const isLowBalance = useLowTokenBalance(); const isRollupLoading = ref(true); const isAddCouponDialogShown = ref(false); +const tokenCardComponent = ref(); + const creditCards = computed((): CreditCard[] => { return billingStore.state.creditCards; }); @@ -310,7 +316,7 @@ const tab = computed({ return TABS[tabStr] ?? 0; }, set: (value: number) => { - router.push({ query: { tab: TABS[value] ?? TABS.overview } }); + router.push({ query: { tab: TABS[value] ?? TABS[tab.value] } }); }, }); @@ -356,13 +362,10 @@ function downloadReport(): void { notify.success('Usage report download started successfully.'); } -/** - * set the tab on route change - */ -watch(route, () => { - const tabStr = route.query['tab']; - tab.value = TABS[tabStr as keyof typeof TABS] ?? 0; -}, { immediate: true }); +function onAddTokensClicked(): void { + tab.value = TABS['payment-methods']; + tokenCardComponent.value?.onAddTokens(); +} onBeforeMount(() => { if (!configStore.state.config.billingFeaturesEnabled) {