Skip to content

Commit

Permalink
Use a single in-progress? flag for signing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Vlasov committed Apr 21, 2020
1 parent 938f3df commit 7705dbc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
16 changes: 10 additions & 6 deletions src/status_im/signing/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@
:enabled? (and unmasked-pass (> (count unmasked-pass) 5)))}))

(fx/defn sign-message
[{{:signing/keys [sign tx] :as db} :db}]
[{{:signing/keys [sign in-progress? tx] :as db} :db}]
(let [{{:keys [data typed? from]} :message} tx
{:keys [in-progress? password]} sign
{:keys [password]} sign
from (or from (ethereum/default-address db))
hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
(when-not in-progress?
(merge
{:db (update db :signing/sign assoc :error nil :in-progress? true)}
{:db (-> db
(assoc-in [:signing/sign :error] nil)
(assoc :signing/in-progress? true))}
(if typed?
{:signing.fx/sign-typed-data {:data data
:account from
Expand All @@ -89,8 +91,8 @@

(fx/defn send-transaction
{:events [:signing.ui/sign-is-pressed]}
[{{:signing/keys [sign tx] :as db} :db :as cofx}]
(let [{:keys [in-progress? password]} sign
[{{:signing/keys [sign in-progress? tx] :as db} :db :as cofx}]
(let [{:keys [password]} sign
{:keys [tx-obj gas gasPrice message]} tx
hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
(if message
Expand All @@ -101,7 +103,9 @@
(when gasPrice
{:gasPrice (str "0x" (abi-spec/number-to-hex gasPrice))}))]
(when-not in-progress?
{:db (update db :signing/sign assoc :error nil :in-progress? true)
{:db (-> db
(assoc-in [:signing/sign :error] nil)
(assoc :signing/in-progress? true))
:signing/send-transaction-fx {:tx-obj tx-obj-to-send
:hashed-password hashed-password
:cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send hashed-password])}})))))
Expand Down
1 change: 1 addition & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@

;;signing
(reg-root-key-sub :signing/tx :signing/tx)
(reg-root-key-sub :signing/in-progress? :signing/in-progress?)
(reg-root-key-sub :signing/edit-fee :signing/edit-fee)

;;intro-wizard
Expand Down
17 changes: 10 additions & 7 deletions src/status_im/ui/screens/signing/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
[separator]]))

(defn header
[{:keys [in-progress?] :as sign}
[sign in-progress?
{:keys [contact amount token approve?] :as tx}
display-symbol fee fee-display-symbol]
[react/view styles/header
Expand Down Expand Up @@ -136,7 +136,7 @@
(defn signature-request [{:keys [error formatted-data
fiat-amount fiat-currency
keycard-step
in-progress? enabled?] :as sign} small-screen?]
enabled?] :as sign} in-progress? small-screen?]
(let [message (:message formatted-data)
title (case keycard-step
:connect :t/looking-for-cards
Expand Down Expand Up @@ -232,7 +232,8 @@
:label (i18n/label :t/close)
:on-press #(re-frame/dispatch [:hide-popover])}]]]))

(views/defview password-view [{:keys [type error in-progress? enabled?] :as sign}]
(views/defview password-view [{:keys [type error enabled?] :as sign}
in-progress?]
(views/letsubs [phrase [:signing/phrase]]
(case type
:password
Expand Down Expand Up @@ -260,9 +261,10 @@

(views/defview message-sheet []
(views/letsubs [{:keys [formatted-data type] :as sign} [:signing/sign]
in-progress? [:signing/in-progress?]
small-screen? [:dimensions/small-screen?]]
(if (= type :pinless)
[signature-request sign small-screen?]
[signature-request sign in-progress? small-screen?]
[react/view (styles/message)
[react/view styles/message-header
[react/text {:style {:typography :title-bold}} (i18n/label :t/signing-a-message)]
Expand All @@ -274,7 +276,7 @@
[react/view styles/message-border
[react/scroll-view
[react/text (or formatted-data "")]]]
[password-view sign]]])))
[password-view sign in-progress?]]])))

(defn amount-item [prices wallet-currency amount amount-error display-symbol fee-display-symbol prices-loading?]
(let [converted-value (* amount (get-in prices [(keyword display-symbol) (keyword (:code wallet-currency)) :price]))]
Expand Down Expand Up @@ -328,6 +330,7 @@

(views/defview sheet [{:keys [from contact amount token approve?] :as tx}]
(views/letsubs [fee [:signing/fee]
in-progress? [:signing/in-progress?]
sign [:signing/sign]
chain [:ethereum/chain-keyword]
{:keys [amount-error gas-error]} [:signing/amount-errors (:address from)]
Expand All @@ -339,11 +342,11 @@
(let [display-symbol (wallet.utils/display-symbol token)
fee-display-symbol (wallet.utils/display-symbol (tokens/native-currency chain))]
[react/view (styles/sheet)
[header sign tx display-symbol fee fee-display-symbol]
[header sign in-progress? tx display-symbol fee fee-display-symbol]
[separator]
(if sign
[react/view {:padding-top 20}
[password-view sign]]
[password-view sign in-progress?]]
[react/view
(when-not mainnet?
[react/view
Expand Down

0 comments on commit 7705dbc

Please sign in to comment.