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

Commit

Permalink
add protocol and network to addresses endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tboeckmann committed Nov 10, 2019
1 parent cf0287b commit 26b6882
Showing 1 changed file with 23 additions and 4 deletions.
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 26b6882

Please sign in to comment.