diff --git a/package.json b/package.json index bd263de..4955f42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bnc-sdk", - "version": "3.7.1", + "version": "4.0.0", "description": "SDK to connect to the blocknative backend via a websocket connection", "keywords": [ "ethereum", diff --git a/src/messages.ts b/src/messages.ts index 2d1178a..0037df8 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -238,7 +238,8 @@ export function handleMessage(this: any, msg: { data: string }): void { // replace originalHash to match webhook API if (newState.originalHash) { - newState.replaceHash = newState.originalHash + newState.replaceHash = newState.hash + newState.hash = newState.originalHash delete newState.originalHash } @@ -296,7 +297,7 @@ export function handleMessage(this: any, msg: { data: string }): void { ) } else { const transactionObj = this._watchedTransactions.find( - (tx: Tx) => tx.hash === transaction.hash || transaction.txid + (tx: Tx) => tx.hash === newState.hash || newState.txid ) const emitterResult = @@ -305,6 +306,17 @@ export function handleMessage(this: any, msg: { data: string }): void { this._transactionHandlers.forEach((handler: TransactionHandler) => handler({ transaction: newState, emitterResult }) ) + + // replace the emitter hash to the replace hash on replacement txs + if (newState.status === 'speedup' || newState.status === 'cancel') { + this._watchedTransactions = this._watchedTransactions.map((tx: Tx) => { + if (tx.hash === newState.hash || newState.txid) { + return { ...tx, hash: newState.replaceHash } + } + + return tx + }) + } } } }