Skip to content

Commit a5029cf

Browse files
authored
show error message when invoice exceeds the job funds (#472)
1 parent 25a1128 commit a5029cf

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

ui/resources/public/less/page/new-invoice.less

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@
9595
}
9696
}
9797

98-
> .max-available > div {
99-
display: inline;
100-
margin-left: 0.3rem;
98+
> .max-available {
99+
&.not-enough {
100+
color: red;
101+
}
102+
> div {
103+
margin-bottom: 0.3rem;
104+
> div {
105+
display: inline;
106+
margin-left: 0.3rem;
107+
}
108+
}
101109
}
102110
}
103111

ui/src/ethlance/ui/page/new_invoice.cljs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
no-job-selected? (nil? @*invoiced-job)
7575
focus-on-element (fn [id _event] (.focus (.getElementById js/document id)))
7676
validations (re/subscribe [:page.new-invoice/validations])
77+
enough-funding? (:invoice-amount-enough @validations)
7778
tx-in-progress? @(re/subscribe [:page.new-invoice/tx-in-progress?])
7879
button-disabled? (not (every? true? (vals @validations)))]
7980
[c-main-layout {:container-opts {:class :new-invoice-main-container}}
@@ -120,7 +121,12 @@
120121
[:div.post-label token-display-name]]
121122
[:div.usd-estimate @estimated-usd]
122123
(when show-balance-left?
123-
[:div.max-available "Max available:" [c-token-info balance-left job-token-details]])]
124+
[:div.max-available
125+
{:class (when-not enough-funding? "not-enough")}
126+
[:div "Max available:" [c-token-info balance-left job-token-details]]
127+
[:div.warning
128+
{:style {:visibility (if enough-funding? "hidden" "visible")}}
129+
"You cannot create an invoice that exceeds the available funds for the job."]])]
124130
[:div.right-form
125131
[:div.label "Message"]
126132
[c-textarea-input

ui/src/ethlance/ui/page/new_invoice/subscriptions.cljs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@
6464
:page.new-invoice/validations
6565
:<- [::form-fields]
6666
(fn [{:keys [invoiced-job invoice-amount]}]
67-
(let [balance-left (get-in invoiced-job [:job :balance-left])]
67+
(let [balance-left (get-in invoiced-job [:job :balance-left])
68+
positive-invoice-amount? (and (not (nil? (get invoice-amount :token-amount)))
69+
(> (:token-amount invoice-amount) 0))]
6870
{:invoiced-job (not (nil? invoiced-job))
69-
:invoice-amount (and (not (nil? (get invoice-amount :token-amount)))
70-
(> (:token-amount invoice-amount) 0)
71-
(<= (:token-amount invoice-amount) balance-left))})))
71+
:invoice-amount positive-invoice-amount?
72+
:invoice-amount-enough (or (not positive-invoice-amount?)
73+
(<= (:token-amount invoice-amount) balance-left))})))

0 commit comments

Comments
 (0)