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 f79ab2d..f995ac7 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 = Uint8Array | null + export interface UsageResponse { totalHostedHapps: number totalHostedAgents: number @@ -277,6 +281,7 @@ interface HposCallArgs { method: string path: string headers?: Record + responseType?: string params?: Record } @@ -337,6 +342,7 @@ export function useHposInterface(): HposInterface { method = 'get', path, headers: userHeaders = {}, + responseType = 'json', params }: HposCallArgs): Promise { const fullUrl = `${HPOS_API_URL}${pathPrefix}${path}` @@ -357,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': @@ -517,6 +524,8 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -592,6 +601,8 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -626,10 +637,12 @@ export function useHposInterface(): HposInterface { const hostPreferences = await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) - return hostPreferences + return decode(hostPreferences) } catch (error) { console.error('getHostPreferences encountered an error: ', error) return false @@ -732,15 +745,17 @@ export function useHposInterface(): HposInterface { const response = await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) // 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 } + return { agentAddress, nickname, avatarUrl } } function getHoloFuelProfile(): unknown { @@ -786,6 +801,8 @@ export function useHposInterface(): HposInterface { await hposHolochainCall({ method: 'post', path: '/zome_call', + pathPrefix: '/api/v2', + responseType: 'arraybuffer', params }) @@ -885,11 +902,17 @@ 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', + responseType: 'arraybuffer', params: getReserveDetailsParams - })) as ReserveSettingsResponse + }) + + const reserveAccountsDetails: ReserveSettingsResponse = decode( + response + ) as ReserveSettingsResponse if (reserveAccountsDetails[0]) { const initiateRedemptionParams = { @@ -906,11 +929,17 @@ 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', + responseType: 'arraybuffer', 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"