From fac70a2789cfb6d9bea17e505fed355d420c343e Mon Sep 17 00:00:00 2001 From: Javad Khalilian Date: Thu, 24 Oct 2024 12:06:46 +0200 Subject: [PATCH] refactor(client): host url --- packages/libs/client/src/client/client.ts | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) 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,