Skip to content

Commit

Permalink
Release 4.3.0 [master] (#189)
Browse files Browse the repository at this point in the history
* 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)

* 4.1.0 Release - Develop (#175)

* Update version

* Add gasGwei values

* Feature/ws simulate (#178)

4.1.0-0.1.0: Handles websocket simulation requests

* DEVELOP - Release/4.2.0 (#180)

4.2.0 Release

* 4.2.0-0.1.0 [Feature] Error Handling for UNSUPPORTED_CHAIN_MSG (#186)

* 4.2.0-0.1.0 [ feature ] : Mumbai testnet support (#185)

* add support for matic-mumbai

* add support for matic-mumbai

* add support for matic-mumbai

* v4.3.0

* Bump ajv from 6.12.2 to 6.12.6 (#182)

Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.12.2 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](ajv-validator/ajv@v6.12.2...v6.12.6)

---
updated-dependencies:
- dependency-name: ajv
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump minimist from 1.2.5 to 1.2.6 (#179)

Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Create issue-to-notion.yml (#177)

* 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 <[email protected]>
Co-authored-by: Arseniy Ivanov <[email protected]>

* Create issue-to-notion.yml

Co-authored-by: Adam Carpenter <[email protected]>
Co-authored-by: Aaron Barnard <[email protected]>
Co-authored-by: Arseniy Ivanov <[email protected]>

* 4.2.0-0.2.0: [enhancement] - Expose Watched Items (#191)

* Expose watchedItems

* Increment version

* Fix eventCode error

Co-authored-by: Aaron Barnard <[email protected]>
Co-authored-by: Adam Carpenter <[email protected]>
Co-authored-by: Arseniy Ivanov <[email protected]>
Co-authored-by: Julie <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Taylor Dawson <[email protected]>
  • Loading branch information
7 people authored Jun 9, 2022
1 parent 4499d2f commit e79b150
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 111 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/issue-to-notion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Github issue -> Notion card
on:
workflow_dispatch:
issues:
types: [opened]
jobs:
issue:
name: "Issue to Notion"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
people=$(for i in $(echo $NOTION_USER_IDS | tr "," " "); do echo -n '{"object":"user","id":"'$i'"},'; done)
curl 'https://api.notion.com/v1/pages' \
-H 'Authorization: Bearer '"$NOTION_TOKEN"'' \
-H "Content-Type: application/json" \
-H "Notion-Version: 2022-02-22" \
--data '{"parent":{"type":"database_id","database_id":"'"$DATABASE_ID"'"},"icon":{"type":"emoji","emoji":"🐛"},"properties":{"Name":{"type":"title","title":[{"type":"text","text":{"content":"'"$TITLE"'"}}]},"Assigned":{"people":['${people:0:-1}']},"Status":{"select":{"name":"'"$STATUS"'"}},"Type":{"multi_select":[{"name":"bug"}]},"Project":{"multi_select":[{"name":"'"$PROJECT_NAME"'"}]}},"children":[{"object":"block","type":"bookmark","bookmark":{"url":"'"$ISSUE_URL"'"}}]}'
env:
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
STATE: ${{ github.event.issue.state }}
ISSUE_URL: ${{ github.event.issue.html_url }}
TITLE: ${{ github.event.issue.title }}
STATUS: Current Sprint
# Product Work Board
DATABASE_ID: 29876f9a9b864ca39a984f42e17fd345
PROJECT_NAME: SDK
# User ids of who to assign the card to in notion: Taylor, Adam, Aaron
NOTION_USER_IDS: f6cbb362-4908-4138-9ef0-434003d9a9f8,8a3a2287-5d2c-4665-906d-02ae9a113340,3b407adf-6552-40de-b22f-5efa852c34a2
shell: bash
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.2.0",
"version": "4.3.0",
"description": "SDK to connect to the blocknative backend via a websocket connection",
"keywords": [
"ethereum",
Expand Down
7 changes: 4 additions & 3 deletions src/account.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createEmitter } from './utilities'
import { Emitter, Ac } from './interfaces'
import Blocknative from '.'

function account(
this: any,
this: Blocknative,
address: string
): { emitter: Emitter; details: { address: string } } {
if (this._destroyed)
Expand All @@ -19,7 +20,7 @@ function account(
// create eventCode for transaction
const eventCode = 'watch'

const existingAddressWatcher = this._watchedAccounts.find(
const existingAddressWatcher = this.watchedAccounts.find(
(ac: Ac) => ac.address === address
)

Expand All @@ -28,7 +29,7 @@ function account(
existingAddressWatcher.emitters.push(emitter)
} else {
// put in accounts queue
this._watchedAccounts.push({
this.watchedAccounts.push({
address,
emitters: [emitter]
})
Expand Down
9 changes: 5 additions & 4 deletions src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Subject } from 'rxjs'
import { take, timeout } from 'rxjs/operators'
import Blocknative from '.'
import { Config, Emitter } from './interfaces'
import { createEmitter } from './utilities'

function configuration(
this: any,
this: Blocknative,
config: Config
): Promise<string | { details: { config: Config }; emitter?: Emitter }> {
if (this._destroyed) {
Expand All @@ -17,18 +18,18 @@ function configuration(
this._system === 'ethereum' ? config.scope.toLowerCase() : config.scope

// resolve previous configuration if exists
const previousConfiguration = this._configurations.get(casedScope)
const previousConfiguration = this.configurations.get(casedScope)

previousConfiguration &&
previousConfiguration.subscription &&
previousConfiguration.subscription.next()

const subscription = new Subject()
const subscription = new Subject<string>()

// create emitter for transaction
const emitter = config.watchAddress ? { emitter: createEmitter() } : {}

this._configurations.set(casedScope, {
this.configurations.set(casedScope, {
...config,
...emitter,
subscription
Expand Down
3 changes: 2 additions & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const networks: { [key: string]: { [key: string]: string } } = {
'56': 'bsc-main',
'100': 'xdai',
'137': 'matic-main',
'250': 'fantom-main'
'250': 'fantom-main',
'80001': 'matic-mumbai'
}
}

Expand Down
58 changes: 29 additions & 29 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,26 @@ const DEFAULT_APP_VERSION = 'unknown'
const DEFAULT_SYSTEM = 'ethereum'

class Blocknative {
private _storageKey: string
private _connectionId: string | undefined
private _dappId: string
private _system: string
private _networkId: number
private _appName: string
private _appVersion: string
private _transactionHandlers: TransactionHandler[]
private _socket: any
private _connected: boolean
private _sendMessage: (msg: EventObject) => void
private _watchedTransactions: Tx[]
private _watchedAccounts: Ac[]
private _configurations: Map<string, EnhancedConfig>
private _pingTimeout?: NodeJS.Timeout
private _heartbeat?: () => void
private _destroyed: boolean
private _onerror: ((error: SDKError) => void) | undefined
private _queuedMessages: EventObject[]
private _limitRules: LimitRules
private _waitToRetry: null | Promise<void>
private _processingQueue: boolean
private _processQueue: () => Promise<void>
protected _storageKey: string
protected _connectionId: string | undefined
protected _dappId: string
protected _system: string
protected _networkId: number
protected _appName: string
protected _appVersion: string
protected _transactionHandlers: TransactionHandler[]
protected _socket: any
protected _connected: boolean
protected _sendMessage: (msg: EventObject) => void
protected _pingTimeout?: NodeJS.Timeout
protected _heartbeat?: () => void
protected _destroyed: boolean
protected _onerror: ((error: SDKError) => void) | undefined
protected _queuedMessages: EventObject[]
protected _limitRules: LimitRules
protected _waitToRetry: null | Promise<void>
protected _processingQueue: boolean
protected _processQueue: () => Promise<void>

public transaction: Transaction
public account: Account
Expand All @@ -72,6 +69,9 @@ class Blocknative {
public unsubscribe: Unsubscribe
public destroy: Destroy
public configuration: Configuration
public watchedTransactions: Tx[]
public watchedAccounts: Ac[]
public configurations: Map<string, EnhancedConfig>

constructor(options: InitializationOptions) {
validateOptions(options)
Expand Down Expand Up @@ -131,9 +131,6 @@ class Blocknative {
this._socket = socket
this._connected = false
this._sendMessage = sendMessage.bind(this)
this._watchedTransactions = []
this._watchedAccounts = []
this._configurations = new Map()
this._pingTimeout = undefined
this._destroyed = false
this._onerror = onerror
Expand All @@ -160,6 +157,9 @@ class Blocknative {
}

// public API
this.watchedTransactions = []
this.watchedAccounts = []
this.configurations = new Map()
this.transaction = transaction.bind(this)
this.account = account.bind(this)
this.event = event.bind(this)
Expand Down Expand Up @@ -219,11 +219,11 @@ async function onReopen(this: any, handler: (() => void) | undefined) {

// re-register all configurations on re-connection
const configurations: EnhancedConfig[] = Array.from(
this._configurations.values()
this.configurations.values()
)

// register global config first and wait for it to complete
const globalConfiguration = this._configurations.get('global')
const globalConfiguration = this.configurations.get('global')

if (globalConfiguration) {
try {
Expand Down Expand Up @@ -256,7 +256,7 @@ async function onReopen(this: any, handler: (() => void) | undefined) {
// re-register all accounts to be watched by server upon
// re-connection as they don't get transferred over automatically
// to the new connection like tx hashes do
this._watchedAccounts.forEach((account: Ac) => {
this.watchedAccounts.forEach((account: Ac) => {
this._sendMessage({
eventCode: 'accountAddress',
categoryCode: 'watch',
Expand Down
64 changes: 54 additions & 10 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type Network =
| 'bsc-main'
| 'matic-main'
| 'fantom-main'
| 'matic-mumbai'
| 'local'

export type Status =
Expand Down Expand Up @@ -276,7 +277,7 @@ export interface SimulationTransaction {
to: string
value: number
gas: number
input: string,
input: string
gasPrice?: number
maxPriorityFeePerGas?: number
maxFeePerGas?: number
Expand Down Expand Up @@ -311,26 +312,69 @@ export interface SimulationTransactionOutput {
}

export interface Simulate {
(system: System, network: Network, transaction: SimulationTransaction): Promise<SimulationTransactionOutput>
(
system: System,
network: Network,
transaction: SimulationTransaction
): Promise<SimulationTransactionOutput>
}

export interface EventObject {
export type BaseEventObject = {
eventCode: string
categoryCode: string
transaction?: TransactionEventLog
wallet?: {
balance: string
}
contract?: {
}

export type BaseTransactionEventObject = {
startTime?: number
status?: string
id?: string
}

export type BitcoinTransactionEventObject = BaseTransactionEventObject & {
txid: string
}

export type EthereumTransactionEventObject = BaseTransactionEventObject & {
hash: string
}

export type TransactionEventObject = BaseEventObject & {
transaction:
| BitcoinTransactionEventObject
| EthereumTransactionEventObject
| SimulationTransaction
}

export type WalletEventObject = BaseEventObject & {
balance: { balance: string }
}
export type ContractEventObject = BaseEventObject & {
contract: {
methodName: string
parameters: any[]
}
account?: {
}

export type AccountEventObject = BaseEventObject & {
account: {
address: string
}
connectionId?: string
}

export type InitializeEventObject = BaseEventObject & { connectionId: string }

export type ConfigEventObject = BaseEventObject & {
config: Config
}

export type EventObject =
| TransactionEventObject
| WalletEventObject
| ContractEventObject
| AccountEventObject
| InitializeEventObject
| ConfigEventObject

export interface TransactionHandler {
(transaction: TransactionEvent): void
}
Expand Down
Loading

0 comments on commit e79b150

Please sign in to comment.