Rename Subscription component to SubscriptionEthereum

This commit is contained in:
silverpill 2022-09-05 16:01:34 +00:00
parent 6c05372f24
commit ee142eefa9
7 changed files with 51 additions and 32 deletions

View file

@ -0,0 +1,24 @@
import { BACKEND_URL } from "@/constants"
import { http } from "./common"
export interface SubscriptionOption {
type: string;
price: number | null;
payout_address: number | null;
}
export async function getSubscriptionOptions(
authToken: string,
): Promise<SubscriptionOption[]> {
const url = `${BACKEND_URL}/api/v1/subscriptions/options`
const response = await http(url, {
method: "GET",
authToken,
})
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.message)
} else {
return data
}
}

View file

@ -71,28 +71,6 @@ export async function getSubscriptionAuthorization(
} }
} }
export interface SubscriptionOption {
type: string;
price: number | null;
payout_address: number | null;
}
export async function getSubscriptionOptions(
authToken: string,
): Promise<SubscriptionOption[]> {
const url = `${BACKEND_URL}/api/v1/subscriptions/options`
const response = await http(url, {
method: "GET",
authToken,
})
const data = await response.json()
if (response.status !== 200) {
throw new Error(data.message)
} else {
return data
}
}
export async function configureSubscriptions( export async function configureSubscriptions(
contractAddress: string, contractAddress: string,
signer: Signer, signer: Signer,

View file

@ -6,7 +6,7 @@ import {
formatAmount, formatAmount,
getPricePerMonth as _getPricePerMonth, getPricePerMonth as _getPricePerMonth,
getPricePerSec as _getPricePerSec, getPricePerSec as _getPricePerSec,
} from "./subscriptions" } from "./subscriptions-ethereum"
import { Profile, User } from "./users" import { Profile, User } from "./users"
export function getPricePerSec(pricePerMonth: number): number { export function getPricePerSec(pricePerMonth: number): number {

View file

@ -1,5 +1,4 @@
<template> <template>
<h1>Subscription</h1>
<div class="subscription"> <div class="subscription">
<div class="participants"> <div class="participants">
<component <component
@ -120,7 +119,7 @@ import {
makeSubscriptionPayment, makeSubscriptionPayment,
SubscriptionConfig, SubscriptionConfig,
SubscriptionState, SubscriptionState,
} from "@/api/subscriptions" } from "@/api/subscriptions-ethereum"
import Avatar from "@/components/Avatar.vue" import Avatar from "@/components/Avatar.vue"
import Loader from "@/components/Loader.vue" import Loader from "@/components/Loader.vue"
import { useWallet } from "@/composables/wallet" import { useWallet } from "@/composables/wallet"

View file

@ -73,23 +73,25 @@ import { $, $$, $computed, $ref } from "vue/macros"
import { DateTime } from "luxon" import { DateTime } from "luxon"
import { ProfileWrapper } from "@/api/users" import { ProfileWrapper } from "@/api/users"
import {
getSubscriptionOptions,
SubscriptionOption,
} from "@/api/subscriptions-common"
import { import {
configureSubscriptions, configureSubscriptions,
getPricePerSec, getPricePerSec,
getSubscribers, getSubscribers,
getSubscriptionAuthorization, getSubscriptionAuthorization,
getSubscriptionConfig, getSubscriptionConfig,
getSubscriptionOptions,
getSubscriptionState, getSubscriptionState,
getSubscriptionToken, getSubscriptionToken,
onSubscriptionsEnabled, onSubscriptionsEnabled,
withdrawReceived, withdrawReceived,
Subscription, Subscription,
SubscriptionConfig, SubscriptionConfig,
SubscriptionOption,
SubscriptionState, SubscriptionState,
SubscriptionToken, SubscriptionToken,
} from "@/api/subscriptions" } from "@/api/subscriptions-ethereum"
import Loader from "@/components/Loader.vue" import Loader from "@/components/Loader.vue"
import ProfileListItem from "@/components/ProfileListItem.vue" import ProfileListItem from "@/components/ProfileListItem.vue"
import { useWallet } from "@/composables/wallet" import { useWallet } from "@/composables/wallet"

View file

@ -40,7 +40,10 @@
import { onMounted } from "vue" import { onMounted } from "vue"
import { $, $ref } from "vue/macros" import { $, $ref } from "vue/macros"
import { getSubscriptionOptions, SubscriptionOption } from "@/api/subscriptions" import {
getSubscriptionOptions,
SubscriptionOption,
} from "@/api/subscriptions-common"
import { import {
enableMoneroSubscriptions, enableMoneroSubscriptions,
getPricePerMonth, getPricePerMonth,

View file

@ -1,26 +1,32 @@
<template> <template>
<sidebar-layout v-if="profile && isLocalUser()"> <sidebar-layout v-if="profile && isLocalUser()">
<template #content> <template #content>
<subscription :profile="profile"></subscription> <h1>Subscription</h1>
<subscription-ethereum v-if="isEthereum()" :profile="profile"></subscription-ethereum>
</template> </template>
</sidebar-layout> </sidebar-layout>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted } from "vue" import { onMounted } from "vue"
import { $, $ref } from "vue/macros" import { $, $computed, $ref } from "vue/macros"
import { useRoute } from "vue-router" import { useRoute } from "vue-router"
import { getProfile, Profile } from "@/api/users" import { getProfile, Profile } from "@/api/users"
import SidebarLayout from "@/components/SidebarLayout.vue" import SidebarLayout from "@/components/SidebarLayout.vue"
import Subscription from "@/components/Subscription.vue" import SubscriptionEthereum from "@/components/SubscriptionEthereum.vue"
import { useCurrentUser } from "@/store/user" import { useCurrentUser } from "@/store/user"
import { useInstanceInfo } from "@/store/instance"
const route = useRoute() const route = useRoute()
const { authToken } = $(useCurrentUser()) const { authToken } = $(useCurrentUser())
const { instance } = $(useInstanceInfo())
let profile = $ref<Profile | null>(null) let profile = $ref<Profile | null>(null)
const blockchain = $computed(() => instance?.blockchains[0])
onMounted(async () => { onMounted(async () => {
// Recipient
profile = await getProfile( profile = await getProfile(
authToken, authToken,
route.params.profileId as string, route.params.profileId as string,
@ -33,4 +39,11 @@ function isLocalUser(): boolean {
} }
return profile.username === profile.acct return profile.username === profile.acct
} }
function isEthereum(): boolean {
if (!blockchain) {
return false
}
return blockchain.chain_id.startsWith("eip155")
}
</script> </script>