Skip to content

Commit

Permalink
fix: concurrently fetch logs for endorsement chain events
Browse files Browse the repository at this point in the history
  • Loading branch information
MinHtet-O committed Jul 22, 2024
1 parent a9e776b commit 8e18ca7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/common/hooks/useEndorsementChain/retrieveEndorsementChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export const getEndorsementChain = async (
let previousBeneficiary = "";
let previousHolder = "";

for (const log of logChain) {
const timestamp = await fetchEventTime(log.blockNumber, provider);
const timestampPromises = logChain.map((log) => fetchEventTime(log.blockNumber, provider));
const timestamps = await Promise.all(timestampPromises);

logChain.forEach((log, index) => {
const timestamp = timestamps[index];
const transactionDetails = {
type: log.type,
transactionHash: log.transactionHash,
Expand All @@ -33,22 +36,25 @@ export const getEndorsementChain = async (
log.type === "TRANSFER_HOLDER" ||
log.type === "INITIAL"
) {
// Owner/Holder change
historyChain.push(transactionDetails);
previousHolder = transactionDetails.holder;
previousBeneficiary = transactionDetails.owner;
} else if (log.type === "SURRENDER_ACCEPTED") {
// Title Escrow Voided
previousHolder = "";
previousBeneficiary = "";
historyChain.push(transactionDetails);
} else if (log.type === "SURRENDERED" || log.type === "SURRENDER_REJECTED") {
// No state changes, except document owner
historyChain.push(transactionDetails);
} else {
// No state changes
historyChain.push(transactionDetails);
}
}
});

// const endTime = new Date().getTime();
// const durationMs = endTime - startTime;
// console.log("historyChain:", historyChain);
// console.groupEnd();
// console.log(`> getEndorsementChain executed in ${durationMs} milliseconds at ${new Date(endTime).toISOString()}`);

return historyChain;
};
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module.exports = {
},
historyApiFallback: true,
hot: true,
port: 3000,
port: 3001,
},
stats: {
colors: true,
Expand Down

0 comments on commit 8e18ca7

Please sign in to comment.