diff --git a/src/networkProviders/apiNetworkProvider.ts b/src/networkProviders/apiNetworkProvider.ts index b0e092c3..bf9cf685 100644 --- a/src/networkProviders/apiNetworkProvider.ts +++ b/src/networkProviders/apiNetworkProvider.ts @@ -18,7 +18,7 @@ import { DefinitionOfFungibleTokenOnNetwork, DefinitionOfTokenCollectionOnNetwor import { FungibleTokenOfAccountOnNetwork, NonFungibleTokenOfAccountOnNetwork } from "./tokens"; import { TransactionOnNetwork, prepareTransactionForBroadcasting } from "./transactions"; import { TransactionStatus } from "./transactionStatus"; -import { extendUserAgent, isBackend } from "./userAgent"; +import { extendUserAgentIfBackend } from "./userAgent"; // TODO: Find & remove duplicate code between "ProxyNetworkProvider" and "ApiNetworkProvider". export class ApiNetworkProvider implements INetworkProvider { @@ -34,9 +34,7 @@ export class ApiNetworkProvider implements INetworkProvider { this.config = { ...defaultAxiosConfig, ...config }; this.backingProxyNetworkProvider = new ProxyNetworkProvider(url, proxyConfig); this.axios = getAxios(); - if (isBackend()) { - extendUserAgent(this.userAgentPrefix, this.config); - } + extendUserAgentIfBackend(this.userAgentPrefix, this.config); } private getProxyConfig(config: NetworkProviderConfig | undefined) { diff --git a/src/networkProviders/proxyNetworkProvider.ts b/src/networkProviders/proxyNetworkProvider.ts index 505ca908..5b205975 100644 --- a/src/networkProviders/proxyNetworkProvider.ts +++ b/src/networkProviders/proxyNetworkProvider.ts @@ -15,7 +15,7 @@ import { DefinitionOfFungibleTokenOnNetwork, DefinitionOfTokenCollectionOnNetwor import { FungibleTokenOfAccountOnNetwork, NonFungibleTokenOfAccountOnNetwork } from "./tokens"; import { TransactionOnNetwork, prepareTransactionForBroadcasting } from "./transactions"; import { TransactionStatus } from "./transactionStatus"; -import { extendUserAgent, isBackend } from "./userAgent"; +import { extendUserAgentIfBackend } from "./userAgent"; // TODO: Find & remove duplicate code between "ProxyNetworkProvider" and "ApiNetworkProvider". export class ProxyNetworkProvider implements INetworkProvider { @@ -28,9 +28,7 @@ export class ProxyNetworkProvider implements INetworkProvider { this.url = url; this.config = { ...defaultAxiosConfig, ...config }; this.axios = getAxios(); - if (isBackend()) { - extendUserAgent(this.userAgentPrefix, this.config); - } + extendUserAgentIfBackend(this.userAgentPrefix, this.config); } async getNetworkConfig(): Promise { diff --git a/src/networkProviders/userAgent.ts b/src/networkProviders/userAgent.ts index 41b6a55b..bea3d1cb 100644 --- a/src/networkProviders/userAgent.ts +++ b/src/networkProviders/userAgent.ts @@ -2,7 +2,13 @@ import { AxiosHeaders } from "axios"; import { UnknownClientName } from "./constants"; import { NetworkProviderConfig } from "./networkProviderConfig"; -export function extendUserAgent(userAgentPrefix: string, config: NetworkProviderConfig) { +export function extendUserAgentIfBackend(userAgentPrefix: string, config: NetworkProviderConfig) { + if (isBackend()) { + extendUserAgent(userAgentPrefix, config); + } +} + +function extendUserAgent(userAgentPrefix: string, config: NetworkProviderConfig) { if (!config.headers) { config.headers = new AxiosHeaders({}); } @@ -22,6 +28,6 @@ export function extendUserAgent(userAgentPrefix: string, config: NetworkProvider headers.setUserAgent(newUserAgent, true); } -export function isBackend(): boolean { +function isBackend(): boolean { return typeof window === "undefined"; }