Skip to content

Commit

Permalink
Invoke contract methods for decimal and symbol data
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov committed Mar 31, 2020
1 parent 0d75e1c commit de520f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
32 changes: 29 additions & 3 deletions src/status_im/hardwallet/sign.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.hardwallet.card :as card]
[status-im.utils.fx :as fx]
[status-im.utils.types :as types]
Expand Down Expand Up @@ -33,12 +34,13 @@
(common/show-wrong-keycard-alert card-connected?))))))

(def sign-typed-data-listener (atom nil))
(fx/defn sign-typed-data

(fx/defn sign-typed-data
{:events [:hardwallet/sign-typed-data]}
[{:keys [db] :as cofx}]
(let [card-connected? (get-in db [:hardwallet :card-connected?])
hash (get-in db [:hardwallet :hash])]
hash (get-in db [:hardwallet :hash])
_ (log/info "###sign-typed-data" (get db :signing/sign))]
(if card-connected?
(do
(when @sign-typed-data-listener
Expand All @@ -54,10 +56,34 @@
(common/set-on-card-connected :hardwallet/sign-typed-data)
{:db (assoc-in db [:signing/sign :keycard-step] :signing)})))))

(fx/defn fetch-currency-symbol-on-success
{:events [:hardwallet/fetch-currency-symbol-on-success]}
[{:keys [db] :as cofx} currency]
{:db (assoc-in db [:signing/sign :formatted-data :message :formatted-currency] currency)})

(fx/defn fetch-currency-decimals-on-success
{:events [:hardwallet/fetch-currency-decimals-on-success]}
[{:keys [db] :as cofx} decimals]
{:db (update-in db [:signing/sign :formatted-data :message]
#(assoc % :formatted-amount (/ (:amount %) (Math/pow 10 decimals))))})

(fx/defn store-hash-and-sign-typed
{:events [:hardwallet/store-hash-and-sign-typed]}
[{:keys [db] :as cofx} result]
(let [{:keys [result error]} (types/json->clj result)]
(let [{:keys [result error]} (types/json->clj result)
currency-contract (get-in db [:signing/sign :formatted-data :message :currency])]
(json-rpc/eth-call {:contract currency-contract
:method "decimals()"
:outputs ["uint8"]
:on-success (fn [[decimals]]
(re-frame/dispatch [:hardwallet/fetch-currency-decimals-on-success decimals]))})

(json-rpc/eth-call {:contract currency-contract
:method "symbol()"
:outputs ["string"]
:on-success (fn [[currency]]
(re-frame/dispatch [:hardwallet/fetch-currency-symbol-on-success currency]))})

(fx/merge cofx
{:db (assoc-in db [:hardwallet :hash] result)}
sign-typed-data)))
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/ui/screens/signing/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@
[react/view {:style {:align-self :flex-start :padding-left 16 :margin-bottom 24}}
[react/text {:style {:font-size (if small-screen? 15 17) :font-weight "700"}}
(i18n/label :t/confirmation-request)]]
(when (and (:amount message) (:currency message))
(when (and (:formatted-amount message) (:formatted-currency message))
[react/view {:style {:margin-bottom 24 :align-self :stretch}}
[react/nested-text {:style {:font-weight "500" :font-size (if small-screen? 34 44)
:text-align :center}}
(str (:amount message) " ")
[{:style {:color colors/gray}} (:currency message)]]
(str (:formatted-amount message) " ")
[{:style {:color colors/gray}} (:formatted-currency message)]]
[react/text {:style {:font-size 19 :text-align :center
:margin-bottom 16}}
(str fiat-amount " " fiat-currency)]
Expand Down

0 comments on commit de520f7

Please sign in to comment.