From 50919c8eb8e49f82c3f01ab0576b3dce5a4632db Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 10 Oct 2017 14:37:51 +0200 Subject: [PATCH] hide faucet when in mainnet, show different in renkeby --- resources/js/bots/console/bot.js | 112 +++++++++++-------- src/status_im/commands/handlers/loading.cljs | 33 +++--- src/status_im/utils/js_resources.cljs | 3 + 3 files changed, 90 insertions(+), 58 deletions(-) diff --git a/resources/js/bots/console/bot.js b/resources/js/bots/console/bot.js index 34d55d097e..ab040ccdbd 100644 --- a/resources/js/bots/console/bot.js +++ b/resources/js/bots/console/bot.js @@ -493,17 +493,35 @@ var phoneConfig = { status.response(phoneConfig); status.command(phoneConfig); -var faucets = [ - /*{ - name: "Ethereum Ropsten Faucet", - url: "http://faucet.ropsten.be:3001" - },*/ +var ropstenNetworkId = 3; +var rinkebyNetworkId = 4; + +var ropstenFaucets = [ { name: "Status Testnet Faucet", url: "http://46.101.129.137:3001", } ]; +var rinkebyFaucets = [ + { + name: "Status Rinkeby Faucet", + url: "not specified yet", + } +]; + +function getFaucets(networkId) { + if (networkId == ropstenNetworkId) { + return ropstenFaucets; + } else if (networkId == rinkebyNetworkId) { + return rinkebyFaucets; + } else { + return []; + } +} + +var faucets = getFaucets(status.ethereumNetworkId); + function faucetSuggestions(params) { var suggestions = faucets.map(function (entry) { return status.components.touchable( @@ -535,49 +553,55 @@ function faucetSuggestions(params) { return {markup: view}; } -status.command({ - name: "faucet", - title: I18n.t('faucet_title'), - description: I18n.t('faucet_description'), - color: "#7099e6", - registeredOnly: true, - params: [{ - name: "url", - type: status.types.TEXT, - suggestions: faucetSuggestions, - placeholder: I18n.t('faucet_placeholder') - }], - preview: function (params) { - return { - markup: status.components.text( - {}, - params.url - ) - }; - }, - shortPreview: function (params) { - return { - markup: status.components.text( - {}, - I18n.t('faucet_title') + ": " + params.url - ) - }; - }, - validator: function (params, context) { - var f = faucets.map(function (entry) { - return entry.url; - }); +var faucetCommandConfig = + { + name: "faucet", + title: I18n.t('faucet_title'), + description: I18n.t('faucet_description'), + color: "#7099e6", + registeredOnly: true, + params: [{ + name: "url", + type: status.types.TEXT, + suggestions: faucetSuggestions, + placeholder: I18n.t('faucet_placeholder') + }], + preview: function (params) { + return { + markup: status.components.text( + {}, + params.url + ) + }; + }, + shortPreview: function (params) { + return { + markup: status.components.text( + {}, + I18n.t('faucet_title') + ": " + params.url + ) + }; + }, + validator: function (params, context) { + var f = faucets.map(function (entry) { + return entry.url; + }); - if (f.indexOf(params.url) == -1) { - var error = status.components.validationMessage( - I18n.t('faucet_incorrect_title'), - I18n.t('faucet_incorrect_description') - ); + if (f.indexOf(params.url) == -1) { + var error = status.components.validationMessage( + I18n.t('faucet_incorrect_title'), + I18n.t('faucet_incorrect_description') + ); - return {markup: error}; + return {markup: error}; + } } } -}); +; + +if (faucets.length > 0) { + status.command(faucetCommandConfig); +} function debugSuggestions(params) { var suggestions = ["On", "Off"].map(function (entry) { diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index e196079b6f..f6aa493f5f 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -13,7 +13,7 @@ [status-im.i18n :refer [label]] [status-im.utils.homoglyph :as h] [status-im.utils.js-resources :as js-res] - [status-im.utils.random :as random] + [status-im.utils.random :as random] [status-im.bots.constants :as bots-constants] [status-im.utils.datetime :as time] [status-im.data-store.local-storage :as local-storage] @@ -75,21 +75,26 @@ (hash file)) (defn parse-commands! - [_ [{{:keys [whisper-identity]} :contact - :keys [callback]} - file]] + [{:networks/keys [networks] + :keys [network] + :as db} + [{{:keys [whisper-identity]} :contact + :keys [callback]} + file]] (let [data (local-storage/get-data whisper-identity) - local-storage-js (js-res/local-storage-data data)] + local-storage-js (js-res/local-storage-data data) + network-id (get-in networks [network :raw-config :NetworkId]) + ethereum-id-js (js-res/network-id network-id)] (status/parse-jail - whisper-identity (str local-storage-js file) - (fn [result] - (let [{:keys [error result]} (json->clj result)] - (log/debug "Parsing commands results: " error result) - (if error - (dispatch [::loading-failed! whisper-identity ::error-in-jail error]) - (do - (dispatch [::add-commands whisper-identity file result]) - (when callback (callback))))))))) + whisper-identity (str local-storage-js ethereum-id-js file) + (fn [result] + (let [{:keys [error result]} (json->clj result)] + (log/debug "Parsing commands results: " error result) + (if error + (dispatch [::loading-failed! whisper-identity ::error-in-jail error]) + (do + (dispatch [::add-commands whisper-identity file result]) + (when callback (callback))))))))) (defn validate-hash [db [_ file]] diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index d1d0c1c604..fa4bee5efe 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -49,3 +49,6 @@ (defn local-storage-data [data] (str "var localStorageData = " (or data "{}") ";")) + +(defn network-id [id] + (str "status.ethereumNetworkId = " (or id "null") "; "))