Revert "[#7133] sign tx with keycard"

This reverts commit feffcaf33d.

Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
Dmitry Novotochinov 2019-04-02 20:00:59 +03:00
parent feffcaf33d
commit 4ccb1ea52d
No known key found for this signature in database
GPG Key ID: 43D1DAF5AD39C927
21 changed files with 122 additions and 438 deletions

View File

@ -1 +1 @@
0.23.0-beta.10
0.23.0-beta.8-chaos

View File

@ -54,7 +54,7 @@
"react-native-safe-area-view": "0.9.0",
"react-native-securerandom": "git+https://github.com/status-im/react-native-securerandom.git#0.1.1-2",
"react-native-splash-screen": "3.1.1",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.4.0",
"react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.3.10",
"react-native-svg": "^9.2.4",
"react-native-svg-transformer": "^0.12.1",
"react-native-tcp": "git+https://github.com/status-im/react-native-tcp.git#v3.3.0-1-status",

View File

@ -5355,9 +5355,9 @@ react-native-splash-screen@3.1.1:
resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.1.1.tgz#1a4e46c9fdce53ff52af2a2cb4181788c4e30b30"
integrity sha512-PU2YocOSGbLjL9Vgcq/cwMNuHHKNjjuPpa1IPMuWo+6EB/fSZ5VOmxSa7+eucQe3631s3NhGuk3eHKahU03a4Q==
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.4.0":
version "2.4.0"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#b9a66144b3942e40ffb30cb27fa01202b0d11061"
"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.3.10":
version "2.3.10"
resolved "git+https://github.com/status-im/react-native-status-keycard.git#a6da0a7889fdbc8cdf61771cf1b989c5cfb14b08"
react-native-svg-transformer@^0.12.1:
version "0.12.1"

View File

@ -700,45 +700,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void hashMessage(final String message, final Callback callback) {
Log.d(TAG, "hashMessage");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.hashMessage(message);
callback.invoke(res);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void hashTypedData(final String data, final Callback callback) {
Log.d(TAG, "hashTypedData");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.hashTypedData(data);
callback.invoke(res);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void sendTransactionWithSignature(final String txArgsJSON, final String signature, final Callback callback) {
Log.d(TAG, "sendTransactionWithSignature");

View File

@ -949,7 +949,7 @@
(handlers/register-handler-fx
:hardwallet/get-application-info
(fn [cofx _]
(hardwallet/get-application-info cofx nil nil)))
(hardwallet/get-application-info cofx nil)))
(handlers/register-handler-fx
:hardwallet.callback/on-get-application-info-success
@ -1089,11 +1089,6 @@
(fn [cofx [_ data]]
(hardwallet/on-get-keys-success cofx data)))
(handlers/register-handler-fx
:hardwallet.callback/on-sign-success
(fn [cofx [_ data]]
(hardwallet/on-sign-success cofx data)))
(handlers/register-handler-fx
:hardwallet/auto-login
(fn [cofx _]
@ -1114,11 +1109,6 @@
(fn [cofx [_ error]]
(hardwallet/on-get-keys-error cofx error)))
(handlers/register-handler-fx
:hardwallet.callback/on-sign-error
(fn [cofx [_ error]]
(hardwallet/on-sign-error cofx error)))
(handlers/register-handler-fx
:hardwallet.ui/status-hardwallet-option-pressed
(fn [cofx _]
@ -1253,11 +1243,6 @@
(fn [cofx [_ number step]]
(hardwallet/update-pin cofx number step)))
(handlers/register-handler-fx
:hardwallet.ui/navigate-back-button-clicked
(fn [cofx _]
(hardwallet/navigate-back-button-clicked cofx)))
(handlers/register-handler-fx
:hardwallet/process-pin-input
(fn [cofx _]
@ -1351,11 +1336,6 @@
(fn [cofx _]
(hardwallet/navigate-to-reset-card-screen cofx)))
(handlers/register-handler-fx
:hardwallet/sign
(fn [cofx _]
(hardwallet/sign cofx)))
;; browser module
(handlers/register-handler-fx

View File

@ -154,11 +154,3 @@
(getKeys pairing pin)
(then #(re-frame/dispatch [:hardwallet.callback/on-get-keys-success %]))
(catch #(re-frame/dispatch [:hardwallet.callback/on-get-keys-error (error-object->map %)]))))
(defn sign
[{:keys [pairing pin hash]}]
(when (and pairing pin hash)
(.. keycard
(sign pairing pin hash)
(then #(re-frame/dispatch [:hardwallet.callback/on-sign-success %]))
(catch #(re-frame/dispatch [:hardwallet.callback/on-sign-error (error-object->map %)])))))

View File

@ -7,16 +7,13 @@
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]
[status-im.i18n :as i18n]
[status-im.utils.types :as types]
[status-im.accounts.create.core :as accounts.create]
[status-im.node.core :as node]
[status-im.utils.datetime :as utils.datetime]
[status-im.data-store.accounts :as accounts-store]
[status-im.utils.ethereum.core :as ethereum]
[clojure.string :as string]
[status-im.accounts.login.core :as accounts.login]
[status-im.accounts.recover.core :as accounts.recover]
[status-im.models.wallet :as models.wallet]))
[status-im.accounts.recover.core :as accounts.recover]))
(def default-pin "000000")
@ -30,7 +27,7 @@
(defn get-pairing
([db]
(get-pairing db (get-in db [:hardwallet :application-info :instance-uid])))
(get-pairing db nil))
([db instance-uid]
(or
(get-in db [:account/account :keycard-pairing])
@ -39,21 +36,6 @@
(:keycard-pairing
(find-account-by-keycard-instance-uid db instance-uid))))))
(fx/defn navigate-back-button-clicked
[{:keys [db] :as cofx}]
(let [screen-before (second (get db :navigation-stack))
navigate-to-browser? (contains? #{:wallet-sign-message-modal
:wallet-send-transaction-modal
:wallet-send-modal-stack} screen-before)]
(if navigate-to-browser?
(fx/merge cofx
{:db (assoc-in db [:hardwallet :on-card-connected] nil)}
(models.wallet/discard-transaction)
(navigation/navigate-to-cofx :browser nil))
(fx/merge cofx
{:db (assoc-in db [:hardwallet :on-card-connected] nil)}
(navigation/navigate-back)))))
(fx/defn remove-pairing-from-account
[{:keys [db]} {:keys [remove-instance-uid?]}]
(let [account (cond-> (:account/account db)
@ -206,7 +188,6 @@
(defn enter-pin-screen-did-load
[{:keys [db]}]
{:db (-> db
(assoc-in [:hardwallet :pin :sign] [])
(assoc-in [:hardwallet :pin :login] [])
(assoc-in [:hardwallet :pin :current] []))})
@ -293,8 +274,7 @@
(let [info' (js->clj info :keywordize-keys true)
{:keys [pin-retry-counter puk-retry-counter instance-uid]} info'
connect-screen? (= (:view-id db) :hardwallet-connect)
{:keys [card-state on-card-read]} (:hardwallet db)
on-success' (or on-success on-card-read)
card-state (get-in db [:hardwallet :card-state])
accounts-screen? (= :accounts (:view-id db))
auto-login? (and accounts-screen?
(not= on-success :hardwallet/auto-login))
@ -315,10 +295,9 @@
instance-uid)
(check-card-state))
(if (zero? puk-retry-counter)
{:utils/show-popup {:title (i18n/label :t/error)
:content (i18n/label :t/keycard-blocked)}}
(when on-success'
(dispatch-event on-success'))))))
(navigation/navigate-to-cofx :keycard-settings nil)
(when on-success
(dispatch-event on-success))))))
(fx/defn on-get-application-info-error
[{:keys [db] :as cofx} error]
@ -591,13 +570,12 @@
:enter-step :puk
:puk []})}))
(fx/defn get-application-info
[{:keys [db]} pairing on-card-read]
[{:keys [db]} pairing]
(let [instance-uid (get-in db [:hardwallet :application-info :instance-uid])
pairing' (or pairing
(when instance-uid
(get-pairing db instance-uid)))]
{:hardwallet/get-application-info {:pairing pairing'
:on-success on-card-read}}))
{:hardwallet/get-application-info {:pairing pairing'}}))
(fx/defn on-verify-pin-success
[{:keys [db] :as cofx}]
@ -608,7 +586,7 @@
(update-in [:hardwallet :pin] merge {:status nil
:error-label nil}))}
(when-not (contains? #{:hardwallet/unpair :hardwallet/unpair-and-delete} on-verified)
(get-application-info pairing nil))
(get-application-info pairing))
(when on-verified
(dispatch-on-verified-event on-verified)))))
@ -635,7 +613,7 @@
:error-label nil}))
:utils/show-popup {:title ""
:content (i18n/label :t/pin-changed {:pin pin})}}
(navigation/navigate-back))))
(navigation/navigate-to-cofx :keycard-settings nil))))
(fx/defn on-change-pin-error
[{:keys [db]} error]
@ -686,8 +664,7 @@
(defn- unblock-pin
[{:keys [db] :as fx}]
(let [puk (vector->string (get-in fx [:db :hardwallet :pin :puk]))
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
pairing (get-pairing db instance-uid)]
pairing (get-pairing db)]
{:db (assoc-in db [:hardwallet :pin :status] :verifying)
:hardwallet/unblock-pin {:puk puk
:new-pin default-pin
@ -732,26 +709,8 @@
(assoc-in [:hardwallet :on-card-read] :hardwallet/login-with-keycard))}
(navigation/navigate-to-cofx :hardwallet-connect nil)))))
(fx/defn sign
[{:keys [db] :as cofx}]
(let [card-connected? (get-in db [:hardwallet :card-connected?])
pairing (get-pairing db)
hash (get-in db [:hardwallet :hash])
pin (vector->string (get-in db [:hardwallet :pin :sign]))]
(if card-connected?
{:db (-> db
(assoc-in [:hardwallet :card-read-in-progress?] true)
(assoc-in [:hardwallet :pin :status] :verifying))
:hardwallet/sign {:hash (ethereum/naked-address hash)
:pairing pairing
:pin pin}}
(fx/merge cofx
{:db (assoc-in db [:hardwallet :on-card-connected] :hardwallet/sign)}
(navigation/navigate-to-cofx :hardwallet-connect nil)))))
; PIN enter steps:
; login - PIN is used to login
; sign - PIN for transaction sign
; current - current PIN to perform actions which require PIN auth
; original - new PIN when user changes it or creates new one
; confirmation - confirmation for new PIN
@ -779,10 +738,6 @@
(= pin-code-length numbers-entered))
(verify-pin)
(and (= enter-step :sign)
(= pin-code-length numbers-entered))
(sign)
(and (= enter-step :puk)
(= puk-code-length numbers-entered))
(unblock-pin)
@ -843,11 +798,11 @@
:else (get-in db [:hardwallet :on-card-read]))
pairing (get-pairing db instance-uid)]
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :card-connected?] true)
(assoc-in [:hardwallet :card-read-in-progress?] (boolean on-card-read)))}
(when (not= on-card-connected :hardwallet/sign)
(get-application-info pairing on-card-read))
{:db (-> db
(assoc-in [:hardwallet :card-connected?] true)
(assoc-in [:hardwallet :card-read-in-progress?] (boolean on-card-read)))
:hardwallet/get-application-info {:pairing pairing
:on-success on-card-read}}
(when (and on-card-connected
(not login?))
(dispatch-event on-card-connected))
@ -1102,81 +1057,30 @@
encryption-public-key]} (js->clj data :keywordize-keys true)
whisper-public-key' (str "0x" whisper-public-key)
{:keys [photo-path name]} (get-in db [:accounts/accounts wallet-address])
password encryption-public-key
instance-uid (get-in db [:hardwallet :application-info :instance-uid])]
password encryption-public-key]
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :pin :status] nil)
(assoc-in [:hardwallet :pin :login] [])
(assoc-in [:hardwallet :whisper-public-key] whisper-public-key')
(assoc-in [:hardwallet :whisper-private-key] whisper-private-key)
(assoc-in [:hardwallet :wallet-address] wallet-address)
(assoc-in [:hardwallet :encryption-public-key] encryption-public-key)
(update :accounts/login assoc
:password password
:address wallet-address
:photo-path photo-path
:name name))
:hardwallet/get-application-info {:pairing (get-pairing db instance-uid)}}
{:db (-> db
(assoc-in [:hardwallet :pin :status] nil)
(assoc-in [:hardwallet :whisper-public-key] whisper-public-key')
(assoc-in [:hardwallet :whisper-private-key] whisper-private-key)
(assoc-in [:hardwallet :wallet-address] wallet-address)
(assoc-in [:hardwallet :encryption-public-key] encryption-public-key)
(update :accounts/login assoc
:password password
:address wallet-address
:photo-path photo-path
:name name))}
(accounts.login/user-login true))))
(fx/defn on-get-keys-error
[{:keys [db] :as cofx} error]
(log/debug "[hardwallet] get keys error: " error)
(let [tag-was-lost? (= "Tag was lost." (:error error))
instance-uid (get-in db [:hardwallet :application-info :instance-uid])]
(let [tag-was-lost? (= "Tag was lost." (:error error))]
(if tag-was-lost?
{:utils/show-popup {:title (i18n/label :t/error)
:content (i18n/label :t/tag-was-lost)}}
(fx/merge cofx
{:hardwallet/get-application-info {:pairing (get-pairing db instance-uid)}
{:hardwallet/get-application-info {:pairing (get-pairing db)}
:db (update-in db [:hardwallet :pin] merge {:status :error
:login []
:error-label :t/pin-mismatch})}
(navigation/navigate-to-cofx :enter-pin nil)))))
(fx/defn send-transaction-with-signature
[_ data]
{:send-transaction-with-signature data})
(fx/defn sign-message-completed
[{:keys [db]} signature]
(let [screen-params (get-in db [:navigation/screen-params :wallet-sign-message-modal])
signature' (-> signature
; add 27 to last byte
; https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L431
(clojure.string/replace-first #"00$", "1b")
(clojure.string/replace-first #"01$", "1c")
(ethereum/normalized-address))]
{:dispatch
[:status-im.ui.screens.wallet.send.events/sign-message-completed
screen-params
{:result signature'}]}))
(fx/defn on-sign-success
[{:keys [db] :as cofx} signature]
(log/debug "[hardwallet] sign success: " signature)
(let [transaction (get-in db [:hardwallet :transaction])]
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :pin :sign] [])
(assoc-in [:hardwallet :pin :status] nil)
(assoc-in [:hardwallet :on-card-connected] nil)
(assoc-in [:hardwallet :hash] nil)
(assoc-in [:hardwallet :transaction] nil))}
(get-application-info (get-pairing db) nil)
(if transaction
(send-transaction-with-signature {:transaction (types/clj->json transaction)
:signature signature
:on-completed #(re-frame/dispatch [:status-im.ui.screens.wallet.send.events/transaction-completed (types/json->clj %)])})
(sign-message-completed signature)))))
(fx/defn on-sign-error
[{:keys [db] :as cofx} error]
(log/debug "[hardwallet] sign error: " error)
(fx/merge cofx
{:db (update-in db [:hardwallet :pin] merge {:status :error
:sign []
:error-label :t/pin-mismatch})}
(navigation/navigate-to-cofx :enter-pin nil)
(get-application-info (get-pairing db) nil)))

View File

@ -77,15 +77,6 @@
:hardwallet/get-keys
card/get-keys)
(re-frame/reg-fx
:hardwallet/sign
card/sign)
(re-frame/reg-fx
:hardwallet/login-with-keycard
statusgo/login-with-keycard)
(re-frame/reg-fx
:send-transaction-with-signature
(fn [{:keys [transaction signature on-completed]}]
(statusgo/send-transaction-with-signature transaction signature on-completed)))

View File

@ -120,7 +120,7 @@
:error message}
:webview webview-bridge}))
(defn dapp-complete-transaction [id result method message-id webview keycard?]
(defn dapp-complete-transaction [id result method message-id webview]
(cond-> {:browser/send-to-bridge {:message {:type constants/web3-send-async-callback
:messageId message-id
:result {:jsonrpc "2.0"
@ -130,7 +130,7 @@
:dispatch [:navigate-back]}
(constants/web3-sign-message? method)
(assoc :dispatch (if keycard? [:navigate-to :browser] [:navigate-back]))
(assoc :dispatch [:navigate-back])
(= method constants/web3-send-transaction)
(assoc :dispatch [:navigate-to-clean :wallet-transaction-sent-modal])))

View File

@ -58,12 +58,6 @@
(defn hash-transaction [rpcParams callback]
(native-module/hash-transaction rpcParams callback))
(defn hash-message [message callback]
(native-module/hash-message message callback))
(defn hash-typed-data [data callback]
(native-module/hash-typed-data data callback))
(defn send-transaction-with-signature [rpcParams sig callback]
(native-module/send-transaction-with-signature rpcParams sig callback))

View File

@ -98,14 +98,6 @@
(when (and @node-started status)
(.hashTransaction status rpcParams callback)))
(defn hash-message [message callback]
(when (and @node-started status)
(.hashMessage status message callback)))
(defn hash-typed-data [data callback]
(when (and @node-started status)
(.hashTypedData status data callback)))
(defn sign-typed-data [data password callback]
(when (and @node-started status)
(.signTypedData status data password callback)))

View File

@ -40,8 +40,7 @@
(i18n/label :t/go-to-settings)]]])
(defview hardwallet-connect []
(letsubs [nfc-enabled? [:hardwallet/nfc-enabled?]
setup-step [:hardwallet-setup-step]]
(letsubs [nfc-enabled? [:hardwallet/nfc-enabled?]]
[react/view styles/container
[status-bar/status-bar]
[react/view {:flex 1
@ -54,11 +53,10 @@
(if nfc-enabled?
[nfc-enabled]
[nfc-disabled])]
(if (= setup-step :begin)
[react/view styles/bottom-container
[react/touchable-highlight {:on-press #(.openURL react/linking "https://hardwallet.status.im")}
[react/view styles/product-info-container
[react/text {:style styles/product-info-text}
(i18n/label :t/product-information)]
[vector-icons/icon :main-icons/link {:color colors/blue
:container-style styles/external-link-icon}]]]])]]))
[react/view styles/bottom-container
[react/touchable-highlight {:on-press #(.openURL react/linking "https://hardwallet.status.im")}
[react/view styles/product-info-container
[react/text {:style styles/product-info-text}
(i18n/label :t/product-information)]
[vector-icons/icon :main-icons/link {:color colors/blue
:container-style styles/external-link-icon}]]]]]]))

View File

@ -9,8 +9,7 @@
[status-im.ui.screens.hardwallet.components :as components]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.components.status-bar.view :as status-bar]
[status-im.ui.components.toolbar.actions :as actions]
[status-im.ui.components.toolbar.actions :as toolbar.actions]))
[status-im.ui.components.toolbar.actions :as actions]))
(defn numpad-button [n step enabled?]
[react/touchable-highlight
@ -32,7 +31,8 @@
[numpad-row [4 5 6] step enabled?]
[numpad-row [7 8 9] step enabled?]
[react/view styles/numpad-row-container
[react/view styles/numpad-empty-button]
[react/view styles/numpad-empty-button
[react/text {:style styles/numpad-empty-button-text}]]
[numpad-button 0 step enabled?]
[react/touchable-highlight
{:on-press #(when enabled?
@ -125,12 +125,7 @@
[react/view {:flex 1
:background-color colors/white}
[status-bar/status-bar]
[toolbar/toolbar
nil
[toolbar/nav-button (assoc toolbar.actions/default-back
:handler
#(re-frame/dispatch [:hardwallet.ui/navigate-back-button-clicked]))]
nil]
[toolbar/toolbar nil toolbar/default-nav-back nil]
(if (zero? pin-retry-counter)
[pin-view {:pin pin
:retry-counter (when (< puk-retry-counter puk-retries) puk-retry-counter)
@ -149,7 +144,6 @@
:t/current-pin)
:description-label (case step
:current :t/current-pin-description
:sign :t/current-pin-description
:login :t/login-pin-description
:t/new-pin-description)
:step step

View File

@ -33,9 +33,3 @@
:keycard-reset-card-disabled?
(fn [db]
(get-in db [:hardwallet :reset-card :disabled?] false)))
(re-frame/reg-sub
:keycard-account?
(fn [db]
(boolean
(get-in db [:account/account :keycard-instance-uid]))))

View File

@ -4,17 +4,13 @@
[{:name :wallet-send-modal-stack
:screens [:wallet-send-transaction-modal
:wallet-transaction-sent-modal
:wallet-transaction-fee
:hardwallet-connect
:enter-pin]
:wallet-transaction-fee]
:config {:initialRouteName :wallet-send-transaction-modal}}
{:name :wallet-send-modal-stack-with-onboarding
:screens [:wallet-onboarding-setup-modal
:wallet-send-transaction-modal
:wallet-transaction-sent-modal
:wallet-transaction-fee
:hardwallet-connect
:enter-pin]
:wallet-transaction-fee]
:config {:initialRouteName :wallet-onboarding-setup-modal}}
:chat-modal
:show-extension-modal

View File

@ -11,8 +11,6 @@
:screens [:wallet-send-transaction
:recent-recipients
:wallet-transaction-sent
:enter-pin
:hardwallet-connect
:recipient-qr-code
:wallet-send-assets]}
{:name :request-transaction-stack

View File

@ -20,8 +20,7 @@
[status-im.utils.types :as types]
[status-im.utils.utils :as utils]
[status-im.utils.config :as config]
[status-im.transport.utils :as transport.utils]
[status-im.hardwallet.core :as hardwallet]))
[status-im.transport.utils :as transport.utils]))
;;;; FX
@ -78,6 +77,27 @@
#(re-frame/dispatch [::transaction-completed (types/json->clj %)])
password]}))))
;; SIGN MESSAGE
(handlers/register-handler-fx
:wallet/sign-message
(fn [_ [_ typed? screen-params password-error-cb]]
(let [{:keys [data from password]} screen-params]
(if typed?
{::sign-typed-data {:data data
:password password
:account from
:on-completed #(re-frame/dispatch [::sign-message-completed
screen-params
(types/json->clj %)
password-error-cb])}}
{::sign-message {:params {:data data
:password (security/safe-unmask-data password)
:account from}
:on-completed #(re-frame/dispatch [::sign-message-completed
screen-params
(types/json->clj %)
password-error-cb])}}))))
;; SEND TRANSACTION CALLBACK
(handlers/register-handler-fx
::transaction-completed
@ -119,20 +139,6 @@
(if on-result
{:dispatch (conj on-result id result method)})))))
(handlers/register-handler-fx
::hash-message-completed
(fn [{:keys [db] :as cofx} [_ {:keys [result error]}]]
(let [db' (assoc-in db [:wallet :send-transaction :in-progress?] false)]
(if error
;; ERROR
(models.wallet/handle-transaction-error (assoc cofx :db db') error)
;; RESULT
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :pin :enter-step] :sign)
(assoc-in [:hardwallet :hash] result))}
(navigation/navigate-to-cofx :enter-pin nil))))))
;; DISCARD TRANSACTION
(handlers/register-handler-fx
:wallet/discard-transaction
@ -142,9 +148,8 @@
(handlers/register-handler-fx
:wallet.dapp/transaction-on-result
(fn [{db :db} [_ message-id id result method]]
(let [webview (:webview-bridge db)
keycard? (boolean (get-in db [:account/account :keycard-instance-uid]))]
(models.wallet/dapp-complete-transaction (int id) result method message-id webview keycard?))))
(let [webview (:webview-bridge db)]
(models.wallet/dapp-complete-transaction (int id) result method message-id webview))))
(handlers/register-handler-fx
:wallet.dapp/transaction-on-error
@ -160,7 +165,6 @@
(let [{:keys [send-transaction transactions-queue]} (:wallet db)
{:keys [payload message-id] :as queued-transaction} (last transactions-queue)
{:keys [method params id]} payload
keycard? (boolean (get-in db [:account/account :keycard-instance-uid]))
db' (update-in db [:wallet :transactions-queue] drop-last)]
(when (and (not (contains? #{:wallet-transaction-sent
:wallet-transaction-sent-modal}
@ -178,18 +182,14 @@
(let [typed? (not= constants/web3-personal-sign method)
[address data] (models.wallet/normalize-sign-message-params params)]
(if (and address data)
(let [signing-phrase (-> (get-in db [:account/account :signing-phrase])
(clojure.string/replace-all #" " " "))
screen-params {:id (str (or id message-id))
:from address
:data data
:typed? typed?
:decoded-data (if typed? (types/json->clj data) (transport.utils/to-utf8 data))
:on-result [:wallet.dapp/transaction-on-result message-id]
:on-error [:wallet.dapp/transaction-on-error message-id]
:method method
:signing-phrase signing-phrase
:keycard? keycard?}]
(let [screen-params {:id (str (or id message-id))
:from address
:data data
:typed? typed?
:decoded-data (if typed? (types/json->clj data) (transport.utils/to-utf8 data))
:on-result [:wallet.dapp/transaction-on-result message-id]
:on-error [:wallet.dapp/transaction-on-error message-id]
:method method}]
(navigation/navigate-to-cofx {:db db'} :wallet-sign-message-modal screen-params))
{:db db'})))))))
@ -205,7 +205,7 @@
#(when send-command?
(commands-sending/send % chat-id send-command? params))
(navigation/navigate-to-clean
(if (contains? #{:wallet-send-transaction :enter-pin :hardwallet-connect} (:view-id db))
(if (= (:view-id db) :wallet-send-transaction)
:wallet-transaction-sent
:wallet-transaction-sent-modal)
{})))))
@ -314,74 +314,3 @@
{:dispatch-later [{:ms 400 :dispatch [:check-dapps-transactions-queue]}]}
(navigation/navigate-back))))
(re-frame/reg-fx
::hash-transaction
(fn [{:keys [transaction all-tokens symbol chain on-completed]}]
(status/hash-transaction (types/clj->json transaction) on-completed)))
(re-frame/reg-fx
::hash-message
(fn [{:keys [message on-completed]}]
(status/hash-message message on-completed)))
(re-frame/reg-fx
::hash-typed-data
(fn [{:keys [data on-completed]}]
(status/hash-typed-data data on-completed)))
(defn send-keycard-transaction
[{{:keys [chain] :as db} :db}]
(let [{:keys [symbol] :as transaction} (get-in db [:wallet :send-transaction])
all-tokens (:wallet/all-tokens db)
from (get-in db [:account/account :address])]
{::hash-transaction {:transaction (models.wallet/prepare-send-transaction from transaction)
:all-tokens all-tokens
:symbol symbol
:chain chain
:on-completed #(re-frame/dispatch [:wallet.callback/hash-transaction-completed %])}}))
(handlers/register-handler-fx
:wallet.callback/hash-transaction-completed
(fn [{:keys [db] :as cofx} [_ result]]
(let [{:keys [transaction hash]} (:result (types/json->clj result))]
(fx/merge cofx
{:db (-> db
(assoc-in [:hardwallet :pin :enter-step] :sign)
(assoc-in [:hardwallet :transaction] transaction)
(assoc-in [:hardwallet :hash] hash))}
(navigation/navigate-to-clean :enter-pin nil)))))
(handlers/register-handler-fx
:wallet.ui/sign-transaction-button-clicked
(fn [{:keys [db] :as cofx} _]
(let [keycard-account? (boolean (get-in db [:account/account :keycard-instance-uid]))]
(if keycard-account?
(send-keycard-transaction cofx)
{:db (assoc-in db [:wallet :send-transaction :show-password-input?] true)}))))
(handlers/register-handler-fx
:wallet.ui/sign-message-button-clicked
(fn [{:keys [db]} [_ typed? screen-params password-error-cb]]
(let [{:keys [data from password]} screen-params
keycard-account? (boolean (get-in db [:account/account :keycard-instance-uid]))]
(if keycard-account?
(if typed?
{::hash-typed-data {:data data
:on-completed #(re-frame/dispatch [::hash-message-completed (types/json->clj %)])}}
{::hash-message {:message (ethereum/naked-address data)
:on-completed #(re-frame/dispatch [::hash-message-completed (types/json->clj %)])}})
(if typed?
{::sign-typed-data {:data data
:password password
:account from
:on-completed #(re-frame/dispatch [::sign-message-completed
screen-params
(types/json->clj %)
password-error-cb])}}
{::sign-message {:params {:data data
:password (security/safe-unmask-data password)
:account from}
:on-completed #(re-frame/dispatch [::sign-message-completed
screen-params
(types/json->clj %)
password-error-cb])}})))))

View File

@ -89,9 +89,3 @@
(models.wallet/add-max-fee)
(check-sufficient-funds balance symbol amount)
(check-sufficient-gas balance symbol amount))))
(re-frame/reg-sub
:wallet.send/signing-phrase-with-padding
:<- [:account/account]
(fn [{:keys [signing-phrase]}]
(clojure.string/replace-all signing-phrase #" " " ")))

View File

@ -41,8 +41,8 @@
(defn- advanced-cartouche [native-currency {:keys [max-fee gas gas-price]}]
[react/view
[wallet.components/cartouche {:on-press #(do (re-frame/dispatch [:wallet.send/clear-gas])
(re-frame/dispatch [:navigate-to :wallet-transaction-fee]))}
[wallet.components/cartouche {:on-press #(do (re-frame/dispatch [:wallet.send/clear-gas])
(re-frame/dispatch [:navigate-to :wallet-transaction-fee]))}
(i18n/label :t/wallet-transaction-fee)
[react/view {:style styles/advanced-options-text-wrapper
:accessibility-label :transaction-fee-button}
@ -67,11 +67,11 @@
[advanced-cartouche native-currency transaction])])
(defview password-input-panel [message-label spinning?]
(letsubs [account [:account/account]
(letsubs [account [:account/account]
wrong-password? [:wallet.send/wrong-password?]
signing-phrase (:signing-phrase @account)
bottom-value (animation/create-value -250)
opacity-value (animation/create-value 0)]
signing-phrase (:signing-phrase @account)
bottom-value (animation/create-value -250)
opacity-value (animation/create-value 0)]
{:component-did-mount #(send.animations/animate-sign-panel opacity-value bottom-value)}
[react/animated-view {:style (styles/animated-sign-panel bottom-value)}
(when wrong-password?
@ -119,7 +119,7 @@
;; "Sign Transaction >" button
(defn- sign-transaction-button [amount-error to amount sufficient-funds? sufficient-gas? modal? online?]
(let [sign-enabled? (and (nil? amount-error)
(or modal? (not (empty? to))) ;;NOTE(goranjovic) - contract creation will have empty `to`
(or modal? (not (empty? to))) ;;NOTE(goranjovic) - contract creation will have empty `to`
(not (nil? amount))
sufficient-funds?
sufficient-gas?
@ -129,32 +129,19 @@
[react/view]
[button/button {:style components.styles/flex
:disabled? (not sign-enabled?)
:on-press #(re-frame/dispatch [:wallet.ui/sign-transaction-button-clicked])
:on-press #(re-frame/dispatch [:set-in
[:wallet :send-transaction :show-password-input?]
true])
:text-style {:color :white}
:accessibility-label :sign-transaction-button}
(i18n/label :t/transactions-sign-transaction)
[vector-icons/icon :main-icons/next {:color (if sign-enabled? colors/white colors/white-light-transparent)}]]]))
(defn signing-phrase-view [signing-phrase]
[react/view {:flex-direction :column
:align-items :center
:margin-top 10}
[react/view (assoc styles/signing-phrase-container :width "90%" :height 40)
[react/text {:accessibility-label :signing-phrase-text
:style {:padding-vertical 16
:text-align :center}}
signing-phrase]]
[react/text {:style {:color :white
:text-align :center
:font-size 12
:padding-vertical 14}}
(i18n/label :t/signing-phrase-warning)]])
(defn- render-send-transaction-view [{:keys [modal? transaction scroll advanced? keycard? signing-phrase network all-tokens amount-input network-status]}]
(defn- render-send-transaction-view [{:keys [modal? transaction scroll advanced? network all-tokens amount-input network-status]}]
(let [{:keys [amount amount-text amount-error asset-error show-password-input? to to-name sufficient-funds?
sufficient-gas? in-progress? from-chat? symbol]} transaction
chain (ethereum/network->chain-keyword network)
native-currency (tokens/native-currency chain)
chain (ethereum/network->chain-keyword network)
native-currency (tokens/native-currency chain)
{:keys [decimals] :as token} (tokens/asset-for all-tokens chain symbol)
online? (= :online network-status)]
[wallet.components/simple-screen {:avoid-keyboard? (not modal?)
@ -185,9 +172,7 @@
:amount-text amount-text
:input-options {:on-change-text #(re-frame/dispatch [:wallet.send/set-and-validate-amount % symbol decimals])
:ref (partial reset! amount-input)}} token]
[advanced-options advanced? native-currency transaction scroll]
(when keycard?
[signing-phrase-view signing-phrase])]]
[advanced-options advanced? native-currency transaction scroll]]]
(if show-password-input?
[enter-password-buttons in-progress?
#(re-frame/dispatch [:wallet/cancel-entering-password])
@ -201,11 +186,11 @@
;; MAIN SEND TRANSACTION VIEW
(defn- send-transaction-view [{:keys [scroll] :as opts}]
(let [amount-input (atom nil)
handler (fn [_]
(when (and scroll @scroll @amount-input
(.isFocused @amount-input))
(log/debug "Amount field focused, scrolling down")
(.scrollToEnd @scroll)))]
handler (fn [_]
(when (and scroll @scroll @amount-input
(.isFocused @amount-input))
(log/debug "Amount field focused, scrolling down")
(.scrollToEnd @scroll)))]
(reagent/create-class
{:component-will-mount (fn [_]
;;NOTE(goranjovic): keyboardDidShow is for android and keyboardWillShow for ios
@ -216,41 +201,33 @@
;; SEND TRANSACTION FROM WALLET (CHAT)
(defview send-transaction []
(letsubs [transaction [:wallet.send/transaction]
advanced? [:wallet.send/advanced?]
network [:account/network]
scroll (atom nil)
(letsubs [transaction [:wallet.send/transaction]
advanced? [:wallet.send/advanced?]
network [:account/network]
scroll (atom nil)
network-status [:network-status]
all-tokens [:wallet/all-tokens]
signing-phrase [:wallet.send/signing-phrase-with-padding]
keycard? [:keycard-account?]]
all-tokens [:wallet/all-tokens]]
[send-transaction-view {:modal? false
:transaction transaction
:scroll scroll
:advanced? advanced?
:keycard? keycard?
:signing-phrase signing-phrase
:network network
:all-tokens all-tokens
:network-status network-status}]))
;; SEND TRANSACTION FROM DAPP
(defview send-transaction-modal []
(letsubs [transaction [:wallet.send/transaction]
advanced? [:wallet.send/advanced?]
network [:account/network]
scroll (atom nil)
(letsubs [transaction [:wallet.send/transaction]
advanced? [:wallet.send/advanced?]
network [:account/network]
scroll (atom nil)
network-status [:network-status]
all-tokens [:wallet/all-tokens]
signing-phrase [:wallet.send/signing-phrase-with-padding]
keycard? [:keycard-account?]]
all-tokens [:wallet/all-tokens]]
(if transaction
[send-transaction-view {:modal? true
:transaction transaction
:scroll scroll
:advanced? advanced?
:keycard? keycard?
:signing-phrase signing-phrase
:network network
:all-tokens all-tokens
:network-status network-status}]

View File

@ -7,7 +7,6 @@
[status-im.ui.screens.wallet.components.views :as components]
[status-im.ui.screens.wallet.components.views :as wallet.components]
[status-im.ui.screens.wallet.send.styles :as styles]
[status-im.ui.screens.wallet.send.views :as wallet.send.views]
[status-im.ui.screens.wallet.main.views :as wallet.main.views]
[status-im.ui.components.toolbar.actions :as actions]
[status-im.ui.components.toolbar.view :as toolbar]
@ -31,11 +30,10 @@
#(actions/default-handler)))]
[toolbar/content-title {:color :white} title]]))
(defview enter-password-buttons [value-atom {:keys [spinning? keycard?]} cancel-handler sign-handler sign-label]
(defview enter-password-buttons [value-atom spinning? cancel-handler sign-handler sign-label]
(letsubs [network-status [:network-status]]
(let [password (:password @value-atom)
sign-enabled? (or keycard?
(and (not (nil? password)) (not= password "")))]
sign-enabled? (and (not (nil? password)) (not= password ""))]
[bottom-buttons/bottom-buttons
styles/sign-buttons
[button/button {:style components.styles/flex
@ -84,7 +82,7 @@
;; SIGN MESSAGE FROM DAPP
(defview sign-message-modal []
(letsubs [value-atom (reagent/atom nil)
{:keys [decoded-data in-progress? typed? keycard? signing-phrase] :as screen-params} [:get-screen-params :wallet-sign-message-modal]
{:keys [decoded-data in-progress? typed?] :as screen-params} [:get-screen-params :wallet-sign-message-modal]
network-status [:network-status]]
[wallet.components/simple-screen {:status-bar-type :modal-wallet}
[toolbar true (i18n/label :t/sign-message)]
@ -98,24 +96,17 @@
[components/amount-input
{:disabled? true
:input-options {:multiline true
:height (if typed? 300 100)}
:height 100}
:amount-text (if typed?
(str "Domain\n" (:domain decoded-data) "\nMessage\n" (:message decoded-data))
decoded-data)}
nil]]]
(when keycard?
[wallet.send.views/signing-phrase-view signing-phrase])]
[enter-password-buttons
value-atom
{:spinning? false :keycard? keycard?}
nil]]]]
[enter-password-buttons value-atom false
#(re-frame/dispatch [:wallet/discard-transaction-navigate-back])
#(re-frame/dispatch [:wallet.ui/sign-message-button-clicked
typed?
(merge screen-params @value-atom)
#(re-frame/dispatch [:wallet/sign-message typed? (merge screen-params @value-atom)
(fn []
(swap! value-atom assoc :wrong-password? true))])
:t/transactions-sign]
(when-not keycard?
[password-input-panel value-atom :t/signing-message-phrase-description false])
[password-input-panel value-atom :t/signing-message-phrase-description false]
(when in-progress?
[react/view styles/processing-view])]]))

View File

@ -630,7 +630,6 @@
"wallet-choose-from-contacts": "Choose from Contacts",
"send-sending-to": "to {{recipient-name}}",
"signing-phrase-description": "If you recognize these words, enter your login password to sign the transaction",
"signing-phrase-warning": "Only confirm the transaction if you recognize\n your three words",
"currency-display-name-mad": "Moroccan Dirham",
"here-is-your-signing-phrase": "Here is your signing phrase. You will use it to verify your transactions. *Write it down and keep it safe!*",
"wants-to-access-profile": "wants to access to your profile",