Skip to content

Commit

Permalink
Merge pull request #204 from blocknative/release/4.6.0
Browse files Browse the repository at this point in the history
Release 4.6.0
  • Loading branch information
lnbc1QWFyb24 authored Aug 8, 2022
2 parents 15b58a6 + 89bc7e3 commit a7698b0
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-sdk",
"version": "4.5.0",
"version": "4.6.0",
"description": "SDK to connect to the blocknative backend via a websocket connection",
"keywords": [
"ethereum",
Expand Down
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import {
SDKError,
LimitRules,
EnhancedConfig,
MultiChainOptions
MultiChainOptions,
InitializationOptionsApiUrl,
InitializationOptionsDappId
} from './types'

const DEFAULT_APP_NAME = 'unknown'
Expand All @@ -45,7 +47,7 @@ const DEFAULT_SYSTEM = 'ethereum'
class SDK {
protected _storageKey: string
protected _connectionId: string | undefined
protected _dappId: string
protected _dappId?: string
protected _system: string
protected _networkId: number
protected _appName: string
Expand Down Expand Up @@ -80,13 +82,11 @@ class SDK {
validateOptions(options)

const {
dappId,
system = DEFAULT_SYSTEM,
name = DEFAULT_APP_NAME,
appVersion = DEFAULT_APP_VERSION,
networkId,
transactionHandlers = [],
apiUrl,
ws,
onopen,
ondown,
Expand All @@ -95,6 +95,9 @@ class SDK {
onclose
} = options

const { apiUrl } = options as InitializationOptionsApiUrl
const { dappId } = options as InitializationOptionsDappId

// override default timeout to allow for slow connections
const timeout = { connectTimeout: 10000 }

Expand Down
12 changes: 9 additions & 3 deletions src/multichain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import {
ChainId,
MultiChainOptions,
EthereumTransactionData,
SDKError
SDKError,
MultiChainOptionsApiKey,
MultiChainOptionsApiUrl
} from '../types'

//**Experimental API that is not yet finalized and is in BETA*/
class MultiChain {
public apiKey: string
public ws: WebSocket | void
public ws?: any
public apiUrl: string
public connections: Record<ChainId, SDK | null>
public transactions$: Observable<EthereumTransactionData>
public errors$: Subject<SDKError>
Expand All @@ -24,9 +27,12 @@ class MultiChain {
protected onTransaction$: Subject<EthereumTransactionData>

constructor(options: MultiChainOptions, Blocknative: typeof SDK) {
const { apiKey, ws } = options
const { ws } = options
const { apiKey } = options as MultiChainOptionsApiKey
const { apiUrl } = options as MultiChainOptionsApiUrl

this.apiKey = apiKey
this.apiUrl = apiUrl
this.ws = ws
this.connections = {}
this.onTransaction$ = new Subject()
Expand Down
30 changes: 26 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,48 @@ export interface Vout {
}
}

export type MultiChainOptions = {
export type MultiChainOptionsApiKey = {
apiKey: string
ws?: any
}

export type InitializationOptions = {
export type MultiChainOptionsApiUrl = {
apiUrl: string
ws?: any
}

export type MultiChainOptions =
| MultiChainOptionsApiUrl
| MultiChainOptionsApiKey

export type BaseInitializationOptions = {
networkId: number
dappId: string
system?: System
name?: string
appVersion?: string
transactionHandlers?: TransactionHandler[]
apiUrl?: string
ws?: any
onopen?: () => void
ondown?: (closeEvent: CloseEvent) => void
onreopen?: () => void
onerror?: (error: SDKError) => void
onclose?: () => void
}

export type InitializationOptionsDappId = BaseInitializationOptions & {
dappId: string
apiUrl?: string
}

export type InitializationOptionsApiUrl = BaseInitializationOptions & {
apiUrl: string
}

/** Requires a dappId or an apiUrl with the apikey in the query parameter */
export type InitializationOptions =
| InitializationOptionsApiUrl
| InitializationOptionsDappId

export interface SDKError {
message: string
error?: any
Expand Down
7 changes: 6 additions & 1 deletion src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export function validateOptions(options: any): never | void {
'Initialization Options'
)

validateType({ name: 'dappId', value: dappId, type: 'string' })
validateType({
name: 'dappId',
value: dappId,
type: 'string',
optional: true
})

validateType({
name: 'system',
Expand Down

0 comments on commit a7698b0

Please sign in to comment.