Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Commit

Permalink
fix(setup): fix race conditions around setup and imports of wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Feb 20, 2018
1 parent e4b7f60 commit f4c6bb5
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 36 deletions.
4 changes: 1 addition & 3 deletions app/components/wallet-backup/component.js
@@ -1,5 +1,4 @@
import Component from '@ember/component';
import { set } from '@ember/object';

import { service } from 'ember-decorators/service';
import { action } from 'ember-decorators/object';
Expand Down Expand Up @@ -34,7 +33,7 @@ export default Component.extend({
},

@action
confirmDone(wallet, seed) {
confirmDone(wallet) {
const needsConfirm = this.get('needsConfirm');
if (needsConfirm) {
this.toggleProperty('hasConfirmed');
Expand All @@ -46,7 +45,6 @@ export default Component.extend({
return reject();
}

set(wallet, 'seed', seed);
return wallet;
},
});
11 changes: 9 additions & 2 deletions app/components/wallet-import/component.js
@@ -1,5 +1,6 @@
import Component from '@ember/component';
import { get, set } from '@ember/object';
import { tryInvoke } from '@ember/utils';

import { service } from 'ember-decorators/service';
import { action } from 'ember-decorators/object';
Expand All @@ -22,12 +23,18 @@ export default Component.extend({
onSubmit: null,

@action
convertMnemonic(wallet, changeset) {
convertMnemonic(changeset) {
const type = this.get('type');
if (type === 'mnemonic') {
const mnemonic = get(changeset, 'mnemonic');
const seed = bip39.mnemonicToEntropy(mnemonic);
set(wallet, 'seed', seed);
set(changeset, 'seed', seed);
}
},

@action
clearSeed(changeset) {
set(changeset, 'seed', null);
tryInvoke(changeset, 'destroy');
},
});
2 changes: 1 addition & 1 deletion app/components/wallet-import/template.hbs
Expand Up @@ -4,7 +4,7 @@
{{/modal.header}}
{{#modal.body}}
{{#with (changeset (hash type=type seed=seed mnemonic=(mnemonic seed)) ImportWalletValidations) as |model|}}
{{#bs-form model=model onSubmit=(action (queue (action 'convertMnemonic') (action onSubmit)) wallet) as |form|}}
{{#bs-form model=model onSubmit=(action (queue (action 'convertMnemonic') (action onSubmit wallet) (action 'clearSeed'))) as |form|}}
{{#form.group}}
{{#bs-button-group type="radio" property="type" value=type onChange=(action (queue (action (mut model.type)) (action onChange))) as |bg|}}
{{#bg.button type="secondary" value='seed'}}
Expand Down
2 changes: 1 addition & 1 deletion app/login/route.js
Expand Up @@ -37,7 +37,7 @@ export default Route.extend(UnauthenticatedRouteMixin, {
},

@action
async unlockWallet(changeset) {
unlockWallet(changeset) {
const wallet = get(changeset, 'wallet');
const password = get(changeset, 'password');
try {
Expand Down
19 changes: 15 additions & 4 deletions app/setup/backup/route.js
@@ -1,17 +1,28 @@
import Route from '@ember/routing/route';
import { get } from '@ember/object';

import { hash } from 'rsvp';
import { action } from 'ember-decorators/object';
import { service } from 'ember-decorators/service';

import generateSeed from '../../utils/generate-seed';

export default Route.extend({
@service rpc: null,

model() {
const wallet = this.modelFor('setup');
const wallet = this.modelFor('setup').save();
const seed = generateSeed();
return {
return hash({
wallet,
seed,
};
});
},

afterModel(model) {
const wallet = get(model, 'wallet.id');
const seed = get(model, 'seed');
return this.get('rpc').walletChangeSeed(wallet, seed);
},

@action
Expand All @@ -21,6 +32,6 @@ export default Route.extend({

@action
done(wallet) {
return this.transitionTo('setup.password', wallet.save());
return this.transitionTo('setup.password', wallet);
},
});
11 changes: 9 additions & 2 deletions app/setup/import/route.js
@@ -1,8 +1,12 @@
import Route from '@ember/routing/route';
import { get } from '@ember/object';

import { service } from 'ember-decorators/service';
import { action } from 'ember-decorators/object';

export default Route.extend({
@service rpc: null,

@action
cancel() {
return this.transitionTo('setup');
Expand All @@ -19,7 +23,10 @@ export default Route.extend({
},

@action
changeSeed(wallet) {
return this.transitionTo('setup.password', wallet.save());
async changeSeed(model, changeset) {
const wallet = get(model, 'id');
const seed = get(changeset, 'seed');
await this.get('rpc').walletChangeSeed(wallet, seed);
return this.transitionTo('setup.password', wallet);
},
});
2 changes: 1 addition & 1 deletion app/status/service.js
Expand Up @@ -45,7 +45,7 @@ const Service = ObjectProxy.extend(PromiseProxyMixin, {
}
},

async onPoll() {
onPoll() {
const rpc = this.get('rpc');
const blocks = rpc.blockCount();
const peers = rpc.peers().then(p => Object.keys(p));
Expand Down
18 changes: 2 additions & 16 deletions app/wallet/adapter.js
Expand Up @@ -16,21 +16,7 @@ export default DS.Adapter.extend({
return { wallet, accounts };
},

async createRecord(store, type, snapshot) {
const data = await this.get('rpc').walletCreate();
const seed = snapshot.attr('seed');
if (seed) {
const { wallet } = data;
const rpc = this.get('rpc');
await rpc.walletChangeSeed(wallet, seed);
}

return data;
},

async updateRecord(store, type, snapshot) {
const rpc = this.get('rpc');
const { wallet, seed } = this.serialize(snapshot, { includeId: true });
await rpc.walletChangeSeed(wallet, seed);
createRecord() {
return this.get('rpc').walletCreate();
},
});
2 changes: 1 addition & 1 deletion app/wallets/controller.js
Expand Up @@ -29,7 +29,7 @@ export default Controller.extend({
}
},

async onPoll() {
onPoll() {
if (!this.isDestroying) {
const model = this.get('model');
if (model) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/setup/backup/route-test.js
Expand Up @@ -5,7 +5,7 @@ import { setupTest } from 'ember-mocha';
describe('Unit | Route | setup/backup', () => {
setupTest('route:setup/backup', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
needs: ['service:rpc'],
});

it('exists', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/setup/import/route-test.js
Expand Up @@ -5,7 +5,7 @@ import { setupTest } from 'ember-mocha';
describe('Unit | Route | setup/import', () => {
setupTest('route:setup/import', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
needs: ['service:rpc'],
});

it('exists', function () {
Expand Down
6 changes: 3 additions & 3 deletions translations/en-us.yaml
Expand Up @@ -24,9 +24,9 @@ balance: 'Balance'
pending: 'Pending'
node: 'node'
data: 'data'
downloading: 'Downloading {asset}'
verifying: 'Verifying {asset}'
extracting: 'Extracting {asset}'
downloading: 'Downloading {asset}...'
verifying: 'Verifying {asset}...'
extracting: 'Extracting {asset}...'
starting: 'Starting node'
currency: '{amount} NANO'
status:
Expand Down

0 comments on commit f4c6bb5

Please sign in to comment.