From c6569a3e0b61e43be98bafad9519c4baa7fa894b Mon Sep 17 00:00:00 2001 From: vikastc Date: Thu, 22 Jun 2023 13:21:02 +0530 Subject: [PATCH] Created a config service for url and token support Signed-off-by: vikastc --- packages/config/src/ConfigService.ts | 8 ++++++++ packages/modules/src/cordconfig/CordConfig.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/config/src/ConfigService.ts b/packages/config/src/ConfigService.ts index 817b7a42..23d2bbde 100644 --- a/packages/config/src/ConfigService.ts +++ b/packages/config/src/ConfigService.ts @@ -19,6 +19,8 @@ import { import { SDKErrors } from '@cord.network/utils' import { SubscriptionPromise } from '@cord.network/types' +const { CORD_WSS_URL, CORD_API_URL, CORD_API_TOKEN } = process.env + const DEFAULT_DEBUG_LEVEL = typeof process !== 'undefined' && process.env?.DEBUG && @@ -30,6 +32,9 @@ export type configOpts = { api: ApiPromise logLevel: LogLevel submitTxResolveOn: SubscriptionPromise.ResultEvaluator + apiUrl: string + wssUrl: string + token: string | undefined } & { [key: string]: any } /** @@ -52,6 +57,9 @@ export function modifyLogLevel(level: LogLevel): LogLevel { const defaultConfig: Partial = { logLevel: DEFAULT_DEBUG_LEVEL, + apiUrl: CORD_API_URL ?? 'localhost:3009', + wssUrl: CORD_WSS_URL ?? 'localhost:9944', + token: CORD_API_TOKEN ?? 'dummyToken', } let configuration: Partial = { ...defaultConfig } diff --git a/packages/modules/src/cordconfig/CordConfig.ts b/packages/modules/src/cordconfig/CordConfig.ts index 3cbf1c52..bb95766a 100644 --- a/packages/modules/src/cordconfig/CordConfig.ts +++ b/packages/modules/src/cordconfig/CordConfig.ts @@ -41,7 +41,14 @@ export async function connect( ...apiOpts }: Omit = {} ): Promise { - const provider = new WsProvider(blockchainRpcWsUrl) + let provider: any + + if (blockchainRpcWsUrl) { + provider = new WsProvider(blockchainRpcWsUrl) + } else { + provider = undefined + } + const api = await ApiPromise.create({ provider, typesBundle,