From fceaa0981f9b3845e210d0ff3bb50ab4355c21ac Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Mon, 5 Nov 2018 17:56:12 +0100 Subject: [PATCH] Fixed some extensions issues (smallish) Signed-off-by: Julien Eluard --- src/status_im/chat/commands/core.cljs | 12 ++++---- src/status_im/extensions/core.cljs | 25 +++++++++++------ src/status_im/extensions/ethereum.cljs | 39 ++++++++++++++++++++++---- src/status_im/models/wallet.cljs | 25 ----------------- 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/status_im/chat/commands/core.cljs b/src/status_im/chat/commands/core.cljs index 81a7ce516b..92663ebf22 100644 --- a/src/status_im/chat/commands/core.cljs +++ b/src/status_im/chat/commands/core.cljs @@ -136,10 +136,10 @@ :preview :view :on-send? :event :on-receive? :event - :parameters [{:id :keyword - :type {:one-of #{:text :phone :password :number}} - :placeholder :string - :suggestions? :view}]} + :parameters? [{:id :keyword + :type {:one-of #{:text :phone :password :number}} + :placeholder :string + :suggestions? :view}]} :hook (reify hooks/Hook (hook-in [_ id {:keys [description scope parameters preview short-preview on-send on-receive]} cofx] @@ -149,8 +149,8 @@ (description [_] description) (parameters [_] parameters) (validate [_ _ _]) - (on-send [_ command-message _] (when on-send {:dispatch (on-send {:value command-message})})) - (on-receive [_ command-message _] (when on-receive {:dispatch (on-receive {:value command-message})})) + (on-send [_ command-message _] (when on-send {:dispatch (on-send command-message)})) + (on-receive [_ command-message _] (when on-receive {:dispatch (on-receive command-message)})) (short-preview [_ props] (short-preview props)) (preview [_ props] (preview props)))] (load-commands cofx [new-command]))) diff --git a/src/status_im/extensions/core.cljs b/src/status_im/extensions/core.cljs index 6385732534..a5c395f0f9 100644 --- a/src/status_im/extensions/core.cljs +++ b/src/status_im/extensions/core.cljs @@ -42,7 +42,7 @@ (fn [db [_ {:keys [key]}]] (get-in db [:extensions-store :collectible key]))) -(re-frame/reg-sub :identity +(re-frame/reg-sub :extensions/identity (fn [_ [_ {:keys [value]}]] value)) (handlers/register-handler-fx @@ -152,11 +152,12 @@ :style {:width "100%"} :on-change-text #(re-frame/dispatch (on-change {:value %}))}]) -(defn touchable-opacity [{:keys [on-press]} & children] - (into [react/touchable-opacity {:on-press #(re-frame/dispatch (on-press {}))}] children)) +(defn touchable-opacity [{:keys [style on-press]} & children] + (into [react/touchable-opacity (merge {:on-press #(re-frame/dispatch (on-press {}))} + (when style {:style style}))] children)) (defn image [{:keys [uri style]}] - [react/image (merge {:style (merge {:width 100 :height 100} style)} (when uri {:source {:uri uri}}))]) + [react/image (merge {:style (merge {:width 100 :height 100} style)} {:source {:uri uri}})]) (defn link [{:keys [uri]}] [react/text @@ -165,17 +166,23 @@ :on-press #(re-frame/dispatch [:browser.ui/message-link-pressed uri])} uri]) +(defn text [o & children] + (if (map? o) + [react/text o children] + (into [react/text {} o] children))) + (defn list [{:keys [data item-view]}] [list/flat-list {:data data :key-fn (fn [_ i] (str i)) :render-fn item-view}]) (defn checkbox [{:keys [on-change checked]}] [react/view {:style {:background-color colors/white}} - [checkbox/checkbox (merge {:checked checked :style {:padding 0}} - (when on-change {:on-value-change #(re-frame/dispatch (on-change {:value %}))}))]]) + [checkbox/checkbox {:checked? checked + :style {:padding 0} + :on-value-change #(re-frame/dispatch (on-change {:value %}))}]]) (def capacities {:components {'view {:value react/view} - 'text {:value react/text} + 'text {:value text} 'touchable-opacity {:value touchable-opacity :properties {:on-press :event}} 'image {:value image :properties {:uri :string}} 'input {:value input :properties {:on-change :event :placeholder :string}} @@ -217,11 +224,11 @@ 'store/put {:permissions [:read] :value :store/put - :arguments {:key :string :value :string}} + :arguments {:key :string :value :map}} 'store/append {:permissions [:read] :value :store/append - :arguments {:key :string :value :string}} + :arguments {:key :string :value :map}} 'store/clear {:permissions [:read] :value :store/put diff --git a/src/status_im/extensions/ethereum.cljs b/src/status_im/extensions/ethereum.cljs index 7e165dad1e..6717d8e2aa 100644 --- a/src/status_im/extensions/ethereum.cljs +++ b/src/status_im/extensions/ethereum.cljs @@ -1,11 +1,15 @@ (ns status-im.extensions.ethereum - (:require [status-im.utils.handlers :as handlers] + (:require [clojure.string :as string] [re-frame.core :as re-frame] + [status-im.constants :as constants] + [status-im.i18n :as i18n] [status-im.models.wallet :as models.wallet] + [status-im.utils.hex :as hex] + [status-im.ui.screens.navigation :as navigation] [status-im.utils.ethereum.abi-spec :as abi-spec] [status-im.utils.fx :as fx] - [status-im.ui.screens.navigation :as navigation] - [clojure.string :as string])) + [status-im.utils.handlers :as handlers] + [status-im.utils.money :as money])) (handlers/register-handler-fx :extensions/transaction-on-result @@ -20,12 +24,37 @@ (fn [{db :db} [_ on-result message]] (when on-result {:dispatch (on-result {:error message :result nil})}))) +;; EXTENSION TRANSACTION -> SEND TRANSACTION +(defn prepare-extension-transaction [params contacts on-result] + (let [{:keys [to value data gas gasPrice nonce]} params + contact (get contacts (hex/normalize-hex to))] + (cond-> {:id "extension-id" + :to-name (or (when (nil? to) + (i18n/label :t/new-contract)) + contact) + :symbol :ETH + :method constants/web3-send-transaction + :to to + :amount (money/bignumber (or value 0)) + :gas (cond + gas + (money/bignumber gas) + (and value (empty? data)) + (money/bignumber 21000)) + :gas-price (when gasPrice + (money/bignumber gasPrice)) + :data data + :on-result [:extensions/transaction-on-result on-result] + :on-error [:extensions/transaction-on-error on-result]} + nonce + (assoc :nonce nonce)))) + (handlers/register-handler-fx :extensions/ethereum-send-transaction (fn [{db :db} [_ {:keys [method params on-result] :as arguments}]] (let [tx-object (assoc (select-keys arguments [:to :gas :gas-price :value :nonce]) :data (when (and method params) (abi-spec/encode method params))) - transaction (models.wallet/prepare-extension-transaction tx-object (:contacts/contacts db) on-result)] + transaction (prepare-extension-transaction tx-object (:contacts/contacts db) on-result)] (models.wallet/open-modal-wallet-for-transaction db transaction tx-object)))) (handlers/register-handler-fx @@ -41,4 +70,4 @@ result (if (and outputs result-str) (abi-spec/decode (string/replace result-str #"0x" "") outputs) result-str)] - (re-frame/dispatch (on-result {:error %1 :result result}))))]}))) \ No newline at end of file + (re-frame/dispatch (on-result {:error %1 :result result}))))]}))) diff --git a/src/status_im/models/wallet.cljs b/src/status_im/models/wallet.cljs index 09f89e0259..ecd65ced8d 100644 --- a/src/status_im/models/wallet.cljs +++ b/src/status_im/models/wallet.cljs @@ -88,31 +88,6 @@ nonce (assoc :nonce nonce)))) -;; EXTENSION TRANSACTION -> SEND TRANSACTION -(defn prepare-extension-transaction [params contacts on-result] - (let [{:keys [to value data gas gasPrice nonce]} params - contact (get contacts (utils.hex/normalize-hex to))] - (cond-> {:id "extension-id" - :to-name (or (when (nil? to) - (i18n/label :t/new-contract)) - contact) - :symbol :ETH - :method constants/web3-send-transaction - :to to - :amount (money/bignumber (or value 0)) - :gas (cond - gas - (money/bignumber gas) - (and value (empty? data)) - (money/bignumber 21000)) - :gas-price (when gasPrice - (money/bignumber gasPrice)) - :data data - :on-result [:extensions/transaction-on-result on-result] - :on-error [:extensions/transaction-on-error on-result]} - nonce - (assoc :nonce nonce)))) - ;; SEND TRANSACTION -> RPC TRANSACTION (defn prepare-send-transaction [from {:keys [amount to gas gas-price data nonce]}] (cond-> {:from (ethereum/normalized-address from)