Skip to content

Commit 252d09e

Browse files
janherichrasom
authored andcommitted
Fix the bug and remove requests
1 parent 6de53a5 commit 252d09e

File tree

11 files changed

+107
-146
lines changed

11 files changed

+107
-146
lines changed

src/status_im/chat/commands/impl/transactions.cljs

Lines changed: 58 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[re-frame.core :as re-frame]
66
[status-im.chat.commands.protocol :as protocol]
77
[status-im.chat.commands.impl.transactions.styles :as transactions-styles]
8-
[status-im.data-store.requests :as requests-store]
8+
[status-im.data-store.messages :as messages-store]
99
[status-im.ui.components.react :as react]
1010
[status-im.ui.components.icons.vector-icons :as vector-icons]
1111
[status-im.ui.components.colors :as colors]
@@ -258,6 +258,12 @@
258258
prices)
259259
:currency currency)))
260260

261+
(defn- params-unchanged? [send-message request-message]
262+
(and (= (get-in send-message [:content :params :asset])
263+
(get-in request-message [:content :params :asset]))
264+
(= (get-in send-message [:content :params :amount])
265+
(get-in request-message [:content :params :amount]))))
266+
261267
(deftype PersonalSendCommand []
262268
protocol/Command
263269
(id [_] "send")
@@ -268,10 +274,13 @@
268274
;; Only superficial/formatting validation, "real validation" will be performed
269275
;; by the wallet, where we yield control in the next step
270276
(personal-send-request-validation parameters cofx))
271-
(on-send [_ {:keys [chat-id]} {:keys [db]}]
277+
(on-send [_ {:keys [chat-id] :as send-message} {:keys [db]}]
272278
(when-let [{:keys [responding-to]} (get-in db [:chats chat-id :input-metadata])]
273-
{:db (update-in db [:chats chat-id :requests] dissoc responding-to)
274-
:data-store/tx [(requests-store/mark-request-as-answered-tx chat-id responding-to)]}))
279+
(when-let [request-message (get-in db [:chats chat-id :messages responding-to])]
280+
(when (params-unchanged? send-message request-message)
281+
(let [updated-request-message (assoc-in request-message [:content :params :answered?] true)]
282+
{:db (assoc-in db [:chats chat-id :messages responding-to] updated-request-message)
283+
:data-store/tx [(messages-store/save-message-tx updated-request-message)]})))))
275284
(on-receive [_ command-message cofx]
276285
(when-let [tx-hash (get-in command-message [:content :params :tx-hash])]
277286
(wallet.transactions/store-chat-transaction-hash tx-hash cofx)))
@@ -370,67 +379,55 @@
370379
(defview request-preview
371380
[{:keys [message-id content outgoing timestamp timestamp-str group-chat]}]
372381
(letsubs [id->command [:get-id->command]
373-
answered? [:is-request-answered? message-id]
374382
status-initialized? [:get :status-module-initialized?]
375383
network [:network-name]
376384
prices [:prices]]
377-
(let [{:keys [amount asset fiat-amount currency] request-network :network} (:params content)
378-
recipient-name (get-in content [:params :bot-db :public :recipient])
385+
(let [{:keys [amount asset fiat-amount currency answered?] request-network :network} (:params content)
379386
network-mismatch? (and request-network (not= request-network network))
380387
command (get id->command ["send" #{:personal-chats}])
381-
on-press-handler (cond
382-
network-mismatch?
383-
nil
384-
(and (not answered?)
385-
status-initialized?)
386-
#(re-frame/dispatch [:select-chat-input-command
387-
command
388-
[(or asset "ETH") amount]
389-
{:responding-to message-id}]))]
390-
[react/view
391-
[react/touchable-highlight
392-
{:on-press on-press-handler}
393-
[react/view (transactions-styles/command-request-message-view outgoing)
394-
[react/view
395-
[react/view
396-
[react/text {:style (transactions-styles/command-request-header-text outgoing)}
397-
(i18n/label :transaction-request)]]
398-
[react/view transactions-styles/command-request-row
399-
[react/text {:style transactions-styles/command-request-amount-text
400-
:font :medium}
401-
amount
402-
[react/text {:style (transactions-styles/command-amount-currency-separator outgoing)}
403-
"."]
404-
[react/text {:style (transactions-styles/command-request-currency-text outgoing)
405-
:font :default}
406-
asset]]]
407-
[react/view transactions-styles/command-request-fiat-amount-row
408-
[react/text {:style transactions-styles/command-request-fiat-amount-text}
409-
(str "~ " fiat-amount " " (or currency (i18n/label :usd-currency)))]]
410-
(when (and group-chat recipient-name)
411-
[react/text {:style transactions-styles/command-request-recipient-text}
412-
(str
413-
(i18n/label :request-requesting-from)
414-
" "
415-
recipient-name)])
416-
(when network-mismatch?
417-
[react/text {:style transactions-styles/command-request-network-text}
418-
(str (i18n/label :on) " " request-network)])
419-
[react/view transactions-styles/command-request-timestamp-row
420-
[react/text {:style (transactions-styles/command-request-timestamp-text outgoing)}
421-
(str
422-
(datetime/timestamp->mini-date timestamp)
423-
" "
424-
(i18n/label :at)
425-
" "
426-
timestamp-str)]]
427-
(when-not outgoing
428-
[react/view
429-
[react/view transactions-styles/command-request-separator-line]
430-
[react/view transactions-styles/command-request-button
431-
[react/text {:style (transactions-styles/command-request-button-text answered?)
432-
:on-press on-press-handler}
433-
(i18n/label (if answered? :command-button-sent :command-button-send))]]])]]]])))
388+
markup [react/view (transactions-styles/command-request-message-view outgoing)
389+
[react/view
390+
[react/text {:style (transactions-styles/command-request-header-text outgoing)}
391+
(i18n/label :transaction-request)]]
392+
[react/view transactions-styles/command-request-row
393+
[react/text {:style transactions-styles/command-request-amount-text
394+
:font :medium}
395+
amount
396+
[react/text {:style (transactions-styles/command-amount-currency-separator outgoing)}
397+
"."]
398+
[react/text {:style (transactions-styles/command-request-currency-text outgoing)
399+
:font :default}
400+
asset]]]
401+
[react/view transactions-styles/command-request-fiat-amount-row
402+
[react/text {:style transactions-styles/command-request-fiat-amount-text}
403+
(str "~ " fiat-amount " " (or currency (i18n/label :usd-currency)))]]
404+
(when network-mismatch?
405+
[react/text {:style transactions-styles/command-request-network-text}
406+
(str (i18n/label :on) " " request-network)])
407+
[react/view transactions-styles/command-request-timestamp-row
408+
[react/text {:style (transactions-styles/command-request-timestamp-text outgoing)}
409+
(str
410+
(datetime/timestamp->mini-date timestamp)
411+
" "
412+
(i18n/label :at)
413+
" "
414+
timestamp-str)]]
415+
(when-not outgoing
416+
[react/view
417+
[react/view transactions-styles/command-request-separator-line]
418+
[react/view transactions-styles/command-request-button
419+
[react/text {:style (transactions-styles/command-request-button-text answered?)}
420+
(i18n/label (if answered? :command-button-sent :command-button-send))]]])]]
421+
(if (and (not network-mismatch?)
422+
status-initialized?
423+
(not outgoing)
424+
(not answered?))
425+
[react/touchable-highlight {:on-press #(re-frame/dispatch [:select-chat-input-command
426+
command
427+
[(or asset "ETH") amount]
428+
{:responding-to message-id}])}
429+
markup]
430+
markup))))
434431

435432
(deftype PersonalRequestCommand []
436433
protocol/Command
@@ -441,13 +438,7 @@
441438
(validate [_ parameters cofx]
442439
(personal-send-request-validation parameters cofx))
443440
(on-send [_ _ _])
444-
(on-receive [_ {:keys [message-id chat-id]} {:keys [db]}]
445-
(let [request {:chat-id chat-id
446-
:message-id message-id
447-
:response "send"
448-
:status "open"}]
449-
{:db (assoc-in db [:chats chat-id :requests message-id] request)
450-
:data-store/tx [(requests-store/save-request-tx request)]}))
441+
(on-receive [_ _ _])
451442
(short-preview [_ command-message]
452443
(personal-send-request-short-preview :command-requesting command-message))
453444
(preview [_ command-message]

src/status_im/chat/events.cljs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns status-im.chat.events
22
(:require status-im.chat.events.input
3-
status-im.chat.events.requests
43
status-im.chat.events.send-message
54
status-im.chat.events.receive-message
65
[clojure.string :as string]

src/status_im/chat/events/requests.cljs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/status_im/chat/subs.cljs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,6 @@
304304
(fn [[show-suggestions-box? selected-command]]
305305
(and show-suggestions-box? (not selected-command))))
306306

307-
(reg-sub
308-
:is-request-answered?
309-
:<- [:get-current-chat]
310-
(fn [{:keys [requests]} [_ message-id]]
311-
(not= "open" (get-in requests [message-id :status]))))
312-
313307
(reg-sub
314308
:unviewed-messages-count
315309
(fn [[_ chat-id]]

src/status_im/data_store/core.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
status-im.data-store.browser
1111
status-im.data-store.accounts
1212
status-im.data-store.local-storage
13-
status-im.data-store.mailservers
14-
status-im.data-store.requests))
13+
status-im.data-store.mailservers))
1514

1615
(defn init [encryption-key]
1716
(if @data-source/base-realm

src/status_im/data_store/realm/schemas/account/core.cljs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
[status-im.data-store.realm.schemas.account.v6.core :as v6]
99
[status-im.data-store.realm.schemas.account.v7.core :as v7]
1010
[status-im.data-store.realm.schemas.account.v8.core :as v8]
11-
[status-im.data-store.realm.schemas.account.v9.core :as v9]))
11+
[status-im.data-store.realm.schemas.account.v9.core :as v9]
12+
[status-im.data-store.realm.schemas.account.v10.core :as v10]))
1213

1314
;; TODO(oskarth): Add failing test if directory vXX exists but isn't in schemas.
1415

@@ -39,4 +40,7 @@
3940
:migration v8/migration}
4041
{:schema v9/schema
4142
:schemaVersion 9
42-
:migration v9/migration}])
43+
:migration v9/migration}
44+
{:schema v10/schema
45+
:schemaVersion 10
46+
:migration v10/migration}])
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(ns status-im.data-store.realm.schemas.account.v10.core
2+
(:require [status-im.data-store.realm.schemas.account.v5.chat :as chat]
3+
[status-im.data-store.realm.schemas.account.v6.transport :as transport]
4+
[status-im.data-store.realm.schemas.account.v1.contact :as contact]
5+
[status-im.data-store.realm.schemas.account.v7.message :as message]
6+
[status-im.data-store.realm.schemas.account.v1.user-status :as user-status]
7+
[status-im.data-store.realm.schemas.account.v1.local-storage :as local-storage]
8+
[status-im.data-store.realm.schemas.account.v2.mailserver :as mailserver]
9+
[status-im.data-store.realm.schemas.account.v8.browser :as browser]
10+
[status-im.data-store.realm.schemas.account.v9.dapp-permissions :as dapp-permissions]
11+
[cljs.reader :as reader]
12+
[taoensso.timbre :as log]))
13+
14+
(def schema [chat/schema
15+
transport/schema
16+
contact/schema
17+
message/schema
18+
mailserver/schema
19+
user-status/schema
20+
local-storage/schema
21+
browser/schema
22+
dapp-permissions/schema])
23+
24+
(defn message-by-id [realm message-id]
25+
(some-> realm
26+
(.objects "message")
27+
(.filtered (str "message-id = \"" message-id "\""))
28+
(aget 0)))
29+
30+
(defn migration [old-realm new-realm]
31+
(log/debug "migrating v10 account database")
32+
(some-> old-realm
33+
(.objects "request")
34+
(.filtered (str "status = \"answered\""))
35+
(.map (fn [request _ _]
36+
(let [message-id (aget request "message-id")
37+
message (message-by-id new-realm message-id)
38+
content (reader/read-string (aget message "content"))
39+
new-content (assoc-in content [:params :answered?] true)]
40+
(aset message "content" (pr-str new-content)))))))

src/status_im/data_store/requests.cljs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/status_im/init/events.cljs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
(re-frame/inject-cofx :data-store/get-user-statuses)
7171
(re-frame/inject-cofx :data-store/get-unviewed-messages)
7272
(re-frame/inject-cofx :data-store/message-ids)
73-
(re-frame/inject-cofx :data-store/get-unanswered-requests)
7473
(re-frame/inject-cofx :data-store/get-local-storage-data)
7574
(re-frame/inject-cofx :data-store/get-all-contacts)
7675
(re-frame/inject-cofx :data-store/get-all-mailservers)

src/status_im/models/chat.cljs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,18 @@
4343
(defn initialize-chats [{:keys [db
4444
default-dapps
4545
all-stored-chats
46-
stored-unanswered-requests
4746
get-stored-messages
4847
get-stored-user-statuses
4948
get-stored-unviewed-messages
5049
stored-message-ids] :as cofx}]
51-
(let [chat->message-id->request (reduce (fn [acc {:keys [chat-id message-id] :as request}]
52-
(assoc-in acc [chat-id message-id] request))
53-
{}
54-
stored-unanswered-requests)
55-
stored-unviewed-messages (get-stored-unviewed-messages (:current-public-key db))
50+
(let [stored-unviewed-messages (get-stored-unviewed-messages (:current-public-key db))
5651
chats (reduce (fn [acc {:keys [chat-id] :as chat}]
5752
(let [chat-messages (index-messages (get-stored-messages chat-id))
5853
message-ids (keys chat-messages)
5954
unviewed-ids (get stored-unviewed-messages chat-id)]
6055
(assoc acc chat-id
6156
(assoc chat
6257
:unviewed-messages unviewed-ids
63-
:requests (get chat->message-id->request chat-id)
6458
:messages chat-messages
6559
:message-statuses (get-stored-user-statuses chat-id message-ids)
6660
:not-loaded-message-ids (set/difference (get stored-message-ids chat-id)

0 commit comments

Comments
 (0)