-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add passphrase compatibility to the hw wallet #2218
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,14 +1,17 @@ | ||||||
import { Component, Inject } from '@angular/core'; | ||||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; | ||||||
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog, MatDialogConfig } from '@angular/material/dialog'; | ||||||
import { WalletService } from '../../../../services/wallet.service'; | ||||||
import { HwWalletService } from '../../../../services/hw-wallet.service'; | ||||||
import { ChildHwDialogParams } from '../hw-options-dialog/hw-options-dialog.component'; | ||||||
import { HwDialogBaseComponent } from '../hw-dialog-base.component'; | ||||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms'; | ||||||
import { Wallet } from '../../../../app.datatypes'; | ||||||
import { HwPassphraseHelpDialogComponent } from '../hw-passphrase-help-dialog/hw-passphrase-help-dialog.component'; | ||||||
|
||||||
enum States { | ||||||
Initial, | ||||||
PassphraseWarning, | ||||||
Adding, | ||||||
Finished, | ||||||
Failed, | ||||||
} | ||||||
|
@@ -20,7 +23,7 @@ enum States { | |||||
}) | ||||||
export class HwAddedDialogComponent extends HwDialogBaseComponent<HwAddedDialogComponent> { | ||||||
|
||||||
closeIfHwDisconnected = false; | ||||||
closeIfHwDisconnected = true; | ||||||
|
||||||
currentState: States = States.Initial; | ||||||
states = States; | ||||||
|
@@ -34,8 +37,26 @@ export class HwAddedDialogComponent extends HwDialogBaseComponent<HwAddedDialogC | |||||
private walletService: WalletService, | ||||||
hwWalletService: HwWalletService, | ||||||
private formBuilder: FormBuilder, | ||||||
private dialog: MatDialog, | ||||||
) { | ||||||
super(hwWalletService, dialogRef); | ||||||
this.operationSubscription = hwWalletService.getFeatures().subscribe(features => { | ||||||
if (features.rawResponse.passphraseProtection) { | ||||||
this.currentState = States.PassphraseWarning; | ||||||
} else { | ||||||
this.startAdding(); | ||||||
} | ||||||
}); | ||||||
} | ||||||
|
||||||
cancel() { | ||||||
this.data.requestOptionsComponentRefresh('hardware-wallet.added.canceled'); | ||||||
this.closeModal(); | ||||||
} | ||||||
|
||||||
startAdding() { | ||||||
this.currentState = States.Adding; | ||||||
|
||||||
this.operationSubscription = this.walletService.createHardwareWallet().subscribe(wallet => { | ||||||
this.walletService.updateWalletHasHwSecurityWarnings(wallet).subscribe(() => { | ||||||
this.wallet = wallet; | ||||||
|
@@ -44,6 +65,7 @@ export class HwAddedDialogComponent extends HwDialogBaseComponent<HwAddedDialogC | |||||
label: [wallet.label, Validators.required], | ||||||
}); | ||||||
|
||||||
this.closeIfHwDisconnected = false; | ||||||
this.currentState = States.Finished; | ||||||
this.data.requestOptionsComponentRefresh(); | ||||||
}); | ||||||
|
@@ -58,4 +80,10 @@ export class HwAddedDialogComponent extends HwDialogBaseComponent<HwAddedDialogC | |||||
this.walletService.saveHardwareWallets(); | ||||||
this.closeModal(); | ||||||
} | ||||||
|
||||||
openHelp() { | ||||||
this.dialog.open(HwPassphraseHelpDialogComponent, <MatDialogConfig> { | ||||||
width: '450px', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Strings must use doublequote.
Suggested change
|
||||||
}); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ import { HwChangePinDialogComponent } from '../hw-change-pin-dialog/hw-change-pi | |||||
import { HwRestoreSeedDialogComponent } from '../hw-restore-seed-dialog/hw-restore-seed-dialog.component'; | ||||||
import { Observable } from 'rxjs/Observable'; | ||||||
import { HwDialogBaseComponent } from '../hw-dialog-base.component'; | ||||||
import { HwPassphraseActivationDialogComponent } from '../hw-passphrase-activation-dialog/hw-passphrase-activation-dialog.component'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Strings must use doublequote.
Suggested change
|
||||||
|
||||||
enum States { | ||||||
Disconnected, | ||||||
|
@@ -26,6 +27,7 @@ enum States { | |||||
export interface ChildHwDialogParams { | ||||||
wallet: Wallet; | ||||||
walletHasPin: boolean; | ||||||
walletHasPassphrase: boolean; | ||||||
requestOptionsComponentRefresh: any; | ||||||
} | ||||||
|
||||||
|
@@ -44,6 +46,7 @@ export class HwOptionsDialogComponent extends HwDialogBaseComponent<HwOptionsDia | |||||
customErrorMsg = ''; | ||||||
needsBackup: boolean; | ||||||
needsPin: boolean; | ||||||
hasPassphrase: boolean; | ||||||
|
||||||
private dialogSubscription: ISubscription; | ||||||
|
||||||
|
@@ -97,6 +100,10 @@ export class HwOptionsDialogComponent extends HwDialogBaseComponent<HwOptionsDia | |||||
this.openDialog(HwRestoreSeedDialogComponent); | ||||||
} | ||||||
|
||||||
changePassphraseActivation() { | ||||||
this.openDialog(HwPassphraseActivationDialogComponent); | ||||||
} | ||||||
|
||||||
private openDialog(dialogType) { | ||||||
this.customErrorMsg = ''; | ||||||
|
||||||
|
@@ -108,6 +115,7 @@ export class HwOptionsDialogComponent extends HwDialogBaseComponent<HwOptionsDia | |||||
config.data = <ChildHwDialogParams> { | ||||||
wallet: this.wallet, | ||||||
walletHasPin: !this.needsPin, | ||||||
walletHasPassphrase: this.hasPassphrase, | ||||||
requestOptionsComponentRefresh: ((error: string = null, recheckSecurityOnly: boolean = false) => { | ||||||
if (!error) { | ||||||
if (!recheckSecurityOnly) { | ||||||
|
@@ -147,6 +155,7 @@ export class HwOptionsDialogComponent extends HwDialogBaseComponent<HwOptionsDia | |||||
return this.walletService.updateWalletHasHwSecurityWarnings(this.wallet).map(warnings => { | ||||||
this.needsBackup = warnings.includes(HwSecurityWarnings.NeedsBackup); | ||||||
this.needsPin = warnings.includes(HwSecurityWarnings.NeedsPin); | ||||||
this.hasPassphrase = warnings.includes(HwSecurityWarnings.HasPassphrase); | ||||||
|
||||||
return warnings; | ||||||
}); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<app-modal class="modal" | ||
[headline]="(activating ? 'hardware-wallet.options.activate-passphrase' : 'hardware-wallet.options.deactivate-passphrase') | translate" | ||
[dialog]="dialogRef" | ||
[disableDismiss]="currentState === states.Processing"> | ||
<div *ngIf="currentState === states.Initial"> | ||
<app-hw-message | ||
[text]="(activating ? 'hardware-wallet.activate-passphrase.warning-activate' : 'hardware-wallet.activate-passphrase.warning-deactivate') | translate" | ||
[linkText]="'hardware-wallet.passphrase-help.link' | translate" | ||
[icon]="msgIcons.Warning" | ||
(linkClicked)="openHelp()" | ||
></app-hw-message> | ||
|
||
<div class="-buttons"> | ||
<app-button (action)="closeModal()"> | ||
{{ 'hardware-wallet.general.cancel' | translate }} | ||
</app-button> | ||
<app-button (action)="changeConfig()" class="primary"> | ||
{{ 'hardware-wallet.general.continue' | translate }} | ||
</app-button> | ||
</div> | ||
</div> | ||
|
||
<div *ngIf="currentState !== states.Initial"> | ||
<app-hw-message *ngIf="currentState === states.Processing" | ||
[text]="'hardware-wallet.general.confirm' | translate" | ||
[icon]="msgIcons.Confirm" | ||
></app-hw-message> | ||
|
||
<app-hw-message *ngIf="currentState === states.ReturnedSuccess" | ||
[text]="'hardware-wallet.general.completed' | translate" | ||
[icon]="msgIcons.Success" | ||
></app-hw-message> | ||
|
||
<app-hw-message *ngIf="currentState === states.ReturnedRefused" | ||
[text]="'hardware-wallet.general.refused' | translate" | ||
[icon]="msgIcons.Error" | ||
></app-hw-message> | ||
|
||
<app-hw-message *ngIf="currentState === states.Failed" | ||
[text]="'hardware-wallet.general.generic-error' | translate" | ||
[icon]="msgIcons.Error" | ||
></app-hw-message> | ||
|
||
<div class="-buttons" *ngIf="currentState !== states.Processing"> | ||
<app-button (action)="closeModal()" class="primary"> | ||
{{ 'hardware-wallet.general.close' | translate }} | ||
</app-button> | ||
</div> | ||
</div> | ||
</app-modal> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||
|
||||||
import { HwPassphraseActivationDialogComponent } from './hw-passphrase-activation-dialog.component'; | ||||||
|
||||||
describe('HwPassphraseActivationDialogComponent', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Strings must use doublequote.
Suggested change
|
||||||
let component: HwPassphraseActivationDialogComponent; | ||||||
let fixture: ComponentFixture<HwPassphraseActivationDialogComponent>; | ||||||
|
||||||
beforeEach(async(() => { | ||||||
TestBed.configureTestingModule({ | ||||||
declarations: [ HwPassphraseActivationDialogComponent ], | ||||||
}) | ||||||
.compileComponents(); | ||||||
})); | ||||||
|
||||||
beforeEach(() => { | ||||||
fixture = TestBed.createComponent(HwPassphraseActivationDialogComponent); | ||||||
component = fixture.componentInstance; | ||||||
fixture.detectChanges(); | ||||||
}); | ||||||
|
||||||
it('should be created', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Codacy has a fix for the issue: Strings must use doublequote.
Suggested change
|
||||||
expect(component).toBeTruthy(); | ||||||
}); | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codacy has a fix for the issue: Strings must use doublequote.