Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-notify",
"version": "1.6.1",
"version": "1.6.1-0.1.1",
"description": "Show web3 users realtime transaction notifications",
"keywords": [
"ethereum",
Expand Down
7 changes: 6 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type {
BitcoinTransactionLog,
EthereumTransactionLog
EthereumTransactionLog,
SDKError
} from 'bnc-sdk/dist/types/src/interfaces'

export interface InitOptions extends ConfigOptions {
dappId?: string
transactionHandler?: TransactionHandler
name?: string
apiUrl?: string
onerror?: ErrorHandler
}

export type ErrorHandler = (error: SDKError) => void

export interface TransactionHandler {
(transaction: TransactionEvent): void
}
Expand Down Expand Up @@ -115,6 +119,7 @@ export interface AppStore {
name?: string
networkId?: number
nodeSynced: boolean
onerror?: ErrorHandler
mobilePosition: 'bottom' | 'top'
desktopPosition: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight'
darkMode: boolean
Expand Down
37 changes: 19 additions & 18 deletions src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function init(options: InitOptions): API {
validateInit(options)

const { system, transactionHandler, apiUrl, ...appOptions } = options
const { dappId, networkId, name, clientLocale } = appOptions
const { dappId, networkId, name, clientLocale, onerror } = appOptions

const transactionHandlers: TransactionHandler[] = [handleTransactionEvent]

Expand All @@ -91,17 +91,22 @@ function init(options: InitOptions): API {
blocknative = new BlocknativeSdk({
dappId,
networkId,
onerror,
transactionHandlers,
name: name || 'Notify',
apiUrl,
system
})

// filter out pending simulation events
blocknative.configuration({
scope: 'global',
filters: [{ status: 'pending-simulation', _not: true }]
})
blocknative
.configuration({
scope: 'global',
filters: [{ status: 'pending-simulation', _not: true }]
})
.catch(() => {
// swallow server timeout response error as we are not waiting on it
})
}

// save config to app store
Expand Down Expand Up @@ -151,12 +156,8 @@ function init(options: InitOptions): API {
)
}

try {
const result = blocknative.account(address)
return result
} catch (error) {
throw new Error(error)
}
const result = blocknative.account(address)
return result
}

function hash(hash: string, id?: string) {
Expand All @@ -166,12 +167,8 @@ function init(options: InitOptions): API {
)
}

try {
const result = blocknative.transaction(hash, id)
return result
} catch (error) {
throw new Error(error)
}
const result = blocknative.transaction(hash, id)
return result
}

function transaction(
Expand All @@ -188,7 +185,11 @@ function init(options: InitOptions): API {
const emitter = createEmitter()

const result = preflightTransaction(blocknative, options, emitter).catch(
err => err
err => {
const { onerror } = get(app)
onerror && onerror(err)
return err
}
)

return {
Expand Down
9 changes: 9 additions & 0 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const validInitKeys = [
'system',
'transactionHandler',
'name',
'onerror',
'mobilePosition',
'desktopPosition',
'darkMode',
Expand Down Expand Up @@ -97,6 +98,7 @@ export function validateInit(init: InitOptions): void {
transactionHandler,
name,
apiUrl,
onerror,
...otherParams
} = init

Expand Down Expand Up @@ -139,6 +141,13 @@ export function validateInit(init: InitOptions): void {
optional: true
})

validateType({
name: 'onerror',
value: onerror,
type: 'function',
optional: true
})

validateConfig(otherParams)
}

Expand Down