Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Merge 880f0eb into c8d5fc8
Browse files Browse the repository at this point in the history
  • Loading branch information
tboeckmann committed Nov 17, 2019
2 parents c8d5fc8 + 880f0eb commit 1fb6b96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { MailchainTestService } from './test/test-helpers/mailchain-test.service
import { ModalConnectivityErrorComponent } from './modals/modal-connectivity-error/modal-connectivity-error.component';
import { NgModule } from '@angular/core';
import { errorMessages } from './services/helpers/error-messages/error-messages'
import { HttpHelpersService } from './services/helpers/http-helpers/http-helpers.service';


// Workaround:
// Error from entryComponents not present in TestBed. Fix ref: https://stackoverflow.com/a/42399718
Expand All @@ -34,6 +36,9 @@ describe('AppComponent', () => {
],
declarations: [
AppComponent,
],
providers: [
HttpHelpersService,
]
}).compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpClientTestingModule, HttpTestingController } from '@angular/common/

import { AddressesService } from './addresses.service';
import { MailchainTestService } from 'src/app/test/test-helpers/mailchain-test.service';
import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service';


describe('AddressesService', () => {
Expand All @@ -13,13 +14,14 @@ describe('AddressesService', () => {
let serverResponse
let expectedAddresses

const desiredUrl = `http://127.0.0.1:8080/api/addresses`
const desiredUrl = `http://127.0.0.1:8080/api/addresses?protocol=ethereum&network=mainnet`


beforeEach(() => {
TestBed.configureTestingModule({
providers: [
AddressesService,
HttpHelpersService,
],
imports: [HttpClientTestingModule]
});
Expand Down Expand Up @@ -51,7 +53,7 @@ describe('AddressesService', () => {
addressesService.getAddresses().then(res => {
expect(res).toEqual(expectedAddresses)
});

// handle open connections
const req = httpTestingController.expectOne(desiredUrl);
expect(req.request.method).toBe("GET");
Expand Down
27 changes: 23 additions & 4 deletions src/app/services/mailchain/addresses/addresses.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { LocalStorageServerService } from '../../helpers/local-storage-server/local-storage-server.service';
import { LocalStorageProtocolService } from '../../helpers/local-storage-protocol/local-storage-protocol.service';
import { HttpHelpersService } from '../../helpers/http-helpers/http-helpers.service';

@Injectable({
providedIn: 'root'
})
export class AddressesService {

private url: string
private protocol: string
private network: string

constructor(
private http: HttpClient,
private httpHelpersService: HttpHelpersService,
private localStorageServerService: LocalStorageServerService,
private localStorageProtocolService: LocalStorageProtocolService,
) {
this.initUrl()
}
Expand All @@ -20,19 +26,27 @@ export class AddressesService {
* Initialize URL from local storage
*/
initUrl(){
this.url = `${this.localStorageServerService.getCurrentServerDetails()}/api`
this.url = `${this.localStorageServerService.getCurrentServerDetails()}/api`,
this.protocol = this.localStorageProtocolService.getCurrentProtocol()
this.network = this.localStorageServerService.getCurrentNetwork()
}

/**
* Get and return the public addresses from my wallet to send from
*/
async getAddresses() {
var httpOptions = this.httpHelpersService.getHttpOptions([
['protocol',this.protocol],
['network',this.network]
])

var addresses = []
let res = await this.http.get(
this.url + `/addresses`
this.url + `/addresses`,
httpOptions
// TODO handle failure
).toPromise();
res["addresses"].forEach(address => {
res["body"]["addresses"].forEach(address => {
addresses.push(this.handleAddressFormatting(address,'ethereum'))
});
return addresses
Expand All @@ -51,9 +65,14 @@ export class AddressesService {
* Returns the addresses response with status codes
*/
public getAddressesResponse(){
var httpOptions = this.httpHelpersService.getHttpOptions([
['protocol',this.protocol],
['network',this.network]
])

return this.http.get(
this.url + `/addresses`,
{observe: 'response'}
httpOptions
)
}

Expand Down

0 comments on commit 1fb6b96

Please sign in to comment.