diff --git a/src/status_im/add_new/core.cljs b/src/status_im/add_new/core.cljs index 384ba8b7dd..f3f43a2ea8 100644 --- a/src/status_im/add_new/core.cljs +++ b/src/status_im/add_new/core.cljs @@ -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) diff --git a/src/status_im/contact/chat.cljs b/src/status_im/contact/chat.cljs index e3e4b15cc5..73e4167805 100644 --- a/src/status_im/contact/chat.cljs +++ b/src/status_im/contact/chat.cljs @@ -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 %))))) diff --git a/src/status_im/ui/screens/profile/contact/views.cljs b/src/status_im/ui/screens/profile/contact/views.cljs index 6469f13a5b..d25469c7e5 100644 --- a/src/status_im/ui/screens/profile/contact/views.cljs +++ b/src/status_im/ui/screens/profile/contact/views.cljs @@ -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 diff --git a/src/status_im2/contexts/contacts/events.cljs b/src/status_im2/contexts/contacts/events.cljs index d4fa4fa47e..bdc64655e8 100644 --- a/src/status_im2/contexts/contacts/events.cljs +++ b/src/status_im2/contexts/contacts/events.cljs @@ -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" diff --git a/translations/en.json b/translations/en.json index 58c851a47b..ae8059ee6b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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",