Skip to content

Commit

Permalink
Merge pull request #31 from district0x/transaction-usability
Browse files Browse the repository at this point in the history
improve transaction usability
  • Loading branch information
ginesdt committed Dec 1, 2023
2 parents f9f4a93 + 2ec633d commit 1f85c85
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 50 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
is.d0x/district-ui-web3 {:mvn/version "23.8.7"}
is.d0x/district-ui-web3-accounts {:mvn/version "23.8.7"}
is.d0x/district-ui-web3-chain {:mvn/version "23.8.7"}
is.d0x/district-ui-web3-tx-id {:mvn/version "23.8.7"}
is.d0x/district-ui-web3-tx-id {:mvn/version "23.10.6"}
mount/mount {:mvn/version "0.1.16"}
org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.4"}
Expand Down
15 changes: 11 additions & 4 deletions src/streamtide/ui/admin/black_listing/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[district.ui.web3-accounts.queries :as account-queries]
[district.ui.web3-tx.events :as tx-events]
[re-frame.core :as re-frame]
[streamtide.ui.components.error-notification :as error-notification]
[streamtide.ui.events :refer [wallet-chain-interceptors]]
[streamtide.ui.utils :refer [build-tx-opts]]))

Expand All @@ -25,7 +26,13 @@
:related-href {:name :route.admin/black-listing}}
:on-tx-success-n [[::logging/info (str tx-name " tx success") ::blacklist]
[::notification-events/show (str "Address " address " successfully " (if blacklisted? "blacklisted" "whitelisted"))]]
:on-tx-error [::logging/error (str tx-name " tx error")
{:user {:id active-account}
:address address}
::blacklist]}]})))
:on-tx-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:address address}
::blacklist]
[::error-notification/show-error "Transaction failed"]]
:on-tx-hash-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:address address}
::blacklist]
[::error-notification/show-error "Transaction failed"]]}]})))
5 changes: 3 additions & 2 deletions src/streamtide/ui/admin/black_listing/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@
loading? (subscribe [::bl-subs/blacklisting? address])
blacklist-tx-pending? (subscribe [::tx-id-subs/tx-pending? {:streamtide/blacklist tx-id}])
blacklist-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/blacklist tx-id}])
waiting-wallet? (subscribe [::st-subs/waiting-wallet? {:streamtide/blacklist tx-id}])
blacklist-button (fn [{:keys [:text :pending :completed :class]} blacklisted?]
[pending-button {:pending? @blacklist-tx-pending?
[pending-button {:pending? (or @blacklist-tx-pending? @waiting-wallet?)
:pending-text pending
:disabled (or @blacklist-tx-pending? @blacklist-tx-success?)
:disabled (or @blacklist-tx-pending? @blacklist-tx-success? @waiting-wallet?)
:class (str "btBasic btBasic-light " class)
:on-click (fn [e]
(.stopPropagation e)
Expand Down
46 changes: 33 additions & 13 deletions src/streamtide/ui/admin/round/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[district.ui.web3-accounts.queries :as account-queries]
[district.ui.web3-tx.events :as tx-events]
[re-frame.core :as re-frame]
[streamtide.ui.components.error-notification :as error-notification]
[streamtide.ui.events :refer [wallet-chain-interceptors]]
[streamtide.ui.utils :refer [build-tx-opts]]
[taoensso.timbre :as log]))
Expand Down Expand Up @@ -51,10 +52,16 @@
:params {:round round}}}
:on-tx-success-n [[::logging/info (str tx-name " tx success") ::distribute]
[::notification-events/show (str "Matching pool successfully distributed for round " round)]]
:on-tx-error [::logging/error (str tx-name " tx error")
{:user {:id active-account}
:matchings matchings}
::distribute]}]})))
:on-tx-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:matchings matchings}
::distribute]
[::error-notification/show-error "Transaction failed"]]
:on-tx-hash-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:matchings matchings}
::distribute]
[::error-notification/show-error "Transaction failed"]]}]})))

(re-frame/reg-event-fx
::fill-matching-pool
Expand All @@ -73,11 +80,18 @@
:params {:round round}}}
:on-tx-success-n [[::logging/info (str tx-name " tx success") ::fill-matching-pool]
[::notification-events/show (str "Matching pool successfully filled with " amount " ETH")]]
:on-tx-error [::logging/error (str tx-name " tx error")
{:user {:id active-account}
:round round
:amount amount}
::fill-matching-pool]}]})))
:on-tx-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:round round
:amount amount}
::fill-matching-pool]
[::error-notification/show-error "Transaction failed"]]
:on-tx-hash-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:round round
:amount amount}
::fill-matching-pool]
[::error-notification/show-error "Transaction failed"]]}]})))

(re-frame/reg-event-fx
::close-round
Expand All @@ -97,10 +111,16 @@
:on-tx-success-n [[::logging/info (str tx-name " tx success") ::close-round]
[::notification-events/show "Round successfully closed"]
[::round-closed]]
:on-tx-error [::logging/error (str tx-name " tx error")
{:user {:id active-account}
:round round}
::close-round]}]})))
:on-tx-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:round round}
::close-round]
[::error-notification/show-error "Transaction failed"]]
:on-tx-hash-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:round round}
::close-round]
[::error-notification/show-error "Transaction failed"]]}]})))

(re-frame/reg-event-fx
::round-closed
Expand Down
20 changes: 12 additions & 8 deletions src/streamtide/ui/admin/round/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[streamtide.ui.components.general :refer [nav-anchor no-items-found]]
[streamtide.ui.components.spinner :as spinner]
[streamtide.ui.components.user :refer [user-photo social-links]]
[streamtide.ui.subs :as st-subs]
[streamtide.ui.utils :as ui-utils]))

(def page-size 1000)
Expand Down Expand Up @@ -269,6 +270,7 @@
(let [tx-id (str "distribute_" round-id)
distribute-tx-pending (subscribe [::tx-id-subs/tx-pending? {:streamtide/distribute tx-id}])
distribute-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/distribute tx-id}])
waiting-wallet? (subscribe [::st-subs/waiting-wallet? {:streamtide/distribute tx-id}])

all-donations (->> @donations-search
(mapcat (fn [r] (-> r :search-donations :items)))
Expand All @@ -291,9 +293,9 @@
(not= "0" (:round/matching-pool round)) ; ... and has something to distribute
last-round? ; ... be the last existing round
)
[pending-button {:pending? @distribute-tx-pending
[pending-button {:pending? (or @distribute-tx-pending @waiting-wallet?)
:pending-text "Distributing"
:disabled (or @distribute-tx-pending @distribute-tx-success?)
:disabled (or @distribute-tx-pending @distribute-tx-success? @waiting-wallet?)
:class (str "btBasic btBasic-light btDistribute" (when-not @distribute-tx-success? " distributed"))
:on-click (fn [e]
(.stopPropagation e)
Expand Down Expand Up @@ -363,18 +365,20 @@
(when (round-open? round)
(let [match-pool-tx-pending? (subscribe [::tx-id-subs/tx-pending? {:streamtide/fill-matching-pool tx-id-mp}])
match-pool-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/fill-matching-pool tx-id-mp}])
match-pool-waiting-wallet? (subscribe [::st-subs/waiting-wallet? {:streamtide/fill-matching-pool tx-id-mp}])
close-round-tx-pending? (subscribe [::tx-id-subs/tx-pending? {:streamtide/close-round tx-id-cr}])
close-round-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/close-round tx-id-cr}])]
close-round-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/close-round tx-id-cr}])
close-round-waiting-wallet? (subscribe [::st-subs/waiting-wallet? {:streamtide/close-round tx-id-cr}])]
[:<>
[:div.form.fillPoolForm
[:label.inputField
[:span "Amount"]
[amount-input {:id :amount
:form-data form-data}]]
[pending-button {:pending? @match-pool-tx-pending?
[pending-button {:pending? (or @match-pool-tx-pending? @match-pool-waiting-wallet?)
:pending-text "Filling Up Matching Pool"
:disabled (or @match-pool-tx-pending? @match-pool-tx-success?
@close-round-tx-pending? @close-round-tx-success?
:disabled (or @match-pool-tx-pending? @match-pool-tx-success? @match-pool-waiting-wallet?
@close-round-tx-pending? @close-round-tx-success? @close-round-waiting-wallet?
(>= 0 (:amount @form-data)))
:class (str "btBasic btBasic-light btMatchPool")
:on-click (fn [e]
Expand All @@ -384,9 +388,9 @@
:round round}]))}
(if @match-pool-tx-success? "Matching Pool Filled up" "Fill Up Matching Pool")]]
[:div.form.closeRoundForm
[pending-button {:pending? @close-round-tx-pending?
[pending-button {:pending? (or @close-round-tx-pending? @close-round-waiting-wallet?)
:pending-text "Closing Round"
:disabled (or @close-round-tx-pending? @close-round-tx-success?)
:disabled (or @close-round-tx-pending? @close-round-tx-success? @close-round-waiting-wallet?)
:class (str "btBasic btBasic-light btCloseRound")
:on-click (fn [e]
(.stopPropagation e)
Expand Down
15 changes: 11 additions & 4 deletions src/streamtide/ui/admin/rounds/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[district.ui.web3-accounts.queries :as account-queries]
[district.ui.web3-tx.events :as tx-events]
[re-frame.core :as re-frame]
[streamtide.ui.components.error-notification :as error-notification]
[streamtide.ui.events :refer [wallet-chain-interceptors]]
[streamtide.ui.utils :refer [build-tx-opts]]
[streamtide.shared.utils :as shared-utils]))
Expand All @@ -29,10 +30,16 @@
:on-tx-success-n [[::logging/info (str tx-name " tx success") ::start-round]
[::notification-events/show (str "New round successfully started")]
[::round-started]]
:on-tx-error [::logging/error (str tx-name " tx error")
{:user {:id active-account}
:duration duration}
::start-round]}]})))
:on-tx-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:duration duration}
::start-round]
[::error-notification/show-error "Transaction failed"]]
:on-tx-hash-error-n [[::logging/error (str tx-name " tx error")
{:user {:id active-account}
:duration duration}
::start-round]
[::error-notification/show-error "Transaction failed"]]}]})))

(re-frame/reg-event-fx
::round-started
Expand Down
8 changes: 5 additions & 3 deletions src/streamtide/ui/admin/rounds/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[streamtide.ui.components.infinite-scroll :refer [infinite-scroll]]
[streamtide.ui.components.spinner :as spinner]
[streamtide.ui.components.warn-popup :as warn-popup]
[streamtide.ui.subs :as st-subs]
[streamtide.ui.utils :as ui-utils]))

(def page-size 6)
Expand Down Expand Up @@ -101,7 +102,8 @@
:refetch-on [::r-events/round-started]}])
last-active? (-> @rounds-search first :search-rounds :items first (shared-utils/active-round? (shared-utils/now-secs)))
start-round-tx-pending? (subscribe [::tx-id-subs/tx-pending? {:streamtide/start-round tx-id}])
start-round-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/start-round tx-id}])]
start-round-tx-success? (subscribe [::tx-id-subs/tx-success? {:streamtide/start-round tx-id}])
waiting-wallet? (subscribe [::st-subs/waiting-wallet? {:streamtide/start-round tx-id}])]
[admin-layout
[:div.headerRound
[:span.titleCel "Start new Round"]
Expand All @@ -124,9 +126,9 @@
[:span "ETH"]
[amount-input {:id :pool
:form-data form-data}]]]]
[pending-button {:pending? @start-round-tx-pending?
[pending-button {:pending? (or @start-round-tx-pending? @waiting-wallet?)
:pending-text "Starting"
:disabled (or @start-round-tx-pending? @start-round-tx-success? last-active?)
:disabled (or @start-round-tx-pending? @start-round-tx-success? last-active? @waiting-wallet?)
:class (str "btBasic btBasic-light btStartRound")
:on-click (fn [e]
(.stopPropagation e)
Expand Down
26 changes: 19 additions & 7 deletions src/streamtide/ui/components/error_notification.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
(str "[ERROR] " message ".")
(when (and details? @details-visible) [:span.details (str "Details: " details)])])))

(defn- unwrap-error [js-error]
(loop [js-error js-error]
(if (and (coll? js-error) (not (map? js-error)))
(recur (first js-error))
js-error)))

(defn- parse-error [js-error]
(let [js-error (if (and (coll? js-error) (not (map? js-error))) (first js-error) js-error)]
(let [{:keys [:message :error]} (js->clj js-error :keywordize-keys true)]
(or message error))))
(let [js-error (unwrap-error js-error)]
(let [{:keys [:message :error :code :status]} (js->clj js-error :keywordize-keys true)]
(if (or (and code (< code 0) message) (= status :tx.status/error))
"Transaction reverted"
(or message error)))))

(re-frame/reg-event-fx
::show-error
(fn [{:keys [db]} [_ message [error]]]
{:dispatch [::notification-events/show
{:message [error-notification {:message message
:details (parse-error error)}]}]}))
(fn [{:keys [db]} [_ message error]]
{:dispatch-n [[::notification-events/hide-notification]
[::notification-events/clear-queue]]
:dispatch-later {:ms 200
:dispatch
[::notification-events/show
{:message [error-notification {:message message
:details (parse-error error)}]}]}}))

0 comments on commit 1f85c85

Please sign in to comment.