-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/app/components/walletconnect-from-to/walletconnect-from-to.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<ng-container> | ||
<airgap-from-to [transaction]="airGapTransaction"></airgap-from-to> | ||
</ng-container> | ||
<ng-container *ngIf="rawTransaction !== undefined"> | ||
<ion-row class="rawdata--container ion-padding-bottom ion-margin-bottom"> | ||
<ion-col class="ion-no-padding"> | ||
<ion-item class="ion-no-padding" lines="none"> | ||
<ion-label>Change Fees</ion-label> | ||
<ion-toggle [(ngModel)]="advanced" slot="end" (ngModelChange)="initForms()"></ion-toggle> | ||
</ion-item> | ||
|
||
<ng-container *ngIf="advanced && formGroup !== undefined"> | ||
<form [formGroup]="formGroup" class="ion-padding-bottom"> | ||
<ion-row class="padding-top"> | ||
<ion-col size="6"> | ||
<ion-item mode="md" color="light"> | ||
<ion-label class="ion-no-margin" position="stacked">Gas Price</ion-label> | ||
<ion-input type="text" formControlName="gasPrice" id="gasPrice"></ion-input> | ||
</ion-item> | ||
</ion-col> | ||
<ion-col size="6"> | ||
<ion-item mode="md" color="light"> | ||
<ion-label class="ion-no-margin" position="stacked">Gas Limit</ion-label> | ||
<ion-input type="text" formControlName="gasLimit" id="gasLimit"></ion-input> | ||
</ion-item> | ||
</ion-col> | ||
</ion-row> | ||
</form> | ||
|
||
<ion-button color="primary" (click)="updateRawTransaction()" [disabled]="formGroup.invalid">Update</ion-button> | ||
</ng-container> | ||
</ion-col> | ||
</ion-row> | ||
</ng-container> |
Empty file.
58 changes: 58 additions & 0 deletions
58
src/app/components/walletconnect-from-to/walletconnect-from-to.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Component, Input, Output, EventEmitter } from '@angular/core' | ||
import { IAirGapTransaction, RawEthereumTransaction } from '@airgap/coinlib-core' | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms' | ||
import BigNumber from 'bignumber.js' | ||
|
||
@Component({ | ||
selector: 'walletconnect-from-to', | ||
templateUrl: './walletconnect-from-to.component.html', | ||
styleUrls: ['./walletconnect-from-to.component.scss'] | ||
}) | ||
export class WalletconnectFromToComponent { | ||
public formGroup: FormGroup | undefined | ||
|
||
@Input() | ||
public airGapTransaction: IAirGapTransaction | undefined | ||
|
||
@Input() | ||
public rawTransaction: RawEthereumTransaction | undefined | ||
|
||
@Output() | ||
public readonly onRawTransactionUpdate: EventEmitter<RawEthereumTransaction> = new EventEmitter<RawEthereumTransaction>() | ||
|
||
constructor(private readonly formBuilder: FormBuilder) {} | ||
|
||
public advanced: boolean = false | ||
|
||
public async initForms() { | ||
const gasLimitValue = this.hexToDecimal(this.rawTransaction.gasLimit) | ||
const gasPriceValue = new BigNumber(this.hexToDecimal(this.rawTransaction.gasPrice)).shiftedBy(-9).toNumber() | ||
|
||
const gasPriceControl = this.formBuilder.control(gasPriceValue, [Validators.required, Validators.min(0)]) | ||
const gasLimitControl = this.formBuilder.control(gasLimitValue, [Validators.required, Validators.min(0)]) | ||
|
||
this.formGroup = this.formBuilder.group({ | ||
gasPrice: gasPriceControl, | ||
gasLimit: gasLimitControl | ||
}) | ||
} | ||
|
||
private hexToDecimal(hex: string): number { | ||
return parseInt(hex, 16) | ||
} | ||
private decimalToHex(decimal: number): string { | ||
return `0x${decimal.toString(16)}` | ||
} | ||
|
||
public async updateRawTransaction() { | ||
const gasPriceValue = this.decimalToHex(new BigNumber(this.formGroup.controls.gasPrice.value).shiftedBy(9).toNumber()) | ||
|
||
this.rawTransaction = { | ||
...this.rawTransaction, | ||
gasPrice: gasPriceValue, | ||
gasLimit: this.decimalToHex(this.formGroup.controls.gasLimit.value) | ||
} | ||
this.onRawTransactionUpdate.emit(this.rawTransaction) | ||
this.advanced = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters