diff --git a/package.json b/package.json index 1914651..48a79a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bnc-notify", - "version": "1.9.2", + "version": "1.9.2-0.0.1", "description": "Show web3 users realtime transaction notifications", "keywords": [ "ethereum", @@ -50,7 +50,7 @@ }, "dependencies": { "bignumber.js": "^9.0.0", - "bnc-sdk": "^3.5.0", + "bnc-sdk": "4.0.0", "lodash.debounce": "^4.0.8", "regenerator-runtime": "^0.13.3", "uuid": "^3.3.3" diff --git a/src/notifications.ts b/src/notifications.ts index 68f2b6a..57ae631 100644 --- a/src/notifications.ts +++ b/src/notifications.ts @@ -41,7 +41,7 @@ function createBitcoinNotificationObject( outputs } = transactionDetails const type: NotificationType = eventToType(eventCode) - const key = `${id}-${ + const key = `${id || txid}-${ (typeof customization === 'object' && customization.eventCode) || eventCode }` @@ -121,7 +121,7 @@ function createEthereumNotificationObject( } = transactionDetails const type: NotificationType = eventToType(eventCode) - const key = `${id}-${ + const key = `${id || hash}-${ (typeof customization === 'object' && customization.eventCode) || eventCode }` const counterpartyShortened: string | undefined = diff --git a/src/transactions.ts b/src/transactions.ts index 4bc67d7..35ca539 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -70,22 +70,35 @@ export function handlePreFlightEvent( export function handleTransactionEvent(event) { const { transaction, emitterResult } = event - - if (!transaction.id) { - transaction.id = transaction.hash || transaction.txid + const currentId = transaction.id + const transactionId = transaction.hash || transaction.txid + + // returns a boolean indicating whether this transaction state is a new state + // for an existing transaction or is a new transaction + const predicate = (txInState: TransactionData) => { + return ( + (txInState.id && txInState.id === currentId) || + txInState.hash === transaction.hash || + txInState.replaceHash === transaction.hash + ) } - const predicate = (tx: TransactionData) => { - return transaction.replaceHash - ? tx.id === transaction.replaceHash || tx.hash === transaction.replaceHash - : tx.id === transaction.id || tx.hash === transaction.hash + // replace UUID used for pre-hash identitification with hash or txid(bitcoin) + if ( + (transactionId && + transactionId !== currentId && + transaction.eventCode === 'txSent') || + !currentId + ) { + transaction.id = transactionId } transactions.updateQueue(transaction, predicate) - // update notification id if replaced if (transaction.replaceHash) { - notifications.updateId(transaction.replaceHash, transaction.hash) + // remove pending notification for replaceHash if exists, + // this happens is pending comes before speedup event + notifications.remove(transaction.replaceHash, 'txPool') } // create notification if dev hasn't opted out and not connected to a local network diff --git a/yarn.lock b/yarn.lock index 22307ce..03910bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2175,10 +2175,10 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.1.0.tgz#30fa40c9e7fe07dbc895678cd287024dea241dd9" integrity sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ== -bnc-sdk@^3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/bnc-sdk/-/bnc-sdk-3.5.0.tgz#b863a2d947857d87c56d53261bd43529f1a5c03e" - integrity sha512-4CSon8xRTjtD7YOUDJcyqZ/bKCNNwDc4sOPq6O19AlolYTsbbVvh+p5EOmYqL4Re30hI3lKQxN4sh12A6VnAPQ== +bnc-sdk@4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/bnc-sdk/-/bnc-sdk-4.0.0.tgz#0bf8af5c7c3fab7912912431e1af0e48e01b608b" + integrity sha512-ob0GP1dS2yGvV+2hpJgpmrJeen0W68K4jsfjikbuL7ogBAVaQaWbPAzKw2w9tgq9BUM96CR43UpAobSyTZDx7g== dependencies: crypto-es "^1.2.2" rxjs "^6.6.3"