Skip to content

Commit 5b6479f

Browse files
committed
fix: events being emitted in the wrong order on tx channel
1 parent 57d2493 commit 5b6479f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/features/transactions/createTransactionChannel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ export default function createTransactionChannel(tx, { wait = false } = {}) {
5959
}
6060

6161
if (number >= confirmations) {
62-
emit(END);
63-
6462
/**
6563
* For some reason, on Kovan sometimes the confirmation #0 is not emitted,
6664
* the first one to happen is confirmation #1.
@@ -81,6 +79,8 @@ export default function createTransactionChannel(tx, { wait = false } = {}) {
8179
});
8280
}
8381

82+
emit(END);
83+
8484
resultChannel.put({ type: 'FULFILLED', payload: { txHash } });
8585
resultChannel.put(END);
8686
}

src/features/transactions/transactionsSlice.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,23 @@ export const selectByTxHash = txHash => state => state.transactions.entities[txH
108108
* @param {PromiEvent} tx the transaction PromiEvent from web3.js
109109
* @param {object} options the options object
110110
* @param {false|number} [options.wait=false] if the saga must wait for the transaction to be mined.
111-
* If `false`, it will return right after the transaction hash is calculated.
112-
* If `0`, it will wait until the transaction is mined.
113-
* If `n`, it will wait until `n` confirmations.
114-
* @param {number} [options.ttl=10] time in milliseconds which the transaction data should be kept
115-
* in the store.
111+
* If `false`, it will return right after the transaction hash is calculated.
112+
* If `0`, it will wait until the transaction is mined.
113+
* If `n`, it will wait until `n` confirmations.
114+
* @param {number} [options.ttl=10] time in milliseconds which the transaction data should be kept in the store.
116115
* @param {boolean|ShouldNotifyOption} [options.shouldNotify=true] time in milliseconds which the transaction data should be kept
116+
* @param {function} [options.onSuccess=] a function/generator to be executed if the transaction is sucessfully mined.
117+
* @param {function} [options.onFailure=] a function/generator to be executed if the transaction fails.
117118
*/
118119
export function* registerTxSaga(
119120
tx,
120-
{ wait = false, shouldNotify = true, onSuccess = () => {}, onFailure = () => {}, ttl = DEFAULT_TTL } = {}
121+
{
122+
wait = false,
123+
shouldNotify = true,
124+
ttl = DEFAULT_TTL,
125+
onSuccess = function* () {},
126+
onFailure = function* () {},
127+
} = {}
121128
) {
122129
const txChannel = yield call(createTransactionChannel, tx, { wait });
123130

@@ -169,7 +176,7 @@ export function* registerTxSaga(
169176
}
170177
}
171178

172-
function* afterTxResultSaga(txHash, { onSuccess = () => {}, onFailure = () => {} }) {
179+
function* afterTxResultSaga(txHash, { onSuccess = function* () {}, onFailure = function* () {} }) {
173180
const matchesActionType = action => [confirm, fail].some(({ match }) => match(action));
174181
const matchesTxHash = action => action.payload?.txHash === txHash;
175182

0 commit comments

Comments
 (0)