Commit 4b6fbd86 authored by dev0tion's avatar dev0tion

Wallet balance to real API

parent 50517ad6
...@@ -46,7 +46,7 @@ export class LoginComponent implements OnInit { ...@@ -46,7 +46,7 @@ export class LoginComponent implements OnInit {
} }
private setGlobalWalletName(walletName: string) { private setGlobalWalletName(walletName: string) {
this.globalService.setCurrentWalletName(walletName); this.globalService.setWalletName(walletName);
} }
private getWalletFiles() { private getWalletFiles() {
...@@ -85,7 +85,8 @@ export class LoginComponent implements OnInit { ...@@ -85,7 +85,8 @@ export class LoginComponent implements OnInit {
console.log(response); console.log(response);
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
let responseMessage = response.json(); let responseMessage = response.json();
this.globalService.setCurrentWalletName(walletLoad.name) this.globalService.setWalletName(walletLoad.name)
this.globalService.setCoinType(1);
this.router.navigate(['/wallet']); this.router.navigate(['/wallet']);
} }
}, },
......
export class WalletInfo { export class WalletInfo {
constructor(walletName: string, coinType: number, accountName: string) { constructor(walletName: string, coinType: number) {
this.walletName = walletName; this.walletName = walletName;
this.coinType = coinType; this.coinType = coinType;
this.accountName = accountName;
} }
public walletName: string; public walletName: string;
public coinType: number; public coinType: number;
public accountName: string;
} }
...@@ -63,25 +63,33 @@ export class ApiService { ...@@ -63,25 +63,33 @@ export class ApiService {
*/ */
getWalletStatus(): Observable<any> { getWalletStatus(): Observable<any> {
return this.http return this.http
.get(this.mockApiUrl + '/wallet/status') .get(this.webApiUrl + '/wallet/status')
.map((response: Response) => response); .map((response: Response) => response);
} }
/** /**
* Get wallet balance info from the API. * 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 return this.http
.get(this.mockApiUrl + '/wallet/balance') .get(this.webApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response); .map((response: Response) => response);
} }
/** /**
* Get a wallets transaction history info from the API. * 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 return this.http
.get(this.mockApiUrl + '/wallet/history') .get(this.webApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -92,7 +100,7 @@ export class ApiService { ...@@ -92,7 +100,7 @@ export class ApiService {
let params: URLSearchParams = new URLSearchParams(); let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName); params.set('walletName', data.walletName);
params.set('coinType', data.coinType.toString()); params.set('coinType', data.coinType.toString());
params.set('accountName', data.accountName);
return this.http return this.http
.get(this.webApiUrl + '/wallet/address', new RequestOptions({headers: this.headers, search: params})) .get(this.webApiUrl + '/wallet/address', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response); .map((response: Response) => response);
......
...@@ -6,6 +6,7 @@ export class GlobalService { ...@@ -6,6 +6,7 @@ export class GlobalService {
private walletPath: string; private walletPath: string;
private currentWalletName: string; private currentWalletName: string;
private coinType: number;
getWalletPath() { getWalletPath() {
return this.walletPath; return this.walletPath;
...@@ -15,11 +16,19 @@ export class GlobalService { ...@@ -15,11 +16,19 @@ export class GlobalService {
this.walletPath = walletPath; this.walletPath = walletPath;
} }
getCurrentWalletName() { getWalletName() {
return this.currentWalletName; return this.currentWalletName;
} }
setCurrentWalletName(currentWalletName: string) { setWalletName(currentWalletName: string) {
this.currentWalletName = currentWalletName; 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 { Component, OnInit } from '@angular/core';
import { ApiService } from '../../shared/services/api.service'; import { ApiService } from '../../shared/services/api.service';
import { GlobalService } from '../../shared/services/global.service';
import { WalletInfo } from '../../shared/classes/wallet-info';
@Component({ @Component({
selector: 'dashboard-component', selector: 'dashboard-component',
...@@ -7,8 +9,8 @@ import { ApiService } from '../../shared/services/api.service'; ...@@ -7,8 +9,8 @@ import { ApiService } from '../../shared/services/api.service';
styleUrls: ['./dashboard.component.css'], styleUrls: ['./dashboard.component.css'],
}) })
export class DashboardComponent { export class DashboardComponent {
constructor(private apiService: ApiService) {} constructor(private apiService: ApiService, private globalService: GlobalService) {}
private balanceResponse: any; private balanceResponse: any;
private confirmedBalance: number; private confirmedBalance: number;
private unconfirmedBalance: number; private unconfirmedBalance: number;
...@@ -19,21 +21,22 @@ export class DashboardComponent { ...@@ -19,21 +21,22 @@ export class DashboardComponent {
} }
private getWalletBalance() { private getWalletBalance() {
this.apiService.getWalletBalance() let walletInfo = new WalletInfo(this.globalService.getWalletName(), this.globalService.getCoinType())
.subscribe( this.apiService.getWalletBalance(walletInfo)
response => { .subscribe(
if (response.status >= 200 && response.status < 400) { response => {
this.balanceResponse = response.json(); if (response.status >= 200 && response.status < 400) {
this.confirmedBalance = this.balanceResponse.confirmed; this.balanceResponse = response.json();
this.unconfirmedBalance = this.balanceResponse.unconfirmed; this.confirmedBalance = this.balanceResponse.confirmed;
} this.unconfirmedBalance = this.balanceResponse.unconfirmed;
}, }
error => { },
if (error.status >= 400) { error => {
this.errorMessage = <any>error; if (error.status >= 400) {
console.log(this.errorMessage); 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