diff --git a/src/app/_services/auth.service.ts b/src/app/_services/auth.service.ts index 6b47210..c27074d 100644 --- a/src/app/_services/auth.service.ts +++ b/src/app/_services/auth.service.ts @@ -3,7 +3,8 @@ import {MutableKeyStore, MutablePgpKeyStore} from '@app/_helpers'; import { hobaParseChallengeHeader } from '@src/assets/js/hoba.js'; import { signChallenge } from '@src/assets/js/hoba-pgp.js'; import {environment} from '@src/environments/environment'; -import {HttpClient} from '@angular/common/http'; +import {LoggingService} from '@app/_services/logging.service'; +import {HttpWrapperService} from '@app/_services/http-wrapper.service'; @Injectable({ providedIn: 'root' @@ -15,7 +16,8 @@ export class AuthService { mutableKeyStore: MutableKeyStore = new MutablePgpKeyStore(); constructor( - private http: HttpClient + private httpWrapperService: HttpWrapperService, + private loggingService: LoggingService ) { if (sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN'))) { this.sessionToken = sessionStorage.getItem(btoa('CICADA_SESSION_TOKEN')); @@ -88,14 +90,14 @@ export class AuthService { this.getWithToken(); return true; } catch (e) { - console.error('login token failed', e); + this.loggingService.sendErrorLevelMessage('Login token failed', this, {error: e}); } } else { try { const o = this.getChallenge(); return true; } catch (e) { - console.error('login challenge failed', e); + this.loggingService.sendErrorLevelMessage('Login challenge failed', this, {error: e}); } } return false; @@ -118,7 +120,7 @@ export class AuthService { await this.mutableKeyStore.importPrivateKey(privateKeyArmored); localStorage.setItem(btoa('CICADA_PRIVATE_KEY'), privateKeyArmored); } catch (e) { - console.error('failed setting key', e); + this.loggingService.sendErrorLevelMessage('Failed setting key', this, {error: e}); return false; } this.loginView(); @@ -131,11 +133,165 @@ export class AuthService { } async getPublicKeys(): Promise { - this.http.get(`${environment.publicKeysUrl}/keys.asc`).subscribe(async res => { - await this.mutableKeyStore.importPublicKey(res); - }, error => { - console.error('There was an error!', error); - }); + // this.httpWrapperService.get(`${environment.publicKeysUrl}/keys.asc`).pipe(first()).subscribe(async res => { + // await this.mutableKeyStore.importPublicKey(res.body); + // }, error => { + // this.loggingService.sendErrorLevelMessage('There was an error!', this, {error}); + // }); + const armoredPublicKeys = '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' + + '\n' + + 'mQGNBF+hSOgBDACpkPQEjADjnQtjmAsdPYpx5N+OMJBYj1DAoIYsDtV6vbcBJQt9\n' + + '4Om3xl7RBhv9m2oLgzPsiRwjCEFRWyNSu0BUp5CFjcXfm0S4K2egx4erFnTnSSC9\n' + + 'S6tmVNrVNEXvScE6sKAnmJ7JNX1ExJuEiWPbUDRWJ1hoI9+AR+8EONeJRLo/j0Np\n' + + '+S4IFDn0PsxdT+SB0GY0z2cEgjvjoPr4lW9IAb8Ft9TDYp+mOzejn1Fg7CuIrlBR\n' + + 'SAv+sj7bVQw15dh1SpbwtS5xxubCa8ExEGI4ByXmeXdR0KZJ+EA5ksO0iSsQ/6ip\n' + + 'SOdSg+i0niOClFNm1P/OhbUsYAxCUfiX654FMn2zoxVBEjJ3e7l0pH7ktodaxEct\n' + + 'PofQLBA9LSDUIejqJsU0npw/DHDD2uvxG+/A6lgV9L8ETlvgp8RzeOCf2bHuiKYY\n' + + 'z87txvkFwsXgU1+TZxbk+mtCBbngsVPLNarY/KGkVJL+yhcHRD0Pl4wXUd6auQuY\n' + + '6vQ9AuKiCT1We2sAEQEAAbQeTWVyIE1hbiA8bWVybWFuQGdyZXlza3VsbC5jb20+\n' + + 'iQHUBBMBCAA+FiEE8/r2aOgu9RJNUYe67yb0aCND9pIFAl+hSOgCGwMFCQPCZwAF\n' + + 'CwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQ7yb0aCND9pLwiwwAhFJbAyUK05TJ\n' + + 'KfDz81757N472STtB8sfr0auwmRr8Zs1utHRVM0b/jkjTuo4uJNr7YVVKTKgE7+r\n' + + 'J+pwhm3wlTQ44LVLjByWAi/7NWg3E9b2elm+qkfgm/RfFt3vkuOxGSyZyIFFh+/t\n' + + 'wv6iABPvr6w7MZwrFaS0UP3g1VGa5TFqg6KNxod9H/gPLxv45lutXf3VvBZT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ZBQIzTdEXIaEwhVosbgY7A1iwOJ/gT2dcF2KJa7tygrtcbgdVzYCibynw\n' + + 'tlvDGXukweuYLQFsObyBG3UHRhJg61p7n344sy1U9uwCP3/pVCr9bNY9mLZpCgHF\n' + + 'kqxErmB8cWouQkbwnqxQFm21KtGFzjUawuKBXVtDEeA8C5Ha0sx7lw5JrX8GD3EL\n' + + '60qKWjqujJsR1kyijXx1No7Xr9NWWuPoIDYH06ZoYE+j065VTRqZIGr3NjUZnqT7\n' + + 's9M41roQMnKAzRBXousRXRW9dXfS5YIG4nWTlwARAQABiQG8BBgBCAAmFiEE9kXg\n' + + 'R+5bxOKCTJTbQtyRz6iroCsFAl+hSRoCGwwFCQPCZwAACgkQQtyRz6iroCt8igwA\n' + + 'gopqy+UgxJ7oTL2zvOgL1ez7bv+E/U1/7Rdy5MHwr4WF6oZRpIBlgv3GXXeIFH9b\n' + + 'FdDhgyPKgh+Tz24JBL+7YjUtWGe/G/pmmNK1YazB/OxrwiGFpTCyk1zhxEkhMu7H\n' + + 'u3LgD571K+4TUUpaPCqEeoBBg6O3T29DH1AxpWpEPGXlOrRDHYgVziEpLdUNahAj\n' + + 'F53auNWvya+Vc2qZwM4NFt608LLf7J5yIA2vbsvf6+gVopPE3whXESKXo08B2hC1\n' + + 'f3Pr9/Tgt6oIvy9/dAcTMalxRyyc42E2wX5kyzDlfhY9kqaNNfaGMZJO5g//gB7B\n' + + 'dtrAfo/LhWtary/YfAOtbbnMYkf+HODAPZItaIjMZngBM0c0m78YoCetAQE8uBFK\n' + + '6aXmht3BZGPOwgyZpK5QT6ClYst2N9ca3tPUEfnddotKySmCEk/JWtu5/0lFl75W\n' + + 'zHulc7iUNGJmnUffVZyH12CjBWsTtqombHDkdEKFocavqpVcCCbKbtW5GZhuZC65\n' + + 'mQGNBF+hSUIBDADStlWquV7SdREZtxXBVVzdCkV1xkeHYfo2Z244W0LTwmvpbO+o\n' + + '6P5GCAW2c336qWElsMO9ujeV2nuUZy3k3AtJLx19i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VUnwJJAg8pMLo+QzhTAd3PyPdIkc3yVQQuCycU9El7ysKhmiS\n' + + 'AgqZjqrtPnU4y7SY1II1y/XDFDIuw2MggdolNahzx5VTKrNm5LYUT0m5XQmCehtJ\n' + + 'ABEBAAGJAbwEGAEIACYWIQTFMBghgDfv6cesuTGwIKs7vZC0mAUCX6UhqgIbDAUJ\n' + + 'A8JnAAAKCRCwIKs7vZC0mI4eC/0cMG9+fZfyq8V7wB47L/qmfS0O+bSE4AlZjtoa\n' + + '30UqbW8Yp2oa1uZXaF8loC3RW9d7VdnSh6K5vSnHh/0+OkwqAbpYDaF6Kuk/zVHX\n' + + 'r4vQ1FaE1uzZisaqEORW/LG+oWiOFDhF7lXGVKj7iXwfFVVudDxHLHj34dC9rrsm\n' + + '5cTNdHalP0OW00H17nM/R4CR62mkhIM7zUuA1Z8MxSa8I3A9SL35G9iaWRYXE892\n' + + 'KcPYSAgLna7rW+gHD1QI0sqsR6qdaojO5BDVrEYnP58D5aCOTeZ50ACO43JaZlYm\n' + + 'o3jdqBvvYKpYuJ2is1T3unnrY6ztblz78OE+37d9gyAp1j0dhIzOfdpSHCyUYUQL\n' + + '4YNGLs/3yfelr1XXLwYXzKlioNDu7k4rggwN3td1122p3U1vfVY4qb2eTyjDPizb\n' + + 'NdtbiWRXKFibzG0OoiAaq0ZC8nZsP6xy7vmI05hN7PocAWllJVdpaXVh75OViGaj\n' + + 'KuNFGWsKI1qTd1aEMRQzT4s+JJM=\n' + + '=8257\n' + + '-----END PGP PUBLIC KEY BLOCK-----\n'; + await this.mutableKeyStore.loadKeyring(); + await this.mutableKeyStore.importPublicKey(armoredPublicKeys); + this.loggingService.sendInfoLevelMessage(this.mutableKeyStore.getPublicKeys()); if (this.privateKey !== undefined) { await this.mutableKeyStore.importPrivateKey(this.privateKey); } diff --git a/src/app/_services/block-sync.service.ts b/src/app/_services/block-sync.service.ts index 3401253..f6637a5 100644 --- a/src/app/_services/block-sync.service.ts +++ b/src/app/_services/block-sync.service.ts @@ -6,6 +6,7 @@ import {first} from 'rxjs/operators'; import {TransactionService} from '@app/_services/transaction.service'; import {environment} from '@src/environments/environment'; import {HttpGetter} from '@app/_helpers'; +import {LoggingService} from '@app/_services/logging.service'; @Injectable({ providedIn: 'root' @@ -15,7 +16,10 @@ export class BlockSyncService { readyState: number = 0; fileGetter = new HttpGetter(); - constructor(private transactionService: TransactionService) { } + constructor( + private transactionService: TransactionService, + private loggingService: LoggingService + ) { } blockSync(): any { const settings = new Settings(this.scan); @@ -35,7 +39,7 @@ export class BlockSyncService { window.dispatchEvent(this.newConversionEvent(transaction)); }; settings.registry.onload = (addressReturned: number): void => { - console.log('loaded network contracts', addressReturned); + this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`); this.readyStateProcessor(settings, readyStateElements.network); }; @@ -45,7 +49,6 @@ export class BlockSyncService { readyStateProcessor(settings, bit): void { this.readyState |= bit; if (this.readyStateTarget === this.readyState && this.readyStateTarget) { - // console.log('reached readyState target', this.readyStateTarget); const wHeadSync = new Worker('./../assets/js/block-sync/head.js'); wHeadSync.onmessage = (m) => { settings.txHelper.processReceipt(m.data); @@ -91,22 +94,16 @@ export class BlockSyncService { } fetcher(settings: any, offset: number = 0, limit: number = 100): void { - this.transactionService.getAllTransactions(offset, limit).pipe(first()).subscribe(data => { - const blockFilterBinstr = window.atob(data.block_filter); + this.transactionService.getAllTransactions(offset, limit).pipe(first()).subscribe(res => { + const blockFilterBinstr = window.atob(res.body.block_filter); const bOne = new Uint8Array(blockFilterBinstr.length); bOne.map((e, i, v) => v[i] = blockFilterBinstr.charCodeAt(i)); - const blocktxFilterBinstr = window.atob(data.blocktx_filter); + const blocktxFilterBinstr = window.atob(res.body.blocktx_filter); const bTwo = new Uint8Array(blocktxFilterBinstr.length); bTwo.map((e, i, v) => v[i] = blocktxFilterBinstr.charCodeAt(i)); - for (let i = 0; i < blockFilterBinstr.length; i++) { - if (bOne[i] > 0 ) { - // console.debug('blocktx value on', i); - } - } - - settings.scanFilter(settings, data.low, data.high, bOne, bTwo, data.filter_rounds); + settings.scanFilter(settings, res.body.low, res.body.high, bOne, bTwo, res.body.filter_rounds); }); } } diff --git a/src/app/_services/index.ts b/src/app/_services/index.ts index 75a40af..a8a1b33 100644 --- a/src/app/_services/index.ts +++ b/src/app/_services/index.ts @@ -4,3 +4,5 @@ export * from '@app/_services/user.service'; export * from '@app/_services/token.service'; export * from '@app/_services/block-sync.service'; export * from '@app/_services/location.service'; +export * from '@app/_services/logging.service'; +export * from '@app/_services/http-wrapper.service'; diff --git a/src/app/_services/location.service.ts b/src/app/_services/location.service.ts index 343999c..9491332 100644 --- a/src/app/_services/location.service.ts +++ b/src/app/_services/location.service.ts @@ -1,8 +1,8 @@ import { Injectable } from '@angular/core'; import {BehaviorSubject} from 'rxjs'; -import {HttpClient} from '@angular/common/http'; import {environment} from '@src/environments/environment'; import {first} from 'rxjs/operators'; +import {HttpWrapperService} from '@app/_services/'; @Injectable({ providedIn: 'root' @@ -13,10 +13,10 @@ export class LocationService { locationsSubject = this.locationsList.asObservable(); constructor( - private http: HttpClient + private httpWrapperService: HttpWrapperService, ) { } getLocations(): void { - this.http.get(`${environment.cicCacheUrl}/locations`).pipe(first()).subscribe(locations => this.locationsList.next(locations)); + this.httpWrapperService.get(`${environment.cicCacheUrl}/locations`).pipe(first()).subscribe(res => this.locationsList.next(res.body)); } } diff --git a/src/app/_services/token.service.ts b/src/app/_services/token.service.ts index 014e4a3..b3e0934 100644 --- a/src/app/_services/token.service.ts +++ b/src/app/_services/token.service.ts @@ -1,11 +1,10 @@ import { Injectable } from '@angular/core'; -import {HttpClient} from '@angular/common/http'; import {environment} from '@src/environments/environment'; -import {first} from 'rxjs/operators'; -import {BehaviorSubject} from 'rxjs'; +import {BehaviorSubject, Observable} from 'rxjs'; import {HttpGetter, Registry, TokenRegistry} from '@app/_helpers'; import {CICRegistry} from 'cic-client'; import Web3 from 'web3'; +import {HttpWrapperService} from '@app/_services/http-wrapper.service'; @Injectable({ providedIn: 'root' @@ -20,7 +19,7 @@ export class TokenService { tokensSubject = this.tokensList.asObservable(); constructor( - private http: HttpClient + private httpWrapperService: HttpWrapperService, ) { } async getTokens(): Promise { @@ -29,8 +28,8 @@ export class TokenService { return Array.from({length: count}, async (v, i) => await tokenRegistryQuery.entry(i)); } - getTokenBySymbol(symbol: string): any { - return this.http.get(`${environment.cicCacheUrl}/tokens/${symbol}`); + getTokenBySymbol(symbol: string): Observable { + return this.httpWrapperService.get(`${environment.cicCacheUrl}/tokens/${symbol}`); } async getTokenBalance(address: string): Promise { diff --git a/src/app/_services/transaction.service.ts b/src/app/_services/transaction.service.ts index 9d06493..590f979 100644 --- a/src/app/_services/transaction.service.ts +++ b/src/app/_services/transaction.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; -import {HttpClient} from '@angular/common/http'; -import {first, map} from 'rxjs/operators'; +import {first} from 'rxjs/operators'; import {BehaviorSubject, Observable} from 'rxjs'; import {environment} from '@src/environments/environment'; import {Envelope, User} from 'cic-client-meta'; @@ -14,6 +13,8 @@ import * as secp256k1 from 'secp256k1'; import {AuthService} from '@app/_services/auth.service'; import {Registry} from '@app/_helpers'; import {defaultAccount} from '@app/_models'; +import {LoggingService} from '@app/_services/logging.service'; +import {HttpWrapperService} from '@app/_services/http-wrapper.service'; const Web3 = require('web3'); const vCard = require('vcard-parser'); @@ -29,23 +30,18 @@ export class TransactionService { registry = new Registry(environment.registryAddress); constructor( - private http: HttpClient, + private httpWrapperService: HttpWrapperService, private authService: AuthService, - private userService: UserService + private userService: UserService, + private loggingService: LoggingService ) { } getAllTransactions(offset: number, limit: number): Observable { - return this.http.get(`${environment.cicCacheUrl}/tx/${offset}/${limit}`) - .pipe(map(response => { - return response; - })); + return this.httpWrapperService.get(`${environment.cicCacheUrl}/tx/${offset}/${limit}`); } getAddressTransactions(address: string, offset: number, limit: number): Observable { - return this.http.get(`${environment.cicCacheUrl}/tx/${address}/${offset}/${limit}`) - .pipe(map(response => { - return response; - })); + return this.httpWrapperService.get(`${environment.cicCacheUrl}/tx/${address}/${offset}/${limit}`); } async setTransaction(transaction, cacheSize: number): Promise { @@ -54,12 +50,12 @@ export class TransactionService { if (this.transactions.find(cachedTx => cachedTx.tx.txHash === transaction.tx.txHash)) { return; } try { this.userService.getAccountDetailsFromMeta(await User.toKey(transaction.from)).pipe(first()).subscribe(async (res) => { - transaction.sender = this.getAccountInfo(res); + transaction.sender = this.getAccountInfo(res.body); }, error => { transaction.sender = defaultAccount; }); this.userService.getAccountDetailsFromMeta(await User.toKey(transaction.to)).pipe(first()).subscribe(async (res) => { - transaction.recipient = this.getAccountInfo(res); + transaction.recipient = this.getAccountInfo(res.body); }, error => { transaction.recipient = defaultAccount; }); @@ -75,7 +71,7 @@ export class TransactionService { conversion.toValue = Number(conversion.toValue); try { this.userService.getAccountDetailsFromMeta(await User.toKey(conversion.trader)).pipe(first()).subscribe(async (res) => { - conversion.sender = conversion.recipient = this.getAccountInfo(res); + conversion.sender = conversion.recipient = this.getAccountInfo(res.body); }, error => { conversion.sender = conversion.recipient = defaultAccount; }); @@ -127,8 +123,8 @@ export class TransactionService { tx.setSignature(r, s, v); const txWire = add0x(toHex(tx.serializeRLP())); const result = await this.web3.eth.sendSignedTransaction(txWire); - console.log('Result', result); + this.loggingService.sendInfoLevelMessage(`Result: ${result}`); const transaction = await this.web3.eth.getTransaction(result.transactionHash); - console.log('Transaction', transaction); + this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`); } } diff --git a/src/app/_services/user.service.ts b/src/app/_services/user.service.ts index 1048347..3407f9c 100644 --- a/src/app/_services/user.service.ts +++ b/src/app/_services/user.service.ts @@ -5,6 +5,9 @@ import {environment} from '@src/environments/environment'; import {first} from 'rxjs/operators'; import {AccountIndex, MutableKeyStore, MutablePgpKeyStore, PGPSigner, Registry, Signer} from '@app/_helpers'; import {ArgPair, Envelope, Syncable, User} from 'cic-client-meta'; +import {MetaResponse} from '@app/_models'; +import {LoggingService} from '@app/_services/logging.service'; +import {HttpWrapperService} from '@app/_services/http-wrapper.service'; const vCard = require('vcard-parser'); @Injectable({ @@ -29,45 +32,57 @@ export class UserService { private staffList = new BehaviorSubject(this.staff); staffSubject = this.staffList.asObservable(); - constructor(private http: HttpClient) { + constructor( + private http: HttpClient, + private httpWrapperService: HttpWrapperService, + private loggingService: LoggingService + ) { } resetPin(phone: string): Observable { const params = new HttpParams().set('phoneNumber', phone); - return this.http.get(`${environment.cicUssdUrl}/pin`, { params }); + return this.httpWrapperService.get(`${environment.cicUssdUrl}/pin`, {params}); } - async changeAccountInfo(address: string, status: string, name: string, phoneNumber: string, age: string, type: string, token: string, - failedPinAttempts: string, bio: string, gender: string, businessCategory: string, userLocation: string, - location: string, locationType: string, referrer: string): Promise { - const accountDetails = { - status, - name, - phoneNumber, - age, - type, - token, - failedPinAttempts, - bio, - gender, - businessCategory, - userLocation, - location, - locationType, - referrer - }; + getAccountStatus(phone: string): any { + const params = new HttpParams().set('phoneNumber', phone); + return this.httpWrapperService.get(`${environment.cicUssdUrl}/pin`, {params}); + } + + getLockedAccounts(offset: number, limit: number): any { + return this.httpWrapperService.get(`${environment.cicUssdUrl}/accounts/locked/${offset}/${limit}`); + } + + async changeAccountInfo(address: string, name: string, phoneNumber: string, age: string, type: string, bio: string, gender: string, + businessCategory: string, userLocation: string, location: string, locationType: string, metaAccount: MetaResponse + ): Promise { + let reqBody = metaAccount; + let accountInfo = reqBody.m.data; + accountInfo.vcard.fn[0].value = name; + accountInfo.vcard.n[0].value = name.split(' '); + accountInfo.vcard.tel[0].value = phoneNumber; + accountInfo.products = [bio]; + accountInfo.gender = gender; + accountInfo.age = age; + accountInfo.type = type; + accountInfo.category = businessCategory; + accountInfo.location.area = location; + accountInfo.location.area_name = userLocation; + accountInfo.location.area_type = locationType; + accountInfo.vcard = vCard.generate(accountInfo.vcard); + reqBody.m.data = accountInfo; const accountKey = await User.toKey(address); - this.http.get(`${environment.cicMetaUrl}/${accountKey}`, { headers: this.headers }).pipe(first()).subscribe(async res => { - const syncableAccount: Syncable = Envelope.fromJSON(JSON.stringify(res)).unwrap(); + this.httpWrapperService.get(`${environment.cicMetaUrl}/${accountKey}`, { headers: this.headers }).pipe(first()).subscribe(async res => { + const syncableAccount: Syncable = Envelope.fromJSON(JSON.stringify(res.body)).unwrap(); let update = []; - for (const prop in accountDetails) { - update.push(new ArgPair(prop, accountDetails[prop])); + for (const prop in reqBody) { + update.push(new ArgPair(prop, reqBody[prop])); } syncableAccount.update(update, 'client-branch'); await this.updateMeta(syncableAccount, accountKey, this.headers); }, async error => { - console.error('There is an error!', error); - const syncableAccount: Syncable = new Syncable(accountKey, accountDetails); + this.loggingService.sendErrorLevelMessage('Can\'t find account info in meta service', this, {error}); + const syncableAccount: Syncable = new Syncable(accountKey, accountInfo); await this.updateMeta(syncableAccount, accountKey, this.headers); }); return accountKey; @@ -76,66 +91,67 @@ export class UserService { async updateMeta(syncableAccount: Syncable, accountKey: string, headers: HttpHeaders): Promise { const envelope = await this.wrap(syncableAccount , this.signer); const reqBody = envelope.toJSON(); - this.http.put(`${environment.cicMetaUrl}/${accountKey}`, reqBody , { headers }).pipe(first()).subscribe(res => { - console.log(res); + this.httpWrapperService.put(`${environment.cicMetaUrl}/${accountKey}`, reqBody , { headers }).pipe(first()).subscribe(res => { + this.loggingService.sendInfoLevelMessage(`Response: ${res.body}`); }); } getAccounts(): void { - this.http.get(`${environment.cicCacheUrl}/accounts`).pipe(first()).subscribe(accounts => this.accountsList.next(accounts)); + this.httpWrapperService.get(`${environment.cicCacheUrl}/accounts`).pipe(first()).subscribe(res => this.accountsList.next(res.body)); } getAccountById(id: number): Observable { - return this.http.get(`${environment.cicCacheUrl}/accounts/${id}`); + return this.httpWrapperService.get(`${environment.cicCacheUrl}/accounts/${id}`); } getActions(): void { - this.http.get(`${environment.cicCacheUrl}/actions`).pipe(first()).subscribe(actions => this.actionsList.next(actions)); + this.httpWrapperService.get(`${environment.cicCacheUrl}/actions`).pipe(first()).subscribe(res => this.actionsList.next(res.body)); } getActionById(id: string): any { - return this.http.get(`${environment.cicCacheUrl}/actions/${id}`); + return this.httpWrapperService.get(`${environment.cicCacheUrl}/actions/${id}`); } approveAction(id: string): Observable { - return this.http.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: true }); + return this.httpWrapperService.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: true }); } revokeAction(id: string): Observable { - return this.http.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: false }); + return this.httpWrapperService.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: false }); } getHistoryByUser(id: string): Observable { - return this.http.get(`${environment.cicCacheUrl}/history/${id}`); + return this.httpWrapperService.get(`${environment.cicCacheUrl}/history/${id}`); } getStaff(): void { - this.http.get(`${environment.cicCacheUrl}/staff`).pipe(first()).subscribe(staff => this.staffList.next(staff)); + this.httpWrapperService.get(`${environment.cicCacheUrl}/staff`).pipe(first()).subscribe(res => this.staffList.next(res.body)); } getStaffById(id: string): Observable { - return this.http.get(`${environment.cicCacheUrl}/staff/${id}`); + return this.httpWrapperService.get(`${environment.cicCacheUrl}/staff/${id}`); } activateStaff(id: string): Observable { - return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'activated'}); + return this.httpWrapperService.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'activated'}); } deactivateStaff(id: string): Observable { - return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'deactivated'}); + return this.httpWrapperService.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'deactivated'}); } changeStaffType(id: string, type: string): Observable { - return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {accountType: type}); + return this.httpWrapperService.post(`${environment.cicCacheUrl}/staff/${id}`, {accountType: type}); } getAccountDetailsFromMeta(userKey: string): Observable { - return this.http.get(`${environment.cicMetaUrl}/${userKey}`, { headers: this.headers }); + return this.httpWrapperService.get(`${environment.cicMetaUrl}/${userKey}`, { headers: this.headers }); } getUser(userKey: string): any { - return this.http.get(`${environment.cicMetaUrl}/${userKey}`, { headers: this.headers }).pipe(first()).subscribe(async res => { - return Envelope.fromJSON(JSON.stringify(res)).unwrap(); + return this.httpWrapperService.get(`${environment.cicMetaUrl}/${userKey}`, { headers: this.headers }) + .pipe(first()).subscribe(async res => { + return Envelope.fromJSON(JSON.stringify(res.body)).unwrap(); }); }