diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 2d2b184445..d783be2701 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -122,9 +122,15 @@ (assoc :new-contact-identity ""))) (register-handler :add-new-contact - (-> add-new-contact - ((after save-contact)) - ((after watch-contact)))) + (u/side-effect! + (fn [_ [_ {:keys [whisper-identity] :as contact}]] + (when-not (contacts/get-contact whisper-identity) + (dispatch [::new-contact contact]))))) + +(register-handler ::new-contact + (-> add-new-contact + ((after save-contact)) + ((after watch-contact)))) (defn set-contact-identity-from-qr [db [_ _ contact-identity]] diff --git a/src/status_im/models/contacts.cljs b/src/status_im/models/contacts.cljs index 70f67ac34c..83dc2f637b 100644 --- a/src/status_im/models/contacts.cljs +++ b/src/status_im/models/contacts.cljs @@ -9,6 +9,9 @@ (r/sorted :name :asc) r/collection->map)) +(defn get-contact [id] + (r/get-one-by-field :account :contact :whisper-identity id)) + (defn create-contact [{:keys [whisper-identity] :as contact}] (let [contact-from-db (r/get-one-by-field :account :contact :whisper-identity whisper-identity)]