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

Commit

Permalink
feat(wallet): Always restore wallet to storage when entering route
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Jan 11, 2018
1 parent 6112d2f commit 198d891
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/ajax/service.js
Expand Up @@ -26,7 +26,7 @@ export default AjaxService.extend({
} finally {
promise.xhr.abort();
}
}).enqueue().maxConcurrency(5),
}).enqueue().maxConcurrency(10),

request(...args) {
const originalFn = this._super;
Expand Down
1 change: 0 additions & 1 deletion app/index/route.js
Expand Up @@ -12,7 +12,6 @@ export default Route.extend({
if (!wallet) {
transaction.abort();
wallet = await this.store.createRecord('wallet').save();
settings.setProperties(this.store.serialize(wallet, { includeId: true }));
return this.transitionTo('wallets', wallet);
}

Expand Down
48 changes: 23 additions & 25 deletions app/rpc/service.js
Expand Up @@ -6,12 +6,13 @@ import { service } from 'ember-decorators/service';

export const actions = {
WALLET_CREATE: 'wallet_create',
WALLET_BALANCE_TOTAL: 'wallet_balance_total',
WALLET_CHANGE_SEED: 'wallet_change_seed',
ACCOUNT_CREATE: 'account_create',
ACCOUNT_INFO: 'account_info',
WALLET_BALANCE_TOTAL: 'wallet_balance_total',
ACCOUNT_LIST: 'account_list',
SEND: 'send',
ACCOUNT_HISTORY: 'account_history',
SEND: 'send',
PEERS: 'peers',
BLOCK_COUNT: 'block_count',
};
Expand All @@ -28,6 +29,15 @@ export default Service.extend({
return this.call(actions.WALLET_CREATE);
},

walletBalanceTotal(wallet) {
return this.call(actions.WALLET_BALANCE_TOTAL, { wallet });
},

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

accountCreate(wallet) {
return this.call(actions.ACCOUNT_CREATE, { wallet });
},
Expand All @@ -50,23 +60,10 @@ export default Service.extend({
return info;
},

walletBalanceTotal(wallet) {
return this.call(actions.WALLET_BALANCE_TOTAL, { wallet });
},

accountList(wallet) {
return this.call(actions.ACCOUNT_LIST, { wallet });
},

send(wallet, source, destination, amount) {
return this.call(actions.SEND, {
wallet,
source,
destination,
amount,
});
},

async accountHistory(account, count = 1) {
const { history } = await this.call(actions.ACCOUNT_HISTORY, {
account,
Expand All @@ -76,18 +73,19 @@ export default Service.extend({
return A(history);
},

async peers() {
const { peers } = await this.call(actions.PEERS);
send(wallet, source, destination, amount) {
return this.call(actions.SEND, {
wallet,
source,
destination,
amount,
});
},

async peers() {
// When there are no peers, the RPC replies with an empty string.
if (!peers) {
return Object.create(null);
}

return Object.entries(peers).reduce((acc, [key, value]) => {
acc[key] = parseInt(value, 10);
return acc;
}, Object.create(null));
const { peers } = await this.call(actions.PEERS);
return peers || {};
},

blockCount() {
Expand Down
1 change: 1 addition & 0 deletions app/wallet/model.js
Expand Up @@ -6,4 +6,5 @@ export default DS.Model.extend({
@hasMany('account', { async: true }) accounts: null,

@attr('big-number') balance: null,
@attr('big-number') pending: null,
});
9 changes: 9 additions & 0 deletions app/wallets/route.js
@@ -1,4 +1,13 @@
import Route from '@ember/routing/route';

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

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

async afterModel(model) {
const settings = this.get('settings');
const serialized = this.store.serialize(model, { includeId: true });
settings.setProperties(serialized);
},
});

0 comments on commit 198d891

Please sign in to comment.