Skip to content

Commit 229e68b

Browse files
authored
feat: new demand creation view and asset types integration (#14)
- Redesign demand creation UI - Use formik, formik-material-ui, yup for composing forms with validation - Use react-select for autocomplete multi-select component - Backend for storing and matching multiple asset types from IREC registry - `build:ts` for fast compile for the whole project - standardized `id` type as "numeric" string
1 parent 28af5a9 commit 229e68b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1985
-1740
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"clean": "lerna run clean --parallel",
3131
"build:user-asset-registry-origin": "lerna run build --scope @energyweb/user-registry build --scope @energyweb/asset-registry build --scope @energyweb/origin --parallel",
3232
"build:static": "lerna run build:static --parallel",
33+
"build:ts": "lerna run build-ts --stream",
3334
"run:demo": "lerna run start --scope @energyweb/utils-demo --stream",
3435
"run:backend": "lerna run start --scope @energyweb/utils-testbackend --stream",
3536
"run:ui": "lerna run start --scope @energyweb/origin-ui --stream",

packages/asset-registry/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"scripts": {
2727
"build": "yarn compile && yarn build-schemas && yarn build-ts",
28-
"build-and-deploy": "npm run build && npm run deploy-contracts",
28+
"build-and-deploy": "yarn build && yarn deploy-contracts",
2929
"build-schema:AssetPropertiesOffChain": "typescript-json-schema --ignoreErrors --required src/blockchain-facade/Asset.ts IOffChainProperties",
3030
"build-schema:ProducingAssetPropertiesOffChain": "typescript-json-schema --ignoreErrors --required src/blockchain-facade/ProducingAsset.ts IOffChainProperties",
3131
"build-schemas": "./scripts/buildSchemas.js",

packages/asset-registry/src/blockchain-facade/ProducingAsset.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,22 @@
1313
// GNU General Public License for more details, at <http://www.gnu.org/licenses/>.
1414
//
1515
// @authors: slock.it GmbH; Heiko Burkhardt, heiko.burkhardt@slock.it; Martin Kuechler, martin.kuchler@slock.it
16+
import { Compliance, Configuration } from '@energyweb/utils-general';
17+
import moment from 'moment';
18+
import { TransactionReceipt } from 'web3/types';
1619

17-
import { Configuration } from '@energyweb/utils-general';
18-
import * as Asset from './Asset';
1920
import { ProducingAssetPropertiesOffchainSchema } from '..';
20-
import { TransactionReceipt } from 'web3/types';
21-
import moment from 'moment';
2221
import { AssetProducingRegistryLogic } from '../wrappedContracts/AssetProducingRegistryLogic';
22+
import * as Asset from './Asset';
2323

24-
/**
25-
* TODO: in generalLib
26-
*/
27-
export enum Type {
28-
Wind,
29-
Solar,
30-
RunRiverHydro,
31-
BiomassGas
32-
}
3324

34-
export enum Compliance {
35-
none,
36-
IREC,
37-
EEC,
38-
TIGR
39-
}
4025

4126
export interface IOnChainProperties extends Asset.IOnChainProperties {
4227
maxOwnerChanges?: number;
4328
}
4429

4530
export interface IOffChainProperties extends Asset.IOffChainProperties {
46-
assetType: Type;
31+
assetType: string;
4732
complianceRegistry: Compliance;
4833
otherGreenAttributes: string;
4934
typeOfPublicSupport: string;

packages/asset-registry/src/test/AssetProducingFacade.ts

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
1-
// Copyright 2018 Energy Web Foundation
2-
// This file is part of the Origin Application brought to you by the Energy Web Foundation,
3-
// a global non-profit organization focused on accelerating blockchain technology across the energy sector,
4-
// incorporated in Zug, Switzerland.
5-
//
6-
// The Origin Application is free software: you can redistribute it and/or modify
7-
// it under the terms of the GNU General Public License as published by
8-
// the Free Software Foundation, either version 3 of the License, or
9-
// (at your option) any later version.
10-
// This is distributed in the hope that it will be useful,
11-
// but WITHOUT ANY WARRANTY and without an implied warranty of
12-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
// GNU General Public License for more details, at <http://www.gnu.org/licenses/>.
14-
//
15-
// @authors: slock.it GmbH; Heiko Burkhardt, heiko.burkhardt@slock.it; Martin Kuechler, martin.kuchler@slock.it
16-
17-
import { assert } from 'chai';
18-
import * as fs from 'fs';
19-
import Web3 from 'web3';
201
import 'mocha';
21-
import { Configuration } from '@energyweb/utils-general';
22-
import { logger } from '../Logger';
2+
233
import {
24-
UserContractLookup,
25-
UserLogic,
26-
migrateUserRegistryContracts,
274
buildRights,
28-
Role
5+
migrateUserRegistryContracts,
6+
Role,
7+
UserContractLookup,
8+
UserLogic
299
} from '@energyweb/user-registry';
30-
import { migrateAssetRegistryContracts, AssetProducingRegistryLogic } from '..';
31-
import { ProducingAsset } from '..';
10+
import { Configuration, Compliance } from '@energyweb/utils-general';
11+
import { assert } from 'chai';
12+
import * as fs from 'fs';
3213
import moment from 'moment';
14+
import Web3 from 'web3';
15+
16+
import { AssetProducingRegistryLogic, migrateAssetRegistryContracts, ProducingAsset } from '..';
17+
import { logger } from '../Logger';
3318

3419
describe('AssetProducing Facade', () => {
3520
const configFile = JSON.parse(
@@ -50,13 +35,6 @@ describe('AssetProducing Facade', () => {
5035
let assetProducingLogic: AssetProducingRegistryLogic;
5136
let userLogic: UserLogic;
5237

53-
/*
54-
let assetContractLookup: AssetContractLookup;
55-
let assetProducingLogic: AssetProducingRegistryLogic;
56-
let assetProducingDB: AssetProducingDB;
57-
let assetConsumingDB: AssetConsumingDB;
58-
*/
59-
6038
const assetOwnerPK = '0xfaab95e72c3ac39f7c060125d9eca3558758bb248d1a4cdc9c1b7fd3f91a4485';
6139
const assetOwnerAddress = web3.eth.accounts.privateKeyToAccount(assetOwnerPK).address;
6240

@@ -162,8 +140,8 @@ describe('AssetProducing Facade', () => {
162140
houseNumber: '42',
163141
gpsLatitude: '0.0123123',
164142
gpsLongitude: '31.1231',
165-
assetType: ProducingAsset.Type.Wind,
166-
complianceRegistry: ProducingAsset.Compliance.EEC,
143+
assetType: 'Wind',
144+
complianceRegistry: Compliance.EEC,
167145
otherGreenAttributes: '',
168146
typeOfPublicSupport: '',
169147
facilityName: FACILITY_NAME
@@ -219,8 +197,8 @@ describe('AssetProducing Facade', () => {
219197
houseNumber: '42',
220198
gpsLatitude: '0.0123123',
221199
gpsLongitude: '31.1231',
222-
assetType: ProducingAsset.Type.Wind,
223-
complianceRegistry: ProducingAsset.Compliance.EEC,
200+
assetType: 'Wind',
201+
complianceRegistry: Compliance.EEC,
224202
otherGreenAttributes: '',
225203
typeOfPublicSupport: '',
226204
facilityName: 'Wuthering Heights Windfarm'
@@ -229,14 +207,14 @@ describe('AssetProducing Facade', () => {
229207
assert.equal(await ProducingAsset.getAssetListLength(conf), 1);
230208

231209
try {
232-
const asset = await ProducingAsset.createAsset(assetProps, assetPropsOffChain, conf);
210+
await ProducingAsset.createAsset(assetProps, assetPropsOffChain, conf);
233211
} catch (ex) {
234212
assert.include(ex.message, 'smartmeter does already exist');
235213
}
236214
assert.equal(await ProducingAsset.getAssetListLength(conf), 1);
237215
});
238216

239-
it('should log a new meterreading', async () => {
217+
it('should log a new meter reading', async () => {
240218
conf.blockchainProperties.activeUser = {
241219
address: assetSmartmeter,
242220
privateKey: assetSmartmeterPK
@@ -274,8 +252,8 @@ describe('AssetProducing Facade', () => {
274252
houseNumber: '42',
275253
gpsLatitude: '0.0123123',
276254
gpsLongitude: '31.1231',
277-
assetType: 0,
278-
complianceRegistry: 2,
255+
assetType: 'Wind',
256+
complianceRegistry: Compliance.EEC,
279257
otherGreenAttributes: '',
280258
typeOfPublicSupport: '',
281259
facilityName: 'Wuthering Heights Windfarm'
@@ -285,8 +263,7 @@ describe('AssetProducing Facade', () => {
285263

286264
describe('getSmartMeterReads', () => {
287265
it('should correctly return reads', async () => {
288-
let asset = await new ProducingAsset.Entity('0', conf).sync();
289-
266+
const asset = await new ProducingAsset.Entity('0', conf).sync();
290267
const reads = await asset.getSmartMeterReads();
291268

292269
assert.deepEqual(reads, [

packages/asset-registry/src/test/AssetProducingLogic.ts

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,33 @@
1313
// GNU General Public License for more details, at <http://www.gnu.org/licenses/>.
1414
//
1515
// @authors: slock.it GmbH; Martin Kuechler, martin.kuchler@slock.it; Heiko Burkhardt, heiko.burkhardt@slock.it
16-
17-
import { assert } from 'chai';
18-
import * as fs from 'fs';
1916
import 'mocha';
20-
import Web3 from 'web3';
17+
2118
import {
22-
UserContractLookup,
23-
UserLogic,
24-
migrateUserRegistryContracts,
2519
buildRights,
26-
Role
20+
migrateUserRegistryContracts,
21+
Role,
22+
UserContractLookup,
23+
UserLogic
2724
} from '@energyweb/user-registry';
28-
import { migrateAssetRegistryContracts } from '../utils/migrateContracts';
29-
import { AssetContractLookup } from '../wrappedContracts/AssetContractLookup';
30-
import { AssetConsumingRegistryLogic } from '../wrappedContracts/AssetConsumingRegistryLogic';
31-
import { AssetProducingRegistryLogic } from '../wrappedContracts/AssetProducingRegistryLogic';
32-
import { AssetConsumingDB } from '../wrappedContracts/AssetConsumingDB';
33-
import { AssetProducingDB } from '../wrappedContracts/AssetProducingDB';
25+
import { assert } from 'chai';
26+
import * as fs from 'fs';
27+
import moment from 'moment';
28+
import Web3 from 'web3';
29+
3430
import {
35-
AssetContractLookupJSON,
3631
AssetConsumingDBJSON,
3732
AssetConsumingRegistryLogicJSON,
33+
AssetContractLookupJSON,
3834
AssetProducingDBJSON,
3935
AssetProducingRegistryLogicJSON
4036
} from '..';
41-
import moment from 'moment';
37+
import { migrateAssetRegistryContracts } from '../utils/migrateContracts';
38+
import { AssetConsumingDB } from '../wrappedContracts/AssetConsumingDB';
39+
import { AssetConsumingRegistryLogic } from '../wrappedContracts/AssetConsumingRegistryLogic';
40+
import { AssetContractLookup } from '../wrappedContracts/AssetContractLookup';
41+
import { AssetProducingDB } from '../wrappedContracts/AssetProducingDB';
42+
import { AssetProducingRegistryLogic } from '../wrappedContracts/AssetProducingRegistryLogic';
4243

4344
describe('AssetProducingLogic', () => {
4445
const configFile = JSON.parse(
@@ -139,8 +140,6 @@ describe('AssetProducingLogic', () => {
139140

140141
const deployedBytecode = await web3.eth.getCode(deployedContracts[key]);
141142
assert.isTrue(deployedBytecode.length > 0);
142-
143-
// const tempBytecode = contractInfo.deployedBytecode;
144143
assert.equal(deployedBytecode, tempBytecode);
145144
});
146145
});
@@ -210,10 +209,6 @@ describe('AssetProducingLogic', () => {
210209
});
211210

212211
it('should onboard tests-users', async () => {
213-
const userLogicAddress = await userContractLookup.userRegistry();
214-
215-
// userLogic = new UserLogic(web3, userLogicAddress);
216-
217212
await userLogic.createUser(
218213
'propertiesDocumentHash',
219214
'documentDBURL',
@@ -230,34 +225,10 @@ describe('AssetProducingLogic', () => {
230225
);
231226
});
232227

233-
it('should not deploy an asset as user', async () => {
234-
let failed = false;
235-
try {
236-
await assetProducingLogic.createAsset(
237-
assetSmartmeter,
238-
assetOwnerAddress,
239-
true,
240-
[matcher] as any,
241-
'propertiesDocumentHash',
242-
'url',
243-
2,
244-
{
245-
privateKey: '0x191c4b074672d9eda0ce576cfac79e44e320ffef5e3aadd55e000de57341d36c'
246-
}
247-
);
248-
} catch (ex) {
249-
failed = true;
250-
assert.include(ex.message, 'user does not have the required role');
251-
}
252-
assert.isTrue(failed);
253-
});
254-
255228
it('should return empty asset when smart meter is not onboarded yet', async () => {
256229
const deployedAsset = await assetProducingLogic.getAssetBySmartMeter(assetSmartmeter);
257230

258-
// all the properties are in 1 struct
259231
assert.equal(deployedAsset.length, 2);
260-
// checking the number of properties in assetGeneral
261232
assert.equal(deployedAsset.assetGeneral.length, 10);
262233

263234
const ag = deployedAsset.assetGeneral;
@@ -274,7 +245,7 @@ describe('AssetProducingLogic', () => {
274245
assert.isFalse(ag.bundled);
275246
});
276247

277-
it('should throw when trying to access a non exsting AssetGeneral-Struct', async () => {
248+
it('should throw when trying to access a non existing AssetGeneral-Struct', async () => {
278249
let failed = false;
279250
try {
280251
await assetProducingLogic.getAssetGeneral(0);
@@ -340,7 +311,7 @@ describe('AssetProducingLogic', () => {
340311
assert.isFalse(ag.bundled);
341312
});
342313

343-
it('should return asset by smartmeter correctly', async () => {
314+
it('should return asset by smart meter correctly', async () => {
344315
const deployedAsset = await assetProducingLogic.getAssetBySmartMeter(assetSmartmeter);
345316

346317
assert.equal(deployedAsset.length, 2);
@@ -377,7 +348,7 @@ describe('AssetProducingLogic', () => {
377348
assert.isFalse(ag.bundled);
378349
});
379350

380-
it('should fail when trying to log with saveSmartMeterRead using the wrong smartmeter', async () => {
351+
it('should fail when trying to log with saveSmartMeterRead using the wrong smart meter', async () => {
381352
let failed = false;
382353

383354
try {
@@ -421,7 +392,7 @@ describe('AssetProducingLogic', () => {
421392
});
422393
});
423394

424-
it('should fail when trying to log with saveSmartMeterRead and a too low meterreading', async () => {
395+
it('should fail when trying to log with saveSmartMeterRead and a too low meter reading', async () => {
425396
let failed = false;
426397

427398
try {
@@ -466,7 +437,7 @@ describe('AssetProducingLogic', () => {
466437
});
467438
});
468439

469-
it('should fail when trying to deactive an asset as non-manager', async () => {
440+
it('should fail when trying to deactivate an asset as non-manager', async () => {
470441
let failed = false;
471442

472443
try {
@@ -481,7 +452,7 @@ describe('AssetProducingLogic', () => {
481452
assert.isTrue(failed);
482453
});
483454

484-
it('should be able to deactive an asset', async () => {
455+
it('should be able to deactivate an asset', async () => {
485456
const tx = await assetProducingLogic.setActive(0, false, {
486457
privateKey: privateKeyDeployment
487458
});
@@ -535,7 +506,7 @@ describe('AssetProducingLogic', () => {
535506
assert.isTrue(failed);
536507
});
537508

538-
it('should be able to deactive an asset', async () => {
509+
it('should be able to deactivate an asset', async () => {
539510
const tx = await assetProducingLogic.setActive(0, true, {
540511
privateKey: privateKeyDeployment
541512
});
@@ -1183,7 +1154,7 @@ describe('AssetProducingLogic', () => {
11831154
assert.isTrue(ag.bundled);
11841155
});
11851156

1186-
it('should return the correct latest hashes + meterreadings', async () => {
1157+
it('should return the correct latest hashes + meter readings', async () => {
11871158
assert.deepEqual(await assetProducingLogic.getLastMeterReadingAndHash(0), {
11881159
0: '200',
11891160
1: 'lastSmartMeterReadFileHash#2',
@@ -1198,7 +1169,7 @@ describe('AssetProducingLogic', () => {
11981169
_lastSmartMeterReadFileHash: ''
11991170
});
12001171

1201-
it('should fail when trying to return latest hash + meterreading of a non existing asset', async () => {
1172+
it('should fail when trying to return latest hash + meter reading of a non existing asset', async () => {
12021173
let failed = false;
12031174

12041175
try {

packages/event-listener/test/helpers/deployDemo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AssetConsumingRegistryLogic, AssetProducingRegistryLogic, migrateAssetR
66
import { MarketLogic, migrateMarketRegistryContracts } from '@energyweb/market';
77
import { CertificateLogic, migrateCertificateRegistryContracts } from '@energyweb/origin';
88
import { buildRights, migrateUserRegistryContracts, Role, User, UserLogic } from '@energyweb/user-registry';
9-
import { Configuration } from '@energyweb/utils-general';
9+
import { Configuration, Compliance } from '@energyweb/utils-general';
1010

1111
export const deployDemo = async () => {
1212
const connectionConfig = {
@@ -166,8 +166,8 @@ export const deployDemo = async () => {
166166
};
167167

168168
const assetProducingPropsOffChain: ProducingAsset.IOffChainProperties = {
169-
assetType: ProducingAsset.Type.Wind,
170-
complianceRegistry: ProducingAsset.Compliance.IREC,
169+
assetType: 'Wind',
170+
complianceRegistry: Compliance.IREC,
171171
facilityName: 'Wuthering Heights Windfarm',
172172
capacityWh: 0,
173173
city: 'Warsaw',

packages/market-matcher/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ A matcher automates buying and selling certificates on the Origin platform.
77
Update the config file in [example-conf/production-conf.json](example-conf/production-conf.json)
88
- Make sure that `marketContractLookupAddress` and `originContractLookupAddress` match your deployed Origin contracts
99

10-
### Install
11-
Install the dependencies for the Matcher.
12-
- `npm install`
13-
1410
### Run
1511
- `npm start example-conf/production-conf.json`

0 commit comments

Comments
 (0)