From 3d57a0933117410d3e4a04f6afb3c424c39db51c Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 8 Jun 2021 15:27:17 +1000 Subject: [PATCH 1/6] Add error handling --- src/interfaces.ts | 4 ++++ src/notify.ts | 23 ++++++++++------------- src/validation.ts | 9 +++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index cd6292b..df7d8ae 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -8,8 +8,11 @@ export interface InitOptions extends ConfigOptions { transactionHandler?: TransactionHandler name?: string apiUrl?: string + onerror?: ErrorHandler } +export type ErrorHandler = (error: { message: string }) => void + export interface TransactionHandler { (transaction: TransactionEvent): void } @@ -115,6 +118,7 @@ export interface AppStore { name?: string networkId?: number nodeSynced: boolean + onerror?: ErrorHandler mobilePosition: 'bottom' | 'top' desktopPosition: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight' darkMode: boolean diff --git a/src/notify.ts b/src/notify.ts index 89cbe14..81b7d81 100644 --- a/src/notify.ts +++ b/src/notify.ts @@ -91,6 +91,7 @@ function init(options: InitOptions): API { blocknative = new BlocknativeSdk({ dappId, networkId, + onerror: appOptions.onerror, transactionHandlers, name: name || 'Notify', apiUrl, @@ -151,12 +152,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) { @@ -166,12 +163,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( @@ -188,7 +181,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 { diff --git a/src/validation.ts b/src/validation.ts index e0e3df9..a2ea06f 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -11,6 +11,7 @@ const validInitKeys = [ 'system', 'transactionHandler', 'name', + 'onerror', 'mobilePosition', 'desktopPosition', 'darkMode', @@ -97,6 +98,7 @@ export function validateInit(init: InitOptions): void { transactionHandler, name, apiUrl, + onerror, ...otherParams } = init @@ -139,6 +141,13 @@ export function validateInit(init: InitOptions): void { optional: true }) + validateType({ + name: 'onerror', + value: onerror, + type: 'function', + optional: true + }) + validateConfig(otherParams) } From 8b562a1735ea6ef2520ed952e8c64ced35da2504 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 8 Jun 2021 15:27:44 +1000 Subject: [PATCH 2/6] Increment version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0391198..d1881f5 100644 --- a/package.json +++ b/package.json @@ -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", From aca9c5d68b71746bbc23d7c71c764463862d0dfe Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 8 Jun 2021 15:36:54 +1000 Subject: [PATCH 3/6] Use SDKError type --- src/interfaces.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index df7d8ae..ad6f8eb 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,6 +1,7 @@ import type { BitcoinTransactionLog, - EthereumTransactionLog + EthereumTransactionLog, + SDKError } from 'bnc-sdk/dist/types/src/interfaces' export interface InitOptions extends ConfigOptions { @@ -11,7 +12,7 @@ export interface InitOptions extends ConfigOptions { onerror?: ErrorHandler } -export type ErrorHandler = (error: { message: string }) => void +export type ErrorHandler = (error: SDKError) => void export interface TransactionHandler { (transaction: TransactionEvent): void From ce508bddcf5f3da2c506c2091e8fa68d3bca7b5d Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 9 Jun 2021 09:49:46 +1000 Subject: [PATCH 4/6] Destructure onerror property --- src/notify.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notify.ts b/src/notify.ts index 81b7d81..a397e9c 100644 --- a/src/notify.ts +++ b/src/notify.ts @@ -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] @@ -91,7 +91,7 @@ function init(options: InitOptions): API { blocknative = new BlocknativeSdk({ dappId, networkId, - onerror: appOptions.onerror, + onerror, transactionHandlers, name: name || 'Notify', apiUrl, From cb74e6e87d937b66e0e2eccf2411d55cb6f9df3c Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 9 Jun 2021 09:51:29 +1000 Subject: [PATCH 5/6] Handle server timeout error --- src/notify.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/notify.ts b/src/notify.ts index a397e9c..2cccd19 100644 --- a/src/notify.ts +++ b/src/notify.ts @@ -99,10 +99,14 @@ function init(options: InitOptions): API { }) // 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 From dcc1279ece8b3135c6d1a8d6149907475ac45e2b Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 10 Jun 2021 09:35:11 +1000 Subject: [PATCH 6/6] Release 1.6.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d1881f5..75d8209 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bnc-notify", - "version": "1.6.1-0.1.1", + "version": "1.6.2", "description": "Show web3 users realtime transaction notifications", "keywords": [ "ethereum",