Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/status_im/add_new/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/contact/chat.cljs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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)
ilmotta marked this conversation as resolved.
Show resolved Hide resolved
{:dispatch [:chat.ui/start-chat public-key ens-name]})
#(when new-contact?
(navigation/navigate-back %)))))
5 changes: 3 additions & 2 deletions src/status_im/ui/screens/profile/contact/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 19 additions & 14 deletions src/status_im2/contexts/contacts/events.cljs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down