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

Commit

Permalink
fix(wallet-import): save wallet seed during import
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Apr 20, 2018
1 parent 725fa24 commit f6f4b95
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
16 changes: 16 additions & 0 deletions app/components/wallet-import/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Component from '@ember/component';
import { get, set } from '@ember/object';
import { tryInvoke } from '@ember/utils';

import { storageFor } from 'ember-local-storage';

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

Expand All @@ -14,6 +16,8 @@ export default Component.extend({

ImportWalletValidations,

settings: storageFor('settings', 'wallet'),

type: 'seed',
wallet: null,
seed: null,
Expand All @@ -32,6 +36,18 @@ export default Component.extend({
}
},

@action
async saveWallet(model, changeset) {
const wallet = await model.save();
this.set('wallet', wallet);

const settings = this.get('settings');
const seed = get(changeset, 'seed');
const createdAt = new Date().toISOString();
tryInvoke(settings, 'setProperties', [{ seed, createdAt }]);
return wallet;
},

@action
clearSeed(changeset) {
set(changeset, 'seed', null);
Expand Down
2 changes: 1 addition & 1 deletion app/components/wallet-import/template.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h4 class="modal-title">{{t 'wallets.import.title'}}</h4>
{{#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) (action 'clearSeed'))) as |form|}}
{{#bs-form model=model onSubmit=(action (queue (action 'convertMnemonic') (action 'saveWallet' wallet) (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
5 changes: 0 additions & 5 deletions app/setup/import/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ export default Route.extend({
return this.transitionTo({ queryParams: { type } });
},

@action
saveWallet(wallet) {
return wallet.save();
},

@action
async changeSeed(model, changeset) {
const wallet = get(model, 'id');
Expand Down
2 changes: 1 addition & 1 deletion app/setup/import/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
wallet=model
type=type
onChange=(route-action 'changeType')
onSubmit=(action (queue (route-action 'saveWallet') (route-action 'changeSeed')))
onSubmit=(action (route-action 'changeSeed'))
onCancel=(route-action 'cancel')}}

0 comments on commit f6f4b95

Please sign in to comment.