Skip to content

Commit

Permalink
feature #2696 - chat message after wallet send
Browse files Browse the repository at this point in the history
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
  • Loading branch information
goranjovic committed Jul 3, 2018
1 parent f4c156c commit e27d38e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 46 deletions.
14 changes: 0 additions & 14 deletions src/status_im/chat/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,6 @@
(models.message/group-messages current-chat-id new-messages)
(mark-messages-seen current-chat-id))))))

(handlers/register-handler-fx
:execute-stored-command
(fn [cofx _]
(handlers-macro/merge-fx cofx
(events.commands/execute-stored-command)
(navigation/replace-view :wallet-transaction-sent))))

(handlers/register-handler-fx
:execute-stored-command-and-return-to-chat
(fn [cofx [_ chat-id]]
(handlers-macro/merge-fx cofx
(events.commands/execute-stored-command)
(navigate-to-chat chat-id {:navigation-replace? true}))))

(defn start-chat
"Start a chat, making sure it exists"
[chat-id opts {:keys [db] :as cofx}]
Expand Down
9 changes: 1 addition & 8 deletions src/status_im/chat/events/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,5 @@
(fn [{:keys [db]} [message opts]]
(if (and (short-preview? opts)
(shortcuts/shortcut-override? message))
(shortcuts/shortcut-override-fx db message opts)
(shortcuts/shortcut-override-fx db message)
(request-command-message-data db message opts))))

;; NOTE(goranjovic) - continues execution of a command that was paused by a shortcut
(defn execute-stored-command [{:keys [db]}]
(let [{:keys [message opts]} (:commands/stored-command db)]
(-> db
(request-command-message-data message opts)
(dissoc :commands/stored-command))))
2 changes: 1 addition & 1 deletion src/status_im/chat/events/send_message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
(fn [cofx [{:keys [chat-id message]}]]
(let [parsed-message (types/json->clj message)]
(message-model/handle-message-from-bot cofx {:message parsed-message
:chat-id chat-id}))))
:chat-id chat-id}))))
8 changes: 2 additions & 6 deletions src/status_im/chat/events/shortcuts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@
(defn shortcut-override? [message]
(get shortcuts (get-in message [:content :command])))

(defn shortcut-override-fx [db {:keys [chat-id content] :as message} opts]
(defn shortcut-override-fx [db {:keys [chat-id content]}]
(let [command (:command content)
contact (get-in db [:contacts/contacts chat-id])
shortcut-specific-fx (get shortcuts command)
stored-command {:message message :opts opts}]
shortcut-specific-fx (get shortcuts command)]
(-> db
(assoc :commands/stored-command stored-command)
;; NOTE(goranjovic) - stores the command if we want to continue it after
;; shortcut has been executed, see `:execute-stored-command`
(shortcut-specific-fx contact (:params content))
;; TODO(goranjovic) - replace this dispatch with a function call
;; Need to refactor chat events namespaces for this to avoid circular dependecy
Expand Down
32 changes: 31 additions & 1 deletion src/status_im/chat/models/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
[status-im.transport.message.core :as transport]
[status-im.transport.message.v1.protocol :as protocol]
[status-im.data-store.messages :as messages-store]
[status-im.data-store.user-statuses :as user-statuses-store]))
[status-im.data-store.user-statuses :as user-statuses-store]
[status-im.utils.datetime :as datetime]))

(def receive-interceptors
[(re-frame/inject-cofx :random-id)
Expand Down Expand Up @@ -475,3 +476,32 @@

:else
(send-command cofx params))))

(defn custom-send-command-message [whisper-id address asset amount]
{:message nil,
:command {:command {:bot "transactor",
:color "#5fc48d",
:ref ["transactor" :command 83 "send"],
:name "send",
:type :command,
:async-handler false,
:icon "money_white",
:scope #{:global :personal-chats :registered :humans},
:has-handler true,
:preview nil,
:short-preview nil,
:scope-bitmask 83,
:owner-id "transactor"},
:params {:asset asset,
:amount amount},
:to-message nil,
:created-at (datetime/timestamp),
:chat-id whisper-id,
:handler-data nil},
:chat-id whisper-id,
:identity whisper-id,
:address address})

(defn send-custom-send-command [{:keys [whisper-identity address asset amount]} cofx]
(when whisper-identity
(send-command cofx (custom-send-command-message whisper-identity address asset amount))))
11 changes: 7 additions & 4 deletions src/status_im/ui/screens/navigation.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,26 @@
(let [db (re-frame/get-coeffect context :db)]
(re-frame/assoc-coeffect context :db (unload-data! db))))))

(def navigation-interceptors
[unload-data-interceptor (re-frame/enrich preload-data!)])

;; event handlers

(handlers/register-handler-db
:navigate-to
[unload-data-interceptor (re-frame/enrich preload-data!)]
navigation-interceptors
(fn [db [_ & params]]
(apply navigate-to db params)))

(handlers/register-handler-db
:navigate-to-modal
[unload-data-interceptor (re-frame/enrich preload-data!)]
navigation-interceptors
(fn [db [_ modal-view]]
(assoc db :modal modal-view)))

(handlers/register-handler-fx
:navigation-replace
[unload-data-interceptor (re-frame/enrich preload-data!)]
navigation-interceptors
(fn [cofx [_ view-id]]
(replace-view view-id cofx)))

Expand Down Expand Up @@ -118,7 +121,7 @@

(handlers/register-handler-fx
:navigate-to-tab
[unload-data-interceptor (re-frame/enrich preload-data!)]
navigation-interceptors
(fn [{:keys [db] :as cofx} [_ view-id]]
(handlers-macro/merge-fx cofx
{:db (-> db
Expand Down
34 changes: 23 additions & 11 deletions src/status_im/ui/screens/wallet/send/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
[status-im.utils.ethereum.erc20 :as erc20]
[status-im.utils.ethereum.tokens :as tokens]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.hex :as utils.hex]
[status-im.utils.money :as money]
[status-im.utils.security :as security]
[status-im.utils.types :as types]
[status-im.utils.utils :as utils]
[status-im.models.wallet :as models.wallet]
[status-im.chat.models.message :as models.message]
[status-im.constants :as constants]
[status-im.transport.utils :as transport.utils]
[taoensso.timbre :as log]))
[taoensso.timbre :as log]
[status-im.ui.screens.navigation :as navigation]))

;;;; FX

Expand Down Expand Up @@ -272,12 +275,21 @@
(update :gas str)
(dissoc :message-id :id))))

(handlers/register-handler-fx
:send-transaction-message
(concat models.message/send-interceptors
navigation/navigation-interceptors)
(fn [cofx [{:keys [view-id] :as params}]]
(handlers-macro/merge-fx cofx
(models.message/send-custom-send-command params)
(navigation/replace-view view-id))))

(handlers/register-handler-fx
::transaction-completed
(fn [{db :db now :now} [_ {:keys [id response] :as params} modal?]]
(let [{:keys [hash error]} response
{:keys [method from-chat?]} (get-in db [:wallet :send-transaction])
db' (assoc-in db [:wallet :send-transaction :in-progress?] false)]
(let [{:keys [hash error]} response
{:keys [method whisper-identity to symbol amount-text]} (get-in db [:wallet :send-transaction])
db' (assoc-in db [:wallet :send-transaction :in-progress?] false)]
(if (and error (string? error) (not (string/blank? error))) ;; ignore error here, error will be handled in :transaction-failed
{:db db'}
(merge
Expand All @@ -288,17 +300,17 @@
(update-in [:wallet :transactions-unsigned] dissoc id)
true
(update-in [:wallet :send-transaction] merge clear-send-properties {:tx-hash hash}))}
(cond
modal?
(if modal?

(cond-> {:dispatch [:navigate-back]}
(= method constants/web3-send-transaction)
(assoc :dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}]))

from-chat?
{:dispatch [:execute-stored-command]}

:else
{:dispatch [:navigation-replace :wallet-transaction-sent]}))))))
{:dispatch [:send-transaction-message {:view-id :wallet-transaction-sent
:whisper-identity whisper-identity
:address to
:asset (name symbol)
:amount amount-text}]}))))))

(defn on-transactions-modal-completed [raw-results]
(let [result (types/json->clj raw-results)]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/utils/mixpanel_events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
:trigger [:navigate-to-clean :wallet]
:properties {:target :wallet-got-it}}
{:label "Tap"
:trigger [:execute-stored-command]
:trigger [:send-transaction-message]
:properties {:target :wallet-transaction-sent}}

;;Profile
Expand Down

0 comments on commit e27d38e

Please sign in to comment.