|
5 | 5 | [re-frame.core :as re-frame] |
6 | 6 | [status-im.chat.commands.protocol :as protocol] |
7 | 7 | [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] |
9 | 9 | [status-im.ui.components.react :as react] |
10 | 10 | [status-im.ui.components.icons.vector-icons :as vector-icons] |
11 | 11 | [status-im.ui.components.colors :as colors] |
|
258 | 258 | prices) |
259 | 259 | :currency currency))) |
260 | 260 |
|
| 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 | + |
261 | 267 | (deftype PersonalSendCommand [] |
262 | 268 | protocol/Command |
263 | 269 | (id [_] "send") |
|
268 | 274 | ;; Only superficial/formatting validation, "real validation" will be performed |
269 | 275 | ;; by the wallet, where we yield control in the next step |
270 | 276 | (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]}] |
272 | 278 | (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)]}))))) |
275 | 284 | (on-receive [_ command-message cofx] |
276 | 285 | (when-let [tx-hash (get-in command-message [:content :params :tx-hash])] |
277 | 286 | (wallet.transactions/store-chat-transaction-hash tx-hash cofx))) |
|
370 | 379 | (defview request-preview |
371 | 380 | [{:keys [message-id content outgoing timestamp timestamp-str group-chat]}] |
372 | 381 | (letsubs [id->command [:get-id->command] |
373 | | - answered? [:is-request-answered? message-id] |
374 | 382 | status-initialized? [:get :status-module-initialized?] |
375 | 383 | network [:network-name] |
376 | 384 | 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) |
379 | 386 | network-mismatch? (and request-network (not= request-network network)) |
380 | 387 | 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)))) |
434 | 431 |
|
435 | 432 | (deftype PersonalRequestCommand [] |
436 | 433 | protocol/Command |
|
441 | 438 | (validate [_ parameters cofx] |
442 | 439 | (personal-send-request-validation parameters cofx)) |
443 | 440 | (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 [_ _ _]) |
451 | 442 | (short-preview [_ command-message] |
452 | 443 | (personal-send-request-short-preview :command-requesting command-message)) |
453 | 444 | (preview [_ command-message] |
|
0 commit comments