2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2017-01-24 16:18:23 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import { action, computed, observable, transaction } from 'mobx';
|
|
|
|
|
2017-04-21 11:40:22 +02:00
|
|
|
import apiutil from '@parity/api/util';
|
2017-01-24 16:18:23 +01:00
|
|
|
|
|
|
|
import ERRORS from './errors';
|
|
|
|
|
|
|
|
const FAKEPATH = 'C:\\fakepath\\';
|
|
|
|
const STAGE_SELECT_TYPE = 0;
|
|
|
|
const STAGE_CREATE = 1;
|
|
|
|
const STAGE_INFO = 2;
|
2017-06-13 11:02:38 +02:00
|
|
|
const STAGE_CONFIRM_BACKUP = 3;
|
2017-01-24 16:18:23 +01:00
|
|
|
|
|
|
|
export default class Store {
|
|
|
|
@observable accounts = null;
|
|
|
|
@observable address = null;
|
|
|
|
@observable createType = 'fromNew';
|
|
|
|
@observable description = '';
|
|
|
|
@observable gethAccountsAvailable = [];
|
|
|
|
@observable gethAddresses = [];
|
2017-02-23 15:04:58 +01:00
|
|
|
@observable gethImported = [];
|
2017-01-24 16:18:23 +01:00
|
|
|
@observable isBusy = false;
|
|
|
|
@observable isWindowsPhrase = false;
|
|
|
|
@observable name = '';
|
|
|
|
@observable nameError = ERRORS.noName;
|
|
|
|
@observable password = '';
|
|
|
|
@observable passwordHint = '';
|
|
|
|
@observable passwordRepeat = '';
|
|
|
|
@observable phrase = '';
|
2017-06-13 11:02:38 +02:00
|
|
|
@observable backupPhraseAddress = null;
|
|
|
|
@observable phraseBackedUp = '';
|
2017-03-31 23:36:24 +02:00
|
|
|
@observable qrAddress = null;
|
2017-01-24 16:18:23 +01:00
|
|
|
@observable rawKey = '';
|
|
|
|
@observable rawKeyError = ERRORS.nokey;
|
|
|
|
@observable stage = STAGE_SELECT_TYPE;
|
2017-03-03 19:50:54 +01:00
|
|
|
@observable vaultName = '';
|
2017-01-24 16:18:23 +01:00
|
|
|
@observable walletFile = '';
|
|
|
|
@observable walletFileError = ERRORS.noFile;
|
|
|
|
@observable walletJson = '';
|
|
|
|
|
2017-05-18 11:50:16 +02:00
|
|
|
constructor (api, accounts, isTest, loadGeth = true) {
|
2017-01-24 16:18:23 +01:00
|
|
|
this._api = api;
|
|
|
|
this.accounts = Object.assign({}, accounts);
|
2017-05-18 11:50:16 +02:00
|
|
|
this.isTest = isTest;
|
2017-01-24 16:18:23 +01:00
|
|
|
|
|
|
|
if (loadGeth) {
|
|
|
|
this.loadAvailableGethAccounts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed get canCreate () {
|
|
|
|
switch (this.createType) {
|
|
|
|
case 'fromGeth':
|
|
|
|
return this.gethAddresses.length !== 0;
|
|
|
|
|
|
|
|
case 'fromJSON':
|
|
|
|
case 'fromPresale':
|
|
|
|
return !(this.nameError || this.walletFileError);
|
|
|
|
|
|
|
|
case 'fromNew':
|
2017-06-07 16:27:01 +02:00
|
|
|
return !(this.nameError || this.passwordRepeatError) && this.hasAddress && this.hasPhrase;
|
2017-01-24 16:18:23 +01:00
|
|
|
|
|
|
|
case 'fromPhrase':
|
2017-05-18 11:50:16 +02:00
|
|
|
return !(this.nameError || this.passwordRepeatError || this.passPhraseError);
|
2017-01-24 16:18:23 +01:00
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
case 'fromQr':
|
|
|
|
return this.qrAddressValid && !this.nameError;
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
case 'fromRaw':
|
|
|
|
return !(this.nameError || this.passwordRepeatError || this.rawKeyError);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-18 11:50:16 +02:00
|
|
|
@computed get passPhraseError () {
|
|
|
|
return !this.isTest && this.phrase.length === 0;
|
|
|
|
}
|
|
|
|
|
2017-04-03 18:50:11 +02:00
|
|
|
@computed get hasAddress () {
|
|
|
|
return !!(this.address);
|
|
|
|
}
|
|
|
|
|
2017-06-07 16:27:01 +02:00
|
|
|
@computed get hasPhrase () {
|
|
|
|
return this.phrase.length !== 0;
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
@computed get passwordRepeatError () {
|
|
|
|
return this.password === this.passwordRepeat
|
|
|
|
? null
|
|
|
|
: ERRORS.noMatchPassword;
|
|
|
|
}
|
|
|
|
|
2017-06-13 11:02:38 +02:00
|
|
|
@computed get backupPhraseError () {
|
|
|
|
return !this.backupPhraseAddress || this.address === this.backupPhraseAddress
|
|
|
|
? null
|
|
|
|
: ERRORS.noMatchBackupPhrase;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed get phraseBackedUpError () {
|
|
|
|
return this.phraseBackedUp === 'I have written down the phrase'
|
|
|
|
? null
|
|
|
|
: ERRORS.noMatchPhraseBackedUp;
|
|
|
|
}
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
@computed get qrAddressValid () {
|
2017-04-11 16:43:15 +02:00
|
|
|
console.log('qrValid', this.qrAddress, this._api.util.isAddressValid(this.qrAddress));
|
2017-03-31 23:36:24 +02:00
|
|
|
return this._api.util.isAddressValid(this.qrAddress);
|
|
|
|
}
|
|
|
|
|
2017-06-13 11:02:38 +02:00
|
|
|
@action clearPhrase = () => {
|
|
|
|
transaction(() => {
|
|
|
|
this.phrase = '';
|
|
|
|
this.phraseBackedUp = '';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
@action clearErrors = () => {
|
|
|
|
transaction(() => {
|
2017-06-13 11:02:38 +02:00
|
|
|
this.address = '';
|
2017-03-31 23:36:24 +02:00
|
|
|
this.description = '';
|
2017-01-24 16:18:23 +01:00
|
|
|
this.password = '';
|
|
|
|
this.passwordRepeat = '';
|
2017-02-24 12:26:30 +01:00
|
|
|
this.phrase = '';
|
2017-06-13 11:02:38 +02:00
|
|
|
this.backupPhraseAddress = null;
|
|
|
|
this.phraseBackedUp = '';
|
2017-02-24 18:05:39 +01:00
|
|
|
this.name = '';
|
2017-06-07 16:27:01 +02:00
|
|
|
this.nameError = ERRORS.noName;
|
2017-03-31 23:36:24 +02:00
|
|
|
this.qrAddress = null;
|
2017-02-28 14:24:12 +01:00
|
|
|
this.rawKey = '';
|
2017-01-24 16:18:23 +01:00
|
|
|
this.rawKeyError = null;
|
2017-03-03 19:50:54 +01:00
|
|
|
this.vaultName = '';
|
2017-02-28 14:24:12 +01:00
|
|
|
this.walletFile = '';
|
2017-01-24 16:18:23 +01:00
|
|
|
this.walletFileError = null;
|
2017-02-28 14:24:12 +01:00
|
|
|
this.walletJson = '';
|
2017-01-24 16:18:23 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action selectGethAccount = (address) => {
|
|
|
|
if (this.gethAddresses.includes(address)) {
|
|
|
|
this.gethAddresses = this.gethAddresses.filter((_address) => _address !== address);
|
|
|
|
} else {
|
|
|
|
this.gethAddresses = [address].concat(this.gethAddresses.peek());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setAddress = (address) => {
|
|
|
|
this.address = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setBusy = (isBusy) => {
|
|
|
|
this.isBusy = isBusy;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setCreateType = (createType) => {
|
|
|
|
this.clearErrors();
|
|
|
|
this.createType = createType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setDescription = (description) => {
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setGethAccountsAvailable = (gethAccountsAvailable) => {
|
|
|
|
this.gethAccountsAvailable = [].concat(gethAccountsAvailable);
|
|
|
|
}
|
|
|
|
|
2017-02-23 15:04:58 +01:00
|
|
|
@action setGethImported = (gethImported) => {
|
|
|
|
this.gethImported = gethImported;
|
|
|
|
}
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
@action setQrAddress = (qrAddress) => {
|
|
|
|
if (qrAddress && qrAddress.substr(0, 2) !== '0x') {
|
|
|
|
qrAddress = `0x${qrAddress}`;
|
|
|
|
}
|
|
|
|
|
2017-04-11 16:43:15 +02:00
|
|
|
// FIXME: Current native signer encoding is not 100% for EIP-55, lowercase for now
|
2017-07-21 18:23:41 +02:00
|
|
|
this.qrAddress = qrAddress && this._api.util
|
2017-04-11 16:43:15 +02:00
|
|
|
? this._api.util.toChecksumAddress(qrAddress.toLowerCase())
|
|
|
|
: qrAddress;
|
2017-03-31 23:36:24 +02:00
|
|
|
}
|
|
|
|
|
2017-03-03 19:50:54 +01:00
|
|
|
@action setVaultName = (vaultName) => {
|
|
|
|
this.vaultName = vaultName;
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
@action setWindowsPhrase = (isWindowsPhrase = false) => {
|
|
|
|
this.isWindowsPhrase = isWindowsPhrase;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setName = (name) => {
|
|
|
|
let nameError = null;
|
|
|
|
|
|
|
|
if (!name || !name.trim().length) {
|
|
|
|
nameError = ERRORS.noName;
|
|
|
|
}
|
|
|
|
|
|
|
|
transaction(() => {
|
|
|
|
this.name = name;
|
|
|
|
this.nameError = nameError;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-13 11:02:38 +02:00
|
|
|
@action setBackupPhraseAddress = (address) => {
|
|
|
|
this.backupPhraseAddress = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action computeBackupPhraseAddress = () => {
|
|
|
|
return this._api.parity.phraseToAddress(this.phrase)
|
|
|
|
.then(address => {
|
|
|
|
this.setBackupPhraseAddress(address);
|
|
|
|
return address !== this.address;
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('createAccount', error);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setPhraseBackedUp = (backedUp) => {
|
|
|
|
this.phraseBackedUp = backedUp;
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
@action setPassword = (password) => {
|
|
|
|
this.password = password;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setPasswordHint = (passwordHint) => {
|
|
|
|
this.passwordHint = passwordHint;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setPasswordRepeat = (passwordRepeat) => {
|
|
|
|
this.passwordRepeat = passwordRepeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setPhrase = (phrase) => {
|
|
|
|
const recoveryPhrase = phrase
|
|
|
|
.toLowerCase() // wordlists are lowercase
|
|
|
|
.trim() // remove whitespace at both ends
|
|
|
|
.replace(/\s/g, ' ') // replace any whitespace with single space
|
|
|
|
.replace(/ +/g, ' '); // replace multiple spaces with a single space
|
|
|
|
|
|
|
|
const phraseParts = recoveryPhrase
|
|
|
|
.split(' ')
|
|
|
|
.map((part) => part.trim())
|
|
|
|
.filter((part) => part.length);
|
|
|
|
|
|
|
|
this.phrase = phraseParts.join(' ');
|
2017-06-13 11:02:38 +02:00
|
|
|
this.backupPhraseAddress = null;
|
2017-01-24 16:18:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@action setRawKey = (rawKey) => {
|
|
|
|
let rawKeyError = null;
|
|
|
|
|
|
|
|
if (!rawKey || !rawKey.trim().length) {
|
|
|
|
rawKeyError = ERRORS.noKey;
|
|
|
|
} else if (rawKey.substr(0, 2) !== '0x' || rawKey.substr(2).length !== 64 || !apiutil.isHex(rawKey)) {
|
|
|
|
rawKeyError = ERRORS.invalidKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
transaction(() => {
|
|
|
|
this.rawKey = rawKey;
|
|
|
|
this.rawKeyError = rawKeyError;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setStage = (stage) => {
|
|
|
|
this.stage = stage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setWalletFile = (walletFile) => {
|
|
|
|
transaction(() => {
|
|
|
|
this.walletFile = walletFile.replace(FAKEPATH, '');
|
|
|
|
this.walletFileError = ERRORS.noFile;
|
|
|
|
this.walletJson = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action setWalletJson = (walletJson) => {
|
|
|
|
transaction(() => {
|
|
|
|
this.walletFileError = null;
|
|
|
|
this.walletJson = walletJson;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action nextStage = () => {
|
2017-06-07 16:27:01 +02:00
|
|
|
if (this.stage === 0) {
|
|
|
|
this.clearErrors();
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
this.stage++;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action prevStage = () => {
|
|
|
|
this.stage--;
|
|
|
|
}
|
|
|
|
|
2017-03-03 19:50:54 +01:00
|
|
|
createAccount = (vaultStore) => {
|
2017-06-07 16:27:01 +02:00
|
|
|
if (!this.canCreate) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-03 19:50:54 +01:00
|
|
|
this.setBusy(true);
|
|
|
|
|
|
|
|
return this
|
|
|
|
._createAccount()
|
|
|
|
.then(() => {
|
|
|
|
if (vaultStore && this.vaultName && this.vaultName.length) {
|
|
|
|
return vaultStore.moveAccount(this.vaultName, this.address);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.setBusy(false);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
this.setBusy(false);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
_createAccount = () => {
|
2017-01-24 16:18:23 +01:00
|
|
|
switch (this.createType) {
|
|
|
|
case 'fromGeth':
|
|
|
|
return this.createAccountFromGeth();
|
|
|
|
|
|
|
|
case 'fromJSON':
|
|
|
|
case 'fromPresale':
|
|
|
|
return this.createAccountFromWallet();
|
|
|
|
|
|
|
|
case 'fromNew':
|
|
|
|
case 'fromPhrase':
|
|
|
|
return this.createAccountFromPhrase();
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
case 'fromQr':
|
|
|
|
return this.createAccountFromQr();
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
case 'fromRaw':
|
|
|
|
return this.createAccountFromRaw();
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Error(`Cannot create account for ${this.createType}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createAccountFromGeth = (timestamp = Date.now()) => {
|
|
|
|
return this._api.parity
|
|
|
|
.importGethAccounts(this.gethAddresses.peek())
|
2017-02-23 15:04:58 +01:00
|
|
|
.then((gethImported) => {
|
|
|
|
console.log('createAccountFromGeth', gethImported);
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
this.setName('Geth Import');
|
|
|
|
this.setDescription('Imported from Geth keystore');
|
2017-02-23 15:04:58 +01:00
|
|
|
this.setGethImported(gethImported);
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
return Promise.all(gethImported.map((address) => {
|
|
|
|
return this.setupMeta(address, timestamp);
|
|
|
|
}));
|
2017-01-24 16:18:23 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
2017-02-23 15:04:58 +01:00
|
|
|
console.error('createAccountFromGeth', error);
|
2017-01-24 16:18:23 +01:00
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createAccountFromPhrase = (timestamp = Date.now()) => {
|
|
|
|
let formattedPhrase = this.phrase;
|
|
|
|
|
|
|
|
if (this.isWindowsPhrase && this.createType === 'fromPhrase') {
|
|
|
|
formattedPhrase = this.phrase
|
|
|
|
.split(' ') // get the words
|
|
|
|
.map((word) => word === 'misjudged' ? word : `${word}\r`) // add \r after each (except last in dict)
|
|
|
|
.join(' '); // re-create string
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._api.parity
|
|
|
|
.newAccountFromPhrase(formattedPhrase, this.password)
|
|
|
|
.then((address) => {
|
|
|
|
this.setAddress(address);
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
return this.setupMeta(address, timestamp);
|
2017-01-24 16:18:23 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('createAccount', error);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
createAccountFromQr = (timestamp = Date.now()) => {
|
|
|
|
this.setAddress(this.qrAddress);
|
|
|
|
|
|
|
|
return this.setupMeta(this.qrAddress, timestamp, { external: true });
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
createAccountFromRaw = (timestamp = Date.now()) => {
|
|
|
|
return this._api.parity
|
|
|
|
.newAccountFromSecret(this.rawKey, this.password)
|
|
|
|
.then((address) => {
|
|
|
|
this.setAddress(address);
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
return this.setupMeta(address, timestamp);
|
2017-01-24 16:18:23 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('createAccount', error);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createAccountFromWallet = (timestamp = Date.now()) => {
|
|
|
|
return this._api.parity
|
|
|
|
.newAccountFromWallet(this.walletJson, this.password)
|
|
|
|
.then((address) => {
|
|
|
|
this.setAddress(address);
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
return this.setupMeta(address, timestamp);
|
2017-01-24 16:18:23 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('createAccount', error);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-31 23:36:24 +02:00
|
|
|
setupMeta = (address, timestamp = Date.now(), extra = {}) => {
|
|
|
|
const meta = Object.assign({}, extra, {
|
|
|
|
description: this.description,
|
|
|
|
passwordHint: this.passwordHint,
|
|
|
|
timestamp
|
|
|
|
});
|
|
|
|
|
|
|
|
return this._api.parity
|
|
|
|
.setAccountName(address, this.name)
|
|
|
|
.then(() => this._api.parity.setAccountMeta(address, meta));
|
|
|
|
}
|
|
|
|
|
2017-01-24 16:18:23 +01:00
|
|
|
createIdentities = () => {
|
|
|
|
return Promise
|
|
|
|
.all([
|
|
|
|
this._api.parity.generateSecretPhrase(),
|
|
|
|
this._api.parity.generateSecretPhrase(),
|
|
|
|
this._api.parity.generateSecretPhrase(),
|
|
|
|
this._api.parity.generateSecretPhrase(),
|
2017-02-22 15:26:58 +01:00
|
|
|
this._api.parity.generateSecretPhrase(),
|
|
|
|
this._api.parity.generateSecretPhrase(),
|
2017-01-24 16:18:23 +01:00
|
|
|
this._api.parity.generateSecretPhrase()
|
|
|
|
])
|
|
|
|
.then((phrases) => {
|
|
|
|
return Promise
|
|
|
|
.all(phrases.map((phrase) => this._api.parity.phraseToAddress(phrase)))
|
|
|
|
.then((addresses) => {
|
|
|
|
return phrases.reduce((accounts, phrase, index) => {
|
|
|
|
const address = addresses[index];
|
|
|
|
|
|
|
|
accounts[address] = {
|
|
|
|
address,
|
|
|
|
phrase
|
|
|
|
};
|
|
|
|
|
|
|
|
return accounts;
|
|
|
|
}, {});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('createIdentities', error);
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadAvailableGethAccounts () {
|
|
|
|
return this._api.parity
|
|
|
|
.listGethAccounts()
|
|
|
|
.then((_addresses) => {
|
|
|
|
const addresses = (_addresses || []).filter((address) => !this.accounts[address]);
|
|
|
|
|
|
|
|
return Promise
|
|
|
|
.all(addresses.map((address) => this._api.eth.getBalance(address)))
|
|
|
|
.then((balances) => {
|
|
|
|
this.setGethAccountsAvailable(addresses.map((address, index) => {
|
|
|
|
return {
|
|
|
|
address,
|
|
|
|
balance: apiutil.fromWei(balances[index]).toFormat(5)
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.warn('loadAvailableGethAccounts', error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
STAGE_INFO,
|
2017-06-13 11:02:38 +02:00
|
|
|
STAGE_CONFIRM_BACKUP,
|
|
|
|
STAGE_CREATE,
|
2017-01-24 16:18:23 +01:00
|
|
|
STAGE_SELECT_TYPE
|
|
|
|
};
|