diff --git a/src/api/subscriptions-monero.ts b/src/api/subscriptions-monero.ts index 1c8e5c3..360f994 100644 --- a/src/api/subscriptions-monero.ts +++ b/src/api/subscriptions-monero.ts @@ -20,7 +20,7 @@ export function getPricePerMonth(pricePerSec: number): number { return formatAmount(pricePerMonthInt, 12).toUnsafeFloat() } -export async function enableMoneroSubscriptions( +export async function registerMoneroSubscriptionOption( authToken: string, price: number, payoutAddress: string, diff --git a/src/components/SubscriptionSettingsMonero.vue b/src/components/SubscriptionSettingsMonero.vue index 2431346..3a92f59 100644 --- a/src/components/SubscriptionSettingsMonero.vue +++ b/src/components/SubscriptionSettingsMonero.vue @@ -2,7 +2,7 @@
-
+
Subscribers can pay for subscription by navigating to
@@ -21,7 +21,12 @@ {{ getSubscriptionPageUrl() }}
-
+
+ +
+
@@ -37,9 +42,10 @@ type="submit" class="btn" :disabled="!isFormValid()" - @click.prevent="enableSubscriptions()" + @click.prevent="saveSubscriptionSettings()" > - Enable subscriptions + + @@ -56,7 +62,7 @@ import { SubscriptionOption, } from "@/api/subscriptions-common" import { - enableMoneroSubscriptions, + registerMoneroSubscriptionOption, getPricePerMonth, getPricePerSec, } from "@/api/subscriptions-monero" @@ -70,22 +76,31 @@ const { setCurrentUser, } = $(useCurrentUser()) -const subscriptionPrice = $ref(0.01) -const subscriptionPayoutAddress = $ref("") let isLoading = $ref(false) let subscriptionOption = $ref(null) +let subscriptionPrice = $ref(0.01) +let subscriptionPayoutAddress = $ref("") +let isFormVisible = $ref(false) + onMounted(async () => { isLoading = true - await loadSubscriptionConfig() + await loadSubscriptionSettings() isLoading = false }) -async function loadSubscriptionConfig() { +async function loadSubscriptionSettings() { const subscriptionOptions = await getSubscriptionOptions(ensureAuthToken()) subscriptionOption = subscriptionOptions.find((item) => { return item.type === "monero" }) || null + if (subscriptionOption?.price && subscriptionOption?.payout_address) { + subscriptionPrice = getPricePerMonth(subscriptionOption.price) + subscriptionPayoutAddress = subscriptionOption.payout_address + } + if (subscriptionOption === null) { + isFormVisible = true + } } function getSubscriptionPagePath(): string { @@ -100,13 +115,6 @@ function getSubscriptionPageUrl(): string { return window.location.origin + getSubscriptionPagePath() } -function canEnableSubscriptions(): boolean { - return ( - !isLoading && - subscriptionOption === null - ) -} - function isFormValid(): boolean { return ( getPricePerSec(subscriptionPrice) > 0 && @@ -114,15 +122,16 @@ function isFormValid(): boolean { ) } -async function enableSubscriptions() { +async function saveSubscriptionSettings() { isLoading = true - const user = await enableMoneroSubscriptions( + const user = await registerMoneroSubscriptionOption( ensureAuthToken(), getPricePerSec(subscriptionPrice), subscriptionPayoutAddress, ) setCurrentUser(user) - await loadSubscriptionConfig() + await loadSubscriptionSettings() + isFormVisible = false isLoading = false }