Skip to content

Commit

Permalink
Merge pull request #432 from district0x/fixes-11
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
madis authored Jun 10, 2024
2 parents 59be0e8 + d19e707 commit 8667144
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions ui/src/ethlance/ui/page/new_job/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))


Expand Down Expand Up @@ -128,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))})))


Expand Down Expand Up @@ -172,8 +172,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
Expand Down Expand Up @@ -209,27 +209,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])
Expand All @@ -243,6 +244,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)
Expand All @@ -253,8 +255,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
Expand Down Expand Up @@ -308,19 +311,22 @@
: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)
:fx [[:dispatch safe-transfer-with-create-job-tx]]})))


(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])
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)
Expand Down Expand Up @@ -393,5 +399,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"]}))

0 comments on commit 8667144

Please sign in to comment.