Skip to content

Commit

Permalink
Merge pull request #115 from AndreiIarovoi/SKC-00009
Browse files Browse the repository at this point in the history
Issue #112: The option to add an address should be always visible
  • Loading branch information
Senyoret1 authored May 14, 2018
2 parents aff62c7 + a5a8ff8 commit 28d64c7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 12 deletions.
13 changes: 13 additions & 0 deletions e2e/wallets.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ describe('Wallets', () => {
page.navigateTo();
expect<any>(page.canUnlock()).toEqual(true);
});

it('should always display add new address button for the wallet', () => {
page.navigateTo();
expect<any>(page.showAddAddress()).toEqual(true);
});

it('should display unlock wallet component on add new address for locked wallet', () => {
expect<any>(page.showShowUnlockWallet()).toEqual(true);
});

it('should unlock wallet component on add new address for locked wallet', () => {
expect<any>(page.unlockWallet()).toEqual(true);
});
});
35 changes: 30 additions & 5 deletions e2e/wallets.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export class WalletsPage {
const btnCreate = element(by.buttonText('Create'));

label.clear();
label.sendKeys('Test wallet');
label.sendKeys('Test create wallet');
seed.clear();
seed.sendKeys('skycoin-web-e2e-test-seed');
seed.sendKeys('skycoin-web-e2e-test-create-wallet-seed');
confirm.clear();
confirm.sendKeys('skycoin-web-e2e-test-seed');
confirm.sendKeys('skycoin-web-e2e-test-create-wallet-seed');
return btnCreate.isEnabled().then(status => {
if (status) {
btnCreate.click();
Expand Down Expand Up @@ -160,8 +160,9 @@ export class WalletsPage {
}

hideEmptyAddress() {
return element(by.css('.-btn-minus')).click().then(() => {
return element.all(by.css('.coins-column')).filter((address) => {
return element.all(by.css('.-btn-minus')).first().click().then(() => {
const parentWalletElement = element.all(by.css('.-wallet-detail')).first();
return parentWalletElement.all(by.css('.coins-column')).filter((address) => {
return address.getText().then(value => {
return value === '0';
});
Expand Down Expand Up @@ -223,6 +224,30 @@ export class WalletsPage {
});
}

showAddAddress() {
return element.all(by.css('.-expand.rotate-90')).first().click().then(() => {
return element(by.css('.btn-add-address')).isPresent();
});
}

showShowUnlockWallet() {
return element(by.css('.btn-add-address')).click().then(() => {
return element(by.css('app-unlock-wallet')).isPresent();
});
}

unlockWallet() {
const seed = element(by.css('[formcontrolname="seed"]'));
seed.clear();
seed.sendKeys('skycoin-web-e2e-test-seed');

return element(by.buttonText('Unlock')).click().then(() => {
return (element(by.css('app-unlock-wallet')).isPresent()).then((result) => {
return !result;
});
});
}

showPriceInformation() {
return element(by.css('.balance p.dollars')).getText().then(text => {
return this._checkHeaderPriceFormat(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</div>
</ng-container>
<div class="-actions">
<div class="-button" (click)="newAddress()" *ngIf="wallet.seed && wallet.addresses[wallet.addresses.length -1].next_seed">
<div class="-btn-plus">
<div class="-button" (click)="onAddNewAddress()">
<div class="-btn-plus btn-add-address">
<img src="../../../../../assets/img/plus-grey.png">
<span>New Address</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialog } from '@angular/material';
import { MatDialog, MatSnackBar } from '@angular/material';

import { WalletDetailComponent } from './wallet-detail.component';
import { WalletService } from '../../../../services/wallet.service';
Expand All @@ -16,7 +16,8 @@ describe('WalletDetailComponent', () => {
declarations: [ WalletDetailComponent ],
providers: [
{ provide: WalletService, useClass: MockWalletService },
{ provide: MatDialog, useValue: {} }
{ provide: MatDialog, useValue: {} },
{ provide: MatSnackBar, useValue: {} }
]
}).compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Component, Input } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material';

import { Wallet } from '../../../../app.datatypes';
import { WalletService } from '../../../../services/wallet.service';
import { QrCodeComponent } from '../../../layout/qr-code/qr-code.component';
import { ChangeNameComponent } from '../change-name/change-name.component';
import { openUnlockWalletModal } from '../../../../utils/index';

@Component({
selector: 'app-wallet-detail',
Expand All @@ -16,6 +19,7 @@ export class WalletDetailComponent {
constructor(
private walletService: WalletService,
private dialog: MatDialog,
private snackBar: MatSnackBar,
) {}

showQr(address) {
Expand All @@ -31,8 +35,13 @@ export class WalletDetailComponent {
this.dialog.open(ChangeNameComponent, config);
}

newAddress() {
this.walletService.addAddress(this.wallet);
onAddNewAddress() {
if (!this.wallet.seed || !this.wallet.addresses[this.wallet.addresses.length - 1].next_seed) {
openUnlockWalletModal(this.wallet, this.dialog).componentInstance.onWalletUnlocked
.subscribe(() => this.addNewAddress());
} else {
this.addNewAddress();
}
}

toggleEmpty() {
Expand Down Expand Up @@ -62,4 +71,14 @@ export class WalletDetailComponent {
address.isCopying = false;
}, 500);
}

private addNewAddress() {
try {
this.walletService.addAddress(this.wallet);
} catch (exception) {
const config = new MatSnackBarConfig();
config.duration = 5000;
this.snackBar.open(exception.message, null, config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class UnlockWalletComponent implements OnInit {
public dialogRef: MatDialogRef<UnlockWalletComponent>,
private formBuilder: FormBuilder,
private walletService: WalletService,
private snackbar: MatSnackBar,
private snackbar: MatSnackBar
) {}

ngOnInit() {
Expand Down

0 comments on commit 28d64c7

Please sign in to comment.