Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions server/src/ethlance/server/graphql/resolvers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,27 @@
(:sum result))))


(defn job->balance-left-resolver
[root _args _]
(db/with-async-resolver-conn conn
(let [parsed-root (graphql-utils/gql->clj root)
job-id (:job/id parsed-root)
query-funding {:select [[(sql/call :sum :job-funding/amount) :amount]]
:from [:JobFunding]
:where [:= :JobFunding.job/id job-id]}
query-invoices {:select [[(sql/call :* -1 :JobStoryInvoiceMessage.invoice/amount-requested) :amount]]
:from [:JobStoryInvoiceMessage]
:join [:jobStory [:= :JobStory.job-story/id :JobStoryInvoiceMessage.job-story/id]]
:where [:and
[:= :JobStory.job/id job-id]
[:in :JobStoryInvoiceMessage.invoice/status ["created" "dispute-raised"]]]}
query {:select [[(sql/call :coalesce (sql/call :sum :t.amount) 0) :result]]
:from [[{:union-all [query-funding query-invoices]} :t]]}
result (:result (<? (db/get conn query)))]
(log/debug (str "job->balance-left-resolver " job-id " | " result))
result)))


(defn sign-in-mutation
[_ {:keys [:data :data-signature] :as input} {:keys [config]}]
(try-catch-throw
Expand Down Expand Up @@ -1329,6 +1350,7 @@
:invoices job->invoices-resolver
:invoice invoice-resolver
:balance job->balance-resolver
:balanceLeft job->balance-left-resolver
:job_requiredSkills job->required-skills-resolver}
:JobStory {:jobStory_employerFeedback job-story->employer-feedback-resolver
:jobStory_candidateFeedback job-story->candidate-feedback-resolver
Expand Down
1 change: 1 addition & 0 deletions shared/src/ethlance/shared/graphql/schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@
job_dateUpdated: Float # TODO: change back to Date after switching to district-ui-graphql

balance: Float
balanceLeft: Float
job_tokenType: String
job_tokenAmount: Float
job_tokenAddress: String
Expand Down
5 changes: 5 additions & 0 deletions ui/resources/public/less/page/new-invoice.less
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
padding-left: 0.4em;
}
}

> .max-available > div {
display: inline;
margin-left: 0.3rem;
}
}

> .right-form {
Expand Down
6 changes: 5 additions & 1 deletion ui/src/ethlance/ui/page/job_detail.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@
has-accepted-arbiter? (not (nil? (get results :job/arbiter)))
token-details (get results :token-details)
job-balance (get results :balance)
job-balance-left (get results :balance-left)

invoices (get-in results [:invoices :items])
unpaid-invoices (filter #(= "created" (:invoice/status %)) invoices)
Expand All @@ -594,7 +595,9 @@
[:div.ticket-listing
[:div.ticket
[:div.label "Available Funds"]
[c-token-info job-balance token-details]]]
[c-token-info job-balance token-details]
[:div.label "Without unpaid invoices"]
[c-token-info job-balance-left token-details]]]

(when job-ongoing? [c-add-funds contract-address (:job/token-id results) token-details])
[:div.profiles
Expand Down Expand Up @@ -654,6 +657,7 @@
:job/token-address
:job/token-id
:balance
:balance-left

[:token-details
[:token-detail/id
Expand Down
12 changes: 9 additions & 3 deletions ui/src/ethlance/ui/page/new_invoice.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[ethlance.ui.component.select-input :refer [c-select-input]]
[ethlance.ui.component.textarea-input :refer [c-textarea-input]]
[ethlance.ui.component.token-amount-input :refer [c-token-amount-input]]
[ethlance.ui.component.token-info :refer [c-token-info]]
[re-frame.core :as re]))


Expand Down Expand Up @@ -40,6 +41,7 @@
:job/token-amount
:job/token-type
:job/token-id
:balance-left
[:token-details
[:token-detail/id
:token-detail/type
Expand All @@ -65,7 +67,10 @@
(sort-by :job-story/date-created ,,,)
reverse)
token-display-name (name (or (@job-token :symbol) (@job-token :type) ""))
job-token-decimals (get-in @*invoiced-job [:job :token-details :token-detail/decimals])
job-token-details (get-in @*invoiced-job [:job :token-details])
job-token-decimals (:token-detail/decimals job-token-details)
balance-left (get-in @*invoiced-job [:job :balance-left])
show-balance-left? (not (nil? balance-left))
no-job-selected? (nil? @*invoiced-job)
focus-on-element (fn [id _event] (.focus (.getElementById js/document id)))
validations (re/subscribe [:page.new-invoice/validations])
Expand Down Expand Up @@ -113,8 +118,9 @@
:disabled no-job-selected?
:on-change #(re/dispatch [:page.new-invoice/set-invoice-amount %])}]
[:div.post-label token-display-name]]
[:div.usd-estimate @estimated-usd]]

[:div.usd-estimate @estimated-usd]
(when show-balance-left?
[:div.max-available "Max available:" [c-token-info balance-left job-token-details]])]
[:div.right-form
[:div.label "Message"]
[c-textarea-input
Expand Down
8 changes: 5 additions & 3 deletions ui/src/ethlance/ui/page/new_invoice/subscriptions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
:page.new-invoice/validations
:<- [::form-fields]
(fn [{:keys [invoiced-job invoice-amount]}]
{:invoiced-job (not (nil? invoiced-job))
:invoice-amount (and (not (nil? (get invoice-amount :token-amount)))
(> (:token-amount invoice-amount) 0))}))
(let [balance-left (get-in invoiced-job [:job :balance-left])]
{:invoiced-job (not (nil? invoiced-job))
:invoice-amount (and (not (nil? (get invoice-amount :token-amount)))
(> (:token-amount invoice-amount) 0)
(<= (:token-amount invoice-amount) balance-left))})))
Loading