From 51d8b6c8c1f9088cb3891a32d98849202abf5f66 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 20 Sep 2019 15:40:22 +0200 Subject: [PATCH 1/5] Respect disabled button color for all buttons --- app/styles/_buttons.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/styles/_buttons.scss b/app/styles/_buttons.scss index 53f1883..4638711 100644 --- a/app/styles/_buttons.scss +++ b/app/styles/_buttons.scss @@ -32,7 +32,7 @@ button, input[type=submit], .button { padding: 0.2rem 0.8rem; } - &.danger { + &.danger:not(:disabled) { color: $red; background-color: rgba(40, 21, 21, 0.6); border-color: rgba(40, 21, 21, 1); @@ -45,7 +45,7 @@ button, input[type=submit], .button { } } - &.green { + &.green:not(:disabled) { color: $green; background-color: rgba(21, 40, 21, 0.6); border-color: rgba(21, 40, 21, 1); From 1deecafee7f9fff49c38a659b9a1a0b99fa49fb1 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 20 Sep 2019 15:43:34 +0200 Subject: [PATCH 2/5] Handle pending changes for contributions This adds the pending tx data to pending contributions (after adding or vetoing, until the tx is mined). It also disables the veto button while pending. --- app/components/contribution-list/template.hbs | 7 +++++-- app/models/contribution.js | 8 +++++++- app/services/kredits.js | 4 ++++ tests/unit/models/contribution-test.js | 9 +++++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/components/contribution-list/template.hbs b/app/components/contribution-list/template.hbs index d6495a6..f806246 100644 --- a/app/components/contribution-list/template.hbs +++ b/app/components/contribution-list/template.hbs @@ -33,7 +33,7 @@ {{#each contributionsFiltered as |contribution|}}
  • + class="{{contribution-status contribution}}{{if contribution.hasPendingChanges " pending"}}{{if contribution.vetoed " vetoed"}}{{if (eq contribution.id selectedContributionId) " selected"}}">

    {{user-avatar contributor=contribution.contributor}} ({{contribution.kind}}) @@ -45,7 +45,10 @@ {{#unless contribution.vetoed}} {{#unless (is-confirmed-contribution contribution)}}

    - + {{input type="button" class="button small danger" + click=(action "veto" contribution.id) + disabled=contribution.hasPendingChanges + value="veto"}}

    {{/unless}} {{/unless}} diff --git a/app/models/contribution.js b/app/models/contribution.js index c6985fa..1b89125 100644 --- a/app/models/contribution.js +++ b/app/models/contribution.js @@ -1,5 +1,5 @@ import EmberObject, { computed } from '@ember/object'; -import { isEmpty } from '@ember/utils'; +import { isEmpty, isPresent } from '@ember/utils'; import bignumber from 'kredits-web/utils/cps/bignumber'; import moment from 'moment'; @@ -24,6 +24,8 @@ export default EmberObject.extend({ time: null, ipfsData: '', + pendingTx: null, + init () { this._super(...arguments); if (isEmpty(this.details)) this.set('details', {}); @@ -35,6 +37,10 @@ export default EmberObject.extend({ jsDate: computed('iso8601Date', function() { return moment(this.iso8601Date).toDate(); + }), + + hasPendingChanges: computed('pendingTx', function() { + return isPresent(this.pendingTx); }) }); diff --git a/app/services/kredits.js b/app/services/kredits.js index 3fc96d3..30e3eb4 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -225,6 +225,7 @@ export default Service.extend({ console.debug('[kredits] add contribution response', data); attributes.contributor = this.contributors.findBy('id', attributes.contributorId); const contribution = Contribution.create(attributes); + contribution.set('pendingTx', data); contribution.set('confirmedAtBlock', data.blockNumber + 40320); this.contributions.pushObject(contribution); return contribution; @@ -278,10 +279,12 @@ export default Service.extend({ veto (contributionId) { console.debug('[kredits] veto against', contributionId); + const contribution = this.contributions.findBy('id', contributionId); return this.kredits.Contribution.functions.veto(contributionId, { gasLimit: 300000 }) .then(data => { console.debug('[kredits] veto response', data); + contribution.set('pendingTx', data); return data; }); }, @@ -367,6 +370,7 @@ export default Service.extend({ if (contribution) { contribution.set('vetoed', true); + contribution.set('pendingTx', null); } }, diff --git a/tests/unit/models/contribution-test.js b/tests/unit/models/contribution-test.js index 4dc28a1..9ab6905 100644 --- a/tests/unit/models/contribution-test.js +++ b/tests/unit/models/contribution-test.js @@ -24,4 +24,13 @@ module('Unit | Model | contribution', function(hooks) { assert.ok(model.jsDate instanceof Date); assert.equal(model.jsDate.toISOString(), '2019-09-10T09:33:00.141Z'); }); + + test('hasPendingChanges', function(assert) { + const model = Contribution.create({}); + assert.equal(model.hasPendingChanges, false); + + model.set('pendingTx', { hash: 'abcdef123456' }); + assert.equal(model.hasPendingChanges, true); + }); + }); From a7dd058d214b917af9a653670bd1b236484bc317 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Fri, 18 Oct 2019 09:52:38 +0200 Subject: [PATCH 3/5] Remove obsolete parens --- app/services/kredits.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/kredits.js b/app/services/kredits.js index 30e3eb4..87dcb50 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -210,8 +210,8 @@ export default Service.extend({ getContributors () { return this.kredits.Contributor.all() - .then((contributors) => { - return contributors.map((contributor) => { + .then(contributors => { + return contributors.map(contributor => { return Contributor.create(contributor); }); }); From 523d4524b54af3b28d6a476d7b8ec8ef85ba874f Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Fri, 18 Oct 2019 16:37:44 +0200 Subject: [PATCH 4/5] Make contribution-status helper detect pending changes --- app/components/contribution-list/template.hbs | 2 +- app/helpers/contribution-status.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/components/contribution-list/template.hbs b/app/components/contribution-list/template.hbs index a0bd083..49419cb 100644 --- a/app/components/contribution-list/template.hbs +++ b/app/components/contribution-list/template.hbs @@ -33,7 +33,7 @@ {{#each contributionsFiltered as |contribution|}}
  • + class="{{contribution-status contribution}}{{if (eq contribution.id selectedContributionId) " selected"}}">

    {{user-avatar contributor=contribution.contributor}} ({{contribution.kind}}) diff --git a/app/helpers/contribution-status.js b/app/helpers/contribution-status.js index affdf12..4f8ea38 100644 --- a/app/helpers/contribution-status.js +++ b/app/helpers/contribution-status.js @@ -11,13 +11,23 @@ export default Helper.extend({ compute([contribution]) { this.setupRecompute(contribution); + let status = []; + if (contribution.vetoed) { - return 'vetoed'; + status.push('vetoed'); } else if (contribution.confirmedAt > this.currentBlock) { - return 'unconfirmed'; + status.push('unconfirmed'); } else { - return 'confirmed' + status.push('confirmed'); } + + if (contribution.hasPendingChanges) { + status.push('pending'); + } + + status.push('pending'); + + return status.join(' '); }, destroy () { @@ -31,11 +41,13 @@ export default Helper.extend({ contribution.addObserver('vetoed' , this, this.triggerRecompute); contribution.addObserver('confirmedAt' , this, this.triggerRecompute); contribution.addObserver('currentBlock' , this, this.triggerRecompute); + contribution.addObserver('hasPendingChanges' , this, this.triggerRecompute); this.teardown = () => { contribution.removeObserver('vetoed', this, this.triggerRecompute); contribution.removeObserver('confirmedAt', this, this.triggerRecompute); contribution.removeObserver('currentBlock', this, this.triggerRecompute); + contribution.removeObserver('hadPendingChanges', this, this.triggerRecompute); }; }, From 243a41db882530e15e3fef936199ef27e386f1ee Mon Sep 17 00:00:00 2001 From: Garret Alfert Date: Fri, 18 Oct 2019 16:39:10 +0200 Subject: [PATCH 5/5] Remove volatile() property modifier The modifier got deprecated and wasn't actually needed in any of the used cases. --- app/components/topbar-account-panel/component.js | 2 +- app/controllers/dashboard/contributions/show.js | 2 +- app/controllers/dashboard/contributors/show.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/components/topbar-account-panel/component.js b/app/components/topbar-account-panel/component.js index 4934e88..d7ae8a4 100644 --- a/app/components/topbar-account-panel/component.js +++ b/app/components/topbar-account-panel/component.js @@ -14,7 +14,7 @@ export default Component.extend({ userHasEthereumWallet: computed(function() { return isPresent(window.ethereum); - }).volatile(), + }), showConnectButton: computed('userHasEthereumWallet', 'kredits.hasAccounts', function() { diff --git a/app/controllers/dashboard/contributions/show.js b/app/controllers/dashboard/contributions/show.js index ef7f280..cd9a097 100644 --- a/app/controllers/dashboard/contributions/show.js +++ b/app/controllers/dashboard/contributions/show.js @@ -7,6 +7,6 @@ export default Controller.extend({ ipfsGatewayUrl: computed(function() { return config.ipfs.gatewayUrl; - }).volatile() + }) }); diff --git a/app/controllers/dashboard/contributors/show.js b/app/controllers/dashboard/contributors/show.js index ebd0b1e..8d8be09 100644 --- a/app/controllers/dashboard/contributors/show.js +++ b/app/controllers/dashboard/contributors/show.js @@ -12,6 +12,6 @@ export default Controller.extend({ ipfsGatewayUrl: computed(function() { return config.ipfs.gatewayUrl; - }).volatile() + }) });