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

feat/invoice and payment preferences #141

Merged
merged 5 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -26,9 +26,8 @@ function onDueChange(value: number | string): void {
<span>{{ $t('hosting_preferences.invoices.due.part_one') }}</span>

<TimeDropdownSelect
is-disabled
:value="props.data.due.period"
:options="['N/A', 7, 30]"
:options="[7, 14, 28]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two sets of selections: [7, 15, 28] here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that is intentional. The want invoices Due to have a different selection than Invoices Frequency.

@update:selected-value="onDueChange"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ function onFrequencyAmountChange(value: number): void {
<span>{{ $t('hosting_preferences.invoices.frequency.part_one') }}</span>

<TimeDropdownSelect
is-disabled
:value="props.data.frequency.period"
:options="['N/A', 7, 30]"
:options="[7, 15, 30]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two sets of selections: [7, 15, 30] here

@update:selected-value="onFrequencyPeriodChange"
/>

<span>{{ $t('hosting_preferences.invoices.frequency.part_two') }}</span>

<BaseEditableInput
is-disabled
:value="formatCurrency(Number(props.data.frequency.amount), 0)"
unit="HF"
class="invoices-frequency-section__amount"
Expand Down
16 changes: 5 additions & 11 deletions src/components/settings/hostingPreferences/InvoicesSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const props = defineProps<{

const emit = defineEmits(['update:frequency', 'update:due'])

function updateFrequency(value: number | string): void {
function updateFrequency(value: number): void {
emit('update:frequency', value)
}

function updateDue(value) {
function updateDue(value: number) {
emit('update:due', value)
}
</script>
Expand Down Expand Up @@ -46,15 +46,9 @@ function updateDue(value) {

<div class="invoices-section__notes">
<div>
<span>{{ $t('hosting_preferences.invoices.note_one.part_one') }}</span>
<span class="invoices-section__notes-value">{{ 2 * props.data.due.period || 'N/A' }} {{ $t('$.days') }}</span>
<span>{{ $t('hosting_preferences.invoices.note_one.part_two') }}</span>
</div>

<div class="invoices-section__note-two">
<span>{{ $t('hosting_preferences.invoices.note_two.part_one') }}</span>
<span class="invoices-section__notes-value">{{ 4 * props.data.due.period || 'N/A' }} {{ $t('$.days') }}</span>
<span>{{ $t('hosting_preferences.invoices.note_two.part_two') }}</span>
<span>{{ $t('hosting_preferences.invoices.note.part_one') }}</span>
<span class="invoices-section__notes-value">{{ props.data.due.period }} {{ $t('$.days') }}</span>
<span>{{ $t('hosting_preferences.invoices.note.part_two') }}</span>
</div>
</div>
</div>
Expand Down
12 changes: 7 additions & 5 deletions src/interfaces/HposInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,21 @@ interface CoreAppVersionResponse {
}

export interface HostPreferencesResponse {
max_fuel_before_invoice: string
max_time_before_invoice: [number, number]
price_bandwidth: string
price_compute: string
price_storage: string
price_bandwidth: string
max_time_before_invoice: { secs: number; nanos: number }
max_fuel_before_invoice: string
invoice_due_in_days: number
}

export interface DefaultPreferencesPayload {
max_fuel_before_invoice: string
price_compute: string
price_storage: string
price_bandwidth: string
max_time_before_invoice: [number, number]
max_time_before_invoice: { secs: number; nanos: number }
max_fuel_before_invoice: string
invoice_due_in_days: number
}

type HposHolochainCallResponse =
Expand Down
8 changes: 2 additions & 6 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,10 @@ export default {
part_one: 'Payment is due',
part_two: 'after invoice date'
},
note_one: {
part_one: '*hApps will be paused from hosting if payment is not received',
note: {
part_one: '*Apps will be paused from hosting if payment is not received',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing to Apps now?

Copy link
Contributor Author

@zeeshan595 zeeshan595 Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part_two: 'after invoice date'
},
note_two: {
part_one: '*hApps will be removed if payment is not received',
part_two: 'after invoice date'
}
},
prices: {
header: 'Price Configuration',
Expand Down
14 changes: 13 additions & 1 deletion src/pages/HostingPreferences.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PricesSection from '@/components/settings/hostingPreferences/PricesSectio
import TogglePaidHostingSection from '@/components/settings/hostingPreferences/TogglePaidHostingSection.vue'
import { usePreferencesStore } from '@/store/preferences'
import { useUserStore } from '@/store/user'
import type { UpdatePricePayload } from '@/types/types'
import type { InvoiceDue, InvoiceFrequency, UpdatePricePayload } from '@/types/types'
import { EHostingPlan, EUserKycLevel } from '@/types/types'

const preferencesStore = usePreferencesStore()
Expand Down Expand Up @@ -95,6 +95,16 @@ function onTogglePaidHosting(isToggledOn: boolean): void {
function updateHostingPlan(): void {
closeModal()
}

async function invoiceFrequencyChanged({ period, amount }: InvoiceFrequency): Promise<void> {
preferencesStore.updateInvoiceFrequency(period, amount);
await setDefaultHostPreferences();
}

async function invoicePaymentDueChanged({ period }: InvoiceDue): Promise<void> {
preferencesStore.updateInvoiceDue(period);
await setDefaultHostPreferences();
}
</script>

<template>
Expand Down Expand Up @@ -130,6 +140,8 @@ function updateHostingPlan(): void {
:data="invoicesSettings"
class="hosting-preferences__invoices"
data-test-hosting-preferences-invoices-section
@update:frequency="invoiceFrequencyChanged"
@update:due="invoicePaymentDueChanged"
/>

<HAppSelectionSection
Expand Down
52 changes: 33 additions & 19 deletions src/store/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@ export const usePreferencesStore = defineStore('preferences', {
},
invoicesSettings: {
frequency: {
amount: 0, // in fuel type
period: 'N/A' // in duration days
amount: 0,
period: 7
},
due: {
period: 'N/A' // in duration days
period: 7
}
}
}),

actions: {
async setDefaultPreferences(): Promise<void> {
let maxTimeBeforeInvoice = Number(this.invoicesSettings.frequency.period) || 7
let invoiceDuePeriod = Number(this.invoicesSettings.due.period) || 7

const payload: DefaultPreferencesPayload = {
max_fuel_before_invoice: '0',
max_time_before_invoice: [0, 0],
max_fuel_before_invoice: `${this.invoicesSettings.frequency.amount}`,
max_time_before_invoice: {
secs: maxTimeBeforeInvoice * 24 * 60 * 60,
nanos: 0
},
invoice_due_in_days: invoiceDuePeriod,
price_compute: `${this.pricesSettings.cpu}`,
price_storage: `${this.pricesSettings.storage}`,
price_bandwidth: `${this.pricesSettings.bandwidth}`
Expand Down Expand Up @@ -78,8 +85,9 @@ export const usePreferencesStore = defineStore('preferences', {
}

const {
max_fuel_before_invoice: amount,
max_time_before_invoice: durationThreshold,
max_fuel_before_invoice: invoiceHolofuelThreshold,
max_time_before_invoice: invoiceDurationThreshold,
invoice_due_in_days: invoiceDueDays,
price_compute: cpu,
price_storage: storage,
price_bandwidth: bandwidth
Expand All @@ -93,22 +101,28 @@ export const usePreferencesStore = defineStore('preferences', {
}
}

if (amount && durationThreshold) {
// NB: This value is not implemented in DNAs, return mock for now
const deadline = 'N/A'

this.invoicesSettings = {
frequency: {
amount: Number(amount),
period: 'N/A' // durationThreshold
},
due: {
period: deadline
}
this.invoicesSettings = {
frequency: {
amount: Number(invoiceHolofuelThreshold) || 0,
period: Number(invoiceDurationThreshold.secs / 24 / 60 / 60) || 7
},
due: {
period: Number(invoiceDueDays) || 7
}
}

this.isLoaded = true
},
updateInvoiceFrequency(invoiceFrequency: number, invoiceMaxHolofuel: number) {
this.invoicesSettings.frequency = {
amount: invoiceMaxHolofuel,
period: invoiceFrequency
}
},
updateInvoiceDue(invoiceDueInDays: number) {
this.invoicesSettings.due = {
period: invoiceDueInDays
}
}
}
})
13 changes: 11 additions & 2 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export interface PricesData {

export interface InvoicesData {
due: {
period: string
period: number
}
frequency: {
amount: number
period: string
period: number
}
}

Expand Down Expand Up @@ -96,3 +96,12 @@ export interface UpdateHAppPlanProps {
id: string
value: EHostingPlan
}

export type InvoiceFrequency = {
period: number;
amount: number;
}

export type InvoiceDue = {
period: number;
};