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

Commit

Permalink
feat(wallet): Use wallet adapter to change seed
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Jan 11, 2018
1 parent 98eec9d commit 67b84b7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 22 deletions.
10 changes: 3 additions & 7 deletions app/setup/import/route.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import Route from '@ember/routing/route';
import { get } from '@ember/object';
import { get, set } from '@ember/object';

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

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

model() {
return this.store.createRecord('wallet');
},
Expand All @@ -18,10 +15,9 @@ export default Route.extend({

@action
changeSeed(wallet, changeset) {
const rpc = this.get('rpc');
const seed = get(changeset, 'seed');
const model = rpc.walletChangeSeed(get(wallet, 'id'), seed).then(() => wallet);
return this.transitionTo('wallets', model);
set(wallet, 'seed', seed);
return this.transitionTo('wallets', wallet.save());
},

@action
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 @@ -5,7 +5,7 @@
{{#modal.body}}
{{wallet-import wallet=model onSubmit=(action (queue (route-action 'saveWallet') (route-action 'changeSeed')))}}
{{/modal.body}}
{{#modal.footer as |footer|}}
{{#modal.footer}}
{{#bs-button onClick=(action modal.close) type="danger"}}Cancel{{/bs-button}}
{{#bs-button onClick=(action modal.submit) type="success"}}Import{{/bs-button}}
{{/modal.footer}}
Expand Down
6 changes: 6 additions & 0 deletions app/wallet/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ export default DS.Adapter.extend({
createRecord() {
return this.get('rpc').walletCreate();
},

async updateRecord(store, type, snapshot) {
const rpc = this.get('rpc');
const { wallet, seed } = this.serialize(snapshot, { includeId: true });
await rpc.walletChangeSeed(wallet, seed);
},
});
1 change: 1 addition & 0 deletions app/wallet/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export default DS.Model.extend({

@attr('big-number') balance: null,
@attr('big-number') pending: null,
@attr seed: null,
});
6 changes: 6 additions & 0 deletions app/wallet/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ import DS from 'ember-data';

export default DS.JSONSerializer.extend({
primaryKey: 'wallet',

attrs: {
balance: { serialize: false },
pending: { serialize: false },
seed: { serialize: false },
},
});
14 changes: 7 additions & 7 deletions ember-electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ app.on('ready', () => {
});

mainWindow.webContents.on('crashed', () => {
console.log('Your Ember app (or other code) in the main window has crashed.');
console.log('This is a serious issue that needs to be handled and/or debugged.');
log.error('Your Ember app (or other code) in the main window has crashed.');
log.error('This is a serious issue that needs to be handled and/or debugged.');
});

mainWindow.on('unresponsive', () => {
console.log('Your Ember app (or other code) has made the window unresponsive.');
log.warn('Your Ember app (or other code) has made the window unresponsive.');
});

mainWindow.on('responsive', () => {
console.log('The main window has become responsive again.');
log.info('The main window has become responsive again.');
});

mainWindow.on('closed', () => {
Expand All @@ -121,7 +121,7 @@ app.on('ready', () => {
// resources (e.g. file descriptors, handles, etc) before shutting down the process. It is
// not safe to resume normal operation after 'uncaughtException'.
process.on('uncaughtException', (err) => {
console.log('An exception in the main thread was not handled.');
console.log('This is a serious issue that needs to be handled and/or debugged.');
console.log(`Exception: ${err}`);
log.error('An exception in the main thread was not handled.');
log.error('This is a serious issue that needs to be handled and/or debugged.');
log.error(`Exception: ${err}`);
});
11 changes: 10 additions & 1 deletion tests/integration/components/wallet-import/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ describeComponent(
// {{/wallet-import}}
// `);

this.render(hbs`{{wallet-import}}`);
const wallet = {
id: '1',
balance: '1000000000000000000000000000000',
accounts: ['1'],
};

const onSubmit = () => false;

this.setProperties({ wallet, onSubmit });
this.render(hbs`{{wallet-import wallet=wallet onSubmit=onSubmit}}`);
expect(this.$()).to.have.length(1);
});
},
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/validators/seed-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { module, test } from 'qunit';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import validateSeed from 'cairn/validators/seed';

module('Unit | Validator | seed');

test('it exists', (assert) => {
assert.ok(validateSeed());
describe('Unit | Validator | seed', () => {
// Replace this with your real tests.
it('exists', () => {
const result = validateSeed();
expect(result).to.be.ok;
});
});
2 changes: 1 addition & 1 deletion tests/unit/wallets/route-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupTest } from 'ember-mocha';
describe('Unit | Route | wallets', () => {
setupTest('route:wallets', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
needs: ['service:settings'],
});

it('exists', function () {
Expand Down

0 comments on commit 67b84b7

Please sign in to comment.