Skip to content
Permalink
Browse files

fix(wallet-settings): update existing account representatives

Fixes #90.
  • Loading branch information...
devinus committed Feb 20, 2019
1 parent b03a4be commit 05f1a24f919c7f006b747f65d05afefc71884ac8
Showing with 26 additions and 10 deletions.
  1. +3 −2 app/account/adapter.js
  2. +7 −2 app/rpc/service.js
  3. +10 −1 app/wallet/adapter.js
  4. +6 −5 app/wallets/route.js
@@ -24,13 +24,14 @@ export default class AccountAdapter extends Adapter {
}

async updateRecord(store, type, snapshot) {
const data = this.serialize(snapshot, { includeId: true });
const { representative: [, representative] = [] } = snapshot.changedAttributes();
if (representative) {
const { wallet, account } = this.serialize(snapshot, { includeId: true });
const { wallet, account } = data;
await this.get('rpc').accountRepresentativeSet(wallet, account, representative);
}

return snapshot;
return data;
}

async deleteRecord(store, type, snapshot) {
@@ -181,8 +181,13 @@ export default class RPCService extends Service {
return representative;
}

async walletRepresentativeSet(wallet, representative) {
const { set } = await this.call(actions.WALLET_REPRESENTATIVE_SET, { wallet, representative });
async walletRepresentativeSet(wallet, representative, update_existing_accounts = true) {
const { set } = await this.call(actions.WALLET_REPRESENTATIVE_SET, {
wallet,
representative,
update_existing_accounts,
});

if (set !== '1') {
throw new RepresentativeChangeError({ params: { representative } });
}
@@ -1,4 +1,5 @@
import DS from 'ember-data';

import { hash } from 'ember-concurrency';
import { inject as service } from '@ember-decorators/service';

@@ -18,11 +19,19 @@ export default class WalletAdapter extends Adapter {
representative: rpc.walletRepresentative(wallet),
accounts: rpc.accountList(wallet),
});

return { wallet, representative, accounts };
}

async updateRecord(store, type, snapshot) {
return this.serialize(snapshot, { includeId: true });
const data = this.serialize(snapshot, { includeId: true });
const { representative: [, representative] = [] } = snapshot.changedAttributes();
if (representative) {
const { wallet } = data;
await this.get('rpc').walletRepresentativeSet(wallet, representative, true);
}

return data;
}

createRecord() {
@@ -1,5 +1,5 @@
import Route from '@ember/routing/route';
import { get } from '@ember/object';
import { get, set } from '@ember/object';

import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import { action } from '@ember-decorators/object';
@@ -42,15 +42,16 @@ export default class WalletsRoute extends Route.extend(
}

@action
async changeRepresentative(model, changeset) {
async changeRepresentative(wallet, changeset) {
const flashMessages = this.get('flashMessages');
const wallet = get(model, 'id');
const representative = get(changeset, 'representative');
try {
await this.get('rpc').walletRepresentativeSet(wallet, representative);
const representative = get(changeset, 'representative');
set(wallet, 'representative', representative);
await wallet.save();
} catch (err) {
const failureMessage = this.get('intl').t('wallets.settings.representativeChangeFailed');
flashMessages.danger(failureMessage);
wallet.rollbackAttributes();
throw err;
}

0 comments on commit 05f1a24

Please sign in to comment.
You can’t perform that action at this time.