<commit_before>
import StellarSdk from 'stellar-sdk';
import StellarHDWallet from 'stellar-hd-wallet';
import shuffle from 'shuffle-array';

import horizon from '../../core/services/horizon.js';
import translate from '../../core/services/translate.service.js';
import selectFunderModal from './select-funder.html';

export default class CreatePersonalController {

	/* @ngInject */
	constructor($location, Modal, Reviewer, Wallet) {
		this.$location = $location;
		this.Modal = Modal;
		this.Reviewer = Reviewer;
		this.Wallet = Wallet;

		this.state = 1;

		this.account = {
			alias: getAccountName()
		};

		function getAccountName() {
			const accountNum = Wallet.accountList.filter(item => !item.isMultiSig()).length + 1;
			return translate.instant('account.defaultname', {number: accountNum});
		}
	}

	createAccount() {

		const wallet = StellarHDWallet.fromMnemonic(this.mnemonic);
		const publicKey = wallet.getPublicKey(0);
		const secret = wallet.getSecret(0);
		const name = this.account.alias;

		const network = this.account.network;

		const storeAccount = () => {
			const account = this.Wallet.importAccount(publicKey, secret, name, network);
			if (!this.result) {
				account.mnemonic = this.mnemonic;
				account.store();
			}
			this.$location.path('/');
		};

		const funder = this.Wallet.accountList.find(item => {
			return item.alias === this.account.funder && item.network === network;
		});

		if (funder) {

			funder.horizon().loadAccount(funder.id)
			.then(account => {
				const tx = new StellarSdk.TransactionBuilder(account)
				.addOperation(StellarSdk.Operation.createAccount({
					destination: publicKey,
					startingBalance: this.account.amount.toString()
				}))
				.build();

				return {
					tx: tx,
					network: network
				};
			})
			.then(this.Reviewer.review)
			.then(() => storeAccount);
		}

		else {
			storeAccount();
		}
	}

	hasValidFunder() {
		const name = this.account.funder;
		const network = this.account.network;
		return this.Wallet.hasAccount(name, network);
	}

	tap1(index) {
		this.result.push(this.words[index]);
		this.words.splice(index, 1);
		this.match = this.result.join(' ') === this.mnemonic;
	}

	tap2(index) {
		this.words.push(this.result[index]);
		this.result.splice(index, 1);
	}

	skip() {
		this.state = 4;
		this.next();
	}

	next() {
		if (this.state === 1) {
			this.minBalance = horizon.getMinimumAccountBalance(this.account.network);
			this.state = 2;
		}
<commit_msg>Fix a bug when skipping backup on account creation w/ a funder<commit_after>
import StellarSdk from 'stellar-sdk';
import StellarHDWallet from 'stellar-hd-wallet';
import shuffle from 'shuffle-array';

import horizon from '../../core/services/horizon.js';
import translate from '../../core/services/translate.service.js';
import selectFunderModal from './select-funder.html';

export default class CreatePersonalController {

	/* @ngInject */
	constructor($location, Modal, Reviewer, Wallet) {
		this.$location = $location;
		this.Modal = Modal;
		this.Reviewer = Reviewer;
		this.Wallet = Wallet;

		this.state = 1;

		this.account = {
			alias: getAccountName()
		};

		function getAccountName() {
			const accountNum = Wallet.accountList.filter(item => !item.isMultiSig()).length + 1;
			return translate.instant('account.defaultname', {number: accountNum});
		}
	}

	createAccount() {

		const wallet = StellarHDWallet.fromMnemonic(this.mnemonic);
		const publicKey = wallet.getPublicKey(0);
		const secret = wallet.getSecret(0);
		const name = this.account.alias;

		const network = this.account.network;

		const storeAccount = () => {
			const account = this.Wallet.importAccount(publicKey, secret, name, network);
			if (!this.result) {
				account.mnemonic = this.mnemonic;
				account.store();
			}
			this.$location.path('/');
		};

		const funder = this.Wallet.accountList.find(item => {
			return item.alias === this.account.funder && item.network === network;
		});

		if (funder) {

			funder.horizon().loadAccount(funder.id)
			.then(account => {
				const tx = new StellarSdk.TransactionBuilder(account)
				.addOperation(StellarSdk.Operation.createAccount({
					destination: publicKey,
					startingBalance: this.account.amount.toString()
				}))
				.build();

				return {
					tx: tx,
					network: network
				};
			})
			.then(this.Reviewer.review)
			.then(storeAccount);
		}

		else {
			storeAccount();
		}
	}

	hasValidFunder() {
		const name = this.account.funder;
		const network = this.account.network;
		return this.Wallet.hasAccount(name, network);
	}

	tap1(index) {
		this.result.push(this.words[index]);
		this.words.splice(index, 1);
		this.match = this.result.join(' ') === this.mnemonic;
	}

	tap2(index) {
		this.words.push(this.result[index]);
		this.result.splice(index, 1);
	}

	skip() {
		this.createAccount();
	}

	next() {
		if (this.state === 1) {
			this.minBalance = horizon.getMinimumAccountBalance(this.account.network);
			this.state = 2;
		}

{'fraction_non_alphanumeric': 0.15012106537530268, 'fraction_numerical': 0.00423728813559322, 'mean_word_length': 3.5940685820203893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2135033', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1625, 'n_words': 314}