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,217 +23,227 @@ import { TransactionSending } from '../classes/transaction-sending'; ...@@ -23,217 +23,227 @@ 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
*/ /**
getWalletFiles(): Observable<any> { * Gets available wallets at the default path
return this.http */
.get(this.destreamApiUrl + '/wallet/files') getWalletFiles(): Observable<any> {
.map((response: Response) => response); return this.http
} .get(this.destreamApiUrl + '/wallet/files')
.map((response: Response) => response);
/** }
* Get a new mnemonic
*/ /**
getNewMnemonic(): Observable<any> { * Get a new mnemonic
let params: URLSearchParams = new URLSearchParams(); */
params.set('language', 'English'); getNewMnemonic(): Observable<any> {
params.set('wordCount', '12'); let params: URLSearchParams = new URLSearchParams();
params.set('language', 'English');
return this.http params.set('wordCount', '12');
.get(this.destreamApiUrl + '/wallet/mnemonic', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response); return this.http
} .get(this.destreamApiUrl + '/wallet/mnemonic', new RequestOptions({ headers: this.headers, search: params }))
/** .map((response: Response) => response);
* Create a new DeStream wallet. }
*/ /**
createDeStreamWallet(data: WalletCreation): Observable<any> { * Create a new DeStream wallet.
return this.http */
.post(this.destreamApiUrl + '/wallet/create/', JSON.stringify(data), {headers: this.headers}) createDeStreamWallet(data: WalletCreation): Observable<any> {
.map((response: Response) => response); return this.http
} .post(this.destreamApiUrl + '/wallet/create/', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response);
/** }
* Recover a DeStream wallet.
*/ /**
recoverDeStreamWallet(data: WalletRecovery): Observable<any> { * Recover a DeStream wallet.
return this.http */
.post(this.destreamApiUrl + '/wallet/recover/', JSON.stringify(data), {headers: this.headers}) recoverDeStreamWallet(data: WalletRecovery): Observable<any> {
.map((response: Response) => response); return this.http
} .post(this.destreamApiUrl + '/wallet/recover/', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response);
/** }
* Load a DeStream wallet
*/ /**
loadDeStreamWallet(data: WalletLoad): Observable<any> { * Load a DeStream wallet
return this.http */
.post(this.destreamApiUrl + '/wallet/load/', JSON.stringify(data), {headers: this.headers}) loadDeStreamWallet(data: WalletLoad): Observable<any> {
.map((response: Response) => response); return this.http
} .post(this.destreamApiUrl + '/wallet/load/', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response);
/** }
* Get wallet status info from the API.
*/ /**
getWalletStatus(): Observable<any> { * Get wallet status info from the API.
*/
return this.http getWalletStatus(): Observable<any> {
.get(this.currentApiUrl + '/wallet/status')
.map((response: Response) => response); return this.http
} .get(this.currentApiUrl + '/wallet/status')
.map((response: Response) => response);
/** }
* Get general wallet info from the API.
*/ /**
getGeneralInfo(data: WalletInfo): Observable<any> { * Get general wallet info from the API.
*/
let params: URLSearchParams = new URLSearchParams(); getGeneralInfo(data: WalletInfo): Observable<any> {
params.set('Name', data.walletName);
let params: URLSearchParams = new URLSearchParams();
return Observable params.set('Name', data.walletName);
.interval(this.pollingInterval)
.startWith(0) return Observable
.switchMap(() => this.http.get(this.currentApiUrl + '/wallet/general-info', new RequestOptions({headers: this.headers, search: params}))) .interval(this.pollingInterval)
.map((response: Response) => response); .startWith(0)
} .switchMap(() => this.http.get(this.currentApiUrl + '/wallet/general-info', new RequestOptions({ headers: this.headers, search: params })))
.map((response: Response) => response);
/** }
* Get wallet balance info from the API.
*/ /**
getWalletBalance(data: WalletInfo): Observable<any> { * Get wallet balance info from the API.
*/
let params: URLSearchParams = new URLSearchParams(); getWalletBalance(data: WalletInfo): Observable<any> {
params.set('walletName', data.walletName);
let params: URLSearchParams = new URLSearchParams();
return Observable params.set('walletName', data.walletName);
.interval(this.pollingInterval)
.startWith(0) return Observable
.switchMap(() => this.http.get(this.currentApiUrl + '/wallet/balance', new RequestOptions({headers: this.headers, search: params}))) .interval(this.pollingInterval)
.map((response: Response) => response); .startWith(0)
} .switchMap(() => this.http.get(this.currentApiUrl + '/wallet/balance', new RequestOptions({ headers: this.headers, search: params })))
.map((response: Response) => response);
/** }
* Get the maximum sendable amount for a given fee from the API
*/ /**
getMaximumBalance(data): Observable<any> { * Get the maximum sendable amount for a given fee from the API
*/
let params: URLSearchParams = new URLSearchParams(); getMaximumBalance(data): Observable<any> {
params.set('walletName', data.walletName);
params.set('accountName', "account 0"); let params: URLSearchParams = new URLSearchParams();
params.set('feeType', data.feeType); params.set('walletName', data.walletName);
params.set('allowUnconfirmed', "true"); params.set('accountName', this.accountName);
params.set('feeType', data.feeType);
return this.http params.set('allowUnconfirmed', "true");
.get(this.currentApiUrl + '/wallet/maxbalance', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response); return this.http
} .get(this.currentApiUrl + '/wallet/maxbalance', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response);
/** }
* Get a wallets transaction history info from the API.
*/ /**
getWalletHistory(data: WalletInfo): Observable<any> { * Get a wallets transaction history info from the API.
*/
let params: URLSearchParams = new URLSearchParams(); getWalletHistory(data: WalletInfo): Observable<any> {
params.set('walletName', data.walletName);
let params: URLSearchParams = new URLSearchParams();
return Observable params.set('walletName', data.walletName);
.interval(this.pollingInterval)
.startWith(0) return Observable
.switchMap(() => this.http.get(this.currentApiUrl + '/wallet/history', new RequestOptions({headers: this.headers, search: params}))) .interval(this.pollingInterval)
.map((response: Response) => response); .startWith(0)
} .switchMap(() => this.http.get(this.currentApiUrl + '/wallet/history', new RequestOptions({ headers: this.headers, search: params })))
.map((response: Response) => response);
/** }
* Get an unused receive address for a certain wallet from the API.
*/ /**
getUnusedReceiveAddress(data: WalletInfo): Observable<any> { * Get an unused receive address for a certain wallet from the API.
*/
let params: URLSearchParams = new URLSearchParams(); getUnusedReceiveAddress(data: WalletInfo): Observable<any> {
params.set('walletName', data.walletName);
params.set('accountName', "account 0"); //temporary let params: URLSearchParams = new URLSearchParams();
return this.http params.set('walletName', data.walletName);
.get(this.currentApiUrl + '/wallet/unusedaddress', new RequestOptions({headers: this.headers, search: params})) params.set('accountName', this.accountName); //temporary
.map((response: Response) => response); return this.http
} .get(this.currentApiUrl + '/wallet/unusedaddress', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response);
/** }
* Get multiple unused receive addresses for a certain wallet from the API.
*/ /**
getUnusedReceiveAddresses(data: WalletInfo, count: string): Observable<any> { * Get multiple unused receive addresses for a certain wallet from the API.
*/
let params: URLSearchParams = new URLSearchParams(); getUnusedReceiveAddresses(data: WalletInfo, count: string): Observable<any> {
params.set('walletName', data.walletName);
params.set('accountName', "account 0"); //temporary let params: URLSearchParams = new URLSearchParams();
params.set('count', count); params.set('walletName', data.walletName);
return this.http params.set('accountName', this.accountName); //temporary
.get(this.currentApiUrl + '/wallet/unusedaddresses', new RequestOptions({headers: this.headers, search: params})) params.set('count', count);
.map((response: Response) => response); return this.http
} .get(this.currentApiUrl + '/wallet/unusedaddresses', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response);
/** }
* Get get all receive addresses for an account of a wallet from the API.
*/ /**
getAllReceiveAddresses(data: WalletInfo): Observable<any> { * Get get all receive addresses for an account of a wallet from the API.
*/
let params: URLSearchParams = new URLSearchParams(); getAllReceiveAddresses(data: WalletInfo): Observable<any> {
params.set('walletName', data.walletName);
params.set('accountName', "account 0"); //temporary let params: URLSearchParams = new URLSearchParams();
return this.http params.set('walletName', data.walletName);
.get(this.currentApiUrl + '/wallet/addresses', new RequestOptions({headers: this.headers, search: params})) params.set('accountName', this.accountName); //temporary
.map((response: Response) => response); return this.http
} .get(this.currentApiUrl + '/wallet/addresses', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response);
/** }
* Estimate the fee of a transaction
*/ /**
estimateFee(data: FeeEstimation): Observable<any> { * Estimate the fee of a transaction
*/
let params: URLSearchParams = new URLSearchParams(); estimateFee(data: FeeEstimation): Observable<any> {
params.set('walletName', data.walletName);
params.set('accountName', data.accountName); let params: URLSearchParams = new URLSearchParams();
params.set('destinationAddress', data.destinationAddress); params.set('walletName', data.walletName);
params.set('amount', data.amount); params.set('accountName', data.accountName);
params.set('feeType', data.feeType); params.set('destinationAddress', data.destinationAddress);
params.set('allowUnconfirmed', "true"); params.set('amount', data.amount);
params.set('feeType', data.feeType);
return this.http params.set('allowUnconfirmed', "true");
.get(this.currentApiUrl + '/wallet/estimate-txfee', new RequestOptions({headers: this.headers, search: params}))
.map((response: Response) => response); return this.http
} .get(this.currentApiUrl + '/wallet/estimate-txfee', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response);
/** }
* Build a transaction
*/ /**
buildTransaction(data: TransactionBuilding): Observable<any> { * Build a transaction
*/
return this.http buildTransaction(data: TransactionBuilding): Observable<any> {
.post(this.currentApiUrl + '/wallet/build-transaction', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response); return this.http
} .post(this.currentApiUrl + '/wallet/build-transaction', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response);
/** }
* Send transaction
*/ /**
sendTransaction(data: TransactionSending): Observable<any> { * Send transaction
*/
return this.http sendTransaction(data: TransactionSending): Observable<any> {
.post(this.currentApiUrl + '/wallet/send-transaction', JSON.stringify(data), {headers: this.headers})
.map((response: Response) => response); return this.http
} .post(this.currentApiUrl + '/wallet/send-transaction', JSON.stringify(data), { headers: this.headers })
.map((response: Response) => response);
/** }
* Send shutdown signal to the daemon
*/ getExtPubKey(data: WalletInfo): Observable<any> {
shutdownNode(): Observable<any> { let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
return this.http params.set('accountName', this.accountName);
.post(this.currentApiUrl + '/node/shutdown', '') return this.http.get(this.currentApiUrl + '/wallet/extpubkey', new RequestOptions({ headers: this.headers, search: params }))
.map((response: Response) => response); .map((response: Response) => response);
} }
/**
* Send shutdown signal to the daemon
*/
shutdownNode(): Observable<any> {
return this.http
.post(this.currentApiUrl + '/node/shutdown', '')
.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);
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import 'rxjs/add/observable/empty'; import 'rxjs/add/observable/empty';
import { GlobalService } from '../../shared/services/global.service'; 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()
export class AdvancedService { 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());
} }
public generateAddresses(count: number): Observable<string[]> { public generateAddresses(count: number): Observable<string[]> {
const url = this.makeUrl(`unusedaddresses?WalletName=${this.walletName}&AccountName=${this.accountName}&Count=${count}`); const url = this.makeUrl(`unusedaddresses?WalletName=${this.walletName}&AccountName=${this.accountName}&Count=${count}`);
return this.httpClient.get(url).map(x => this.processAddresses(x)); return this.httpClient.get(url).map(x => this.processAddresses(x));
}
public resyncFromDate(date: Date): Observable<any> {
date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); //<- Strip any time values
const url = this.makeUrl('syncfromdate');
const data = JSON.stringify(new dateRequest(date));
return this.httpClient.post(url, data, { headers: this.headers }).map((x: Response) => x);
}
private processAddresses(response: any): string[] {
const addresses = new Array<string>();
for (const address of response) {
addresses.push(address);
} }
return addresses;
}
public resyncFromDate(date: Date): Observable<any> { private makeUrl(urlPostfix: string): string {
date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); //<- Strip any time values return `${this.urlPrefix}${urlPostfix}`;
const url = this.makeUrl('syncfromdate'); }
const data = JSON.stringify(new dateRequest(date));
return this.httpClient.post(url, data, {headers: this.headers}).map((x: Response) => x);
}
private processAddresses(response: any): string[] {
const addresses = new Array<string>();
for (const address of response) {
addresses.push(address);
}
return addresses;
}
private makeUrl(urlPostfix: string): string {
return `${this.urlPrefix}${urlPostfix}`;
}
} }
...@@ -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