From c2740b307f62d8df41f4e2775ac8682335ab3be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20N=C3=B5mme?= Date: Mon, 27 May 2024 15:20:22 +0200 Subject: [PATCH 1/2] Re-enable Create job button on cancelled Tx send. Fixes #429 --- ui/src/ethlance/ui/page/new_job/events.cljs | 34 ++++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ui/src/ethlance/ui/page/new_job/events.cljs b/ui/src/ethlance/ui/page/new_job/events.cljs index a661f5c8..dab26e95 100644 --- a/ui/src/ethlance/ui/page/new_job/events.cljs +++ b/ui/src/ethlance/ui/page/new_job/events.cljs @@ -95,7 +95,6 @@ (re/reg-event-db :page.new-job/decimals-response (fn [db [_ decimals]] - (println ">>> DECIMALS RESPONSE" decimals) (assoc-in db [state-key :job/token-decimals] decimals))) @@ -172,8 +171,8 @@ ipfs-job (reduce-kv (partial db-job->ipfs-job db-job) {} db->ipfs-mapping)] {:ipfs/call {:func "add" :args [(js/Blob. [ipfs-job])] - :on-success [:job-to-ipfs-success] - :on-error [:job-to-ipfs-failure]}}))) + :on-success [::job-to-ipfs-success] + :on-error [::job-to-ipfs-failure]}}))) (re/reg-event-fx @@ -209,27 +208,28 @@ (re/reg-event-fx ::tx-hash-error - (fn [_cofx result] - (println ">>> ⚠️ ⚠️ ::tx-hash-error" result))) + (fn [{:keys [db]} result] + {:db (set-tx-in-progress db false) + :fx [[:dispatch [::notification.events/show "Error with sending transaction"]]]})) (re/reg-event-fx ::erc20-allowance-approval-success (fn [_cofx result] - (println ">>> ::erc20-allowance-approval-success" result) - {:fx [[:dispatch [::send-create-job-tx]]]})) + {:fx [[:dispatch [::notification.events/show "Got the ERC20 allowance approval confirmation"]] + [:dispatch [::send-create-job-tx]]]})) (re/reg-event-fx ::erc20-allowance-approval-error - (fn [_cofx result] - (println ">>> ::erc20-allowance-approval-error" result))) + (fn [{:keys [db]} result] + {:db (set-tx-in-progress db false) + :fx [[:dispatch [::notification.events/show "Error obtaining allowance for the ERC20 token"]]]})) (re/reg-event-fx ::erc20-allowance-amount-success (fn [{:keys [db]} [_ result]] - (println ">>> ::erc20-allowance-amount-success" result (type result)) (let [offered-value (get-job-creation-param db :offered-value) amount (:value offered-value) erc20-address (get-in offered-value [:token :tokenContract :tokenAddress]) @@ -243,6 +243,7 @@ :fn :approve :args [spender amount] :tx-opts {:from owner} + :on-tx-hash-error [::tx-hash-error] :on-tx-success [::erc20-allowance-approval-success] :on-tx-error [::erc20-allowance-approval-error]}]] {:db (set-tx-in-progress db true) @@ -253,8 +254,9 @@ (re/reg-event-fx ::erc20-allowance-amount-error - (fn [_cofx result] - (println ">>> ::erc20-allowance-amount-error" result))) + (fn [{:keys [db]} result] + {:db (set-tx-in-progress db false) + :fx [[:dispatch [::notification.events/show "Couldn't get the ERC20 allowance amount"]]]})) (re/reg-event-fx @@ -308,6 +310,7 @@ :fn :safe-transfer-from :args safe-transfer-args :tx-opts {:from owner} + :on-tx-hash-error [::tx-hash-error] :on-tx-success [::create-job-tx-success] :on-tx-error [::create-job-tx-error]}]] {:db (set-tx-in-progress db true) @@ -315,7 +318,7 @@ (re/reg-event-fx - :job-to-ipfs-success + ::job-to-ipfs-success (fn [cofx event] (let [creator (accounts-queries/active-account (:db cofx)) job-fields (get-in cofx [:db state-key]) @@ -393,5 +396,6 @@ (re/reg-event-fx ::job-to-ipfs-failure - (fn [_ _] - {:dispatch [::notification.events/show "Error with loading new job data to IPFS"]})) + (fn [{:keys [db]} _] + {:db (set-tx-in-progress db false) + :dispatch [::notification.events/show "Error with loading new job data to IPFS"]})) From d19e707c349177a59653c07a68cbb43e3e42adac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20N=C3=B5mme?= Date: Mon, 27 May 2024 15:54:47 +0200 Subject: [PATCH 2/2] Use 1 as token amount for ERC721 on job creation. Fixes #430 --- ui/src/ethlance/ui/page/new_job/events.cljs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/src/ethlance/ui/page/new_job/events.cljs b/ui/src/ethlance/ui/page/new_job/events.cljs index dab26e95..e156e59c 100644 --- a/ui/src/ethlance/ui/page/new_job/events.cljs +++ b/ui/src/ethlance/ui/page/new_job/events.cljs @@ -127,6 +127,7 @@ {:fx [(decimals-fx-fn)] :db (-> db (assoc-in ,,, [state-key :job/token-address] (token-address token-type)) + (assoc-in ,,, [state-key :job/token-amount] 1) (assoc-in ,,, [state-key :job/token-type] token-type))}))) @@ -323,7 +324,9 @@ (let [creator (accounts-queries/active-account (:db cofx)) job-fields (get-in cofx [:db state-key]) token-type (:job/token-type job-fields) - token-amount (get-in job-fields [:job/token-amount :token-amount]) + token-amount (if (= token-type :erc721) + 1 + (get-in job-fields [:job/token-amount :token-amount])) address-placeholder "0x0000000000000000000000000000000000000000" token-address (if (not (= token-type :eth)) (:job/token-address job-fields)