From 6c05372f242bfe228ba9d051af91a8c2aa660fb6 Mon Sep 17 00:00:00 2001 From: silverpill Date: Tue, 6 Sep 2022 19:07:45 +0000 Subject: [PATCH] Use payment options to determine subscription page location --- src/api/users.ts | 34 +++++++++++++++++++++++++++++++-- src/components/Subscription.vue | 2 +- src/views/Profile.vue | 22 ++++++++++----------- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/api/users.ts b/src/api/users.ts index 3368a41..aa7f506 100644 --- a/src/api/users.ts +++ b/src/api/users.ts @@ -1,3 +1,5 @@ +import { RouteLocationRaw } from "vue-router" + import { BACKEND_URL } from "@/constants" import { createDidFromEthereumAddress } from "@/utils/did" import { PAGE_SIZE, http } from "./common" @@ -8,6 +10,13 @@ export interface ProfileField { verified_at: string | null; } +export interface ProfilePaymentOption { + type: string, + name?: string, + href?: string, + price?: number, +} + interface Source { note: string | null; fields: ProfileField[]; @@ -23,13 +32,12 @@ export interface Profile { avatar: string | null; header: string | null; identity_proofs: ProfileField[]; + payment_options: ProfilePaymentOption[]; fields: ProfileField[]; followers_count: number; following_count: number; statuses_count: number; - - subscription_page_url: string | null; } export interface User extends Profile { @@ -56,6 +64,28 @@ export class ProfileWrapper { return null } + getSubscriptionPageLocation(): string | RouteLocationRaw | null { + console.log(this.payment_options) + for (const option of this.payment_options) { + if ( + option.type === "link" && + option.name === "EthereumSubscription" && + option.href + ) { + return option.href + } else if ( + option.type === "ethereum-subscription" || + option.type === "monero-subscription" + ) { + return { + name: "profile-subscription", + params: { profileId: this.id }, + } + } + } + return null + } + } interface UserCreateForm { diff --git a/src/components/Subscription.vue b/src/components/Subscription.vue index 36fd102..92cf833 100644 --- a/src/components/Subscription.vue +++ b/src/components/Subscription.vue @@ -143,11 +143,11 @@ const guest: Profile = { avatar: null, header: null, identity_proofs: [], + payment_options: [], fields: [], followers_count: 0, following_count: 0, statuses_count: 0, - subscription_page_url: null, } const { currentUser } = $(useCurrentUser()) diff --git a/src/views/Profile.vue b/src/views/Profile.vue index 0ccafc1..5e73278 100644 --- a/src/views/Profile.vue +++ b/src/views/Profile.vue @@ -85,24 +85,24 @@ @@ -461,7 +461,7 @@ function canSubscribe(): boolean { Boolean(blockchain?.features.subscriptions) && profile !== null && profile.getVerifiedEthereumAddress() !== null && - profile.subscription_page_url !== null && + profile.getSubscriptionPageLocation() !== null && !isCurrentUser() ) }