add additional check to interceptor to only proceed during a pending revocation

This commit is contained in:
Rob Culliton 2018-05-08 09:41:30 -04:00
parent 773da8d074
commit eed60f8360
No known key found for this signature in database
GPG Key ID: 6FDEF60B3DC84D94
1 changed files with 19 additions and 16 deletions

View File

@ -39,23 +39,26 @@
:id :confirm-hash-update
:after (fn confirm-hash-update-after
[context]
(let [event-name (-> context
:coeffects
:event
first)
start-ob (get-in context [:coeffects :db :owner-bounties])
end-ob (get-in context [:effects :db :owner-bounties])]
(when (not-empty start-ob)
(let [event-name (-> context
:coeffects
:event
first)
pending-revocations (get-in context [:coeffects :db ::db/pending-revocations])
start-ob (get-in context [:coeffects :db :owner-bounties])
end-ob (get-in context [:effects :db :owner-bounties])]
;; proceed when the change isn't caused by page load
(when (not-empty start-ob)
(let [[only-before only-after both] (data/diff
(bounty-confirm-hashes start-ob)
(bounty-confirm-hashes end-ob))]
(when only-after ;; confirm hashes changed, now find out which ones
(let [updated-bounties (->> end-ob
(filter-updated-bounties start-ob)
vals)]
;; for bounties which just had confirm hash set: perform
;; dispatch side effect but interceptor must return context
(doseq [bounty updated-bounties]
(dispatch-bounty bounty))))))
;; proceed when confirm hashes have changed and there is a pending revocation
(when (and only-after (not-empty pending-revocations))
(println "pending revocations are " pending-revocations)
(let [updated-bounties (->> end-ob
(filter-updated-bounties start-ob)
vals)]
;; for bounties which just had confirm hash set: perform
;; dispatch side effect but interceptor must return context
(doseq [bounty updated-bounties]
(dispatch-bounty bounty))))))
context))))