Merge pull request #376 from status-im/bug/#226
Show connectivity issues & displaying errors in console chat (#226)
This commit is contained in:
commit
6806f451fa
|
@ -6,6 +6,7 @@
|
|||
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.READ_PROFILE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
|
|
@ -101,24 +101,12 @@ var phoneConfig = {
|
|||
name: "phone",
|
||||
description: "Send phone number",
|
||||
color: "#5fc48d",
|
||||
validator: function (params) {
|
||||
return {
|
||||
validationHandler: "phone",
|
||||
parameters: [params.phone]
|
||||
};
|
||||
},
|
||||
params: [{
|
||||
name: "phone",
|
||||
type: status.types.PHONE,
|
||||
suggestions: phoneSuggestions,
|
||||
placeholder: "Phone number"
|
||||
}],
|
||||
handler: function (params) {
|
||||
return {
|
||||
event: "sign-up",
|
||||
params: [params.phone, params]
|
||||
};
|
||||
}
|
||||
}]
|
||||
};
|
||||
status.response(phoneConfig);
|
||||
status.command(phoneConfig);
|
||||
|
@ -128,16 +116,6 @@ status.command({
|
|||
name: "help",
|
||||
description: "Help",
|
||||
color: "#7099e6",
|
||||
/* Validator example
|
||||
validator: function (params) {
|
||||
if (params.value != "3") {
|
||||
var error = status.components.view(
|
||||
{backgroundColor: "red"},
|
||||
[status.components.text({}, "ooops :(")]
|
||||
);
|
||||
return {errors: [error]}
|
||||
}
|
||||
},*/
|
||||
params: [{
|
||||
name: "query",
|
||||
type: status.types.TEXT
|
||||
|
@ -152,12 +130,6 @@ status.response({
|
|||
name: "code",
|
||||
type: status.types.NUMBER
|
||||
}],
|
||||
handler: function (params) {
|
||||
return {
|
||||
event: "confirm-sign-up",
|
||||
params: [params.code]
|
||||
};
|
||||
},
|
||||
validator: function (params) {
|
||||
if (!/^[\d]{4}$/.test(params.code)) {
|
||||
var error = status.components.validationMessage(
|
||||
|
@ -184,12 +156,6 @@ status.response({
|
|||
type: status.types.PASSWORD,
|
||||
placeholder: "Please re-enter password to confirm"
|
||||
}],
|
||||
handler: function (params) {
|
||||
return {
|
||||
event: "save-password",
|
||||
params: [params.password]
|
||||
};
|
||||
},
|
||||
validator: function (params, context) {
|
||||
var errorMessages = [];
|
||||
var currentParameter = context["current-parameter"];
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
|
||||
(defn init [& [env]]
|
||||
(dispatch-sync [:reset-app])
|
||||
(dispatch [:listen-to-network-status!])
|
||||
(dispatch [:initialize-crypt])
|
||||
(dispatch [:initialize-geth])
|
||||
(status/set-soft-input-mode status/adjust-resize)
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
[cljs.core.async :as a]
|
||||
status-im.chat.handlers.webview-bridge
|
||||
status-im.chat.handlers.wallet-chat
|
||||
[taoensso.timbre :as log]))
|
||||
status-im.chat.handlers.console))
|
||||
|
||||
(register-handler :set-chat-ui-props
|
||||
(fn [db [_ ui-element value]]
|
||||
|
@ -204,12 +204,14 @@
|
|||
(register-handler :sign-up
|
||||
(after (fn [_ [_ phone-number]]
|
||||
(dispatch [:account-update {:phone phone-number}])))
|
||||
(fn [db [_ phone-number]]
|
||||
(let [formatted (format-phone-number phone-number)]
|
||||
(fn [db [_ phone-number message-id]]
|
||||
(let [formatted (format-phone-number phone-number)]
|
||||
(-> db
|
||||
(assoc :user-phone-number formatted)
|
||||
sign-up-service/start-listening-confirmation-code-sms
|
||||
(server/sign-up formatted sign-up-service/on-sign-up-response)))))
|
||||
(server/sign-up formatted
|
||||
message-id
|
||||
sign-up-service/on-sign-up-response)))))
|
||||
|
||||
(register-handler :stop-listening-confirmation-code-sms
|
||||
(fn [db [_]]
|
||||
|
@ -219,8 +221,11 @@
|
|||
|
||||
(register-handler :sign-up-confirm
|
||||
(u/side-effect!
|
||||
(fn [_ [_ confirmation-code]]
|
||||
(server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response))))
|
||||
(fn [_ [_ confirmation-code message-id]]
|
||||
(server/sign-up-confirm
|
||||
confirmation-code
|
||||
message-id
|
||||
sign-up-service/on-send-code-response))))
|
||||
|
||||
(register-handler :set-signed-up
|
||||
(u/side-effect!
|
||||
|
@ -274,9 +279,9 @@
|
|||
|
||||
(defmethod nav/preload-data! :chat
|
||||
[{:keys [current-chat-id] :as db} [_ _ id]]
|
||||
(let [chat-id (or id current-chat-id)
|
||||
messages (get-in db [:chats chat-id :messages])
|
||||
db' (assoc db :current-chat-id chat-id)
|
||||
(let [chat-id (or id current-chat-id)
|
||||
messages (get-in db [:chats chat-id :messages])
|
||||
db' (assoc db :current-chat-id chat-id)
|
||||
commands-loaded? (get-in db [:chats chat-id :commands-loaded])]
|
||||
(when (= current-chat-id wallet-chat-id)
|
||||
(dispatch [:cancel-command]))
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
(ns status-im.chat.handlers.console
|
||||
(:require [re-frame.core :refer [dispatch dispatch-sync after]]
|
||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||
[status-im.constants :refer [console-chat-id]]
|
||||
[status-im.data-store.messages :as messages]))
|
||||
|
||||
(def console-commands
|
||||
{:password
|
||||
(fn [params _]
|
||||
(dispatch [:create-account (params "password")]))
|
||||
|
||||
:phone
|
||||
(fn [params id]
|
||||
(dispatch [:sign-up (params "phone") id]))
|
||||
|
||||
:confirmation-code
|
||||
(fn [params id]
|
||||
(dispatch [:sign-up-confirm (params "code") id]))})
|
||||
|
||||
(def commands-names (set (keys console-commands)))
|
||||
|
||||
(def commands-with-delivery-status
|
||||
(disj commands-names :password))
|
||||
|
||||
(register-handler :invoke-console-command-handler!
|
||||
(u/side-effect!
|
||||
(fn [_ [_ {:keys [staged-command] :as parameters}]]
|
||||
(let [{:keys [id command params]} staged-command
|
||||
{:keys [name]} command]
|
||||
(dispatch [:prepare-command! parameters])
|
||||
((console-commands (keyword name)) params id)))))
|
||||
|
||||
(register-handler :set-message-status
|
||||
(after
|
||||
(fn [_ [_ message-id status]]
|
||||
(messages/update {:message-id message-id
|
||||
:message-status status})))
|
||||
(fn [db [_ message-id status]]
|
||||
(assoc-in db [:message-statuses message-id] {:status status})))
|
|
@ -13,8 +13,9 @@
|
|||
default-number-of-messages]]
|
||||
[status-im.utils.datetime :as datetime]
|
||||
[status-im.protocol.core :as protocol]
|
||||
[taoensso.timbre :refer-macros [debug]]
|
||||
[taoensso.timbre :as log]))
|
||||
[taoensso.timbre :refer-macros [debug] :as log]
|
||||
[status-im.constants :refer [console-chat-id]]
|
||||
[status-im.chat.handlers.console :as console]))
|
||||
|
||||
(defn prepare-command
|
||||
[identity chat-id clock-value
|
||||
|
@ -53,18 +54,28 @@
|
|||
(not (s/blank? text))
|
||||
(dispatch [::prepare-message data]))))))
|
||||
|
||||
(defn console-command? [chat-id command-name]
|
||||
(and (= console-chat-id chat-id)
|
||||
(console/commands-names (keyword command-name))))
|
||||
|
||||
(register-handler ::check-commands-handlers!
|
||||
(u/side-effect!
|
||||
(fn [_ [_ {:keys [commands message] :as params}]]
|
||||
(fn [_ [_ {:keys [commands message chat-id] :as params}]]
|
||||
(doseq [{:keys [command] :as message} commands]
|
||||
(let [params' (assoc params :staged-command message)]
|
||||
(let [params' (assoc params :staged-command message)
|
||||
command-name (:name (:command message))]
|
||||
(if (:sent-to-jail? message)
|
||||
;; todo there could be other reasons for "long-running"
|
||||
;; hanling of the command besides sendTransaction
|
||||
(dispatch [:navigate-to :confirm])
|
||||
(if (:has-handler command)
|
||||
(cond
|
||||
(console-command? chat-id command-name)
|
||||
(dispatch [:invoke-console-command-handler! params'])
|
||||
|
||||
(:has-handler command)
|
||||
(dispatch [::invoke-command-handlers! params'])
|
||||
|
||||
:else
|
||||
(dispatch [:prepare-command! params'])))))
|
||||
(when-not (s/blank? message)
|
||||
(dispatch [::prepare-message params])))))
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
||||
[status-im.i18n :refer [label]]
|
||||
[status-im.chat.utils :as cu]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[status-im.chat.handlers.console :as console]))
|
||||
|
||||
(defn message-content-status [_]
|
||||
(let [{:keys [chat-id group-chat name color]} (subscribe [:chat-properties [:chat-id :group-chat :name :color]])
|
||||
|
@ -200,10 +201,13 @@
|
|||
:font :default}
|
||||
(str "+ " (- (count user-statuses) 3))])]])))
|
||||
|
||||
(defview message-delivery-status [{:keys [message-id chat-id message-status user-statuses]}]
|
||||
(defview message-delivery-status
|
||||
[{:keys [message-id chat-id message-status user-statuses content]}]
|
||||
[app-db-message-status-value [:get-in [:message-statuses message-id :status]]]
|
||||
(let [delivery-status (get-in user-statuses [chat-id :status])
|
||||
status (if (cu/console? chat-id)
|
||||
command-name (keyword (:command content))
|
||||
status (if (and (not (console/commands-with-delivery-status command-name))
|
||||
(cu/console? chat-id))
|
||||
:seen
|
||||
(or delivery-status message-status app-db-message-status-value :sending))]
|
||||
[view st/delivery-view
|
||||
|
|
|
@ -15,23 +15,12 @@
|
|||
(let [hiccup (generate-hiccup markup)]
|
||||
(assoc-in db [:rendered-commands chat-id message-id] hiccup)))
|
||||
|
||||
(def console-events
|
||||
{:save-password (fn [[parameter]]
|
||||
(dispatch [:create-account parameter]))
|
||||
:sign-up (fn [[parameter]]
|
||||
(dispatch [:sign-up parameter]))
|
||||
:confirm-sign-up (fn [[parameter]]
|
||||
(dispatch [:sign-up-confirm parameter]))})
|
||||
|
||||
(def regular-events {})
|
||||
|
||||
(defn command-hadler!
|
||||
[_ [chat-id
|
||||
{:keys [staged-command] :as parameters}
|
||||
{:keys [result error]}]]
|
||||
(let [{:keys [context returned]} result
|
||||
{:keys [event params]
|
||||
handler-error :error} returned]
|
||||
{handler-error :error} returned]
|
||||
(cond
|
||||
handler-error
|
||||
(log/debug :error-from-handler handler-error
|
||||
|
@ -39,18 +28,11 @@
|
|||
:command staged-command)
|
||||
|
||||
result
|
||||
(let [{:keys [event params]} returned
|
||||
command' (assoc staged-command :handler-data returned)
|
||||
(let [command' (assoc staged-command :handler-data returned)
|
||||
parameters' (assoc parameters :command command')]
|
||||
(if (:eth_sendTransaction context)
|
||||
(dispatch [:wait-for-transaction (:id staged-command) parameters'])
|
||||
(let [events (if (= console-chat-id chat-id)
|
||||
(merge regular-events console-events)
|
||||
regular-events)
|
||||
parameters'' (if-let [handler (events (keyword event))]
|
||||
(assoc parameters' :handler #(handler params command'))
|
||||
parameters')]
|
||||
(dispatch [:prepare-command! parameters'']))))
|
||||
(dispatch [:prepare-command! parameters'])))
|
||||
|
||||
(not (or error handler-error))
|
||||
(dispatch [:prepare-command! parameters])
|
||||
|
|
|
@ -1,32 +1,19 @@
|
|||
(ns status-im.components.react
|
||||
(:require [reagent.core :as r]
|
||||
[status-im.components.styles :as st]
|
||||
[status-im.utils.utils :as u]
|
||||
[status-im.utils.utils :as u
|
||||
:refer [get-react-property get-class adapt-class]]
|
||||
[status-im.utils.platform :refer [platform-specific]]))
|
||||
|
||||
(def react-native (u/require "react-native"))
|
||||
(def native-modules (.-NativeModules react-native))
|
||||
(def device-event-emitter (.-DeviceEventEmitter react-native))
|
||||
(def geth (.-Geth native-modules))
|
||||
|
||||
(def linear-gradient-module (u/require "react-native-linear-gradient"))
|
||||
(def dismiss-keyboard! (u/require "dismissKeyboard"))
|
||||
(def orientation (u/require "react-native-orientation"))
|
||||
(def drawer (u/require "react-native-drawer-layout"))
|
||||
|
||||
;; Getters
|
||||
|
||||
(defn- get-react-property [name]
|
||||
(aget react-native name))
|
||||
|
||||
(defn- adapt-class [class]
|
||||
(when class
|
||||
(r/adapt-react-class class)))
|
||||
|
||||
(defn- get-class [name]
|
||||
(adapt-class (get-react-property name)))
|
||||
|
||||
|
||||
;; React Components
|
||||
|
||||
(def app-registry (get-react-property "AppRegistry"))
|
||||
|
|
|
@ -18,12 +18,13 @@
|
|||
:duration 250})))
|
||||
|
||||
(defn offline-view [_]
|
||||
(let [sync-state (subscribe [:get :sync-state])
|
||||
offline-opacity (anim/create-value 0.0)
|
||||
on-update (fn [_ _]
|
||||
(anim/set-value offline-opacity 0)
|
||||
(when (= @sync-state :offline)
|
||||
(start-offline-animation offline-opacity)))]
|
||||
(let [sync-state (subscribe [:get :sync-state])
|
||||
network-status (subscribe [:get :network-status])
|
||||
offline-opacity (anim/create-value 0.0)
|
||||
on-update (fn [_ _]
|
||||
(anim/set-value offline-opacity 0)
|
||||
(when (or (= @network-status :offline) (= @sync-state :offline))
|
||||
(start-offline-animation offline-opacity)))]
|
||||
(r/create-class
|
||||
{:component-did-mount
|
||||
on-update
|
||||
|
@ -31,7 +32,7 @@
|
|||
on-update
|
||||
:reagent-render
|
||||
(fn [{:keys [top]}]
|
||||
(when (= @sync-state :offline)
|
||||
(when (or (= @network-status :offline) (= @sync-state :offline))
|
||||
[animated-view {:style (st/offline-wrapper top offline-opacity window-width)}
|
||||
[view
|
||||
[text {:style st/offline-text}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
status-im.accounts.handlers
|
||||
status-im.protocol.handlers
|
||||
status-im.transactions.handlers
|
||||
status-im.network.handlers
|
||||
[status-im.utils.types :as t]
|
||||
[status-im.constants :refer [console-chat-id]]))
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
(ns status-im.handlers.server
|
||||
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||
[status-im.utils.utils :refer [http-post]]
|
||||
[taoensso.timbre :as log]))
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.scheduler :as sch]
|
||||
[status-im.data-store.messages :as messages]))
|
||||
|
||||
(defn sign-up
|
||||
[db phone-number handler]
|
||||
[db phone-number message-id handler]
|
||||
(let [current-account-id (get db :current-account-id)
|
||||
{:keys [public-key address]} (get-in db [:accounts current-account-id])]
|
||||
;(user-data/save-phone-number phone-number)
|
||||
|
@ -14,11 +16,22 @@
|
|||
:address address}
|
||||
(fn [body]
|
||||
(log/debug body)
|
||||
(handler)))
|
||||
(dispatch [:set-message-status message-id :seen])
|
||||
(handler))
|
||||
(fn [_]
|
||||
(sch/execute-later
|
||||
#(dispatch [:sign-up phone-number message-id])
|
||||
(sch/s->ms 1))))
|
||||
db))
|
||||
|
||||
(defn sign-up-confirm
|
||||
[confirmation-code handler]
|
||||
[confirmation-code message-id handler]
|
||||
(http-post "sign-up-confirm"
|
||||
{:code confirmation-code}
|
||||
handler))
|
||||
(fn [body]
|
||||
(dispatch [:set-message-status message-id :seen])
|
||||
(handler body))
|
||||
(fn [_]
|
||||
(sch/execute-later
|
||||
#(dispatch [:sign-up-confirm confirmation-code message-id])
|
||||
(sch/s->ms 1)))))
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
(ns status-im.network.handlers
|
||||
(:require [re-frame.core :refer [dispatch debug enrich after]]
|
||||
[status-im.utils.handlers :refer [register-handler]]
|
||||
[status-im.utils.handlers :as u]
|
||||
[status-im.network.net-info :as ni]
|
||||
[clojure.string :as s]))
|
||||
|
||||
(register-handler :listen-to-network-status!
|
||||
(u/side-effect!
|
||||
(fn []
|
||||
(let [handler #(dispatch [:update-network-status %])]
|
||||
(ni/init handler)
|
||||
(ni/add-listener handler)))))
|
||||
|
||||
(register-handler :update-network-status
|
||||
(fn [db [_ is-connected?]]
|
||||
(let [status (if is-connected? :online :offline)]
|
||||
(assoc db :network-status status))))
|
|
@ -0,0 +1,16 @@
|
|||
(ns status-im.network.net-info
|
||||
(:require [status-im.utils.utils :as u]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(def net-info (u/get-react-property "NetInfo"))
|
||||
|
||||
(defn init [callback]
|
||||
(when net-info
|
||||
(.then (.fetch (.-isConnected net-info))
|
||||
(fn [is-connected?]
|
||||
(log/debug "Is connected?" is-connected?)
|
||||
(callback is-connected?)))))
|
||||
|
||||
(defn add-listener [listener]
|
||||
(when net-info
|
||||
(.addEventListener (.-isConnected net-info) "change" listener)))
|
|
@ -184,7 +184,7 @@
|
|||
(register-handler :participant-invited-to-group
|
||||
(u/side-effect!
|
||||
(fn [{:keys [current-public-key]}
|
||||
[_ {:keys [from]
|
||||
[_ {:keys [from]
|
||||
{:keys [group-id identity message-id]} :payload}]]
|
||||
(participant-invited-to-group-message group-id current-public-key identity from message-id)
|
||||
(when-not (= current-public-key identity)
|
||||
|
@ -232,11 +232,11 @@
|
|||
[_ {:keys [from]
|
||||
{:keys [message-id ack-of-message group-id]} :payload}]]
|
||||
(if (chats/is-active? (or group-id from))
|
||||
(let [message-id' (or ack-of-message message-id)
|
||||
group? (boolean group-id)
|
||||
status-path (if (and group? (not= status :sent))
|
||||
[:message-user-statuses message-id' from]
|
||||
[:message-statuses message-id'])
|
||||
(let [message-id' (or ack-of-message message-id)
|
||||
group? (boolean group-id)
|
||||
status-path (if (and group? (not= status :sent))
|
||||
[:message-user-statuses message-id' from]
|
||||
[:message-statuses message-id'])
|
||||
{current-status :status} (get-in db status-path)]
|
||||
(if-not (= :seen current-status)
|
||||
(assoc-in db status-path {:whisper-identity from
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
(ns status-im.utils.scheduler
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [cljs.core.async :refer [<! timeout]]))
|
||||
|
||||
(defn s->ms [s] (* 1000 s))
|
||||
|
||||
(defn execute-later
|
||||
[function timeout-ms]
|
||||
(go (<! (timeout timeout-ms))
|
||||
(function)))
|
|
@ -1,7 +1,8 @@
|
|||
(ns status-im.utils.utils
|
||||
(:require-macros
|
||||
[natal-shell.async-storage :refer [get-item set-item]])
|
||||
(:require [status-im.constants :as const]))
|
||||
(:require [status-im.constants :as const]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(defn require [module]
|
||||
(if (exists? js/window)
|
||||
|
@ -64,3 +65,13 @@
|
|||
(if (cond (first coll))
|
||||
index
|
||||
(recur (inc index) cond (next coll))))))
|
||||
|
||||
(defn get-react-property [name]
|
||||
(aget react-native name))
|
||||
|
||||
(defn adapt-class [class]
|
||||
(when class
|
||||
(r/adapt-react-class class)))
|
||||
|
||||
(defn get-class [name]
|
||||
(adapt-class (get-react-property name)))
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
(defn init-stubs []
|
||||
(register-handler :sign-up
|
||||
(fn []
|
||||
(println :ohh)
|
||||
;; todo save phone number to db
|
||||
(sign-up-service/on-sign-up-response)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue