From 92056517a6f8bb8c99668a65cddf833c44c4c19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Fri, 11 Nov 2022 20:29:54 +0100 Subject: [PATCH] Cache contribution vetos Fixes potentially not marking contributions as vetoed if there's no incoming event after loading the app. Also improves performance either way. --- app/services/kredits.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/services/kredits.js b/app/services/kredits.js index 3a4366a..f47954d 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -675,14 +675,15 @@ export default Service.extend({ await this.browserCache.contributions.setItem(c.id.toString(), c.serialize()); }, - handleContributionVetoed (contributionId) { + async handleContributionVetoed (contributionId) { console.debug('[kredits] ContributionVetoed event received for ', contributionId); - const contribution = this.contributions.findBy('id', contributionId); - console.debug('[kredits] contribution', contribution); + const c = this.contributions.findBy('id', contributionId); - if (contribution) { - contribution.set('vetoed', true); - contribution.set('pendingTx', null); + if (c) { + console.debug('[kredits] Updating contribution', c); + c.set('vetoed', true); + c.set('pendingTx', null); + await this.browserCache.contributions.setItem(c.id.toString(), c.serialize()); } },