Commit b5876cf7 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Merge pull request #273 from stratisproject/ui

Add fee estimation
parents f6752168 5f155766
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<input type="text" class="form-control form-control-success" formControlName="address" id="destinationAddress" placeholder="Please enter the destination address here."> <input type="text" class="form-control form-control-success" formControlName="address" id="destinationAddress" placeholder="Please enter the destination address here.">
<div *ngIf="formErrors.address" class="form-control-feedback">{{ formErrors.address }}</div> <div *ngIf="formErrors.address" class="form-control-feedback">{{ formErrors.address }}</div>
</div> </div>
<!--<div class="form-group"> <!-- <div class="form-group">
<label for="Fees">Fees</label> <label for="Fees">Fees</label>
<div class="col feeSlider text-center"> <div class="col feeSlider text-center">
<input class="form-control" id="dataSlider" type="text" <input class="form-control" id="dataSlider" type="text"
...@@ -37,16 +37,19 @@ ...@@ -37,16 +37,19 @@
<em>A higher fee helps expedite your transaction. <em>A higher fee helps expedite your transaction.
<br>You are sending <strong>1 BTC</strong> with an included <strong>Medium</strong> fee of <strong>0.0001</strong>.</em> <br>You are sending <strong>1 BTC</strong> with an included <strong>Medium</strong> fee of <strong>0.0001</strong>.</em>
</p> </p>
</div>--> </div> -->
<div class="form-group clearfix"> <div class="form-group clearfix">
<label for="feeSlider">Fee</label> <label for="feeSlider">Fee</label>
<input class="form-control col text-center" formControlName="fee" id="feeSlider" type="range" min="1" max="3" value="2"> <input class="form-control col text-center" formControlName="fee" type="range" min="1" max="3" value="2">
</div> </div>
<div class="form-group clearfix"> <div class="form-group clearfix">
<label for="walletPassword">Wallet Password</label> <label for="walletPassword">Wallet Password</label>
<input type="password" class="form-control form-control-success" formControlName="password" id="walletPassword" placeholder="Please enter your wallet password."> <input type="password" class="form-control form-control-success" formControlName="password" id="walletPassword" placeholder="Please enter your wallet password.">
<div *ngIf="formErrors.password" class="form-control-feedback">{{formErrors.password}}</div> <div *ngIf="formErrors.password" class="form-control-feedback">{{formErrors.password}}</div>
</div> </div>
<button type="button" class="btn btn-link" (click)="buildTransaction()" [disabled]="!sendForm.valid">Estimate Fee</button>
<label *ngIf="estimatedFee">Estimated Fee: </label>
<label *ngIf="estimatedFee">{{ estimatedFee | coinNotation }} {{ coinUnit }}</label>
</form> </form>
<!-- /form--> <!-- /form-->
</div> </div>
......
...@@ -22,11 +22,13 @@ export class SendComponent implements OnInit { ...@@ -22,11 +22,13 @@ export class SendComponent implements OnInit {
} }
public sendForm: FormGroup; public sendForm: FormGroup;
public coinUnit: string;
public isSending: boolean = false;
public estimatedFee: number;
private transactionHex: string;
private responseMessage: any; private responseMessage: any;
private errorMessage: string; private errorMessage: string;
public coinUnit: string;
private transaction: TransactionBuilding; private transaction: TransactionBuilding;
public isSending: boolean = false;
ngOnInit() { ngOnInit() {
this.coinUnit = this.globalService.getCoinUnit(); this.coinUnit = this.globalService.getCoinUnit();
...@@ -84,9 +86,7 @@ export class SendComponent implements OnInit { ...@@ -84,9 +86,7 @@ export class SendComponent implements OnInit {
} }
}; };
public send() { public buildTransaction() {
this.isSending = true;
this.transaction = new TransactionBuilding( this.transaction = new TransactionBuilding(
this.globalService.getWalletName(), this.globalService.getWalletName(),
this.globalService.getCoinType(), this.globalService.getCoinType(),
...@@ -108,7 +108,6 @@ export class SendComponent implements OnInit { ...@@ -108,7 +108,6 @@ export class SendComponent implements OnInit {
}, },
error => { error => {
console.log(error); console.log(error);
this.isSending = false;
if (error.status === 0) { if (error.status === 0) {
alert("Something went wrong while connecting to the API. Please restart the application."); alert("Something went wrong while connecting to the API. Please restart the application.");
} else if (error.status >= 400) { } else if (error.status >= 400) {
...@@ -120,23 +119,21 @@ export class SendComponent implements OnInit { ...@@ -120,23 +119,21 @@ export class SendComponent implements OnInit {
} }
} }
}, },
() => this.sendTransaction(this.responseMessage.hex) () => {
this.estimatedFee = this.responseMessage.fee;
this.transactionHex = this.responseMessage.hex;
if (this.isSending) {
this.sendTransaction(this.transactionHex);
}
}
) )
; ;
}; };
private getFeeType(){ public send() {
let feeValue = this.sendForm.get("fee").value; this.isSending = true;
this.buildTransaction();
switch(feeValue){ };
case 1:
return "low";
case 2:
return "medium";
case 3:
return "high";
}
}
private sendTransaction(hex: string) { private sendTransaction(hex: string) {
let transaction = new TransactionSending(hex); let transaction = new TransactionSending(hex);
...@@ -167,6 +164,19 @@ export class SendComponent implements OnInit { ...@@ -167,6 +164,19 @@ export class SendComponent implements OnInit {
; ;
} }
private getFeeType(){
let feeValue = this.sendForm.get("fee").value;
switch(feeValue){
case 1:
return "low";
case 2:
return "medium";
case 3:
return "high";
}
}
private openConfirmationModal() { private openConfirmationModal() {
const modalRef = this.modalService.open(SendConfirmationComponent); const modalRef = this.modalService.open(SendConfirmationComponent);
modalRef.componentInstance.transaction = this.transaction; modalRef.componentInstance.transaction = this.transaction;
......
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