mirror of
https://github.com/status-im/open-bounty.git
synced 2025-01-23 07:50:26 +00:00
rewrite interceptor to be based off of pending revocations which are stored in localstorage
this modification will result in retry behavior rather than the previous model which relied upon spotting the diff in confirm hash or payout receipt as it occurred
This commit is contained in:
parent
b3078b84b6
commit
f657564062
@ -3,22 +3,12 @@
|
|||||||
[re-frame.core :as rf]
|
[re-frame.core :as rf]
|
||||||
[clojure.data :as data]))
|
[clojure.data :as data]))
|
||||||
|
|
||||||
(defn get-bounty-field [owner-bounties field-name]
|
(defn get-confirming-issue-id [owner pending-revocations]
|
||||||
"for app-db representation of owner bounties, return a list of just the relevant field"
|
"returns the issue id for the current revocation matching the desired owner type"
|
||||||
(-> owner-bounties
|
(some (fn [[issue-id revocation]]
|
||||||
vals
|
(when (= owner (:confirming-account revocation))
|
||||||
(->> (map #(field-name %)))))
|
issue-id))
|
||||||
|
pending-revocations))
|
||||||
(defn filter-updated-bounties [field-name old-bounties new-bounties]
|
|
||||||
"filters collection of bounties to only those with a field that has been recently set"
|
|
||||||
(filter (fn [[issue-id owner-bounty]]
|
|
||||||
(let [new-field-value (field-name owner-bounty)
|
|
||||||
old-field-value (get-in old-bounties [issue-id field-name])]
|
|
||||||
(when (and (nil? old-field-value) (some? new-field-value))
|
|
||||||
(println "old value for " field-name " is " old-field-value)
|
|
||||||
(println "new value for " field-name "is " new-field-value)
|
|
||||||
true)))
|
|
||||||
new-bounties))
|
|
||||||
|
|
||||||
(defn dispatch-confirm-payout [bounty]
|
(defn dispatch-confirm-payout [bounty]
|
||||||
"dispatches a bounty via reframe dispatch"
|
"dispatches a bounty via reframe dispatch"
|
||||||
@ -36,9 +26,9 @@
|
|||||||
(rf/dispatch [:remove-pending-revocation (:issue-id bounty)]))
|
(rf/dispatch [:remove-pending-revocation (:issue-id bounty)]))
|
||||||
|
|
||||||
(def watch-confirm-hash
|
(def watch-confirm-hash
|
||||||
"An interceptor which exaimines the event diff for `:load-owner-bounties`
|
"revocations move through 2 states, confirmation by commiteth and then the repo owner
|
||||||
and dispatches a `confirm-payout` event when one of the owner bounties has
|
if a commiteth revocation is detected, check to see if its confirm hash is set, and, if it is
|
||||||
its confirm_hash updated.
|
dispatch a confirm payout event and update the confirming account to owner
|
||||||
|
|
||||||
*Warning* this inteceptor is only intended for use with the
|
*Warning* this inteceptor is only intended for use with the
|
||||||
`:load-owner-bounties` event
|
`:load-owner-bounties` event
|
||||||
@ -51,36 +41,21 @@
|
|||||||
:after (fn confirm-hash-update-after
|
:after (fn confirm-hash-update-after
|
||||||
[context]
|
[context]
|
||||||
(println "watch confirm hash interceptor...")
|
(println "watch confirm hash interceptor...")
|
||||||
(let [event-name (-> context
|
(let [pending-revocations (get-in context [:effects :db ::db/pending-revocations])
|
||||||
:coeffects
|
updated-bounties (get-in context [:effects :db :owner-bounties])
|
||||||
:event
|
confirming-issue-id (get-confirming-issue-id :commiteth pending-revocations)]
|
||||||
first)
|
(when-let [revoking-bounty (get updated-bounties confirming-issue-id)]
|
||||||
pending-revocations (get-in context [:coeffects :db ::db/pending-revocations])
|
(if (:confirm_hash revoking-bounty)
|
||||||
start-ob (get-in context [:coeffects :db :owner-bounties])
|
(do (dispatch-confirm-payout revoking-bounty)
|
||||||
end-ob (get-in context [:effects :db :owner-bounties])]
|
(dispatch-set-pending-revocation revoking-bounty))
|
||||||
;; proceed when the change isn't caused by page load
|
(println (str "currently revoking " confirming-issue-id " but confirm hash has not been set yet."))))
|
||||||
(when (not-empty start-ob)
|
;; interceptor must return context
|
||||||
(let [[only-before only-after both] (data/diff
|
|
||||||
(get-bounty-field start-ob :confirm_hash)
|
|
||||||
(get-bounty-field end-ob :confirm_hash))]
|
|
||||||
;; 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 :confirm_hash 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-confirm-payout bounty)
|
|
||||||
(dispatch-set-pending-revocation bounty))))))
|
|
||||||
context))))
|
context))))
|
||||||
|
|
||||||
|
|
||||||
(def watch-payout-receipt
|
(def watch-payout-receipt
|
||||||
"An interceptor which exaimines the event diff for `:load-owner-bounties`
|
"examine pending revocations with their currently confirming account set to owner
|
||||||
and dispatches a `remove-pending-revocation` event when one of them has
|
when one of them has its payout_receipt set, dispatch `remove-pending-revocation`
|
||||||
its payout_receipt set.
|
|
||||||
|
|
||||||
*Warning* this inteceptor is only intended for use with the
|
*Warning* this inteceptor is only intended for use with the
|
||||||
`:load-owner-bounties` event
|
`:load-owner-bounties` event
|
||||||
@ -93,26 +68,12 @@
|
|||||||
:after (fn payout-receipt-update-after
|
:after (fn payout-receipt-update-after
|
||||||
[context]
|
[context]
|
||||||
(println "watch payout receipt interceptor...")
|
(println "watch payout receipt interceptor...")
|
||||||
(let [event-name (-> context
|
(let [pending-revocations (get-in context [:effects :db ::db/pending-revocations])
|
||||||
:coeffects
|
updated-bounties (get-in context [:effects :db :owner-bounties])
|
||||||
:event
|
confirming-issue-id (get-confirming-issue-id :owner pending-revocations)]
|
||||||
first)
|
(when-let [revoking-bounty (get updated-bounties confirming-issue-id)]
|
||||||
pending-revocations (get-in context [:coeffects :db ::db/pending-revocations])
|
(if (:payout_receipt revoking-bounty)
|
||||||
start-ob (get-in context [:coeffects :db :owner-bounties])
|
(dispatch-remove-pending-revocation revoking-bounty)
|
||||||
end-ob (get-in context [:effects :db :owner-bounties])]
|
(println (str "currently revoking " confirming-issue-id " but confirm hash has not been set yet."))))
|
||||||
;; proceed when the change isn't caused by page load
|
;; interceptor must return context
|
||||||
(when (not-empty start-ob)
|
|
||||||
(let [[only-before only-after both] (data/diff
|
|
||||||
(get-bounty-field start-ob :payout_receipt)
|
|
||||||
(get-bounty-field end-ob :payout_receipt))]
|
|
||||||
;; proceed when payout_receipt has been updated 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 :payout_receipt 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-remove-pending-revocation bounty))))))
|
|
||||||
context))))
|
context))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user