From 8e601b318057b9f5931fddd286418a6aae72a2e4 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 9 Apr 2023 11:53:12 +0000 Subject: [PATCH] Always use first blockchain from "blockchains" property of instance info object --- src/api/instance.ts | 2 +- src/components/Post.vue | 4 ++-- src/components/Sidebar.vue | 4 ++-- src/components/SubscriptionEthereum.vue | 4 ++-- src/components/SubscriptionSettingsEthereum.vue | 4 ++-- src/composables/instance.ts | 7 ++++++- src/composables/wallet.ts | 4 ++-- src/views/LandingPage.vue | 4 ++-- src/views/PostOverlay.vue | 9 +++++++-- src/views/Profile.vue | 4 ++-- src/views/SubscriptionPage.vue | 4 ++-- src/views/SubscriptionsSettings.vue | 4 ++-- 12 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/api/instance.ts b/src/api/instance.ts index 843312f..f3bd539 100644 --- a/src/api/instance.ts +++ b/src/api/instance.ts @@ -16,7 +16,7 @@ interface ChainMetadata { explorer_url: string | null; } -interface BlockchainInfo { +export interface BlockchainInfo { chain_id: string; chain_metadata: ChainMetadata | null; contract_address: string | null; diff --git a/src/components/Post.vue b/src/components/Post.vue index c3af260..0e7d799 100644 --- a/src/components/Post.vue +++ b/src/components/Post.vue @@ -285,7 +285,7 @@ interface PaymentOption { const router = useRouter() const { currentUser, ensureAuthToken } = $(useCurrentUser()) -const { instance, getActorAddress } = $(useInstanceInfo()) +const { getActorAddress, getBlockchainInfo, instance } = $(useInstanceInfo()) /* eslint-disable-next-line no-undef */ const props = defineProps<{ @@ -307,7 +307,7 @@ let menuVisible = $ref(false) let selectedPaymentAddress = $ref(null) let isWaitingForToken = $ref(false) -const blockchain = $computed(() => instance?.blockchains[0]) +const blockchain = $computed(() => getBlockchainInfo()) const author = $computed(() => new ProfileWrapper(props.post.account)) function openProfile(event: Event, profile: Mention | Profile) { diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index 59c71ff..5cead9f 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -55,7 +55,7 @@ const { endUserSession, ensureAuthToken, } = $(useCurrentUser()) -const { instance } = $(useInstanceInfo()) +const { getBlockchainInfo } = $(useInstanceInfo()) const { loadNotifications, getUnreadNotificationCount } = $(useNotifications()) const { loadTheme } = useTheme() @@ -76,7 +76,7 @@ const unreadNotificationCount = $computed(() => { }) function canManageSubscriptions(): boolean { - const blockchain = instance?.blockchains[0] + const blockchain = getBlockchainInfo() const isSubscriptionsFeatureEnabled = Boolean(blockchain?.features.subscriptions) return ( isSubscriptionsFeatureEnabled && diff --git a/src/components/SubscriptionEthereum.vue b/src/components/SubscriptionEthereum.vue index a168e53..9343415 100644 --- a/src/components/SubscriptionEthereum.vue +++ b/src/components/SubscriptionEthereum.vue @@ -137,7 +137,7 @@ const props = defineProps<{ }>() const { currentUser } = $(useCurrentUser()) -const { instance } = $(useInstanceInfo()) +const { getBlockchainInfo } = $(useInstanceInfo()) const { connectWallet: connectEthereumWallet } = useWallet() const recipient = new ProfileWrapper(props.profile) const recipientEthereumAddress = recipient.getVerifiedEthereumAddress() @@ -159,7 +159,7 @@ onMounted(() => { } }) -const blockchain = $computed(() => instance?.blockchains[0]) +const blockchain = $computed(() => getBlockchainInfo()) function canConnectWallet(): boolean { return ( diff --git a/src/components/SubscriptionSettingsEthereum.vue b/src/components/SubscriptionSettingsEthereum.vue index db0a2ef..6cc2965 100644 --- a/src/components/SubscriptionSettingsEthereum.vue +++ b/src/components/SubscriptionSettingsEthereum.vue @@ -110,7 +110,7 @@ import { ethereumAddressMatch } from "@/utils/ethereum" const { ensureAuthToken, ensureCurrentUser, setCurrentUser } = $(useCurrentUser()) const { verifyEthereumAddress } = useEthereumAddressVerification() -const { instance } = $(useInstanceInfo()) +const { getBlockchainInfo } = $(useInstanceInfo()) const { connectWallet: connectEthereumWallet, getSigner } = useWallet() const subscriptionPrice = $ref(1) @@ -124,7 +124,7 @@ let subscriptionState = $ref(null) let subscriptions = $ref([]) let subscriberAddress = $ref(null) -const blockchain = $computed(() => instance?.blockchains[0]) +const blockchain = $computed(() => getBlockchainInfo()) const profile = $computed(() => new ProfileWrapper(ensureCurrentUser())) onMounted(() => { diff --git a/src/composables/instance.ts b/src/composables/instance.ts index b87568f..18f7774 100644 --- a/src/composables/instance.ts +++ b/src/composables/instance.ts @@ -1,6 +1,6 @@ import { ref } from "vue" -import { InstanceInfo, getInstanceInfo } from "@/api/instance" +import { BlockchainInfo, InstanceInfo, getInstanceInfo } from "@/api/instance" import { Mention } from "@/api/posts" import { Profile } from "@/api/users" @@ -23,9 +23,14 @@ export function useInstanceInfo() { return `${profile.username}@${instance.value.uri}` } + function getBlockchainInfo(): BlockchainInfo | null { + return instance.value?.blockchains[0] || null + } + return { instance, loadInstanceInfo, getActorAddress, + getBlockchainInfo, } } diff --git a/src/composables/wallet.ts b/src/composables/wallet.ts index ced7f8c..e2e13b1 100644 --- a/src/composables/wallet.ts +++ b/src/composables/wallet.ts @@ -17,8 +17,8 @@ function disconnectWallet() { } async function connectWallet(): Promise { - const { instance } = useInstanceInfo() - const blockchain = instance.value?.blockchains[0] + const { getBlockchainInfo } = useInstanceInfo() + const blockchain = getBlockchainInfo() if (!blockchain) { throw new Error("blockchain integration disabled") } diff --git a/src/views/LandingPage.vue b/src/views/LandingPage.vue index ffa870c..7e9394c 100644 --- a/src/views/LandingPage.vue +++ b/src/views/LandingPage.vue @@ -121,7 +121,7 @@ import { const router = useRouter() const { setCurrentUser, setAuthToken } = useCurrentUser() -const { instance } = $(useInstanceInfo()) +const { getBlockchainInfo, instance } = $(useInstanceInfo()) const isRegistered = $ref(true) const username = $ref("") @@ -135,7 +135,7 @@ function isWalletRequired(): boolean { if (!instance) { return false } - const blockchain = instance?.blockchains[0] + const blockchain = getBlockchainInfo() return Boolean(blockchain?.features.gate) } diff --git a/src/views/PostOverlay.vue b/src/views/PostOverlay.vue index 25fb6cc..7a2752a 100644 --- a/src/views/PostOverlay.vue +++ b/src/views/PostOverlay.vue @@ -68,7 +68,11 @@ import { formatDate } from "@/utils/dates" const route = useRoute() const router = useRouter() const { currentUser, authToken } = $(useCurrentUser()) -const { instance, getActorAddress } = $(useInstanceInfo()) +const { + getActorAddress, + getBlockchainInfo, + instance, +} = $(useInstanceInfo()) let post = $ref(null) let token = $ref(null) @@ -99,7 +103,8 @@ const actorAddress = $computed(() => { }) const transactionUrl = $computed(() => { - const explorerUrl = instance?.blockchains[0]?.chain_metadata?.explorer_url + const blockchain = getBlockchainInfo() + const explorerUrl = blockchain?.chain_metadata?.explorer_url if (!explorerUrl || !post?.token_tx_id) { return null } diff --git a/src/views/Profile.vue b/src/views/Profile.vue index 21f329c..57a9d97 100644 --- a/src/views/Profile.vue +++ b/src/views/Profile.vue @@ -306,7 +306,7 @@ const { ensureAuthToken, } = $(useCurrentUser()) const { verifyEthereumAddress } = useEthereumAddressVerification() -const { instance, getActorAddress } = $(useInstanceInfo()) +const { getActorAddress, getBlockchainInfo } = $(useInstanceInfo()) let profile = $ref(null) let relationship = $ref(null) @@ -561,7 +561,7 @@ async function onSignActivity() { } function isSubscriptionsFeatureEnabled(): boolean { - const blockchain = instance?.blockchains[0] + const blockchain = getBlockchainInfo() return Boolean(blockchain?.features.subscriptions) } diff --git a/src/views/SubscriptionPage.vue b/src/views/SubscriptionPage.vue index 4578dcf..34c0252 100644 --- a/src/views/SubscriptionPage.vue +++ b/src/views/SubscriptionPage.vue @@ -26,10 +26,10 @@ import { useCurrentUser } from "@/composables/user" const route = useRoute() const { authToken } = $(useCurrentUser()) -const { instance } = $(useInstanceInfo()) +const { getBlockchainInfo } = $(useInstanceInfo()) let profile = $ref(null) -const blockchain = $computed(() => instance?.blockchains[0]) +const blockchain = $computed(() => getBlockchainInfo()) onMounted(async () => { // Recipient diff --git a/src/views/SubscriptionsSettings.vue b/src/views/SubscriptionsSettings.vue index 8377c6c..93e2b62 100644 --- a/src/views/SubscriptionsSettings.vue +++ b/src/views/SubscriptionsSettings.vue @@ -16,9 +16,9 @@ import SubscriptionSettingsEthereum from "@/components/SubscriptionSettingsEther import SubscriptionSettingsMonero from "@/components/SubscriptionSettingsMonero.vue" import { useInstanceInfo } from "@/composables/instance" -const { instance } = $(useInstanceInfo()) +const { getBlockchainInfo } = $(useInstanceInfo()) -const blockchain = $computed(() => instance?.blockchains[0]) +const blockchain = $computed(() => getBlockchainInfo()) function isEthereum(): boolean { if (!blockchain) {