Skip to content

Commit

Permalink
feat: add homeorg profile sync status
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Apr 12, 2024
1 parent e2e7ceb commit ea011ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ export const homeOrgSyncStatus = async (req, res) => {
where: { commited: true },
});

const { sync_status } = await datalayer.getSyncStatus(homeOrg.orgUid);

return res.json({
ready:
walletSynced && Boolean(homeOrg?.synced) && pendingCommitsCount === 0,
status: {
wallet_synced: walletSynced,
home_org_synced: Boolean(homeOrg?.synced),
pending_commits: pendingCommitsCount,
home_org_profile_synced:
sync_status.target_root_hash === homeOrg.orgHash,
},
success: true,
});
Expand Down
29 changes: 29 additions & 0 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,34 @@ const cancelOffer = async (tradeId) => {
}
};

const getSyncStatus = async (storeId) => {
const url = `${CONFIG.DATALAYER_URL}/get_sync_status`;
const { cert, key, timeout } = getBaseOptions();

try {
const response = await superagent
.post(url)
.key(key)
.cert(cert)
.timeout(timeout)
.send({
id: storeId,
});

const data = response.body;

// We just care that we got some response, not what the response is
if (Object.keys(data).includes('success')) {
return data;
}

return false;
} catch (error) {
logger.error(error);
return false;
}
};

export {
addMirror,
makeOffer,
Expand All @@ -737,4 +765,5 @@ export {
takeOffer,
clearPendingRoots,
getValue,
getSyncStatus,
};

0 comments on commit ea011ee

Please sign in to comment.