From 85e2ebfe02fd7483d9c24ae36672c8d45cafd5df Mon Sep 17 00:00:00 2001 From: Mateusz Rybczonek Date: Mon, 17 Jun 2024 09:01:05 +0200 Subject: [PATCH 1/5] chore: update holochain api enpoints --- mock-hpos-api/defaultResponse.js | 16 ++++----- src/interfaces/HposInterface.ts | 52 +++++++++++---------------- src/pages/__tests__/Dashboard.test.js | 2 +- src/pages/__tests__/HApps.test.js | 2 +- src/store/dashboard.ts | 7 +--- 5 files changed, 31 insertions(+), 48 deletions(-) diff --git a/mock-hpos-api/defaultResponse.js b/mock-hpos-api/defaultResponse.js index a16167e0..c5544e56 100644 --- a/mock-hpos-api/defaultResponse.js +++ b/mock-hpos-api/defaultResponse.js @@ -644,22 +644,22 @@ const data = { get: { '/api/v1/config': userConfig, '/api/v1/status': holoNixpkgs, - '/api/v2/hosted_happs': happs, + '/api/v2/apps/hosted': happs, '/holochain-api/v1/get_happs': mockHapps, '/holochain-api/v1/get_hosts': mockHosts, - '/holochain-api/v1/usage': usage, - '/holochain-api/v1/host_earnings': earnings, - '/holochain-api/v1/core_app_version': coreAppVersion, - '/holochain-api/v1/host_invoices': mockPaidInvoicesData, - '/holochain-api/v1/redemptions': mockRedemptionHistoryData, - '/holochain-api/v1/kyc': mockKycData.kyc + '/holochain-api/v2/holoport/usage': usage, + '/holochain-api/v2/host/earnings': earnings, + '/holochain-api/v2/apps/core/version': coreAppVersion, + '/holochain-api/v2/host/invoices': mockPaidInvoicesData, + '/holochain-api/v2/host/redemptions': mockRedemptionHistoryData, + '/holochain-api/v2/host/kyc': mockKycData.kyc }, put: { '/api/v1/config': (args) => args, '/api/v1/holoport/name': {} }, post: { - '/holochain-api/v1/zome_call': (args) => { + '/holochain-api/v1/apps/call_zome': (args) => { switch (args.fnName) { case 'get_my_profile': return getMyProfile diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index ca546a43..d3526f36 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -421,7 +421,7 @@ export function useHposInterface(): HposInterface { // On 401 redirect to login and unset authToken because the reason for 401 might be it's expired try { return await hposCall({ - pathPrefix: '/holochain-api/v1', + pathPrefix: '/holochain-api/v2', ...args }) } catch (err) { @@ -438,7 +438,7 @@ export function useHposInterface(): HposInterface { try { return await hposHolochainCall({ method: 'get', - path: '/usage', + path: '/holoport/usage', params: { usage_interval: 1 } @@ -453,8 +453,7 @@ export function useHposInterface(): HposInterface { try { const result = await hposHolochainCall({ method: 'get', - pathPrefix: '/api/v2', - path: '/hosted_happs', + path: '/apps/hosted', params: { usage_interval: 7 } @@ -478,8 +477,7 @@ export function useHposInterface(): HposInterface { try { const result = await hposHolochainCall({ method: 'get', - pathPrefix: '/api/v2', - path: `/hosted_happs/${id}` + path: `/apps/hosted/${id}` }) if (isHAppDetails(result)) { @@ -500,8 +498,7 @@ export function useHposInterface(): HposInterface { try { const result = await hposHolochainCall({ method: 'post', - pathPrefix: '/api/v2', - path: `/hosted_happs/${id}/enable` + path: `/apps/hosted/${id}/enable` }) return result @@ -517,8 +514,7 @@ export function useHposInterface(): HposInterface { try { const result = await hposHolochainCall({ method: 'post', - pathPrefix: '/api/v2', - path: `/hosted_happs/${id}/disable` + path: `/apps/hosted/${id}/disable` }) return result @@ -542,8 +538,7 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params }) @@ -563,8 +558,7 @@ export function useHposInterface(): HposInterface { promises.push( hposHolochainCall({ method: 'get', - pathPrefix: '/api/v2', - path: `/hosted_happs/${id}/logs?days=30` + path: `/apps/hosted/${id}/logs?days=30` }) ) }) @@ -618,8 +612,7 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params }) @@ -634,7 +627,7 @@ export function useHposInterface(): HposInterface { try { return await hposHolochainCall({ method: 'get', - path: '/host_earnings' + path: '/host/earnings' }) } catch (error) { console.error('getHostEarnings encountered an error: ', error) @@ -654,8 +647,7 @@ export function useHposInterface(): HposInterface { try { const hostPreferences = await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params }) @@ -763,8 +755,7 @@ export function useHposInterface(): HposInterface { const response = await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params }) @@ -819,8 +810,7 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params }) @@ -835,7 +825,7 @@ export function useHposInterface(): HposInterface { try { return await hposHolochainCall({ method: 'get', - path: '/host_invoices', + path: '/host/invoices', params: { invoice_set: 'paid' } }) } catch (error) { @@ -847,7 +837,7 @@ export function useHposInterface(): HposInterface { try { return await hposHolochainCall({ method: 'get', - path: '/host_invoices', + path: '/host/invoices', params: { invoice_set: 'unpaid' } }) } catch (error) { @@ -859,7 +849,7 @@ export function useHposInterface(): HposInterface { try { return await hposHolochainCall({ method: 'get', - path: '/redemptions' + path: '/host/redemptions' }) } catch (error) { return false @@ -872,7 +862,7 @@ export function useHposInterface(): HposInterface { // @ts-ignore const { version: coreAppVersion } = await hposHolochainCall({ method: 'get', - path: '/core_app_version' + path: '/apps/core/version' }) if (typeof coreAppVersion === 'string') { @@ -894,7 +884,7 @@ export function useHposInterface(): HposInterface { // @ts-ignore const data = await hposHolochainCall({ method: 'get', - path: '/kyc' + path: '/host/kyc' }) if (isKycLevel(data)) { @@ -923,8 +913,7 @@ export function useHposInterface(): HposInterface { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const response = await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params: getReserveDetailsParams }) @@ -950,8 +939,7 @@ export function useHposInterface(): HposInterface { // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const response = await hposHolochainCall({ method: 'post', - path: '/zome_call', - pathPrefix: '/api/v2', + path: '/apps/call_zome', responseType: 'arraybuffer', params: initiateRedemptionParams }) diff --git a/src/pages/__tests__/Dashboard.test.js b/src/pages/__tests__/Dashboard.test.js index 96e5f402..72157b99 100644 --- a/src/pages/__tests__/Dashboard.test.js +++ b/src/pages/__tests__/Dashboard.test.js @@ -78,7 +78,7 @@ describe('dashboard page', () => { return Promise.resolve(defaultSshAccessResult) } - if (path.endsWith('hosted_happs')) { + if (path.endsWith('hosted')) { return hostedHappsResult } diff --git a/src/pages/__tests__/HApps.test.js b/src/pages/__tests__/HApps.test.js index 94325adc..3e9ce168 100644 --- a/src/pages/__tests__/HApps.test.js +++ b/src/pages/__tests__/HApps.test.js @@ -86,7 +86,7 @@ describe('hApps page', () => { } axios.get.mockImplementation((path) => { - if (path.endsWith('hosted_happs')) { + if (path.endsWith('hosted')) { return hostedHAppsResult } diff --git a/src/store/dashboard.ts b/src/store/dashboard.ts index 982603d4..638d4d81 100644 --- a/src/store/dashboard.ts +++ b/src/store/dashboard.ts @@ -2,12 +2,7 @@ import { defineStore } from 'pinia' import { HApp, HostEarnings, UsageResponse, useHposInterface } from '@/interfaces/HposInterface' import type { EarningsData } from '@/types/types' -const { - getUsage, - getHostedHApps, - getHostEarnings, - getHoloFuelDailyStats -} = useHposInterface() +const { getUsage, getHostedHApps, getHostEarnings, getHoloFuelDailyStats } = useHposInterface() interface State { usage: UsageResponse | { error: unknown } From 9b8a509eda053bc18df5adb2226650e88ab1d5db Mon Sep 17 00:00:00 2001 From: peeech Date: Mon, 1 Jul 2024 17:16:10 +0200 Subject: [PATCH 2/5] update urls holochain-api => api --- README.md | 2 +- mock-hpos-api/defaultResponse.js | 20 ++++++++++---------- src/interfaces/HposInterface.ts | 2 +- vite.config.ts | 4 ---- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a9e787b8..a6340934 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Start UI server yarn serve ``` -Using this command, all requests to `localhost:8080/api/` and `localhost:8080/holochain-api/` are forwarded to the holoport. This is really helpful for development/testing. +Using this command, all requests to `localhost:8080/api/` are forwarded to the holoport. This is really helpful for development/testing. If you want to run it against mocked data you will need to run it as below. diff --git a/mock-hpos-api/defaultResponse.js b/mock-hpos-api/defaultResponse.js index c5544e56..cf60b0e1 100644 --- a/mock-hpos-api/defaultResponse.js +++ b/mock-hpos-api/defaultResponse.js @@ -639,27 +639,27 @@ let mockDefaultHappPreferences = { price_storage: (Math.random() * 10).toFixed(5).toString() } -// NB: both /api and /holochain-api calls are mocked here +// NB: both /api calls are mocked here const data = { get: { '/api/v1/config': userConfig, '/api/v1/status': holoNixpkgs, '/api/v2/apps/hosted': happs, - '/holochain-api/v1/get_happs': mockHapps, - '/holochain-api/v1/get_hosts': mockHosts, - '/holochain-api/v2/holoport/usage': usage, - '/holochain-api/v2/host/earnings': earnings, - '/holochain-api/v2/apps/core/version': coreAppVersion, - '/holochain-api/v2/host/invoices': mockPaidInvoicesData, - '/holochain-api/v2/host/redemptions': mockRedemptionHistoryData, - '/holochain-api/v2/host/kyc': mockKycData.kyc + '/api/v1/get_happs': mockHapps, + '/api/v1/get_hosts': mockHosts, + '/api/v2/holoport/usage': usage, + '/api/v2/host/earnings': earnings, + '/api/v2/apps/core/version': coreAppVersion, + '/api/v2/host/invoices': mockPaidInvoicesData, + '/api/v2/host/redemptions': mockRedemptionHistoryData, + '/api/v2/host/kyc': mockKycData.kyc }, put: { '/api/v1/config': (args) => args, '/api/v1/holoport/name': {} }, post: { - '/holochain-api/v1/apps/call_zome': (args) => { + '/api/v2/apps/call_zome': (args) => { switch (args.fnName) { case 'get_my_profile': return getMyProfile diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index d3526f36..5a4929b7 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -421,7 +421,7 @@ export function useHposInterface(): HposInterface { // On 401 redirect to login and unset authToken because the reason for 401 might be it's expired try { return await hposCall({ - pathPrefix: '/holochain-api/v2', + pathPrefix: '/api/v2', ...args }) } catch (err) { diff --git a/vite.config.ts b/vite.config.ts index 8bcbfaaa..5d21e869 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -51,10 +51,6 @@ export default defineConfig(({ mode }) => { port: 8080, proxy: { '^/api/*': { - target: env.VITE_HOLOPORT_URL, - changeOrigin: true - }, - '^/holochain-api/*': { target: env.VITE_HOLOPORT_URL, changeOrigin: true } From 93dd2121f23c805a1dc492a6efcefe61d331e141 Mon Sep 17 00:00:00 2001 From: peeech Date: Mon, 1 Jul 2024 19:44:33 +0200 Subject: [PATCH 3/5] fix return value of /apps/core/version --- src/interfaces/HposInterface.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index 5a4929b7..f8d0e4b6 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -110,9 +110,7 @@ interface HoloFuelProfileResponse { avatar_url: string } -interface CoreAppVersionResponse { - version: string -} +type CoreAppVersionResponse = string | null export interface HostPreferencesResponse { price_compute: string @@ -860,7 +858,7 @@ export function useHposInterface(): HposInterface { try { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const { version: coreAppVersion } = await hposHolochainCall({ + const coreAppVersion = await hposHolochainCall({ method: 'get', path: '/apps/core/version' }) From 0776aa5db549c0e3e0b931887713134446bb1dd0 Mon Sep 17 00:00:00 2001 From: peeech Date: Mon, 1 Jul 2024 19:52:57 +0200 Subject: [PATCH 4/5] fix path to /api/v2/host/kyc_level --- mock-hpos-api/defaultResponse.js | 2 +- src/interfaces/HposInterface.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mock-hpos-api/defaultResponse.js b/mock-hpos-api/defaultResponse.js index cf60b0e1..f90dd7e1 100644 --- a/mock-hpos-api/defaultResponse.js +++ b/mock-hpos-api/defaultResponse.js @@ -652,7 +652,7 @@ const data = { '/api/v2/apps/core/version': coreAppVersion, '/api/v2/host/invoices': mockPaidInvoicesData, '/api/v2/host/redemptions': mockRedemptionHistoryData, - '/api/v2/host/kyc': mockKycData.kyc + '/api/v2/host/kyc_level': mockKycData.kyc }, put: { '/api/v1/config': (args) => args, diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index f8d0e4b6..a1643ce3 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -882,7 +882,7 @@ export function useHposInterface(): HposInterface { // @ts-ignore const data = await hposHolochainCall({ method: 'get', - path: '/host/kyc' + path: '/host/kyc_level' }) if (isKycLevel(data)) { From a3fe44025c03e3184b7d3008d53b517746769555 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Wed, 3 Jul 2024 02:16:25 -0500 Subject: [PATCH 5/5] bump ui-common-lib --- ui-common-library | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-common-library b/ui-common-library index f9bc7a8c..83f2a11b 160000 --- a/ui-common-library +++ b/ui-common-library @@ -1 +1 @@ -Subproject commit f9bc7a8ce31db75f811a0414b1440d1286c5c76f +Subproject commit 83f2a11b268b02a25d5d274d73a75da1883eb0f4