Skip to content

Commit b2a4794

Browse files
Adamj1232lnbc1QWFyb24freeatnet
authored
4.1.0 Release - Master (#174)
* 4.0.0-0.1.0 : Add fantom network #173 * Add fantom network (fantom-main) to Network type in interfaces.ts and networks object in defaults.ts * Update version * 4.0.0-0.1.1 - Test whether localStorage is accessible before performing operations (#172) * Update version * Add gasGwei values Co-authored-by: Aaron Barnard <abarnard@protonmail.com> Co-authored-by: Arseniy Ivanov <138289+freeatnet@users.noreply.github.com>
1 parent 8202a07 commit b2a4794

6 files changed

Lines changed: 36 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-sdk",
3-
"version": "4.0.0",
3+
"version": "4.1.0",
44
"description": "SDK to connect to the blocknative backend via a websocket connection",
55
"keywords": [
66
"ethereum",

src/defaults.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const networks: { [key: string]: { [key: string]: string } } = {
1111
'42': 'kovan',
1212
'56': 'bsc-main',
1313
'100': 'xdai',
14-
'137': 'matic-main'
14+
'137': 'matic-main',
15+
'250': 'fantom-main'
1516
}
1617
}
1718

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
LimitRules,
3333
EnhancedConfig
3434
} from './interfaces'
35+
import { isLocalStorageAvailable } from './utilities'
3536

3637
const DEFAULT_APP_NAME = 'unknown'
3738
const DEFAULT_APP_VERSION = 'unknown'
@@ -114,7 +115,7 @@ class Blocknative {
114115

115116
const storageKey = CryptoEs.SHA1(`${dappId} - ${name}`).toString()
116117
const storedConnectionId =
117-
typeof window !== 'undefined' && window.localStorage.getItem(storageKey)
118+
isLocalStorageAvailable() && window.localStorage.getItem(storageKey)
118119

119120
this._storageKey = storageKey
120121
this._connectionId = storedConnectionId || undefined

src/interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export interface EthereumTransactionData extends CommonTransactionData {
6666
replaceHash?: string
6767
counterparty?: string
6868
direction?: string
69+
baseFeePerGasGwei?: number
70+
maxPriorityFeePerGasGwei?: number
71+
maxFeePerGasGwei?: number
72+
gasPriceGwei?: number
6973
}
7074

7175
export interface InternalTransaction {
@@ -119,6 +123,7 @@ export type Network =
119123
| 'xdai'
120124
| 'bsc-main'
121125
| 'matic-main'
126+
| 'fantom-main'
122127
| 'local'
123128

124129
export type Status =

src/messages.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
last,
44
networkName,
55
wait,
6-
jsonPreserveUndefined
6+
jsonPreserveUndefined,
7+
isLocalStorageAvailable
78
} from './utilities'
89
import { version } from '../package.json'
910
import { Ac, Tx, Emitter, EventObject, TransactionHandler } from './interfaces'
@@ -63,7 +64,7 @@ export function handleMessage(this: any, msg: { data: string }): void {
6364
} = JSON.parse(msg.data)
6465

6566
if (connectionId) {
66-
if (typeof window !== 'undefined') {
67+
if (isLocalStorageAvailable()) {
6768
window.localStorage.setItem(this._storageKey, connectionId)
6869
}
6970

src/utilities.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,26 @@ export function wait(time: number) {
114114

115115
export const jsonPreserveUndefined = (k: any, v: any) =>
116116
v === undefined ? 'undefined' : v
117+
118+
/**
119+
* Tests if LocalStorage may be used. Accounts for environments where
120+
* LocalStorage is not supported, as well as those where it is blocked.
121+
*
122+
* @returns `true` if LocalStorage is supported and accessible, `false` otherwise.
123+
*/
124+
export function isLocalStorageAvailable(): boolean {
125+
const isSupported = typeof window !== 'undefined' && 'localStorage' in window
126+
127+
if (isSupported) {
128+
const testKey = '__testLocalStorage'
129+
try {
130+
window.localStorage.setItem(testKey, '1')
131+
window.localStorage.removeItem(testKey)
132+
return true
133+
} catch (err) {
134+
return false
135+
}
136+
}
137+
138+
return false
139+
}

0 commit comments

Comments
 (0)