Skip to content

Commit

Permalink
Merge pull request #396 from district0x/various-fixes-5
Browse files Browse the repository at this point in the history
Various fixes 5
  • Loading branch information
madis authored Apr 24, 2024
2 parents d939e91 + 7b4794b commit 46ea2b2
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 32 deletions.
2 changes: 1 addition & 1 deletion server/src/ethlance/server/syncer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@
:job-arbiter/fee-currency-id (if (keyword? token-type)
(name token-type)
(str token-type))
:job-arbiter/date-accepted (get-timestamp)
:job-arbiter/status "quote-set"}]
(<? (ethlance-db/update-arbitration conn for-the-db)))))

Expand All @@ -239,6 +238,7 @@
job-id (:job args)
new-accepted-arbiter {:job/id job-id
:user/id arbiter-id
:job-arbiter/date-accepted (get-timestamp)
:job-arbiter/status "accepted"}
previous-accepted-query {:select [:JobArbiter.job/id :JobArbiter.user/id]
:from [:JobArbiter]
Expand Down
16 changes: 8 additions & 8 deletions shared/src/ethlance/shared/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -617,18 +617,18 @@


(def categories
#{"Web, Mobile & Software Dev"
"IT & Networking"
#{"Accounting & Consulting"
"Admin Support"
"Customer Service"
"Data Science & Analytics"
"Design & Creative"
"Writing"
"Translation"
"IT & Networking"
"Legal"
"Admin Support"
"Customer Service"
"Other"
"Sales & Marketing"
"Accounting & Consulting"
"Other"})
"Translation"
"Web, Mobile & Software Dev"
"Writing"})


(def category-default "All Categories")
Expand Down
18 changes: 16 additions & 2 deletions ui/src/ethlance/ui/component/token_amount_input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
[cljs.math]))


(defn- non-zero-fraction? [num-str]
(#{"1" "2" "3" "4" "5" "6" "7" "8" "9" "." ","} (last num-str)))

(defn leading-zeroes-preserving-round
"Returns original value if the val is zero expressing string (e.g. 0 or 0.0)
When it becomes non-zero (e.g. 0.01) then returns the result (transform-fn val)"
[val transform-fn]
(if (non-zero-fraction? val)
(transform-fn val)
val))

(defn c-token-amount-input
[{:keys [decimals on-change] :as opts}]
(let [text-input-opts (dissoc opts :decimals)
Expand All @@ -13,11 +24,14 @@
decimals-for-ui (min decimals max-ui-decimals)
step (/ 1 (cljs.math/pow 10 decimals-for-ui))
;; Should use method similar to https://stackoverflow.com/a/10880710/1025412
human->token-amount (fn [human-amount] (.round js/Math (* (cljs.math/pow 10 decimals) human-amount)))
human->token-amount (fn [human-amount]
(.round js/Math (* (cljs.math/pow 10 decimals) human-amount)))
token-on-change (fn [human-amount]
(on-change {:token-amount (human->token-amount human-amount)
:human-amount human-amount
:decimals decimals}))
amount-extras {:type :number :step step :on-change token-on-change}
value-rounded-to-decimals (util-tokens/round decimals-for-ui (:value opts))]
value-rounded-to-decimals (leading-zeroes-preserving-round
(:value opts)
#(util-tokens/round decimals-for-ui %))]
[text-input/c-text-input (merge text-input-opts amount-extras {:value value-rounded-to-decimals})]))
2 changes: 1 addition & 1 deletion ui/src/ethlance/ui/page/invoices/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
::invoice-to-ipfs-success
(fn [cofx [_event invoice ipfs-event]]
(let [contract-address (:job/id invoice)
tx-opts {:from (:payer invoice) :gas 10000000}
tx-opts {:from (:payer invoice)}
invoice-id (:invoice-id invoice)
ipfs-hash (-> ipfs-event :Hash base58->hex)]
{:dispatch [::web3-events/send-tx
Expand Down
6 changes: 3 additions & 3 deletions ui/src/ethlance/ui/page/job_contract/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
ipfs-hash (base58->hex (:Hash ipfs-event))
invoice-id (:invoice/id dispute-details)
job-contract-address (:job/id dispute-details)
tx-opts {:from creator :gas 10000000}]
tx-opts {:from creator}]
{:dispatch [::web3-events/send-tx
{:instance (contract-queries/instance db :job job-contract-address)
:fn :raiseDispute
Expand Down Expand Up @@ -181,7 +181,7 @@
ipfs-hash (base58->hex (:Hash ipfs-event))
job-contract-address (:job/id ipfs-accept)
candidate (:candidate ipfs-accept)
tx-opts {:from creator :gas 10000000}]
tx-opts {:from creator}]
{:dispatch [::web3-events/send-tx
{:instance (contract-queries/instance db :job job-contract-address)
:fn :add-candidate
Expand Down Expand Up @@ -269,7 +269,7 @@
{:tokenType (contract-constants/token-type->enum-val token-type)
:tokenAddress token-address}}}
instance (contract-queries/instance (:db cofx) :job job-address)
tx-opts {:from creator :gas 10000000}
tx-opts {:from creator}
ipfs-hash (base58->hex (:Hash ipfs-data))
contract-args [invoice-id [(clj->js offered-value)] ipfs-hash]]
{:dispatch [::web3-events/send-tx
Expand Down
12 changes: 6 additions & 6 deletions ui/src/ethlance/ui/page/job_detail.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,16 @@
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])]
(println ">>> c-set-arbiter-quote token-amount" @token-amount)
(if invited?
[:div.proposal-form
[:div.label "Set quote to be arbiter"]
[:div.amount-input
[c-text-input
{:placeholder "Token amount"
:type :number
:disabled (not invited?)
:value @token-amount
:on-change #(re/dispatch [:page.job-detail/set-arbitration-token-amount (js/parseFloat %)])}]
[c-token-amount-input
{:value @token-amount
:decimals 3
:placeholder "Token amount"
:on-change #(re/dispatch [:page.job-detail/set-arbitration-token-amount %])}]
[:label "ETH (Ether)"]]

[:div.amount-input
Expand Down
14 changes: 7 additions & 7 deletions ui/src/ethlance/ui/page/job_detail/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@

(re/reg-event-db
:page.job-detail/set-arbitration-token-amount
(fn [db [_ token-amount]]
(fn [db [_ {:keys [human-amount]}]]
(-> db
(assoc-in ,,, [state-key :arbitration-token-amount] token-amount)
(assoc-in ,,, [state-key :arbitration-token-amount] human-amount)
(assoc-in ,,, [state-key :arbitration-token-amount-usd]
(util.tokens/round 2 (* token-amount (conversion-rates.queries/conversion-rate db :ETH :USD)))))))
(util.tokens/round 2 (* human-amount (conversion-rates.queries/conversion-rate db :ETH :USD)))))))


(re/reg-event-db
Expand Down Expand Up @@ -228,7 +228,7 @@
{:tokenType (contract-constants/token-type->enum-val token-type)
:tokenAddress address-placeholder}}}
instance (contract-queries/instance (:db cofx) :job job-address)
tx-opts {:from arbiter-address :gas 10000000}
tx-opts {:from arbiter-address}
ipfs-hash (base58->hex (:Hash ipfs-data))
;; TODO: decide if sending to IPFS would serve for anything or all the
;; information involved is already in the contract & QuoteForArbitrationEvent
Expand Down Expand Up @@ -260,7 +260,7 @@
{:tokenType (contract-constants/token-type->enum-val token-type)
:tokenAddress address-placeholder}}}
instance (contract-queries/instance (:db cofx) :job job-address)
tx-opts {:from employer-address :gas 10000000 :value amount-in-wei}
tx-opts {:from employer-address :value amount-in-wei}
contract-args [arbiter-address [(clj->js offered-value)]]]
{:dispatch [::web3-events/send-tx
{:instance instance
Expand Down Expand Up @@ -298,7 +298,7 @@
(let [job-address (:job/id event-data)
employer-address (:employer event-data)
instance (contract-queries/instance (:db cofx) :job job-address)
tx-opts {:from employer-address :gas 10000000}]
tx-opts {:from employer-address}]
{:db (set-end-job-tx-in-progress db true)
:dispatch [::web3-events/send-tx
{:instance instance
Expand Down Expand Up @@ -408,7 +408,7 @@
::send-add-funds-tx
(fn [{:keys [db]} [_ funds-params]]
(let [token-type (:token-type funds-params)
tx-opts-base {:from (:funder funds-params) :gas 10000000}
tx-opts-base {:from (:funder funds-params)}
offered-value (:offered-value funds-params)
tx-opts (if (= token-type :eth)
(assoc tx-opts-base :value (:value offered-value))
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ethlance/ui/page/new_invoice/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
:tokenContract
{:tokenType (contract-constants/token-type->enum-val token-type)
:tokenAddress token-address}}}
tx-opts {:from creator :gas 10000000}
tx-opts {:from creator}
ipfs-hash (-> ipfs-event :Hash base58->hex)]
{:dispatch [::web3-events/send-tx
{:instance (smart-contracts.queries/instance (:db cofx) :job contract-address)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ethlance/ui/page/new_job/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
offered-value (get-job-creation-param db :offered-value)
ipfs-hash (get-job-creation-param db :ipfs-hash)
arbiters (get-job-creation-param db :arbiters)
tx-opts-base {:from employer :gas "1000000"}
tx-opts-base {:from employer}
token-type (get-job-creation-param db :token-type)
tx-opts (if (= token-type :eth)
(assoc tx-opts-base :value (:value offered-value))
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ethlance/ui/page/profile/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
ipfs-hash (base58->hex (:Hash ipfs-event))
job-contract-address (:job/id ipfs-invitation)
candidate (:candidate ipfs-invitation)
tx-opts {:from creator :gas 10000000}]
tx-opts {:from creator}]
{:dispatch [::web3-events/send-tx
{:instance (contract-queries/instance db :job job-contract-address)
:fn :add-candidate
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ethlance/ui/page/sign_up.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
:label "Upload file"
:file-accept-pred (fn [{:keys [name type size]}]
(log/debug "Veryfing acceptance of file" {:name name :type type :size size})
(and (#{"image/png" "image/gif" "image/jpeg" "image/svg+xml"} type)
(and (#{"image/png" "image/gif" "image/jpeg" "image/svg+xml" "image/webp"} type)
(< size 1500000)))
:on-file-accepted (fn [{:keys [name type size]}]
(swap! form-data update-in [:file-info] dissoc :error)
Expand Down

0 comments on commit 46ea2b2

Please sign in to comment.