Skip to content

Commit

Permalink
Disable Send button while sending / accepting arbiter quote. Fixes #415
Browse files Browse the repository at this point in the history
  • Loading branch information
madis committed May 17, 2024
1 parent fa51e61 commit 5489f0d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
8 changes: 6 additions & 2 deletions ui/src/ethlance/ui/page/job_detail.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@
(let [arbitration-to-accept @(re/subscribe [:page.job-detail/arbitration-to-accept])
job-address (get arbitration-to-accept :job/id)
employer-address (get-in arbitration-to-accept [:job :job/employer-address])
arbiter-to-be-assigned? (= "quote-set" (:arbitration/status arbitration-to-accept))]
arbiter-to-be-assigned? (= "quote-set" (:arbitration/status arbitration-to-accept))
arbiter-tx-in-progress? (re/subscribe [:page.job-detail/arbiter-tx-in-progress?])]
[:div.proposal-form
[:div.label "Accept arbiter quote"]
[:div.amount-input
Expand All @@ -258,6 +259,7 @@
(when arbiter-to-be-assigned?
[c-button {:style (when (nil? arbitration-to-accept) {:background :gray})
:size :small
:disabled? @arbiter-tx-in-progress?
:on-click (fn []
(when arbitration-to-accept
(>evt [:page.job-detail/accept-quote-for-arbitration
Expand Down Expand Up @@ -337,7 +339,8 @@
quote-set? (= "quote-set" (:arbitration/status arbitration-by-current-user))
invited? (= "invited" (:arbitration/status arbitration-by-current-user))
job-address (get arbitration-by-current-user :job/id)
active-user (get-in arbitration-by-current-user [:arbiter :user/id])]
active-user (get-in arbitration-by-current-user [:arbiter :user/id])
arbiter-tx-in-progress? (re/subscribe [:page.job-detail/arbiter-tx-in-progress?])]
(if invited?
[:div.proposal-form
[:div.label "Set quote to be arbiter"]
Expand All @@ -361,6 +364,7 @@
[c-button
{:style (when quote-set? {:background :gray})
:size :small
:disabled? @arbiter-tx-in-progress?
:on-click (fn []
(when invited? (>evt [:page.job-detail/set-quote-for-arbitration
{:job/id job-address
Expand Down
65 changes: 39 additions & 26 deletions ui/src/ethlance/ui/page/job_detail/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{:add-funds-tx-in-progress? false
:end-job-tx-in-progress? false
:invite-arbiters-in-progress? false
:arbiter-tx-in-progress? false
:proposal-offset 0
:proposal-limit 3
:arbitrations-offset 0
Expand Down Expand Up @@ -79,6 +80,8 @@
(re/reg-event-fx :page.job-detail/set-proposal-offset (create-assoc-handler :proposal-offset))

(re/reg-event-fx :page.job-detail/set-arbitrations-offset (create-assoc-handler :arbitrations-offset))
(re/reg-event-fx ::set-arbiter-tx-in-progress (create-assoc-handler :arbiter-tx-in-progress?))



(re/reg-event-db
Expand Down Expand Up @@ -199,6 +202,11 @@
(fn [{:keys [db]} error]
(merge db [state-key :graphql-error] error)))

(re/reg-event-fx
::arbitration-to-ipfs-failed
(fn [_cofx _event]
{:fx [[:dispatch [::notification.events/show "Sending arbitration data to IPFS failed"]]
[:dispatch [::set-arbiter-tx-in-progress false]]]}))

(defn send-arbitration-data-to-ipfs
[_cofx [_ event]]
Expand All @@ -207,11 +215,18 @@
:user/id
:job-arbiter/fee
:job-arbiter/fee-currency-id])]
{:ipfs/call {:func "add"
{:fx [[:dispatch [::set-arbiter-tx-in-progress true]]]
:ipfs/call {:func "add"
:args [(js/Blob. [ipfs-arbitration])]
:on-success [:page.job-detail/arbitration-to-ipfs-success event]
:on-error [:page.job-detail/arbitration-to-ipfs-failure event]}}))
:on-error [::arbitration-to-ipfs-failed]}}))


(re/reg-event-fx
::arbitration-tx-failed
(fn [_cofx _event]
{:fx [[:dispatch [::notification.events/show "Sending arbitration transaction failed"]]
[:dispatch [::set-arbiter-tx-in-progress false]]]}))

(defn set-quote-for-arbitration-tx
[cofx [_event-name forwarded-event-data ipfs-data]]
Expand All @@ -233,15 +248,16 @@
;; TODO: decide if sending to IPFS would serve for anything or all the
;; information involved is already in the contract & QuoteForArbitrationEvent
contract-args [[(clj->js offered-value)]]]
{:dispatch [::web3-events/send-tx
{:instance instance
:fn :set-quote-for-arbitration
:args contract-args
:tx-opts tx-opts
:tx-hash [::arbitration-tx-hash]
:on-tx-hash-error [::set-quote-for-arbitration-tx-hash-error]
:on-tx-success [:page.job-detail/arbitration-tx-success "Transaction to set quote successful"]
:on-tx-error [::set-quote-for-arbitration-tx-error]}]}))
{:fx [[:dispatch [::set-arbiter-tx-in-progress true]]
[:dispatch [::web3-events/send-tx
{:instance instance
:fn :set-quote-for-arbitration
:args contract-args
:tx-opts tx-opts
:tx-hash [::arbitration-tx-hash]
:on-tx-hash-error [::arbitration-tx-failed]
:on-tx-success [:page.job-detail/arbitration-tx-success "Transaction to set quote successful"]
:on-tx-error [::set-quote-for-arbitration-tx-error]}]]]}))


(defn accept-quote-for-arbitration-tx
Expand All @@ -262,15 +278,16 @@
instance (contract-queries/instance (:db cofx) :job job-address)
tx-opts {:from employer-address :value amount-in-wei}
contract-args [arbiter-address [(clj->js offered-value)]]]
{:dispatch [::web3-events/send-tx
{:instance instance
:fn :accept-quote-for-arbitration
:args contract-args
:tx-opts tx-opts
:tx-hash [::arbitration-tx-hash]
:on-tx-hash-error [::accept-quote-for-arbitration-tx-hash-error]
:on-tx-success [:page.job-detail/arbitration-tx-success "Transaction to accept quote successful"]
:on-tx-error [::accept-quote-for-arbitration-tx-error]}]}))
{:fx [[:dispatch [::set-arbiter-tx-in-progress true]]
[:dispatch [::web3-events/send-tx
{:instance instance
:fn :accept-quote-for-arbitration
:args contract-args
:tx-opts tx-opts
:tx-hash [::arbitration-tx-hash]
:on-tx-hash-error [::arbitration-tx-failed]
:on-tx-success [:page.job-detail/arbitration-tx-success "Transaction to accept quote successful"]
:on-tx-error [::arbitration-tx-failed]}]]]}))


(defn invite-arbiters
Expand Down Expand Up @@ -314,14 +331,10 @@
(re/reg-event-fx :page.job-detail/set-quote-for-arbitration send-arbitration-data-to-ipfs)
(re/reg-event-fx :page.job-detail/accept-quote-for-arbitration accept-quote-for-arbitration-tx)
(re/reg-event-fx :page.job-detail/arbitration-to-ipfs-success set-quote-for-arbitration-tx)
(re/reg-event-db :page.job-detail/arbitration-to-ipfs-failure (create-logging-handler))

(re/reg-event-fx ::arbitration-tx-hash (create-logging-handler))
(re/reg-event-fx ::set-quote-for-arbitration-tx-hash-error (create-logging-handler))
(re/reg-event-fx ::set-quote-for-arbitration-tx-error (create-logging-handler))

(re/reg-event-fx ::accept-quote-for-arbitration-tx-hash-error (create-logging-handler))
(re/reg-event-fx ::accept-quote-for-arbitration-tx-error (create-logging-handler))

(re/reg-event-fx :page.job-detail/end-job end-job-tx)
(re/reg-event-fx ::end-job-tx-hash-error (create-logging-handler))
Expand Down Expand Up @@ -365,7 +378,6 @@
(re/reg-event-db
::job-arbiter-status-success
(fn [db [_ job-address arbiter-idle?]]
(println ">>> ::job-arbiter-status-success received" job-address arbiter-idle?)
(assoc-in db [state-key :job-arbiter-idle] arbiter-idle?)))


Expand All @@ -382,7 +394,8 @@
{:db (-> (:db cofx)
(set-invite-arbiters-tx-in-progress ,,, false)
(assoc ,,, state-key state-default))
:fx [[:dispatch [:page.job-detail/arbitrations-updated]]
:fx [[:dispatch [::set-arbiter-tx-in-progress false]]
[:dispatch [:page.job-detail/arbitrations-updated]]
[:dispatch [::notification.events/show message]]]}))


Expand Down
2 changes: 2 additions & 0 deletions ui/src/ethlance/ui/page/job_detail/subscriptions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@
(re/reg-sub :page.job-detail/add-funds-tx-in-progress? (create-get-handler :add-funds-tx-in-progress?))
(re/reg-sub :page.job-detail/end-job-tx-in-progress? (create-get-handler :end-job-tx-in-progress?))
(re/reg-sub :page.job-detail/invite-arbiters-tx-in-progress? (create-get-handler :invite-arbiters-tx-in-progress?))
(re/reg-sub :page.job-detail/arbiter-tx-in-progress? (create-get-handler :arbiter-tx-in-progress?))

0 comments on commit 5489f0d

Please sign in to comment.