From c422477029f03c32f686c2c8451920d125e2470c Mon Sep 17 00:00:00 2001 From: peeech Date: Sun, 24 Dec 2023 02:10:55 -0500 Subject: [PATCH 1/4] make zome calls to /api/v2/ --- src/interfaces/HposInterface.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index f79ab2d..010653c 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -517,6 +517,7 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params }) @@ -592,6 +593,7 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params }) @@ -626,6 +628,7 @@ export function useHposInterface(): HposInterface { const hostPreferences = await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params }) @@ -732,6 +735,7 @@ export function useHposInterface(): HposInterface { const response = await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params }) @@ -786,6 +790,7 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params }) @@ -888,6 +893,7 @@ export function useHposInterface(): HposInterface { const reserveAccountsDetails: ReserveSettingsResponse = (await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params: getReserveDetailsParams })) as ReserveSettingsResponse @@ -909,6 +915,7 @@ export function useHposInterface(): HposInterface { const transaction: RedemptionTransaction = (await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', params: initiateRedemptionParams })) as RedemptionTransaction From ccab51718e49a3fa42ed4fa2bfd2803688c254a0 Mon Sep 17 00:00:00 2001 From: peeech Date: Wed, 17 Jan 2024 13:49:41 +0100 Subject: [PATCH 2/4] zome_call to api/v2 returns serialized bytes --- package.json | 1 + src/interfaces/HposInterface.ts | 24 ++++++++++++++++++------ ui-common-library | 2 +- yarn.lock | 5 +++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index d682865..b55c981 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "email-validator": "^2.0.4", "fast-json-stable-stringify": "^2.1.0", "js-sha512": "^0.8.0", + "@msgpack/msgpack": "^2.8.0", "moment": "^2.29.4", "os-browserify": "^0.3.0", "papaparse": "^5.4.1", diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index 010653c..1e53892 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -1,4 +1,5 @@ /* eslint-disable camelcase */ +import { decode } from "@msgpack/msgpack" import axios from 'axios' import { decodeAgentId } from '../../ui-common-library/src/utils/agent' import { kAuthTokenLSKey, kCoreAppVersionLSKey } from '@/constants' @@ -145,11 +146,14 @@ type HposHolochainCallResponse = | ReserveSettingsResponse | EUserKycLevel | ServiceLogsResponse + | ZomeCallResponse type HposAdminCallResponse = HposConfigResponse type ServiceLogsResponse = Array> +type ZomeCallResponse = number[] | null + export interface UsageResponse { totalHostedHapps: number totalHostedAgents: number @@ -632,7 +636,7 @@ export function useHposInterface(): HposInterface { params }) - return hostPreferences + return decode(hostPreferences) } catch (error) { console.error('getHostPreferences encountered an error: ', error) return false @@ -741,7 +745,7 @@ export function useHposInterface(): HposInterface { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const { agent_address: agentAddress, nickname, avatar_url: avatarUrl } = response + const { agent_address: agentAddress, nickname, avatar_url: avatarUrl } = decode(response) // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment return { agentAddress: Uint8Array.from(agentAddress.data), nickname, avatarUrl } @@ -890,12 +894,16 @@ export function useHposInterface(): HposInterface { } // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - const reserveAccountsDetails: ReserveSettingsResponse = (await hposHolochainCall({ + const response = await hposHolochainCall({ method: 'post', path: '/zome_call', pathPrefix: '/api/v2', params: getReserveDetailsParams - })) as ReserveSettingsResponse + }) + + const reserveAccountsDetails: ReserveSettingsResponse = decode( + response + ) as ReserveSettingsResponse if (reserveAccountsDetails[0]) { const initiateRedemptionParams = { @@ -912,12 +920,16 @@ export function useHposInterface(): HposInterface { } // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - const transaction: RedemptionTransaction = (await hposHolochainCall({ + const response = await hposHolochainCall({ method: 'post', path: '/zome_call', pathPrefix: '/api/v2', params: initiateRedemptionParams - })) as RedemptionTransaction + }) + + const transaction: RedemptionTransaction = decode( + response + ) as RedemptionTransaction return transaction } diff --git a/ui-common-library b/ui-common-library index 9c4760d..fea3d7e 160000 --- a/ui-common-library +++ b/ui-common-library @@ -1 +1 @@ -Subproject commit 9c4760d07a0eeba7e41ccfe1c9a9471c51e424f1 +Subproject commit fea3d7ec9d9a5f532406b67e9eb3232afc816df5 diff --git a/yarn.lock b/yarn.lock index bc72459..6c7af3a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1861,6 +1861,11 @@ "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" +"@msgpack/msgpack@^2.8.0": + version "2.8.0" + resolved "https://registry.yarnpkg.com/@msgpack/msgpack/-/msgpack-2.8.0.tgz#4210deb771ee3912964f14a15ddfb5ff877e70b9" + integrity sha512-h9u4u/jiIRKbq25PM+zymTyW6bhTzELvOoUd+AvYriWOAKpLGnIamaET3pnHYoI5iYphAHBI4ayx0MehR+VVPQ== + "@ndelangen/get-tarball@^3.0.7": version "3.0.7" resolved "https://registry.yarnpkg.com/@ndelangen/get-tarball/-/get-tarball-3.0.7.tgz#87c7aef2df4ff4fbdbab6ac9ed32cee142c4b1a3" From d17c70a35d24d89a7bfda53ba3665af256b4d0db Mon Sep 17 00:00:00 2001 From: peeech Date: Wed, 17 Jan 2024 20:00:24 +0100 Subject: [PATCH 3/4] zome calls return arraybuffer --- mock-hpos-api/defaultResponse.js | 2 +- src/interfaces/HposInterface.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mock-hpos-api/defaultResponse.js b/mock-hpos-api/defaultResponse.js index a16167e..06bf98b 100644 --- a/mock-hpos-api/defaultResponse.js +++ b/mock-hpos-api/defaultResponse.js @@ -660,7 +660,7 @@ const data = { }, post: { '/holochain-api/v1/zome_call': (args) => { - switch (args.fnName) { + switch (args.fn_name) { case 'get_my_profile': return getMyProfile case 'get_all_reserve_accounts_details': diff --git a/src/interfaces/HposInterface.ts b/src/interfaces/HposInterface.ts index 1e53892..f995ac7 100644 --- a/src/interfaces/HposInterface.ts +++ b/src/interfaces/HposInterface.ts @@ -152,7 +152,7 @@ type HposAdminCallResponse = HposConfigResponse type ServiceLogsResponse = Array> -type ZomeCallResponse = number[] | null +type ZomeCallResponse = Uint8Array | null export interface UsageResponse { totalHostedHapps: number @@ -281,6 +281,7 @@ interface HposCallArgs { method: string path: string headers?: Record + responseType?: string params?: Record } @@ -341,6 +342,7 @@ export function useHposInterface(): HposInterface { method = 'get', path, headers: userHeaders = {}, + responseType = 'json', params }: HposCallArgs): Promise { const fullUrl = `${HPOS_API_URL}${pathPrefix}${path}` @@ -361,7 +363,8 @@ export function useHposInterface(): HposInterface { return response.data case 'post': - response = await axios.post(fullUrl, params, { headers }) + response = await axios + .post(fullUrl, params, { responseType, headers }) return response.data case 'put': @@ -522,6 +525,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -598,6 +602,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -633,6 +638,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -740,6 +746,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -748,7 +755,7 @@ export function useHposInterface(): HposInterface { const { agent_address: agentAddress, nickname, avatar_url: avatarUrl } = decode(response) // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment - return { agentAddress: Uint8Array.from(agentAddress.data), nickname, avatarUrl } + return { agentAddress, nickname, avatarUrl } } function getHoloFuelProfile(): unknown { @@ -795,6 +802,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -898,6 +906,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params: getReserveDetailsParams }) @@ -924,6 +933,7 @@ export function useHposInterface(): HposInterface { method: 'post', path: '/zome_call', pathPrefix: '/api/v2', + responseType: 'arraybuffer', params: initiateRedemptionParams }) From 7a2f766f6cbe3e21a2286baffb7a360ba93b2d9b Mon Sep 17 00:00:00 2001 From: peeech Date: Wed, 17 Jan 2024 20:03:29 +0100 Subject: [PATCH 4/4] fix arg name --- mock-hpos-api/defaultResponse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mock-hpos-api/defaultResponse.js b/mock-hpos-api/defaultResponse.js index 06bf98b..a16167e 100644 --- a/mock-hpos-api/defaultResponse.js +++ b/mock-hpos-api/defaultResponse.js @@ -660,7 +660,7 @@ const data = { }, post: { '/holochain-api/v1/zome_call': (args) => { - switch (args.fn_name) { + switch (args.fnName) { case 'get_my_profile': return getMyProfile case 'get_all_reserve_accounts_details':