Merge pull request #447 from status-im/bug/#430

Prevent !send with null "to" address
This commit is contained in:
Roman Volosovskyi 2016-11-15 15:22:12 +02:00 committed by GitHub
commit acfedd19f6
7 changed files with 56 additions and 21 deletions

View File

@ -65,7 +65,17 @@ status.command({
}]
});
function validateBalance(params, context) {
function validateSend(params, context) {
if (!context.to) {
return {
errors: [
status.components.validationMessage(
"Wrong address",
"Recipient address must be specified"
)
]
};
}
if (!params.amount) {
return {
errors: [
@ -136,7 +146,7 @@ var send = {
);
},
handler: sendTransaction,
validator: validateBalance
validator: validateSend
};
status.command(send);

View File

@ -24,7 +24,7 @@
(dispatch [:navigate-to-clean :chat-list])
(dispatch [:navigate-to :chat console-chat-id]))
(do
(dispatch [:navigate-to-clean :accounts])
(dispatch [:navigate-to-clean :chat-list])
(dispatch [:navigate-to :chat-list]))))
(register-handler

View File

@ -243,8 +243,10 @@
:params
(get parameter-idx)
:name)
to (get-in db [:contacts chat-id :address])
context {:current-parameter current-parameter
:from address}
:from address
:to to}
path [(if (= :command type) :commands :responses)
name
:validator]

View File

@ -9,7 +9,8 @@
[status-im.commands.utils :as cu]
[status-im.components.status :as s]
[status-im.constants :as c]
[cljs.reader :refer [read-string]]))
[cljs.reader :refer [read-string]]
[status-im.navigation.handlers :as nav]))
(def web3 (js/require "web3"))
@ -79,18 +80,28 @@
params (:data options)]
(log/debug (str "message from webview: " message))
(case event'
:webview-send-transaction (dispatch [:show-contacts-menu contacts-click-handler :send params])
:webview-receive-transaction (dispatch [:show-contacts-menu contacts-click-handler :request params])
:webview-send-transaction
(dispatch [:navigate-to-modal
:contact-list-modal
{:handler contacts-click-handler
:action :send
:params params}])
:webview-receive-transaction
(dispatch [:navigate-to-modal
:contact-list-modal
{:handler contacts-click-handler
:action :request
:params params}])
:webview-scan-qr (dispatch [:show-scan-qr :webview-address-from-qr])
:webview-send-eth (dispatch [:webview-send-eth! params])
(log/error (str "Unknown event: " event')))))))
(register-handler :show-contacts-menu
(after #(dispatch [:navigate-to-modal :contact-list-modal]))
(fn [db [_ click-handler action params]]
(assoc db :contacts-click-handler click-handler
(defmethod nav/preload-data! :contact-list-modal
[db [_ _ {:keys [handler action params]}]]
(assoc db :contacts-click-handler handler
:contacts-click-action action
:contacts-click-params params)))
:contacts-click-params params
:contacts-filter #(not (nil? (:address %)))))
(def qr-context {:toolbar-title (label :t/address)})

View File

@ -16,9 +16,11 @@
(defmethod nav/preload-data! :group-contacts
[db [_ _ group]]
(dissoc
(if group
(assoc db :contacts-group group)
db))
db)
:contacts-filter))
(defmethod nav/preload-data! :new-group
[db _]
@ -28,7 +30,8 @@
(defmethod nav/preload-data! :contact-list
[db [_ _ click-handler]]
(assoc db :contacts-click-handler click-handler))
(assoc db :contacts-click-handler click-handler
:contacts-filter nil))
(register-handler :remove-contacts-click-handler

View File

@ -60,9 +60,11 @@
(register-sub :contacts-with-letters
(fn [db _]
(let [contacts (reaction (:contacts @db))]
(let [contacts (reaction (:contacts @db))
pred (subscribe [:get :contacts-filter])]
(reaction
(let [ordered (sort-contacts @contacts)]
(let [ordered (sort-contacts @contacts)
ordered (if pred (filter @pred ordered) ordered)]
(reduce (fn [prev cur]
(let [prev-letter (get-contact-letter (last prev))
cur-letter (get-contact-letter cur)]

View File

@ -123,6 +123,13 @@
(remove-pending-message db message-id)))
(register-handler :transaction-queued
(u/side-effect!
(fn [_ [_ {:keys [id args] :as transaction}]]
(if (:to args)
(dispatch [::transaction-queued transaction])
(status/discard-transaction id)))))
(register-handler ::transaction-queued
(after #(dispatch [:navigate-to-modal :confirm]))
(fn [db [_ {:keys [id message_id args]}]]
(let [{:keys [from to value]} args