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

add hp_id param for happ enable/disable call #144

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/components/PrimaryLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ onMounted(async () => {
// we need to fetch user data again.
// eslint-disable-next-line @typescript-eslint/no-misused-promises
await nextTick(async (): Promise<void> => {
if (!userStore.publicKey) {
if (!(userStore.publicKey && userStore.holoportId)) {
isLoading.value = true

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
Expand Down
7 changes: 4 additions & 3 deletions src/components/StopHostingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { ExclamationCircleIcon, CheckCircleIcon } from '@heroicons/vue/24/outlin
import BaseButton from '@uicommon/components/BaseButton'
import BaseModal from '@uicommon/components/BaseModal'
import { useModals } from '@uicommon/composables/useModals'
import { EButtonType } from '@uicommon/types/ui'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { EModal } from '@/constants/ui'
import { useUserStore } from '@/store/user'
import { HAppDetails, useHposInterface } from '@/interfaces/HposInterface'
import { isError as isErrorPredicate } from '@/types/predicates'

const { t } = useI18n()
const { stopHostingHApp, startHostingHApp } = useHposInterface()
const userStore = useUserStore()

// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
const { showModal } = useModals()
Expand All @@ -31,9 +32,9 @@ async function confirm(): Promise<void> {
let result = null

if (props.hApp.enabled) {
result = await stopHostingHApp(props.hApp.id)
result = await stopHostingHApp(props.hApp.id, userStore.holoportId)
} else {
result = await startHostingHApp(props.hApp.id)
result = await startHostingHApp(props.hApp.id, userStore.holoportId)
}

// If failed
Expand Down
14 changes: 8 additions & 6 deletions src/interfaces/HposInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface HposInterface {
getUsage: () => Promise<UsageResponse | { error: unknown }>
getHostedHApps: () => Promise<HApp[] | { error: unknown }>
getHAppDetails: (id: string) => Promise<HAppDetails | { error: unknown }>
startHostingHApp: (id: string) => Promise<void | { error: unknown }>
stopHostingHApp: (id: string) => Promise<void | { error: unknown }>
startHostingHApp: (id: string, hpId: string) => Promise<void | { error: unknown }>
stopHostingHApp: (id: string, hpId: string) => Promise<void | { error: unknown }>
setDefaultHAppPreferences: (preferences: DefaultPreferencesPayload) => Promise<boolean>
updateHAppHostingPlan: (payload: UpdateHAppHostingPlanPayload) => Promise<boolean>
getHostEarnings: () => Promise<HostEarnings | { error: unknown }>
Expand Down Expand Up @@ -476,13 +476,14 @@ export function useHposInterface(): HposInterface {
}

async function startHostingHApp(
id: string
id: string,
hpId: string
): Promise<HposHolochainCallResponse | { error: unknown }> {
try {
const result = await hposHolochainCall({
method: 'post',
pathPrefix: '/api/v2',
path: `/hosted_happs/${id}/enable`
path: `/hosted_happs/${id}/${hpId}enable`
})

return result
Expand All @@ -493,13 +494,14 @@ export function useHposInterface(): HposInterface {
}

async function stopHostingHApp(
id: string
id: string,
hpId: string
): Promise<HposHolochainCallResponse | { error: unknown }> {
try {
const result = await hposHolochainCall({
method: 'post',
pathPrefix: '/api/v2',
path: `/hosted_happs/${id}/disable`
path: `/hosted_happs/${id}/${hpId}enable`
})

return result
Expand Down
5 changes: 5 additions & 0 deletions src/store/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { getCoreAppVersion, getUser, updateHoloFuelProfile, updateHoloportName, g
useHposInterface()

interface State {
holoportId: string | undefined,
publicKey: string | undefined
email: string
networkFlavour: string
Expand All @@ -26,6 +27,7 @@ interface State {

export const useUserStore = defineStore('user', {
state: (): State => ({
holoportId: undefined,
publicKey: undefined,
email: '',
networkFlavour: '',
Expand Down Expand Up @@ -67,6 +69,9 @@ export const useUserStore = defineStore('user', {
if (coreAppVersion) {
this.coreAppVersion = coreAppVersion
}

const hostUrl = window.location.host;
this.holoportId = hostUrl.split(".")[0]
},

async updateHoloFuelProfile({
Expand Down
Loading