Skip to content

Commit

Permalink
Merge pull request #303 from Chia-Network/feature/unconfirmed-transac…
Browse files Browse the repository at this point in the history
…tions

feat: check for unconfirmed transactions
  • Loading branch information
MichaelTaylor3D authored Feb 15, 2022
2 parents 8eae478 + fe22990 commit 5ad42ec
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env.copy
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ DB_PASSWORD=
DB_NAME=
DB_HOST=
DATALAYER_URL=https://localhost:8562
WALLET_URL=https://localhost:9256
USE_SIMULATOR=false
PICKLIST_URL=https://climate-warehouse.s3.us-west-2.amazonaws.com/public/picklists.json
1 change: 1 addition & 0 deletions src/datalayer/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './writeService';
export * from './syncService';
export * from './wallet';
5 changes: 4 additions & 1 deletion src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export const dataLayerWasUpdated = async () => {
rootResponse = await dataLayer.getRoots(subscribedOrgIds);
}

console.log(rootResponse);

if (!rootResponse.success) {
return [];
}
Expand All @@ -125,8 +127,9 @@ export const dataLayerWasUpdated = async () => {
);

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

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/models/organizations/organizations.stub.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"isHome": false
},
{
"orgUid": "65f701dc31b4fee8246448333b3f2149039c6f6952d13f455266ce87b1c52fe9",
"orgUid": "26462fbf4a10175dbc6945dd3fda35e05da845532f585d79097e06d77ef7165e",
"name": "Kyles Org Registry",
"registryId": "f5624ed03a81d8250743f20de5cc2930b6b2b6346e39b5435bf39c0d6d1c098a",
"registryId": "eb9f9440f11f2705dd97da824f6f27079cbde3ad4ff4252539f17c8f0c08a4f9",
"icon": "https://climate-warehouse.s3.us-west-2.amazonaws.com/public/orgs/denmark.svg",
"subscribed": true,
"isHome": false
Expand Down
28 changes: 18 additions & 10 deletions src/utils/data-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';

import { Organization, Unit, Project, Staging } from '../models';
import { transformSerialNumberBlock } from '../utils/helpers';
import { dataLayerAvailable } from '../datalayer';
import { dataLayerAvailable, hasUnconfirmedTransactions } from '../datalayer';

export const assertDataLayerAvailable = async () => {
const isAvailable = await dataLayerAvailable();
Expand All @@ -15,15 +15,23 @@ export const assertDataLayerAvailable = async () => {
};

export const assetNoPendingCommits = async () => {
const pendingCommits = await Staging.findAll({
where: { commited: true },
raw: true,
});

if (pendingCommits.length > 0) {
throw new Error(
'You currently have changes pending on the blockchain. Please wait for them to propagate before making more changes',
);
if (process.env.USE_SIMULATOR === 'true') {
const pendingCommits = await Staging.findAll({
where: { commited: true },
raw: true,
});

if (pendingCommits.length > 0) {
throw new Error(
'You currently have changes pending on the blockchain. Please wait for them to propagate before making more changes',
);
}
} else {
if (await hasUnconfirmedTransactions()) {
throw new Error(
'You currently have changes pending on the blockchain. Please wait for them to propagate before making more changes',
);
}
}
};

Expand Down

0 comments on commit 5ad42ec

Please sign in to comment.