Commit ce6933a8 authored by dev0tion's avatar dev0tion

Prepare max balance call

parent eeed9db1
......@@ -168,6 +168,23 @@ export class ApiService {
.map((response: Response) => response);
}
/**
* Get the maximum sendable amount for a given fee from the API
*/
getMaximumBalance(data): Observable<any> {
this.getCurrentCoin();
let params: URLSearchParams = new URLSearchParams();
params.set('walletName', data.walletName);
params.set('accountName', "account 0");
params.set('feeType', data.feeType);
params.set('allowUnconfirmed', "true");
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.
*/
......
......@@ -9,8 +9,8 @@
<form [formGroup]="sendForm" (ngSubmit)="send()">
<!--<div class="form-group has-danger clearfix">-->
<div class="form-group clearfix">
<label class="float-left" for="yourAddress">Amount</label>
<!--<span class="float-right"><a href="#">max</a></span>-->
<label class="float-left" for="Amount">Amount</label>
<!-- <span class="float-right btn-link" (click)="getMaxBalance()">max</span> -->
<input type="text" class="form-control form-control-danger" formControlName="amount" id="Amount" placeholder="0.00 {{ coinUnit }}">
<div *ngIf="formErrors.amount" class="form-control-feedback">{{ formErrors.amount }}</div>
</div>
......
......@@ -86,6 +86,43 @@ export class SendComponent implements OnInit {
}
};
public getMaxBalance() {
let data = {
walletName: this.globalService.getWalletName(),
feeType: this.sendForm.get("fee").value
}
let balanceResponse;
this.apiService
.getMaximumBalance(data)
.subscribe(
response => {
if (response.status >= 200 && response.status < 400){
balanceResponse = response.json();
console.log(balanceResponse);
}
},
error => {
console.log(error);
if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) {
if (!error.json().errors[0]) {
console.log(error);
}
else {
alert(error.json().errors[0].description);
}
}
},
() => {
this.sendForm.patchValue({amount: balanceResponse.maxSpendableAmount});
this.estimatedFee = balanceResponse.fee;
}
)
};
public buildTransaction() {
this.transaction = new TransactionBuilding(
this.globalService.getWalletName(),
......
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