Dont show add-to-contacts if dapp

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-06-07 11:28:56 +02:00
parent 0beeaa0322
commit 00cd7c8578
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
4 changed files with 30 additions and 2 deletions

View File

@ -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}

View File

@ -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?))))

View File

@ -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}))))))

View File

@ -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