hide faucet when in mainnet, show different in renkeby

This commit is contained in:
Roman Volosovskyi 2017-10-10 14:37:51 +02:00
parent 7133c4a655
commit 50919c8eb8
3 changed files with 90 additions and 58 deletions

View File

@ -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) {

View File

@ -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]]

View File

@ -49,3 +49,6 @@
(defn local-storage-data [data]
(str "var localStorageData = " (or data "{}") ";"))
(defn network-id [id]
(str "status.ethereumNetworkId = " (or id "null") "; "))