diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 09ed3b74ab..a6f9dd071a 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -5,6 +5,7 @@ [status-im.constants :as constants] [status-im.i18n :as i18n] [status-im.chat.models :as models.chat] + [status-im.models.contact :as models.contact] [status-im.chat.styles.screen :as style] [status-im.utils.platform :as platform] [status-im.chat.views.toolbar-content :as toolbar-content] @@ -38,8 +39,8 @@ [vector-icons/icon :icons/dots-horizontal]]]) (defview add-contact-bar [contact-identity] - (letsubs [{:keys [pending?] :as contact} [:get-contact-by-identity contact-identity]] - (when (or pending? (nil? pending?)) ;; contact is pending or not in contact list at all + (letsubs [contact [:get-contact-by-identity contact-identity]] + (when (models.contact/can-add-to-contacts? contact) [react/touchable-highlight {:on-press #(re-frame/dispatch [:add-contact contact-identity]) :accessibility-label :add-to-contacts-button} diff --git a/src/status_im/models/contact.cljs b/src/status_im/models/contact.cljs new file mode 100644 index 0000000000..8ba428cc94 --- /dev/null +++ b/src/status_im/models/contact.cljs @@ -0,0 +1,7 @@ +(ns status-im.models.contact) + +(defn can-add-to-contacts? [{:keys [pending? dapp?]}] + (and (not dapp?) + (or pending? + ;; it's not in the contact list at all + (nil? pending?)))) diff --git a/test/cljs/status_im/test/models/contact.cljs b/test/cljs/status_im/test/models/contact.cljs new file mode 100644 index 0000000000..ce858bf413 --- /dev/null +++ b/test/cljs/status_im/test/models/contact.cljs @@ -0,0 +1,18 @@ +(ns status-im.test.models.contact + (:require [cljs.test :refer-macros [deftest is testing]] + [status-im.models.contact :as model])) + +(deftest can-add-to-contact-test + (testing "a user is already in contacts" + (is (not (model/can-add-to-contacts? {:pending? false})))) + (testing "a user is pending" + (testing "a normal user" + (is (model/can-add-to-contacts? {:pending? true}))) + (testing "a dapp" + (is (not (model/can-add-to-contacts? {:pending? true + :dapp? true}))))) + (testing "the user is not in the contacts" + (testing "a normal user" + (is (model/can-add-to-contacts? {}))) + (testing "a dapp" + (is (not (model/can-add-to-contacts? {:dapp? true})))))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index f50fdc49a0..595c2ec0ea 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -13,6 +13,7 @@ [status-im.test.models.mailserver] [status-im.test.models.bootnode] [status-im.test.models.account] + [status-im.test.models.contact] [status-im.test.transport.core] [status-im.test.transport.inbox] [status-im.test.transport.handlers] @@ -62,6 +63,7 @@ 'status-im.test.models.mailserver 'status-im.test.models.bootnode 'status-im.test.models.account + 'status-im.test.models.contact 'status-im.test.bots.events 'status-im.test.wallet.subs 'status-im.test.wallet.transactions.subs