Commit 36213223 authored by Maxim Bogdanov's avatar Maxim Bogdanov 🙉

Fixes and inprovements to work with destream network.

parent cc4ae9ee
...@@ -53,6 +53,9 @@ export class CoinNotationPipe implements PipeTransform { ...@@ -53,6 +53,9 @@ export class CoinNotationPipe implements PipeTransform {
case "TuSTRAT": case "TuSTRAT":
temp = value / 100; temp = value / 100;
return temp.toFixed(this.decimalLimit); return temp.toFixed(this.decimalLimit);
case "DST":
temp = value / 100000000;
return temp.toFixed(this.decimalLimit);
} }
} }
} }
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Http, Headers, Response, RequestOptions, URLSearchParams} from '@angular/http'; import { Http, Headers, Response, RequestOptions, URLSearchParams } from '@angular/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/switchMap';
...@@ -23,12 +23,14 @@ import { TransactionSending } from '../classes/transaction-sending'; ...@@ -23,12 +23,14 @@ import { TransactionSending } from '../classes/transaction-sending';
*/ */
@Injectable() @Injectable()
export class ApiService { export class ApiService {
constructor(private http: Http, private globalService: GlobalService) {}; constructor(private http: Http, private globalService: GlobalService) { };
private headers = new Headers({'Content-Type': 'application/json'}); private headers = new Headers({ 'Content-Type': 'application/json' });
private pollingInterval = 3000; private pollingInterval = 3000;
private destreamApiUrl = 'http://localhost:56864/api'; private destreamApiUrl = 'http://localhost:56864/api';
private currentApiUrl = 'http://localhost:56864/api'; private currentApiUrl = 'http://localhost:56864/api';
private readonly accountName = 'account 0';
/** /**
* Gets available wallets at the default path * Gets available wallets at the default path
...@@ -48,7 +50,7 @@ export class ApiService { ...@@ -48,7 +50,7 @@ export class ApiService {
params.set('wordCount', '12'); params.set('wordCount', '12');
return this.http return this.http
.get(this.destreamApiUrl + '/wallet/mnemonic', new RequestOptions({headers: this.headers, search: params})) .get(this.destreamApiUrl + '/wallet/mnemonic', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
/** /**
...@@ -56,7 +58,7 @@ export class ApiService { ...@@ -56,7 +58,7 @@ export class ApiService {
*/ */
createDeStreamWallet(data: WalletCreation): Observable<any> { createDeStreamWallet(data: WalletCreation): Observable<any> {
return this.http return this.http
.post(this.destreamApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers}) .post(this.destreamApiUrl + '/wallet/create/', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -65,7 +67,7 @@ export class ApiService { ...@@ -65,7 +67,7 @@ export class ApiService {
*/ */
recoverDeStreamWallet(data: WalletRecovery): Observable<any> { recoverDeStreamWallet(data: WalletRecovery): Observable<any> {
return this.http return this.http
.post(this.destreamApiUrl + '/wallet/recover/', JSON.stringify(data), {headers: this.headers}) .post(this.destreamApiUrl + '/wallet/recover/', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -74,7 +76,7 @@ export class ApiService { ...@@ -74,7 +76,7 @@ export class ApiService {
*/ */
loadDeStreamWallet(data: WalletLoad): Observable<any> { loadDeStreamWallet(data: WalletLoad): Observable<any> {
return this.http return this.http
.post(this.destreamApiUrl + '/wallet/load/', JSON.stringify(data), {headers: this.headers}) .post(this.destreamApiUrl + '/wallet/load/', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -99,7 +101,7 @@ export class ApiService { ...@@ -99,7 +101,7 @@ export class ApiService {
return Observable return Observable
.interval(this.pollingInterval) .interval(this.pollingInterval)
.startWith(0) .startWith(0)
.switchMap(() => this.http.get(this.currentApiUrl + '/wallet/general-info', new RequestOptions({headers: this.headers, search: params}))) .switchMap(() => this.http.get(this.currentApiUrl + '/wallet/general-info', new RequestOptions({ headers: this.headers, search: params })))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -114,7 +116,7 @@ export class ApiService { ...@@ -114,7 +116,7 @@ export class ApiService {
return Observable return Observable
.interval(this.pollingInterval) .interval(this.pollingInterval)
.startWith(0) .startWith(0)
.switchMap(() => this.http.get(this.currentApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params}))) .switchMap(() => this.http.get(this.currentApiUrl + '/wallet/balance', new RequestOptions({ headers: this.headers, search: params })))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -125,12 +127,12 @@ export class ApiService { ...@@ -125,12 +127,12 @@ 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('accountName', "account 0"); params.set('accountName', this.accountName);
params.set('feeType', data.feeType); params.set('feeType', data.feeType);
params.set('allowUnconfirmed', "true"); params.set('allowUnconfirmed', "true");
return this.http return this.http
.get(this.currentApiUrl + '/wallet/maxbalance', new RequestOptions({headers: this.headers, search: params})) .get(this.currentApiUrl + '/wallet/maxbalance', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -145,7 +147,7 @@ export class ApiService { ...@@ -145,7 +147,7 @@ export class ApiService {
return Observable return Observable
.interval(this.pollingInterval) .interval(this.pollingInterval)
.startWith(0) .startWith(0)
.switchMap(() => this.http.get(this.currentApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params}))) .switchMap(() => this.http.get(this.currentApiUrl + '/wallet/history', new RequestOptions({ headers: this.headers, search: params })))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -156,9 +158,9 @@ export class ApiService { ...@@ -156,9 +158,9 @@ 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('accountName', "account 0"); //temporary params.set('accountName', this.accountName); //temporary
return this.http return this.http
.get(this.currentApiUrl + '/wallet/unusedaddress', new RequestOptions({headers: this.headers, search: params})) .get(this.currentApiUrl + '/wallet/unusedaddress', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -169,10 +171,10 @@ export class ApiService { ...@@ -169,10 +171,10 @@ 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('accountName', "account 0"); //temporary params.set('accountName', this.accountName); //temporary
params.set('count', count); params.set('count', count);
return this.http return this.http
.get(this.currentApiUrl + '/wallet/unusedaddresses', new RequestOptions({headers: this.headers, search: params})) .get(this.currentApiUrl + '/wallet/unusedaddresses', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -183,9 +185,9 @@ export class ApiService { ...@@ -183,9 +185,9 @@ 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('accountName', "account 0"); //temporary params.set('accountName', this.accountName); //temporary
return this.http return this.http
.get(this.currentApiUrl + '/wallet/addresses', new RequestOptions({headers: this.headers, search: params})) .get(this.currentApiUrl + '/wallet/addresses', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -203,7 +205,7 @@ export class ApiService { ...@@ -203,7 +205,7 @@ export class ApiService {
params.set('allowUnconfirmed', "true"); params.set('allowUnconfirmed', "true");
return this.http return this.http
.get(this.currentApiUrl + '/wallet/estimate-txfee', new RequestOptions({headers: this.headers, search: params})) .get(this.currentApiUrl + '/wallet/estimate-txfee', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -213,7 +215,7 @@ export class ApiService { ...@@ -213,7 +215,7 @@ export class ApiService {
buildTransaction(data: TransactionBuilding): Observable<any> { buildTransaction(data: TransactionBuilding): Observable<any> {
return this.http return this.http
.post(this.currentApiUrl + '/wallet/build-transaction', JSON.stringify(data), {headers: this.headers}) .post(this.currentApiUrl + '/wallet/build-transaction', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response); .map((response: Response) => response);
} }
...@@ -223,7 +225,15 @@ export class ApiService { ...@@ -223,7 +225,15 @@ export class ApiService {
sendTransaction(data: TransactionSending): Observable<any> { sendTransaction(data: TransactionSending): Observable<any> {
return this.http return this.http
.post(this.currentApiUrl + '/wallet/send-transaction', JSON.stringify(data), {headers: this.headers}) .post(this.currentApiUrl + '/wallet/send-transaction', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response);
}
getExtPubKey(data: WalletInfo): Observable<any> {
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
params.set('accountName', this.accountName);
return this.http.get(this.currentApiUrl + '/wallet/extpubkey', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
......
...@@ -19,5 +19,5 @@ export class NavigationService { ...@@ -19,5 +19,5 @@ export class NavigationService {
navigation$.filter(x => x === `${this.navBase}/destream-wallet`).subscribe(_ => this.pageSubject.next(Page.DeStream)); navigation$.filter(x => x === `${this.navBase}/destream-wallet`).subscribe(_ => this.pageSubject.next(Page.DeStream));
} }
public pageSubject = new ReplaySubject(1); public pageSubject = new ReplaySubject(0);
} }
...@@ -7,7 +7,7 @@ import { GlobalService } from '../../shared/services/global.service'; ...@@ -7,7 +7,7 @@ import { GlobalService } from '../../shared/services/global.service';
import { NavigationService, Page } from '../../shared/services/navigation.service'; import { NavigationService, Page } from '../../shared/services/navigation.service';
class dateRequest { class dateRequest {
constructor(public date: Date){} constructor(public date: Date) { }
} }
@Injectable() @Injectable()
...@@ -15,15 +15,15 @@ export class AdvancedService { ...@@ -15,15 +15,15 @@ export class AdvancedService {
private urlPrefix = ''; private urlPrefix = '';
private readonly walletName; private readonly walletName;
private readonly accountName = 'account 0'; private readonly accountName = 'account 0';
private headers = new HttpHeaders({'Content-Type': 'application/json'}); private headers = new HttpHeaders({ 'Content-Type': 'application/json' });
constructor(private httpClient: HttpClient, private globalService: GlobalService, navigationService: NavigationService) { constructor(private httpClient: HttpClient, private globalService: GlobalService, navigationService: NavigationService) {
this.walletName = this.globalService.getWalletName(); this.walletName = this.globalService.getWalletName();
this.urlPrefix = "http://localhost:56864/api/Wallet/";
navigationService.pageSubject.subscribe(x => this.urlPrefix = `http://localhost:3722${x}/api/Wallet/`);
} }
public getExtPubKey(): Observable<string> { public getExtPubKey(): Observable<string> {
console.info(this.urlPrefix);
const url = this.makeUrl(`extpubkey?WalletName=${this.walletName}&AccountName=${this.accountName}`); const url = this.makeUrl(`extpubkey?WalletName=${this.walletName}&AccountName=${this.accountName}`);
return this.httpClient.get(url).map(x => x.toString()); return this.httpClient.get(url).map(x => x.toString());
} }
...@@ -37,7 +37,7 @@ export class AdvancedService { ...@@ -37,7 +37,7 @@ export class AdvancedService {
date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); //<- Strip any time values date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); //<- Strip any time values
const url = this.makeUrl('syncfromdate'); const url = this.makeUrl('syncfromdate');
const data = JSON.stringify(new dateRequest(date)); const data = JSON.stringify(new dateRequest(date));
return this.httpClient.post(url, data, {headers: this.headers}).map((x: Response) => x); return this.httpClient.post(url, data, { headers: this.headers }).map((x: Response) => x);
} }
private processAddresses(response: any): string[] { private processAddresses(response: any): string[] {
......
...@@ -49,8 +49,8 @@ export class HistoryComponent { ...@@ -49,8 +49,8 @@ export class HistoryComponent {
response => { response => {
if (response.status >= 200 && response.status < 400) { if (response.status >= 200 && response.status < 400) {
const json = response.json(); const json = response.json();
if (json && json.transactionsHistory) { if (json && json.history.length) {
historyResponse = json.transactionsHistory; historyResponse = json.history[0].transactionsHistory;
this.getTransactionInfo(historyResponse); this.getTransactionInfo(historyResponse);
} }
} }
......
...@@ -24,7 +24,7 @@ export class SidebarComponent implements OnInit { ...@@ -24,7 +24,7 @@ export class SidebarComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
public loadDestreamWallet() { public loadDeStreamWallet() {
this.globalService.setCoinName("DeStreamCoin"); this.globalService.setCoinName("DeStreamCoin");
this.globalService.setCoinUnit("DST"); this.globalService.setCoinUnit("DST");
......
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