opportunity-service 0.0.651 → 0.0.652

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,26 +7,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Contract } from 'ethers';
10
+ import { Contract, ethers } from 'ethers';
11
11
  import opportunityService from '../../OpportunityService';
12
12
  import { Contracts } from '../../constants';
13
13
  import addressMap from '../../blockchain/addresses.json';
14
14
  import abiMap from '../../blockchain/abi.json';
15
15
  function registerNewUser() {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
- try {
18
- const msgSender = yield opportunityService.getSignersInterface()._address;
19
- console.log('Registering new user: ' + msgSender);
20
- if (typeof msgSender == 'undefined')
21
- throw new Error('Message sender is undefined');
22
- const txResult = new Contract(addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION], abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
23
- .registerNewUser({
24
- from: msgSender
25
- });
26
- }
27
- catch (error) {
28
- console.log(error);
29
- }
17
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const userRegistrationAddress = addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION];
20
+ const userRegistrationInterface = abiMap[Contracts.USER_REGISTRATION];
21
+ const msgSender = yield opportunityService.getSignersInterface()._address;
22
+ if (typeof msgSender == 'undefined')
23
+ throw new Error('Message sender is undefined');
24
+ const userRegistrationInstance = new ethers.Contract(userRegistrationAddress, userRegistrationInterface, opportunityService.getProviderInterface());
25
+ if (userRegistrationInstance.getTrueIdentification(msgSender) == '0x0000000000000000000000000000000000000000') {
26
+ console.log('Registering new user: ' + msgSender);
27
+ const tx = new Contract(addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION], abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
28
+ .registerNewUser({
29
+ from: msgSender
30
+ });
31
+ const receipt = yield tx.wait();
32
+ console.log('the receipt');
33
+ console.log(receipt);
34
+ if (Number(receipt.status) === 1) {
35
+ resolve(true);
36
+ }
37
+ else {
38
+ resolve(false);
39
+ }
40
+ }
41
+ }
42
+ catch (error) {
43
+ console.log(error);
44
+ reject('An error occurred while trying to complete the registration.');
45
+ }
46
+ }));
30
47
  });
31
48
  }
32
49
  export default registerNewUser;
@@ -1 +1 @@
1
- {"version":3,"file":"register-new-user.js","sourceRoot":"","sources":["../../../src/api/identity/register-new-user.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAe,MAAM,QAAQ,CAAC;AAC/C,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,UAAU,MAAM,iCAAiC,CAAA;AACxD,OAAO,MAAM,MAAM,2BAA2B,CAAA;AAG9C,SAAe,eAAe;;QAC1B,IAAI;YACR,MAAM,SAAS,GAAG,MAAM,kBAAkB,CAAC,mBAAmB,EAAE,CAAC,QAAQ,CAAA;YACzE,OAAO,CAAC,GAAG,CAAC,wBAAwB,GAAG,SAAS,CAAC,CAAA;YAEjD,IAAI,OAAO,SAAS,IAAI,WAAW;gBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;YAEnF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CACzB,UAAU,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAC3E,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAClC,CAAC,OAAO,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,CAAC;iBAClD,eAAe,CAAC;gBACb,IAAI,EAAE,SAAS;aAClB,CAAC,CAAA;SACD;QAAC,OAAM,KAAK,EAAE;YACX,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;SACrB;IACL,CAAC;CAAA;AAED,eAAe,eAAe,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OAAO,CAAC,kBAAkB,CAAC,mBAAmB,EAAE,CAAC;yBACrF,eAAe,CAAC;wBACb,IAAI,EAAE,SAAS;qBACtB,CAAC,CAAA;oBAEF,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,CAAA;oBAC/B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;oBAC1B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;oBAEpB,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;wBAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;qBACjB;yBAAM;wBACH,OAAO,CAAC,KAAK,CAAC,CAAA;qBACjB;iBACJ;aAGJ;YAAC,OAAM,KAAK,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBAClB,MAAM,CAAC,8DAA8D,CAAC,CAAA;aACzE;QACL,CAAC,CAAA,CAAC,CAAA;IACN,CAAC;CAAA;AAED,eAAe,eAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opportunity-service",
3
- "version": "0.0.651",
3
+ "version": "0.0.652",
4
4
  "description": "A service layer that connects all services between the blockchain and ui.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { Contract, Transaction } from 'ethers';
1
+ import { Contract, ethers, Transaction } from 'ethers';
2
2
  import opportunityService from '../../OpportunityService';
3
3
  import { Contracts } from '../../constants';
4
4
 
@@ -7,22 +7,42 @@ import abiMap from '../../blockchain/abi.json'
7
7
  import { Result } from 'ethers/lib/utils';
8
8
 
9
9
  async function registerNewUser() {
10
- try {
11
- const msgSender = await opportunityService.getSignersInterface()._address
12
- console.log('Registering new user: ' + msgSender)
13
-
14
- if (typeof msgSender == 'undefined') throw new Error('Message sender is undefined')
15
-
16
- const txResult = new Contract(
17
- addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION],
18
- abiMap[Contracts.USER_REGISTRATION]
19
- ).connect(opportunityService.getSignersInterface())
20
- .registerNewUser({
21
- from: msgSender
10
+ return new Promise(async (resolve, reject) => {
11
+ try {
12
+ const userRegistrationAddress = addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION]
13
+ const userRegistrationInterface = abiMap[Contracts.USER_REGISTRATION]
14
+ const msgSender = await opportunityService.getSignersInterface()._address
15
+
16
+ if (typeof msgSender == 'undefined') throw new Error('Message sender is undefined')
17
+
18
+ const userRegistrationInstance = new ethers.Contract(userRegistrationAddress, userRegistrationInterface, opportunityService.getProviderInterface())
19
+ if (userRegistrationInstance.getTrueIdentification(msgSender) == '0x0000000000000000000000000000000000000000')
20
+ {
21
+ console.log('Registering new user: ' + msgSender)
22
+ const tx = new Contract(
23
+ addressMap[opportunityService.getEthNetwork()][Contracts.USER_REGISTRATION],
24
+ abiMap[Contracts.USER_REGISTRATION]).connect(opportunityService.getSignersInterface())
25
+ .registerNewUser({
26
+ from: msgSender
27
+ })
28
+
29
+ const receipt = await tx.wait()
30
+ console.log('the receipt')
31
+ console.log(receipt)
32
+
33
+ if (Number(receipt.status) === 1) {
34
+ resolve(true);
35
+ } else {
36
+ resolve(false)
37
+ }
38
+ }
39
+
40
+
41
+ } catch(error) {
42
+ console.log(error)
43
+ reject('An error occurred while trying to complete the registration.')
44
+ }
22
45
  })
23
- } catch(error) {
24
- console.log(error)
25
- }
26
46
  }
27
47
 
28
48
  export default registerNewUser;