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

Commit

Permalink
feat(setup): Start setup routes
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Jan 11, 2018
1 parent 52d9490 commit 98eec9d
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 10 deletions.
10 changes: 10 additions & 0 deletions app/components/wallet-import/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Component from '@ember/component';

import ImportWalletValidations from '../../validations/import-wallet';

export default Component.extend({
ImportWalletValidations,

wallet: null,
seed: null,
});
3 changes: 3 additions & 0 deletions app/components/wallet-import/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#bs-form model=(changeset (hash seed=seed) ImportWalletValidations) onSubmit=(action onSubmit wallet) as |form|}}
{{form.element class="form-control-lg" controlType="text" label="Seed" property="seed" autocomplete='off' minlength=64 maxlength=64 required=true pattern="^[a-fA-F0-9]{64}$"}}
{{/bs-form}}
4 changes: 4 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const Router = EmberRouter.extend({
});

Router.map(function routerMap() {
this.route('setup', function setupRoute() {
this.route('import');
});

return this.route('wallets', { path: '/:wallet_id' }, function walletsRoute() {
this.route('overview');
this.route('send');
Expand Down
4 changes: 2 additions & 2 deletions app/rpc/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default Service.extend({
return this.call(actions.WALLET_BALANCE_TOTAL, { wallet });
},

async walletChangeSeed() {
const { success } = this.call(actions.WALLET_CHANGE_SEED);
async walletChangeSeed(wallet, seed) {
const { success } = await this.call(actions.WALLET_CHANGE_SEED, { wallet, seed });
return success === '';
},

Expand Down
31 changes: 31 additions & 0 deletions app/setup/import/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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,

model() {
return this.store.createRecord('wallet');
},

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

@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);
},

@action
cancel() {
return this.transitionTo('setup');
},
});
12 changes: 12 additions & 0 deletions app/setup/import/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{#bs-modal onHide=(route-action 'cancel') as |modal|}}
{{#modal.header}}
<h4 class="modal-title">Import Wallet</h4>
{{/modal.header}}
{{#modal.body}}
{{wallet-import wallet=model onSubmit=(action (queue (route-action 'saveWallet') (route-action 'changeSeed')))}}
{{/modal.body}}
{{#modal.footer as |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}}
{{/bs-modal}}
16 changes: 16 additions & 0 deletions app/setup/index/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Route from '@ember/routing/route';

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

export default Route.extend({
@action
createWallet() {
const wallet = this.store.createRecord('wallet');
return this.transitionTo('wallets', wallet.save());
},

@action
importWallet() {
return this.transitionTo('setup.import');
},
});
1 change: 1 addition & 0 deletions app/setup/index/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{outlet}}
16 changes: 16 additions & 0 deletions app/setup/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Route from '@ember/routing/route';

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

export default Route.extend({
@action
createWallet() {
const wallet = this.store.createRecord('wallet');
return this.transitionTo('wallets', wallet.save());
},

@action
importWallet() {
return this.transitionTo('setup.import');
},
});
12 changes: 12 additions & 0 deletions app/setup/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{outlet}}

<div class="jumbotron">
<h1 class="display-3">Welcome!</h1>
<p class="lead">Let's get your wallet setup for use with Cairn.</p>
<hr class="my-4">
<p>To begin using Cairn, you must first create a new RaiBlocks wallet or import a wallet that already exists from a seed.</p>
<p class="lead">
<a class="btn btn-primary btn-lg" href="#" role="button" {{action (route-action 'createWallet')}}>Create New Wallet</a>
<a class="btn btn-primary btn-lg" href="#" role="button" {{action (route-action 'importWallet')}}>Import from Seed</a>
</p>
</div>
5 changes: 5 additions & 0 deletions app/validations/import-wallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import validateSeed from '../validators/seed';

export default {
seed: validateSeed(),
};
5 changes: 5 additions & 0 deletions app/validators/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { validateFormat } from 'ember-changeset-validations/validators';

export default function validateSeed() {
return validateFormat({ regex: /^[a-fA-F0-9]{64}$/ });
}
16 changes: 8 additions & 8 deletions public/Cairn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions tests/integration/components/wallet-import/component-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect } from 'chai';
import { describeComponent, it } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

describeComponent(
'wallet-import', 'Integration | Component | wallet import',
{
integration: true,
},
() => {
it('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
// this.render(hbs`
// {{#wallet-import}}
// template content
// {{/wallet-import}}
// `);

this.render(hbs`{{wallet-import}}`);
expect(this.$()).to.have.length(1);
});
},
);
16 changes: 16 additions & 0 deletions tests/unit/setup/import/route-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { describeModule, it } from 'ember-mocha';

describeModule(
'route:setup/import', 'Unit | Route | setup/import',
{
// Specify the other units that are required for this test.
// needs: ['controller:foo']
},
() => {
it('exists', function () {
const route = this.subject();
expect(route).to.be.ok;
});
},
);
16 changes: 16 additions & 0 deletions tests/unit/setup/index/route-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { describeModule, it } from 'ember-mocha';

describeModule(
'route:setup/index', 'Unit | Route | setup/index',
{
// Specify the other units that are required for this test.
// needs: ['controller:foo']
},
() => {
it('exists', function () {
const route = this.subject();
expect(route).to.be.ok;
});
},
);
Loading

0 comments on commit 98eec9d

Please sign in to comment.