Skip to content

Commit

Permalink
Merge pull request #205 from blocknative/release/1.8.0
Browse files Browse the repository at this point in the history
Release 1.8.0
  • Loading branch information
lnbc1QWFyb24 authored Aug 12, 2021
2 parents 0663470 + a68180c commit fc725ac
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 16 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-notify",
"version": "1.7.0",
"version": "1.8.0",
"description": "Show web3 users realtime transaction notifications",
"keywords": [
"ethereum",
Expand Down
7 changes: 7 additions & 0 deletions pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Description
<!-- Add a description of the fix or feature here -->

### Checklist
- [ ] The version field in `package.json` is incremented following [semantic versioning](https://semver.org/)
- [ ] The box that allows repo maintainers to update this PR is checked
- [ ] I tested locally to make sure this feature/fix works
1 change: 1 addition & 0 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function eventToType(eventCode: string | undefined): NotificationType {
case 'txConfirmReminder':
case 'txStallPending':
case 'txStallConfirmed':
case 'txStuck':
return 'hint'
case 'txError':
case 'txSendFail':
Expand Down
6 changes: 4 additions & 2 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const defaultNotifyMessages: any = {
txSent: 'Your transaction has been sent to the network',
txStallPending:
'Your transaction has stalled and has not entered the transaction pool',
txStuck: 'Your transaction is stuck due to a nonce gap',
txPool: 'Your transaction has started',
txStallConfirmed:
"Your transaction has stalled and hasn't been confirmed",
Expand All @@ -27,9 +28,9 @@ export const defaultNotifyMessages: any = {
txPool:
'Your account is {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}',
txSpeedUp:
'Your account is {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}',
'Transaction for {formattedValue} {asset} {preposition} {counterpartyShortened} has been sped up',
txCancel:
'Your account is {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}',
'Transaction for {formattedValue} {asset} {preposition} {counterpartyShortened} has been canceled',
txConfirmed:
'Your account successfully {verb} {formattedValue} {asset} {preposition} {counterpartyShortened}',
txFailed:
Expand All @@ -55,6 +56,7 @@ export const defaultNotifyMessages: any = {
txSent: 'Su transacción ha sido enviada a la red.',
txStallPending:
'Su transacción se ha estancado y no ha ingresado al grupo de transacciones',
txStuck: 'Su transacción está atascada debido a una brecha de nonce',
txPool: 'Su transacción ha comenzado',
txStallConfirmed:
'Su transacción se ha estancado y no ha sido confirmada.',
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface TransactionData {
monitorId?: string
monitorVersion?: string
nonce?: number
replaceHash?: string
r?: string
s?: string
status?: string
Expand Down
18 changes: 14 additions & 4 deletions src/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export const notifications = createNotificationStore([])
function createTransactionStore(initialState: TransactionData[]) {
const { subscribe, update } = writable(initialState)

function updateQueue(transaction: TransactionData) {
const predicate = (tx: TransactionData) => tx.id === transaction.id

function updateQueue(
transaction: TransactionData,
predicate: (tx: TransactionData) => boolean
) {
update((store: TransactionData[]) => {
return replaceOrAdd(store, predicate, transaction)
})
Expand Down Expand Up @@ -88,10 +89,19 @@ function createNotificationStore(
)
}

function updateId(oldId: string, newId: string) {
update((store: (NotificationObject & CustomNotificationObject)[]) =>
store.map((n: NotificationObject & CustomNotificationObject) =>
n.id === oldId ? { ...n, id: newId } : n
)
)
}

return {
subscribe,
add,
remove,
update
update,
updateId
}
}
23 changes: 18 additions & 5 deletions src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js'
import uuid from 'uuid/v4'
import { get } from 'svelte/store'

import { transactions, app } from './stores'
import { transactions, app, notifications } from './stores'
import { createNotification } from './notifications'
import { argsEqual, extractMessageFromError, localNetwork } from './utilities'
import { validateNotificationObject } from './validation'
Expand Down Expand Up @@ -73,13 +73,26 @@ export function handleTransactionEvent(event: {
emitterResult: boolean | void | CustomNotificationObject
}) {
const { transaction, emitterResult } = event
transactions.updateQueue(transaction)
if (!transaction.id) {
transaction.id = transaction.hash || transaction.txid
}

const predicate = (tx: TransactionData) =>
transaction.replaceHash
? tx.id === transaction.replaceHash
: tx.id === transaction.id

transactions.updateQueue(transaction, predicate)

// update notification id if replaced
if (transaction.replaceHash) {
notifications.updateId(transaction.replaceHash, transaction.hash)
}

// create notification if dev hasn't opted out and not connected to a local network
if (emitterResult !== false && !localNetwork(get(app).networkId)) {
const transactionObj = transactionQueue.find(
(tx: TransactionData) => tx.id === transaction.id
)
const transactionObj = transactionQueue.find(predicate)

if (transactionObj) {
createNotification(transactionObj, emitterResult)
}
Expand Down
11 changes: 10 additions & 1 deletion src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ export function replaceOrAdd(
const index = clone.findIndex(predicate)

if (index !== -1) {
const { startTime, contractCall } = clone[index]
const { startTime, contractCall, status } = clone[index]

// if current transaction is a speedup or cancel and new status is pending, ignore update
if (
data.status === 'pending' &&
(status === 'speedup' || status === 'cancel')
) {
return clone
}

const { startTime: serverStartTime } = data
const contractCallMerge = contractCall ? { ...contractCall } : {}

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2798,9 +2798,9 @@ path-key@^2.0.1:
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=

path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"
integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==
version "1.0.7"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==

path-type@^4.0.0:
version "4.0.0"
Expand Down

0 comments on commit fc725ac

Please sign in to comment.