Skip to content

Commit

Permalink
feat: check for confirmed transaction when pushing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Feb 14, 2022
1 parent 9695551 commit b975c7d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const getRoot = async (storeId) => {
try {
const data = JSON.parse(response);

if (data.success) {
if (data.status === 1) {
return data;
}

Expand Down
4 changes: 4 additions & 0 deletions src/datalayer/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const getRoot = async (storeId) => {
);
return Promise.resolve({
hash: null,
status: 1,
success: false,
});
}
Expand All @@ -90,6 +91,7 @@ export const getRoot = async (storeId) => {

return Promise.resolve({
hash,
status: 1,
success: true,
});
};
Expand Down Expand Up @@ -122,13 +124,15 @@ export const getRoots = async (storeIds) => {
.update(JSON.stringify(simulatorTable))
.digest('hex')}`,
id: storeId,
status: 1,
};
}

// no hash for simulated external org tables (they dont exist in simulator)
return {
hash: 0,
id: storeId,
status: 1,
};
}),
success: true,
Expand Down
3 changes: 2 additions & 1 deletion src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export const dataLayerWasUpdated = async () => {
);

if (org) {
return org.registryHash != rootHash.hash;
// store has been updated if its confirmed and the hash has changed
return rootHash.status === 1 && org.registryHash != rootHash.hash;
}

return false;
Expand Down
5 changes: 3 additions & 2 deletions src/datalayer/writeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ const pushChangesWhenStoreIsAvailable = async (storeId, changeList) => {
await pushChangesWhenStoreIsAvailable(storeId, changeList);
}, 5000);
};

if (process.env.USE_SIMULATOR === 'true') {
return simulator.pushChangeListToDataLayer(storeId, changeList);
} else {
const storeExists = await dataLayer.getRoot(storeId);
if (storeExists) {
const storeExistAndIsConfirmed = await dataLayer.getRoot(storeId);
if (storeExistAndIsConfirmed) {
const success = await dataLayer.pushChangeListToDataLayer(
storeId,
changeList,
Expand Down

0 comments on commit b975c7d

Please sign in to comment.