From 31ad32940eef7fd663633cb5805cb66dde265b72 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Fri, 2 Feb 2024 10:50:07 +0800 Subject: [PATCH] update default url at OceanApiClient --- .../ocean-api-client/src/OceanApiClient.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/ocean-api-client/src/OceanApiClient.ts b/packages/ocean-api-client/src/OceanApiClient.ts index ebe18b7b50..84788bcb08 100644 --- a/packages/ocean-api-client/src/OceanApiClient.ts +++ b/packages/ocean-api-client/src/OceanApiClient.ts @@ -2,6 +2,7 @@ import 'url-search-params-polyfill' import AbortController from 'abort-controller' import fetch from 'cross-fetch' import { ApiException, ApiMethod, ApiPagedResponse, ApiResponse, ClientException, TimeoutException } from './' +import { NetworkName } from '@defichain/jellyfish-network' /** * OceanApiClient configurable options @@ -24,7 +25,19 @@ export interface OceanApiClientOptions { /** * Network that ocean client is configured to */ - network?: 'mainnet' | 'testnet' | 'devnet' | 'regtest' | 'changi' | string + network?: NetworkName | 'playground' +} + +/** + * OceanApiClient default options + */ +function getDefaultOptions (network: NetworkName | 'playground'): OceanApiClientOptions { + return { + url: `https://${network}.ocean.jellyfishsdk.com`, + timeout: 60000, + version: 'v0', + network + } } /** @@ -35,10 +48,7 @@ export class OceanApiClient { protected readonly options: OceanApiClientOptions ) { this.options = { - url: 'https://ocean.defichain.com', - timeout: 60000, - version: 'v1', - network: 'mainnet', + ...getDefaultOptions(options?.network ?? 'mainnet'), ...options } this.options.url = this.options.url?.replace(/\/$/, '')