diff --git a/src/datalayer/persistance.js b/src/datalayer/persistance.js index c6354825..236af166 100644 --- a/src/datalayer/persistance.js +++ b/src/datalayer/persistance.js @@ -108,7 +108,7 @@ export const getRoot = async (storeId) => { try { const data = JSON.parse(response); - if (data.success) { + if (data.status === 1) { return data; } diff --git a/src/datalayer/simulator.js b/src/datalayer/simulator.js index 3ec7e592..6657c84c 100644 --- a/src/datalayer/simulator.js +++ b/src/datalayer/simulator.js @@ -78,6 +78,7 @@ export const getRoot = async (storeId) => { ); return Promise.resolve({ hash: null, + status: 1, success: false, }); } @@ -90,6 +91,7 @@ export const getRoot = async (storeId) => { return Promise.resolve({ hash, + status: 1, success: true, }); }; @@ -122,6 +124,7 @@ export const getRoots = async (storeIds) => { .update(JSON.stringify(simulatorTable)) .digest('hex')}`, id: storeId, + status: 1, }; } @@ -129,6 +132,7 @@ export const getRoots = async (storeIds) => { return { hash: 0, id: storeId, + status: 1, }; }), success: true, diff --git a/src/datalayer/syncService.js b/src/datalayer/syncService.js index 2de89701..31aa18cd 100644 --- a/src/datalayer/syncService.js +++ b/src/datalayer/syncService.js @@ -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; diff --git a/src/datalayer/writeService.js b/src/datalayer/writeService.js index 345b4059..e7f0510f 100644 --- a/src/datalayer/writeService.js +++ b/src/datalayer/writeService.js @@ -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,