status.sendMessage in jail
status.showSuggestions in jail jail: fix localStorage behaviour on setItem with null value and getItem with key without value
This commit is contained in:
parent
c56fa0c688
commit
024cf6d6b8
|
@ -28,7 +28,7 @@ status.defineSubscription(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
function superSuggestion(params, context) {
|
function demoSuggestions(params, context) {
|
||||||
var balance = parseFloat(web3.fromWei(web3.eth.getBalance(context.from), "ether"));
|
var balance = parseFloat(web3.fromWei(web3.eth.getBalance(context.from), "ether"));
|
||||||
var defaultSliderValue = balance / 2;
|
var defaultSliderValue = balance / 2;
|
||||||
|
|
||||||
|
@ -73,10 +73,10 @@ function superSuggestion(params, context) {
|
||||||
return {markup: view};
|
return {markup: view};
|
||||||
};
|
};
|
||||||
|
|
||||||
status.addListener("on-message-input-change", superSuggestion);
|
status.addListener("on-message-input-change", demoSuggestions);
|
||||||
status.addListener("init", superSuggestion);
|
status.addListener("init", demoSuggestions);
|
||||||
status.addListener("on-message-send", function (params, context) {
|
status.addListener("on-message-send", function (params, context) {
|
||||||
cnt = localStorage.getItem("cnt");
|
var cnt = localStorage.getItem("cnt");
|
||||||
if(!cnt) {
|
if(!cnt) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,6 @@ status.addListener("on-message-send", function (params, context) {
|
||||||
|
|
||||||
localStorage.setItem("cnt", cnt);
|
localStorage.setItem("cnt", cnt);
|
||||||
if (isNaN(params.message)) {
|
if (isNaN(params.message)) {
|
||||||
|
|
||||||
return {"text-message": "Seems that you don't want to send money :(. cnt = " + cnt};
|
return {"text-message": "Seems that you don't want to send money :(. cnt = " + cnt};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +94,16 @@ status.addListener("on-message-send", function (params, context) {
|
||||||
if (bn(weiValue).greaterThan(bn(balance))) {
|
if (bn(weiValue).greaterThan(bn(balance))) {
|
||||||
return {"text-message": "No way man, you don't have enough money! :)"};
|
return {"text-message": "No way man, you don't have enough money! :)"};
|
||||||
}
|
}
|
||||||
try {
|
web3.eth.sendTransaction({
|
||||||
web3.eth.sendTransaction({
|
from: context.from,
|
||||||
from: context.from,
|
to: context.from,
|
||||||
to: context.from,
|
value: weiValue
|
||||||
value: weiValue
|
}, function (error, hash) {
|
||||||
});
|
if (error) {
|
||||||
return {"text-message": "You are the hero, you sent " + value + " ETH to yourself!"};
|
status.sendMessage("Something went wrong, try again :(");
|
||||||
} catch (err) {
|
status.showSuggestions(demoSuggestions(params, context).markup);
|
||||||
return {"text-message": "Something went wrong :("};
|
} else {
|
||||||
}
|
status.sendMessage("You are the hero, you sent " + value + " ETH to yourself!")
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -209,8 +209,8 @@ var status = {
|
||||||
subscribe: subscribe,
|
subscribe: subscribe,
|
||||||
dispatch: dispatch
|
dispatch: dispatch
|
||||||
},
|
},
|
||||||
setSuggestions: function (view) {
|
showSuggestions: function (view) {
|
||||||
addContext("suggestions", view);
|
statusSignals.showSuggestions(JSON.stringify(view));
|
||||||
},
|
},
|
||||||
setDefaultDb: function (db) {
|
setDefaultDb: function (db) {
|
||||||
addContext("default-db", db);
|
addContext("default-db", db);
|
||||||
|
@ -219,7 +219,7 @@ var status = {
|
||||||
addContext("update-db", db)
|
addContext("update-db", db)
|
||||||
},
|
},
|
||||||
sendMessage: function (text) {
|
sendMessage: function (text) {
|
||||||
addContext("text-message", text);
|
statusSignals.sendMessage(text);
|
||||||
},
|
},
|
||||||
addLogMessage: function (type, message) {
|
addLogMessage: function (type, message) {
|
||||||
var message = {
|
var message = {
|
||||||
|
@ -278,10 +278,18 @@ console = (function (old) {
|
||||||
}(console));
|
}(console));
|
||||||
|
|
||||||
localStorage.setItem = function(key, value) {
|
localStorage.setItem = function(key, value) {
|
||||||
localStorageData[key] = value;
|
if(value === null) {
|
||||||
|
delete localStorageData[key];
|
||||||
|
} else {
|
||||||
|
localStorageData[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
localStorage.set(JSON.stringify(localStorageData));
|
localStorage.set(JSON.stringify(localStorageData));
|
||||||
};
|
};
|
||||||
|
|
||||||
localStorage.getItem = function(key) {
|
localStorage.getItem = function (key) {
|
||||||
|
if (typeof localStorageData[key] === "undefined") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return localStorageData[key];
|
return localStorageData[key];
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
[status-im.utils.datetime :as datetime]
|
[status-im.utils.datetime :as datetime]
|
||||||
[status-im.protocol.core :as protocol]
|
[status-im.protocol.core :as protocol]
|
||||||
[taoensso.timbre :refer-macros [debug] :as log]
|
[taoensso.timbre :refer-macros [debug] :as log]
|
||||||
[status-im.chat.handlers.console :as console]))
|
[status-im.chat.handlers.console :as console]
|
||||||
|
[status-im.utils.types :as types]))
|
||||||
|
|
||||||
(defn prepare-command
|
(defn prepare-command
|
||||||
[identity chat-id clock-value request
|
[identity chat-id clock-value request
|
||||||
|
@ -237,6 +238,27 @@
|
||||||
:from chat-id
|
:from chat-id
|
||||||
:to "me"}]))))))
|
:to "me"}]))))))
|
||||||
|
|
||||||
|
(register-handler :send-message-from-jail
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ {:keys [chat_id message]}]]
|
||||||
|
(dispatch [:received-message
|
||||||
|
{:message-id (random/id)
|
||||||
|
:content (str message)
|
||||||
|
:content-type text-content-type
|
||||||
|
:outgoing false
|
||||||
|
:chat-id chat_id
|
||||||
|
:from chat_id
|
||||||
|
:to "me"}]))))
|
||||||
|
|
||||||
|
(register-handler :show-suggestions-from-jail
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ {:keys [chat_id markup]}]]
|
||||||
|
(let [markup' (types/json->clj markup)
|
||||||
|
result (assoc-in {} [:result :returned :markup] markup')]
|
||||||
|
(dispatch [:suggestions-handler
|
||||||
|
{:result result
|
||||||
|
:chat-id chat_id}])))))
|
||||||
|
|
||||||
(register-handler ::send-message!
|
(register-handler ::send-message!
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [web3 chats network-status current-account-id accounts]
|
(fn [{:keys [web3 chats network-status current-account-id accounts]
|
||||||
|
|
|
@ -38,12 +38,14 @@
|
||||||
|
|
||||||
(defn suggestions-handler!
|
(defn suggestions-handler!
|
||||||
[{:keys [contacts chats] :as db} [{:keys [chat-id default-db command parameter-index result]}]]
|
[{:keys [contacts chats] :as db} [{:keys [chat-id default-db command parameter-index result]}]]
|
||||||
(let [{:keys [markup]} (get-in result [:result :returned])
|
(let [returned (get-in result [:result :returned])
|
||||||
|
contains-markup? (contains? returned :markup)
|
||||||
|
markup (get returned :markup)
|
||||||
{:keys [dapp? dapp-url]} (get contacts chat-id)
|
{:keys [dapp? dapp-url]} (get contacts chat-id)
|
||||||
path (if command
|
path (if command
|
||||||
[:chats chat-id :parameter-boxes (:name command) parameter-index]
|
[:chats chat-id :parameter-boxes (:name command) parameter-index]
|
||||||
[:chats chat-id :parameter-boxes :message])]
|
[:chats chat-id :parameter-boxes :message])]
|
||||||
(when-not (= (get-in db path) markup)
|
(when (and contains-markup? (not= (get-in db path) markup))
|
||||||
(dispatch [:set-in path (when markup {:hiccup markup})])
|
(dispatch [:set-in path (when markup {:hiccup markup})])
|
||||||
(when default-db
|
(when default-db
|
||||||
(dispatch [:update-bot-db {:bot chat-id
|
(dispatch [:update-bot-db {:bot chat-id
|
||||||
|
@ -88,6 +90,6 @@
|
||||||
|
|
||||||
(reg-handler :set-local-storage
|
(reg-handler :set-local-storage
|
||||||
(handlers/side-effect!
|
(handlers/side-effect!
|
||||||
(fn [{:keys [current-chat-id] :as db} [{:keys [data chat_id] :as event}]]
|
(fn [_ [{:keys [data chat_id]}]]
|
||||||
(local-storage/set-data {:chat-id chat_id
|
(local-storage/set-data {:chat-id chat_id
|
||||||
:data data}))))
|
:data data}))))
|
||||||
|
|
|
@ -161,6 +161,8 @@
|
||||||
"local_storage.set" (dispatch [:set-local-storage event])
|
"local_storage.set" (dispatch [:set-local-storage event])
|
||||||
"request_geo_permissions" (dispatch [:request-permissions [:geolocation]
|
"request_geo_permissions" (dispatch [:request-permissions [:geolocation]
|
||||||
#(dispatch [:webview-geo-permissions-granted])])
|
#(dispatch [:webview-geo-permissions-granted])])
|
||||||
|
"jail.send_message" (dispatch [:send-message-from-jail event])
|
||||||
|
"jail.show_suggestions" (dispatch [:show-suggestions-from-jail event])
|
||||||
(log/debug "Event " type " not handled"))))))
|
(log/debug "Event " type " not handled"))))))
|
||||||
|
|
||||||
(register-handler :status-module-initialized!
|
(register-handler :status-module-initialized!
|
||||||
|
|
|
@ -50,8 +50,4 @@
|
||||||
(slurp "resources/web3_init.js")))
|
(slurp "resources/web3_init.js")))
|
||||||
|
|
||||||
(defn local-storage-data [data]
|
(defn local-storage-data [data]
|
||||||
(str "var localStorageData = "
|
(str "var localStorageData = " (or data "{}") ";"))
|
||||||
(if data
|
|
||||||
data
|
|
||||||
"{}")
|
|
||||||
";"))
|
|
||||||
|
|
Loading…
Reference in New Issue