Use correct chain name if custom network added

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
Dmitry Novotochinov 2018-06-26 13:07:39 +03:00 committed by Goran Jovic
parent 30a79c88bb
commit 44f1ca474b
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
8 changed files with 33 additions and 32 deletions

View File

@ -14,9 +14,8 @@
;;TODO(goranjovic): currently we only allow tokens which are enabled in Manage assets here
;; because balances are only fetched for them. Revisit this decision with regard to battery/network consequences
;; if we were to update all balances.
(defn- allowed-assets [network account]
(let [chain (keyword (ethereum/network-names network))
visible-token-symbols (get-in account [:settings :wallet :visible-tokens chain])]
(defn- allowed-assets [chain account]
(let [visible-token-symbols (get-in account [:settings :wallet :visible-tokens chain])]
(->> (tokens/tokens-for chain)
(filter #(not (:nft? %)))
(filter #(contains? visible-token-symbols (:symbol %)))
@ -26,19 +25,19 @@
(defn- generate-context
"Generates context for jail call"
[account current-account-id chat-id group-chat? to network]
[account current-account-id chat-id group-chat? to chain]
(merge {:platform platform/os
:network (ethereum/network-names network)
:network chain
:from current-account-id
:to to
:allowed-assets (clj->js (allowed-assets network account))
:allowed-assets (clj->js (allowed-assets chain account))
:chat {:chat-id chat-id
:group-chat (boolean group-chat?)}}
i18n/delimeters))
(defn request-command-message-data
"Requests command message data from jail"
[{:contacts/keys [contacts] :account/keys [account] :keys [network] :as db}
[{:contacts/keys [contacts] :account/keys [account] :keys [chain] :as db}
{{:keys [command command-scope-bitmask bot params type]} :content
:keys [chat-id group-id] :as message}
{:keys [data-type] :as opts}]
@ -51,7 +50,7 @@
to (get-in contacts [chat-id :address])
address (get-in db [:account/account :address])
jail-params {:parameters params
:context (generate-context account address chat-id (models.message/group-message? message) to network)}]
:context (generate-context account address chat-id (models.message/group-message? message) to chain)}]
{:db db
:call-jail [{:jail-id bot
:path path

View File

@ -15,7 +15,7 @@
:from-chat? true)))
(defn send-shortcut-fx [{:account/keys [account] :as db} contact params]
(let [chain (keyword (ethereum/network-names (:network db)))
(let [chain (keyword (:chain db))
symbol (-> params :asset keyword)
{:keys [decimals]} (tokens/asset-for chain symbol)]
(merge {:db (-> db

View File

@ -386,7 +386,7 @@
:keys [prefill prefillBotDb]
:as request}
{:keys [params command handler-data content-type]}
network
chain
currency
prices
tx-hash]
@ -405,7 +405,7 @@
:prefill-bot-db prefillBotDb}
{:params (cond-> params
(= (:name command) constants/command-send)
(assoc :network (ethereum/network-names network)
(assoc :network chain
:fiat-amount (money/fiat-amount-value (:amount params)
(-> params :asset keyword)
currency
@ -444,7 +444,7 @@
:dispatch [:update-transactions]}]))))
(defn send-command
[{{:keys [current-public-key chats network prices] :as db} :db :keys [now] :as cofx} params]
[{{:keys [current-public-key chats chain prices] :as db} :db :keys [now] :as cofx} params]
(let [{{:keys [handler-data to-message command] :as content} :command chat-id :chat-id} params
;; We send commands to deleted chats as well, i.e. signed later transactions
chat (or (get chats chat-id) {:chat-id chat-id})
@ -454,7 +454,7 @@
currency (-> (currency-settings/get-user-currency db) name string/upper-case keyword)]
(handlers-macro/merge-fx cofx
(upsert-and-send (prepare-command-message current-public-key chat now request content
network currency prices tx-hash))
chain currency prices tx-hash))
(console-events/console-respond-command-messages command handler-data)
(requests-events/request-answered chat-id to-message)
(update-transactions command-name tx-hash {:with-delay? false}))))
@ -470,7 +470,7 @@
(merge {:dispatch-n dn} (dissoc fx :dispatch-n) (dissoc command :dispatch-n)))))
(defn invoke-command-handlers
[{{:contacts/keys [contacts] :keys [network] :as db} :db}
[{{:contacts/keys [contacts] :keys [chain] :as db} :db}
{{:keys [command params id]} :command
:keys [chat-id address]
:as orig-params}]
@ -484,7 +484,7 @@
:context (cond-> {:from address
:to to
:current-account (get db :account/account)
:network (ethereum/network-names network)
:network chain
:message-id id}
(:async-handler command)
(assoc :orig-params orig-params))}]

View File

@ -131,6 +131,7 @@
;;;;NETWORK
(spec/def ::network (spec/nilable string?))
(spec/def ::chain (spec/nilable string?))
(spec/def ::peers-count (spec/nilable integer?))
(spec/def ::peers-summary (spec/nilable vector?))
(spec/def :inbox/fetching? (spec/nilable boolean?))
@ -225,6 +226,7 @@
::sync-state
::sync-data
::network
::chain
:navigation/view-id
:navigation/navigation-stack
:navigation/prev-tab-view-id

View File

@ -337,7 +337,9 @@
status-module-initialized? status-node-started? device-UUID]
:or [network (get app-db :network)]} [_ address]]
(let [console-contact (get contacts constants/console-chat-id)
current-account (accounts address)]
current-account (accounts address)
account-network-id (get current-account :network network)
account-network (get-in current-account [:networks account-network-id])]
(cond-> (assoc app-db
:access-scope->commands-responses access-scope->commands-responses
:current-public-key (:public-key current-account)
@ -350,6 +352,7 @@
:account/account current-account
:network-status network-status
:network network
:chain (ethereum/network->chain-name account-network)
:peers-summary peers-summary
:peers-count peers-count
:device-UUID device-UUID)

View File

@ -39,7 +39,7 @@
(fn [current-account]
(get (:networks current-account) (:network current-account))))
(reg-sub :network-name (comp ethereum/network-names :network))
(reg-sub :network-name :chain)
(reg-sub :sync-state :sync-state)
(reg-sub :network-status :network-status)

View File

@ -51,8 +51,8 @@
(clj->js {:from from :to to :value value :gas gas :gasPrice gas-price})
#()))
(defn- send-tokens [{:keys [web3 from to value gas gas-price symbol network]}]
(let [contract (:address (tokens/symbol->token (keyword (ethereum/network-names network)) symbol))]
(defn- send-tokens [{:keys [web3 from to value gas gas-price symbol chain]}]
(let [contract (:address (tokens/symbol->token (keyword chain) symbol))]
(erc20/transfer web3 contract from to value {:gas gas :gasPrice gas-price} #())))
(re-frame/reg-fx
@ -277,8 +277,8 @@
(dissoc :message-id :id)))
(defn prepare-unconfirmed-status-transaction [db now hash transaction]
(let [network (:network db)
token (tokens/symbol->token (keyword (ethereum/network-names network)) (:symbol transaction))]
(let [chain (:chain db)
token (tokens/symbol->token (keyword chain) (:symbol transaction))]
(-> transaction
(assoc :confirmations "0"
:timestamp (str now)
@ -342,9 +342,8 @@
(handlers/register-handler-fx
:wallet/sign-transaction
(fn [{{:keys [web3] :as db} :db} [_ later?]]
(fn [{{:keys [web3 chain] :as db} :db} [_ later?]]
(let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false)
network (:network db)
{:keys [amount id password to symbol method gas gas-price]} (get-in db [:wallet :send-transaction])]
(if id
{::accept-transaction {:id id
@ -363,7 +362,8 @@
:gas-price gas-price
:symbol symbol
:method method
:network network}}))))
:chain chain}}))))
(handlers/register-handler-fx
:wallet/sign-message-modal
(fn [{db :db} _]

View File

@ -12,14 +12,6 @@
:testnet {:id 3 :name "Ropsten"}
:rinkeby {:id 4 :name "Rinkeby"}})
(def network-names
{"mainnet" "mainnet"
"mainnet_rpc" "mainnet"
"testnet" "testnet"
"testnet_rpc" "testnet"
"rinkeby" "rinkeby"
"rinkeby_rpc" "rinkeby"})
(defn chain-id->chain-keyword [i]
(some #(when (= i (:id (val %))) (key %)) chains))
@ -72,6 +64,11 @@
(defn network->chain-keyword [network]
(chain-id->chain-keyword (network->chain-id network)))
(defn network->chain-name [network]
(-> network
network->chain-keyword
name))
(defn sha3 [s]
(.sha3 dependencies/Web3.prototype (str s)))