Skip to content

Commit

Permalink
Use onTransactionUpdate for tracking new txs
Browse files Browse the repository at this point in the history
Track tx state updates using onTransactionUpdate for better subscription handling
  • Loading branch information
michaelelliot committed Nov 11, 2019
1 parent baf8ac1 commit 84e387a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/providers/MakerProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ function MakerProvider({ children, network, testchainId, backendEnv }) {
const onNewBlockSub = watcher.onNewBlock(blockHeight =>
log(`Latest block height: ${blockHeight}`)
);
const txManagerSub = maker
.service('transactionManager')
.onTransactionUpdate((tx, state, err) => {
log('Tx ' + state, tx.metadata);
setTxLastUpdate(Date.now());
});
dispatch({ type: 'CLEAR_CONTRACT_STATE' });
startWatcher(maker);
return () => {
batchSub.unsub();
onNewBlockSub.unsub();
txManagerSub.unsub();
};
}
}, [maker, dispatch]);
Expand Down Expand Up @@ -114,14 +121,9 @@ function MakerProvider({ children, network, testchainId, backendEnv }) {
}
};

const newTxListener = (transaction, txMessage) => {
const newTxListener = (transaction, txMessage) =>
setTxReferences(current => [...current, [transaction, txMessage]]);

maker.service('transactionManager').listen(transaction, (tx, state) => {
setTxLastUpdate(Date.now());
});
};

const resetTx = () => setTxReferences([]);

const selectors = {
Expand Down

0 comments on commit 84e387a

Please sign in to comment.