Various fixes for Contact Request flows (2nd attempt) (#15685)

- Make sure status-mobile works well with the upcoming status-go changes in PR
  https://github.com/status-im/status-go/pull/3379.
- Replace calls to `wakuext_addContact` with `wakuext_sendContactRequest`. This
  is what's been aligned with the desktop team, as we will go on to remove
  `wakuext_addContact` in the near future.

Fixes https://github.com/status-im/status-mobile/issues/15679
This commit is contained in:
Icaro Motta 2023-04-25 13:32:08 -03:00 committed by GitHub
parent 80bab6d338
commit 30f0b436e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 20 deletions

View File

@ -82,7 +82,7 @@
(if-not validation-result
(if new-contact?
(rf/merge cofx
(contact/add-contact chat-key nickname ens-name)
(contact/send-contact-request chat-key)
(navigation/navigate-to :contacts-list {}))
(chat/start-chat cofx chat-key ens-name))
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)

View File

@ -1,8 +1,8 @@
(ns status-im.contact.chat
(:require [re-frame.core :as re-frame]
[status-im2.contexts.contacts.events :as contact]
[utils.re-frame :as rf]
[status-im2.navigation.events :as navigation]))
[status-im2.navigation.events :as navigation]
[utils.re-frame :as rf]))
(rf/defn contact-code-submitted
{:events [:contact.ui/contact-code-submitted]
@ -11,7 +11,7 @@
(let [{:keys [public-key ens-name]} new-identity]
(rf/merge cofx
#(if new-contact?
(contact/add-contact % public-key nickname ens-name)
(contact/send-contact-request % public-key)
{:dispatch [:chat.ui/start-chat public-key ens-name]})
#(when new-contact?
(navigation/navigate-back %)))))

View File

@ -36,8 +36,9 @@
:disabled blocked?
:accessibility-label :add-to-contacts-button
:action (when-not blocked?
#(re-frame/dispatch [:contact.ui/add-contact-pressed public-key
nil ens-name]))}])
(fn []
(re-frame/dispatch [:contact.ui/send-contact-request
public-key])))}])
[{:label (i18n/label (if (or muted? blocked?) :t/unmute :t/mute))
:icon :main-icons/notification
:accessibility-label :mute-chat

View File

@ -1,10 +1,11 @@
(ns status-im2.contexts.contacts.events
(:require
[utils.re-frame :as rf]
[taoensso.timbre :as log]
[status-im.utils.types :as types]
[oops.core :as oops]
[status-im2.constants :as constants]))
[status-im.utils.types :as types]
[status-im2.constants :as constants]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn <-rpc-js
[^js js-contact]
@ -75,16 +76,20 @@
[{:keys [db]} contacts]
{:db (assoc db :contacts/contacts (into {} (map #(vector (:public-key %) %) contacts)))})
(rf/defn add-contact
"Add a contact and set pending to false"
{:events [:contact.ui/add-contact-pressed]}
[{:keys [db]} public-key nickname ens-name]
(when (not= (get-in db [:multiaccount :public-key]) public-key)
{:json-rpc/call [{:method "wakuext_addContact"
:params [{:id public-key :nickname nickname :ensName ens-name}]
:js-response true
:on-success #(rf/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to add contact" public-key %)}]}))
(rf/defn send-contact-request
{:events [:contact.ui/send-contact-request]}
[{:keys [db]} id]
(when (not= id (get-in db [:multiaccount :public-key]))
{:json-rpc/call
[{:method "wakuext_sendContactRequest"
:js-response true
:params [{:id id :message (i18n/label :t/add-me-to-your-contacts)}]
:on-error (fn [error]
(log/error "Failed to send contact request"
{:error error
:event :contact.ui/send-contact-request
:id id}))
:on-success #(rf/dispatch [:transport/message-sent %])}]}))
(rf/defn remove-contact
"Remove a contact from current account's contact list"

View File

@ -45,6 +45,7 @@
"advanced": "Advanced",
"advanced-settings": "Advanced settings",
"agree-by-continuing": "By continuing you agree\n to our ",
"add-me-to-your-contacts": "Please add me to your contacts",
"all": "All",
"allow": "Allow",
"allowing-authorizes-this-dapp": "Allowing authorizes this DApp to retrieve your wallet address and enable Web3",