Skip to content

Commit

Permalink
Created a config service for url and token support
Browse files Browse the repository at this point in the history
Signed-off-by: vikastc <vikas.tc@dhiway.com>
  • Loading branch information
Vikastc committed Jun 23, 2023
1 parent d7acfa6 commit c6569a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/config/src/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -30,6 +32,9 @@ export type configOpts = {
api: ApiPromise
logLevel: LogLevel
submitTxResolveOn: SubscriptionPromise.ResultEvaluator
apiUrl: string
wssUrl: string
token: string | undefined
} & { [key: string]: any }

/**
Expand All @@ -52,6 +57,9 @@ export function modifyLogLevel(level: LogLevel): LogLevel {

const defaultConfig: Partial<configOpts> = {
logLevel: DEFAULT_DEBUG_LEVEL,
apiUrl: CORD_API_URL ?? 'localhost:3009',
wssUrl: CORD_WSS_URL ?? 'localhost:9944',
token: CORD_API_TOKEN ?? 'dummyToken',
}

let configuration: Partial<configOpts> = { ...defaultConfig }
Expand Down
9 changes: 8 additions & 1 deletion packages/modules/src/cordconfig/CordConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export async function connect(
...apiOpts
}: Omit<ApiOptions, 'provider'> = {}
): Promise<ApiPromise> {
const provider = new WsProvider(blockchainRpcWsUrl)
let provider: any

if (blockchainRpcWsUrl) {
provider = new WsProvider(blockchainRpcWsUrl)
} else {
provider = undefined
}

const api = await ApiPromise.create({
provider,
typesBundle,
Expand Down

0 comments on commit c6569a3

Please sign in to comment.