Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
Return account address as the receive address
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowan de Haas committed Jul 30, 2019
1 parent 776428d commit 1815296
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 52 deletions.
96 changes: 49 additions & 47 deletions StratisCore.UI/src/app/wallet/receive/receive.component.html
Expand Up @@ -22,55 +22,57 @@ <h5 class="modal-title">Receive</h5>
</div>
</div>
</form>

<ng-container *ngIf="!accountsEnabled">
<div class="text-left">
<a *ngIf="showAll" class="link" (click)="showOneAddress()">← back to one address</a>
</div>

<div class="text-left">
<a *ngIf="showAll" class="link" (click)="showOneAddress()">← back to one address</a>
</div>

<form *ngIf="showAll">
<ngb-tabset class="nav nav-tabs mt-4">
<ngb-tab title="Unused Addresses">
<ng-template ngbTabContent class="fullwidth">
<div *ngFor="let unusedAddress of unusedAddresses | paginate: { itemsPerPage: 5, currentPage: pageNumberUnused }" class="tab-pane-line">
<code class="d-inline-block">{{ unusedAddress }}</code>
<button type="button" class="btn btn-outline-secondary d-inline-block float-right btn-sm"
ngxClipboard [cbContent]="unusedAddress" (click)="onCopiedClick()">
<i class="lnr lnr-file-add"></i> copy
</button>
</div>
<pagination-controls (pageChange)="pageNumberUnused = $event"></pagination-controls>
</ng-template>
</ngb-tab>
<ngb-tab title="Used Addresses">
<ng-template ngbTabContent>
<div *ngFor="let usedAddress of usedAddresses | paginate: { itemsPerPage: 5, currentPage: pageNumberUsed }" class="tab-pane-line">
<code class="d-inline-block">{{ usedAddress }}</code>
<button type="button" class="btn btn-outline-secondary d-inline-block float-right btn-sm"
ngxClipboard [cbContent]="usedAddress" (click)="onCopiedClick()">
<i class="lnr lnr-file-add"></i> copy
</button>
</div>
<pagination-controls (pageChange)="pageNumberUsed = $event"></pagination-controls>
</ng-template>
</ngb-tab>
<ngb-tab title="Change Addresses">
<ng-template ngbTabContent>
<div *ngFor="let changeAddress of changeAddresses | paginate: { itemsPerPage: 5, currentPage: pageNumberChange }" class="tab-pane-line">
<code class="d-inline-block">{{ changeAddress }}</code>
<button type="button" class="btn btn-outline-secondary d-inline-block float-right btn-sm"
ngxClipboard [cbContent]="changeAddress" (click)="onCopiedClick()">
<i class="lnr lnr-file-add"></i> copy
</button>
</div>
<pagination-controls (pageChange)="pageNumberChange = $event"></pagination-controls>
</ng-template>
</ngb-tab>
</ngb-tabset>
</form>
<form *ngIf="showAll">
<ngb-tabset class="nav nav-tabs mt-4">
<ngb-tab title="Unused Addresses">
<ng-template ngbTabContent class="fullwidth">
<div *ngFor="let unusedAddress of unusedAddresses | paginate: { itemsPerPage: 5, currentPage: pageNumberUnused }" class="tab-pane-line">
<code class="d-inline-block">{{ unusedAddress }}</code>
<button type="button" class="btn btn-outline-secondary d-inline-block float-right btn-sm"
ngxClipboard [cbContent]="unusedAddress" (click)="onCopiedClick()">
<i class="lnr lnr-file-add"></i> copy
</button>
</div>
<pagination-controls (pageChange)="pageNumberUnused = $event"></pagination-controls>
</ng-template>
</ngb-tab>
<ngb-tab title="Used Addresses">
<ng-template ngbTabContent>
<div *ngFor="let usedAddress of usedAddresses | paginate: { itemsPerPage: 5, currentPage: pageNumberUsed }" class="tab-pane-line">
<code class="d-inline-block">{{ usedAddress }}</code>
<button type="button" class="btn btn-outline-secondary d-inline-block float-right btn-sm"
ngxClipboard [cbContent]="usedAddress" (click)="onCopiedClick()">
<i class="lnr lnr-file-add"></i> copy
</button>
</div>
<pagination-controls (pageChange)="pageNumberUsed = $event"></pagination-controls>
</ng-template>
</ngb-tab>
<ngb-tab title="Change Addresses">
<ng-template ngbTabContent>
<div *ngFor="let changeAddress of changeAddresses | paginate: { itemsPerPage: 5, currentPage: pageNumberChange }" class="tab-pane-line">
<code class="d-inline-block">{{ changeAddress }}</code>
<button type="button" class="btn btn-outline-secondary d-inline-block float-right btn-sm"
ngxClipboard [cbContent]="changeAddress" (click)="onCopiedClick()">
<i class="lnr lnr-file-add"></i> copy
</button>
</div>
<pagination-controls (pageChange)="pageNumberChange = $event"></pagination-controls>
</ng-template>
</ngb-tab>
</ngb-tabset>
</form>

<div class="text-center">
<button *ngIf="!showAll" type="button" class="btn btn-link" (click)="showAllAddresses()">Show all addresses</button>
</div>
<div class="text-center">
<button *ngIf="!showAll" type="button" class="btn btn-link" (click)="showAllAddresses()">Show all addresses</button>
</div>
</ng-container>

<div *ngIf="copied" class="alert alert-success alert-dismissible fade show mt-3 mb-0" role="alert">Your address has
been copied to your clipboard.</div>
Expand Down
29 changes: 24 additions & 5 deletions StratisCore.UI/src/app/wallet/receive/receive.component.ts
Expand Up @@ -7,6 +7,7 @@ import { ModalService } from '@shared/services/modal.service';
import { WalletInfo } from '@shared/models/wallet-info';

import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { CurrentAccountService } from '@shared/services/current-account.service';

@Component({
selector: 'receive-component',
Expand All @@ -15,7 +16,8 @@ import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
})

export class ReceiveComponent {
constructor(private apiService: ApiService, private globalService: GlobalService, public activeModal: NgbActiveModal, private genericModalService: ModalService) {}
accountsEnabled: boolean;
constructor(private apiService: ApiService, private globalService: GlobalService, public activeModal: NgbActiveModal, private genericModalService: ModalService, private currentAccountService: CurrentAccountService) {}

public address: any = "";
public qrString: any;
Expand All @@ -33,7 +35,15 @@ export class ReceiveComponent {

ngOnInit() {
this.sidechainEnabled = this.globalService.getSidechainEnabled();
this.getUnusedReceiveAddresses();
this.accountsEnabled = this.sidechainEnabled && this.currentAccountService.hasActiveAddress();

if (!this.accountsEnabled) {
this.getUnusedReceiveAddresses();
}
else {
// If accounts are enabled, we just use the account address
this.getAccountAddress();
}
}

public onCopiedClick() {
Expand All @@ -56,13 +66,22 @@ export class ReceiveComponent {
.subscribe(
response => {
this.address = response;
// TODO: fix this later to use the actual sidechain name instead of 'cirrus'
const networkName = this.globalService.getSidechainEnabled() ? 'cirrus' : 'stratis';
this.qrString = `${networkName}:${response}`;
this.setQrString(response);
}
);
}

private getAccountAddress() {
this.address = this.currentAccountService.getAddress();
this.setQrString(this.address);
}

private setQrString(address: string) {
// TODO: fix this later to use the actual sidechain name instead of 'cirrus'
const networkName = this.globalService.getSidechainEnabled() ? 'cirrus' : 'stratis';
this.qrString = `${networkName}:${address}`;
}

private getAddresses() {
let walletInfo = new WalletInfo(this.globalService.getWalletName())
this.apiService.getAllAddresses(walletInfo)
Expand Down

0 comments on commit 1815296

Please sign in to comment.