diff --git a/packages/libs/client/src/client/client.ts b/packages/libs/client/src/client/client.ts index 807338afe4..6452d005e9 100644 --- a/packages/libs/client/src/client/client.ts +++ b/packages/libs/client/src/client/client.ts @@ -268,15 +268,16 @@ export interface ICreateClient { chainId: ChainId; networkId: string; type?: 'local' | 'send' | 'poll' | 'listen' | 'spv'; - }) => string | { host: string; headers: Record }, + }) => string | { hostUrl: string; headers: Record }, defaults?: { confirmationDepth?: number }, ): IClient; } const getHostData = ( - hostObject: string | { host: string; headers: Record }, + hostObject: string | { hostUrl: string; headers: Record }, ) => { - const hostUrl = typeof hostObject === 'string' ? hostObject : hostObject.host; + const hostUrl = + typeof hostObject === 'string' ? hostObject : hostObject.hostUrl; const headers = typeof hostObject === 'object' ? hostObject.headers : {}; return { hostUrl, headers }; }; @@ -295,17 +296,15 @@ export const createClient: ICreateClient = ( const client: IBaseClient = { local(body, options) { const cmd: IPactCommand = JSON.parse(body.cmd); - const hostUrl = getHost({ + const hostObject = getHost({ chainId: cmd.meta.chainId, networkId: cmd.networkId, }); - if (typeof hostUrl === 'object') { - return local(body, hostUrl.host, { - ...options, - headers: hostUrl.headers, - }); - } - return local(body, hostUrl, options); + const { hostUrl, headers } = getHostData(hostObject); + return local(body, hostUrl, { + ...options, + headers: headers, + }); }, submit: (async (body) => { const isList = Array.isArray(body); @@ -320,9 +319,7 @@ export const createClient: ICreateClient = ( networkId: cmd.networkId, }); - const hostUrl = - typeof hostObject === 'string' ? hostObject : hostObject.host; - const headers = typeof hostObject === 'object' ? hostObject.headers : {}; + const { hostUrl, headers } = getHostData(hostObject); const { requestKeys } = await send({ cmds: commands }, hostUrl, { headers,