Skip to content
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

[Closes #47] Fix wallets creation #49

Merged
merged 10 commits into from
Mar 14, 2018
2 changes: 1 addition & 1 deletion src/entities/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class User {

getNextWalletIndex(): number {
let max = -1;
this.wallets.forEach(w => max = Math.max(max, w.index));
this.wallets.forEach((w, i) => max = Math.max(max, i));
return max + 1;
}

Expand Down
7 changes: 5 additions & 2 deletions src/services/app/user/user.account.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class UserAccountApplication {
return transformers.transformCreatedUser(user, verifyInitiated);
}

private createNewWallet(logger: SubLogger, user: User, paymentPassword: string) {
private async createNewWallet(logger: SubLogger, user: User, paymentPassword: string) {
logger.debug('Create new wallet');

// should be created every time for fresh master key
Expand Down Expand Up @@ -124,8 +124,11 @@ export class UserAccountApplication {
tokens: []
});
newWallet.index = walletIndex;
logger.debug("Wallet index: " + walletIndex);

user.addWallet(newWallet);
logger.debug("Wallets: ", user.wallets);
await this.userRepository.save(user);

return newWallet;
}
Expand Down Expand Up @@ -173,7 +176,7 @@ export class UserAccountApplication {
});
user.passwordHash = bcrypt.hashSync(userData.password);

this.createNewWallet(logger, user, userData.paymentPassword);
await this.createNewWallet(logger, user, userData.paymentPassword);

logger.debug('Save user');

Expand Down