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

Commit

Permalink
Pause WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ianadavies committed Aug 23, 2019
1 parent e385f0a commit 05e6840
Show file tree
Hide file tree
Showing 23 changed files with 540 additions and 611 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
Expand All @@ -15,51 +15,84 @@ import { GlobalService } from '@shared/services/global.service';
templateUrl: './confirm-mnemonic.component.html',
styleUrls: ['./confirm-mnemonic.component.css']
})
export class ConfirmMnemonicComponent implements OnInit {

public secretWordIndexGenerator = new SecretWordIndexGenerator();

constructor(private apiService: ApiService, private genericModalService: ModalService, private route: ActivatedRoute, private router: Router, private fb: FormBuilder, private globalService: GlobalService) {
export class ConfirmMnemonicComponent implements OnInit, OnDestroy {

constructor(
private apiService: ApiService,
private genericModalService: ModalService,
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private globalService: GlobalService) {
this.buildMnemonicForm();
}

public secretWordIndexGenerator = new SecretWordIndexGenerator();
private newWallet: WalletCreation;
private subscription: Subscription;
public sidechainEnabled: boolean;
public mnemonicForm: FormGroup;
public matchError: string = "";
public matchError = '';
public isCreating: boolean;

formErrors = {
'word1': '',
'word2': '',
'word3': ''
};

validationMessages = {
'word1': {
'required': 'This secret word is required.',
'minlength': 'A secret word must be at least one character long',
'maxlength': 'A secret word can not be longer than 24 characters',
'pattern': 'Please enter a valid scret word. [a-Z] are the only characters allowed.'
},
'word2': {
'required': 'This secret word is required.',
'minlength': 'A secret word must be at least one character long',
'maxlength': 'A secret word can not be longer than 24 characters',
'pattern': 'Please enter a valid scret word. [a-Z] are the only characters allowed.'
},
'word3': {
'required': 'This secret word is required.',
'minlength': 'A secret word must be at least one character long',
'maxlength': 'A secret word can not be longer than 24 characters',
'pattern': 'Please enter a valid scret word. [a-Z] are the only characters allowed.'
}
};

ngOnInit() {
this.sidechainEnabled = this.globalService.getSidechainEnabled();
this.subscription = this.route.queryParams.subscribe(params => {
this.newWallet = new WalletCreation(
params["name"],
params["mnemonic"],
params["password"],
params["passphrase"]
)
params['name'],
params['mnemonic'],
params['password'],
params['passphrase']
);
});
}

private buildMnemonicForm(): void {
this.mnemonicForm = this.fb.group({
"word1": ["",
'word1': ['',
Validators.compose([
Validators.required,
Validators.minLength(1),
Validators.maxLength(24),
Validators.pattern(/^[a-zA-Z]*$/)
])
],
"word2": ["",
'word2': ['',
Validators.compose([
Validators.required,
Validators.minLength(1),
Validators.maxLength(24),
Validators.pattern(/^[a-zA-Z]*$/)
])
],
"word3": ["",
'word3': ['',
Validators.compose([
Validators.required,
Validators.minLength(1),
Expand All @@ -76,7 +109,9 @@ export class ConfirmMnemonicComponent implements OnInit {
}

onValueChanged(data?: any) {
if (!this.mnemonicForm) { return; }
if (!this.mnemonicForm) {
return;
}
const form = this.mnemonicForm;
for (const field in this.formErrors) {
this.formErrors[field] = '';
Expand All @@ -89,36 +124,9 @@ export class ConfirmMnemonicComponent implements OnInit {
}
}

this.matchError = "";
this.matchError = '';
}

formErrors = {
'word1': '',
'word2': '',
'word3': ''
};

validationMessages = {
'word1': {
'required': 'This secret word is required.',
'minlength': 'A secret word must be at least one character long',
'maxlength': 'A secret word can not be longer than 24 characters',
'pattern': 'Please enter a valid scret word. [a-Z] are the only characters allowed.'
},
'word2': {
'required': 'This secret word is required.',
'minlength': 'A secret word must be at least one character long',
'maxlength': 'A secret word can not be longer than 24 characters',
'pattern': 'Please enter a valid scret word. [a-Z] are the only characters allowed.'
},
'word3': {
'required': 'This secret word is required.',
'minlength': 'A secret word must be at least one character long',
'maxlength': 'A secret word can not be longer than 24 characters',
'pattern': 'Please enter a valid scret word. [a-Z] are the only characters allowed.'
}
};

public onConfirmClicked() {
this.checkMnemonic();
if (this.checkMnemonic()) {
Expand All @@ -128,19 +136,26 @@ export class ConfirmMnemonicComponent implements OnInit {
}

public onBackClicked() {
this.router.navigate(['/setup/create/show-mnemonic'], { queryParams : { name: this.newWallet.name, mnemonic: this.newWallet.mnemonic, password: this.newWallet.password, passphrase: this.newWallet.passphrase }});
this.router.navigate(['/setup/create/show-mnemonic'], {
queryParams: {
name: this.newWallet.name,
mnemonic: this.newWallet.mnemonic,
password: this.newWallet.password,
passphrase: this.newWallet.passphrase
}
});
}

private checkMnemonic(): boolean {
let mnemonic = this.newWallet.mnemonic;
let mnemonicArray = mnemonic.split(" ");
const mnemonic = this.newWallet.mnemonic;
const mnemonicArray = mnemonic.split(' ');

if (this.mnemonicForm.get('word1').value.trim() === mnemonicArray[this.secretWordIndexGenerator.index1] &&
this.mnemonicForm.get('word2').value.trim() === mnemonicArray[this.secretWordIndexGenerator.index2] &&
this.mnemonicForm.get('word3').value.trim() === mnemonicArray[this.secretWordIndexGenerator.index3]) {
this.mnemonicForm.get('word2').value.trim() === mnemonicArray[this.secretWordIndexGenerator.index2] &&
this.mnemonicForm.get('word3').value.trim() === mnemonicArray[this.secretWordIndexGenerator.index3]) {
return true;
} else {
this.matchError = 'The secret words do not match.'
this.matchError = 'The secret words do not match.';
return false;
}
}
Expand All @@ -149,12 +164,17 @@ export class ConfirmMnemonicComponent implements OnInit {
this.apiService.createStratisWallet(wallet)
.subscribe(
response => {
this.genericModalService.openModal("Wallet Created", "Your wallet has been created.<br>Keep your secret words, password and passphrase safe!");
this.genericModalService.openModal(
'Wallet Created', 'Your wallet has been created.<br>Keep your secret words, password and passphrase safe!');
this.router.navigate(['']);
},
error => {
this.isCreating = false;
}
);
}

public ngOnDestroy(): void {

}
}
25 changes: 24 additions & 1 deletion StratisCore.UI/src/app/shared/models/transaction-info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { TransactionsHistoryItem } from '@shared/services/interfaces/api.i';

export class TransactionInfo {
constructor(transactionType: string, transactionId: string, transactionAmount: number, transactionFee: number, transactionConfirmedInBlock: number, transactionTimestamp: number) {
constructor(
transactionType: string,
transactionId: string,
transactionAmount: number,
transactionFee: number,
transactionConfirmedInBlock: number,
transactionTimestamp: number) {
this.transactionType = transactionType;
this.transactionId = transactionId;
this.transactionAmount = transactionAmount;
Expand All @@ -14,4 +22,19 @@ export class TransactionInfo {
public transactionFee: number;
public transactionConfirmedInBlock?: number;
public transactionTimestamp: number;

public static mapFromTransactionsHistoryItems(transactions: TransactionsHistoryItem[], maxTransactionCount?: number): TransactionInfo[] {
const mapped = transactions.map(transaction => {
return new TransactionInfo(
transaction.type === 'send' ? 'sent' : transaction.type,
transaction.id,
transaction.amount,
transaction.fee || 0,
transaction.confirmedInBlock,
transaction.timestamp);
});

return maxTransactionCount ? mapped.slice(0, maxTransactionCount) : mapped;

}
}
Loading

0 comments on commit 05e6840

Please sign in to comment.