Commit 4b6fbd86 authored by dev0tion's avatar dev0tion

Wallet balance to real API

parent 50517ad6
......@@ -46,7 +46,7 @@ export class LoginComponent implements OnInit {
}
private setGlobalWalletName(walletName: string) {
this.globalService.setCurrentWalletName(walletName);
this.globalService.setWalletName(walletName);
}
private getWalletFiles() {
......@@ -85,7 +85,8 @@ export class LoginComponent implements OnInit {
console.log(response);
if (response.status >= 200 && response.status < 400) {
let responseMessage = response.json();
this.globalService.setCurrentWalletName(walletLoad.name)
this.globalService.setWalletName(walletLoad.name)
this.globalService.setCoinType(1);
this.router.navigate(['/wallet']);
}
},
......
export class WalletInfo {
constructor(walletName: string, coinType: number, accountName: string) {
constructor(walletName: string, coinType: number) {
this.walletName = walletName;
this.coinType = coinType;
this.accountName = accountName;
}
public walletName: string;
public coinType: number;
public accountName: string;
}
......@@ -63,25 +63,33 @@ export class ApiService {
*/
getWalletStatus(): Observable<any> {
return this.http
.get(this.mockApiUrl + '/wallet/status')
.get(this.webApiUrl + '/wallet/status')
.map((response: Response) => response);
}
/**
* Get wallet balance info from the API.
*/
getWalletBalance(): Observable<any> {
getWalletBalance(data: WalletInfo): Observable<any> {
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
params.set('coinType', data.coinType.toString());
return this.http
.get(this.mockApiUrl + '/wallet/balance')
.get(this.webApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response);
}
/**
* Get a wallets transaction history info from the API.
*/
getWalletHistory(): Observable<any> {
getWalletHistory(data: WalletInfo): Observable<any> {
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
params.set('coinType', data.coinType.toString());
return this.http
.get(this.mockApiUrl + '/wallet/history')
.get(this.webApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response);
}
......@@ -92,7 +100,7 @@ export class ApiService {
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
params.set('coinType', data.coinType.toString());
params.set('accountName', data.accountName);
return this.http
.get(this.webApiUrl + '/wallet/address', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response);
......
......@@ -6,6 +6,7 @@ export class GlobalService {
private walletPath: string;
private currentWalletName: string;
private coinType: number;
getWalletPath() {
return this.walletPath;
......@@ -15,11 +16,19 @@ export class GlobalService {
this.walletPath = walletPath;
}
getCurrentWalletName() {
getWalletName() {
return this.currentWalletName;
}
setCurrentWalletName(currentWalletName: string) {
setWalletName(currentWalletName: string) {
this.currentWalletName = currentWalletName;
}
}
\ No newline at end of file
getCoinType () {
return this.coinType;
}
setCoinType (coinType: number) {
this.coinType = coinType;
}
}
import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/services/api.service';
import { GlobalService } from '../../shared/services/global.service';
import { WalletInfo } from '../../shared/classes/wallet-info';
@Component({
selector: 'dashboard-component',
......@@ -7,8 +9,8 @@ import { ApiService } from '../../shared/services/api.service';
styleUrls: ['./dashboard.component.css'],
})
export class DashboardComponent {
constructor(private apiService: ApiService) {}
constructor(private apiService: ApiService, private globalService: GlobalService) {}
private balanceResponse: any;
private confirmedBalance: number;
private unconfirmedBalance: number;
......@@ -19,21 +21,22 @@ export class DashboardComponent {
}
private getWalletBalance() {
this.apiService.getWalletBalance()
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
this.balanceResponse = response.json();
this.confirmedBalance = this.balanceResponse.confirmed;
this.unconfirmedBalance = this.balanceResponse.unconfirmed;
}
},
error => {
if (error.status >= 400) {
this.errorMessage = <any>error;
console.log(this.errorMessage);
}
}
let walletInfo = new WalletInfo(this.globalService.getWalletName(), this.globalService.getCoinType())
this.apiService.getWalletBalance(walletInfo)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400) {
this.balanceResponse = response.json();
this.confirmedBalance = this.balanceResponse.confirmed;
this.unconfirmedBalance = this.balanceResponse.unconfirmed;
}
},
error => {
if (error.status >= 400) {
this.errorMessage = <any>error;
console.log(this.errorMessage);
}
}
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment