-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract client creation logic to
core
- Loading branch information
Showing
3 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { ChainConfig } from "../config.js"; | ||
import { createClient } from "polkadot-api"; | ||
import type { JsonRpcProvider } from "polkadot-api/ws-provider/web"; | ||
|
||
export async function getClient(chainConfig: ChainConfig) { | ||
const providerOrGetter = await chainConfig.provider; | ||
|
||
// Hack to detect wether function is a `JsonRpcProvider` or a getter of `JsonRpcProvider` | ||
const provider = await (providerOrGetter.length > 0 | ||
? (providerOrGetter as JsonRpcProvider) | ||
: ( | ||
providerOrGetter as Exclude<typeof providerOrGetter, JsonRpcProvider> | ||
)()); | ||
|
||
return createClient(provider); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters