Add display name
This commit is contained in:
parent
61fd5fd791
commit
5e814b7a03
|
@ -6,8 +6,10 @@
|
|||
|
||||
(defn <-rpc [contact]
|
||||
(-> contact
|
||||
(clojure.set/rename-keys {:id :public-key
|
||||
(clojure.set/rename-keys
|
||||
{:id :public-key
|
||||
:ensVerifiedAt :ens-verified-at
|
||||
:displayName :display-name
|
||||
:ensVerified :ens-verified
|
||||
:ensVerificationRetries :ens-verification-retries
|
||||
:hasAddedUs :has-added-us
|
||||
|
|
|
@ -6,10 +6,12 @@
|
|||
(let [contact {:id "pk"
|
||||
:address "address"
|
||||
:name "name"
|
||||
:displayName "display-name"
|
||||
:identicon "identicon"
|
||||
:lastUpdated 1}
|
||||
expected-contact {:public-key "pk"
|
||||
:address "address"
|
||||
:display-name "display-name"
|
||||
:mutual? nil
|
||||
:name "name"
|
||||
:identicon "identicon"
|
||||
|
|
|
@ -23,29 +23,36 @@
|
|||
|
||||
(defn contact-names
|
||||
"Returns map of all existing names for contact"
|
||||
[{:keys [name preferred-name alias public-key ens-verified nickname]}]
|
||||
[{:keys [name
|
||||
display-name
|
||||
preferred-name
|
||||
alias
|
||||
public-key
|
||||
ens-verified
|
||||
nickname]}]
|
||||
(let [ens-name (or preferred-name
|
||||
name)]
|
||||
(cond-> {:nickname nickname
|
||||
:display-name display-name
|
||||
:three-words-name (or alias (gfycat/generate-gfy public-key))}
|
||||
;; Preferred name is our own otherwise we make sure it's verified
|
||||
(or preferred-name (and ens-verified name))
|
||||
(assoc :ens-name (str "@" (or (stateofus/username ens-name) ens-name))))))
|
||||
|
||||
;; NOTE: this does a bit of unnecessary work, we could short-circuit the work
|
||||
;; once the first two are found, i.e don't calculate short key if 2 are already
|
||||
;; available
|
||||
(defn contact-two-names
|
||||
"Returns vector of two names in next order nickname, ens name, three word name, public key"
|
||||
"Returns vector of two names in next order nickname, ens name, display-name, three word name, public key"
|
||||
[{:keys [names public-key] :as contact} public-key?]
|
||||
(let [{:keys [nickname ens-name three-words-name]} (or names (contact-names contact))
|
||||
(let [{:keys [nickname
|
||||
ens-name
|
||||
display-name
|
||||
three-words-name]} (or names (contact-names contact))
|
||||
short-public-key (when public-key? (utils/get-shortened-address public-key))]
|
||||
(cond (not (string/blank? nickname))
|
||||
[nickname (or ens-name three-words-name short-public-key)]
|
||||
(not (string/blank? ens-name))
|
||||
[ens-name (or three-words-name short-public-key)]
|
||||
(not (string/blank? three-words-name))
|
||||
[three-words-name short-public-key]
|
||||
:else
|
||||
(when public-key?
|
||||
[short-public-key short-public-key]))))
|
||||
(->> [nickname ens-name display-name three-words-name short-public-key]
|
||||
(remove string/blank?)
|
||||
(take 2))))
|
||||
|
||||
(defn contact-with-names
|
||||
"Returns contact with :names map "
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
(ns status-im.multiaccounts.core-test
|
||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||
[status-im.multiaccounts.core :as ma]))
|
||||
|
||||
(def public-key "0x0461f576da67dc0bca9888cdb4cb28c80285b756b324109da94a081585ed6f007cf00afede6b3ee5638593674fee100b590318fc7bdb0054b8dd9445acea216ad2")
|
||||
(def short-public-key "0x0461…ad2")
|
||||
(def random-name "Studious Gold Mustang")
|
||||
(def override-random-name (str "override" random-name))
|
||||
(def nickname "nickname")
|
||||
(def override-nickname (str nickname "override"))
|
||||
(def display-name "display-name")
|
||||
(def override-display-name (str display-name "override"))
|
||||
(def ens-name "jakubgs.eth")
|
||||
(def formatted-ens (str "@" ens-name))
|
||||
(def override-ens-name (str "override" ens-name))
|
||||
|
||||
(def contact
|
||||
{:nickname nickname
|
||||
:name ens-name
|
||||
:ens-verified true
|
||||
:public-key public-key
|
||||
:display-name display-name})
|
||||
|
||||
(deftest contact-two-names-test
|
||||
(testing "names is nil"
|
||||
(testing "nickname has precedence"
|
||||
(is
|
||||
(= [nickname formatted-ens]
|
||||
(ma/contact-two-names contact public-key))))
|
||||
(testing "ens name is second option"
|
||||
(is
|
||||
(= [formatted-ens display-name]
|
||||
(ma/contact-two-names
|
||||
(dissoc contact :nickname)
|
||||
public-key))))
|
||||
(testing "ens name is second option but not verified"
|
||||
(is
|
||||
(= [display-name random-name]
|
||||
(ma/contact-two-names
|
||||
(dissoc contact :nickname :ens-verified)
|
||||
public-key))))
|
||||
(testing "display name is third option"
|
||||
(is
|
||||
(= [display-name random-name]
|
||||
(ma/contact-two-names
|
||||
(dissoc contact :nickname :name)
|
||||
public-key))))
|
||||
(testing "3 random words is fallback"
|
||||
(is
|
||||
(= [random-name short-public-key]
|
||||
(ma/contact-two-names
|
||||
(dissoc contact
|
||||
:nickname
|
||||
:name
|
||||
:display-name)
|
||||
public-key)))))
|
||||
(testing "names is provided"
|
||||
(let [names {:nickname override-nickname
|
||||
:display-name override-display-name
|
||||
:three-words-name override-random-name
|
||||
:ens-name override-ens-name}
|
||||
contact-with-names (assoc contact :names names)]
|
||||
|
||||
(testing "nickname has precedence"
|
||||
(is
|
||||
(= [override-nickname override-ens-name]
|
||||
(ma/contact-two-names contact-with-names public-key))))
|
||||
(testing "ens name is second option"
|
||||
(is
|
||||
(= [override-ens-name override-display-name]
|
||||
(ma/contact-two-names
|
||||
(update contact-with-names :names dissoc :nickname)
|
||||
public-key))))
|
||||
(testing "display name is third option"
|
||||
(is
|
||||
(= [override-display-name override-random-name]
|
||||
(ma/contact-two-names
|
||||
(update contact-with-names :names dissoc :nickname :ens-name)
|
||||
public-key))))
|
||||
(testing "3 random words is fallback"
|
||||
(is
|
||||
(= [override-random-name short-public-key]
|
||||
(ma/contact-two-names
|
||||
(update contact-with-names :names dissoc :nickname :ens-name :display-name)
|
||||
public-key)))))))
|
|
@ -50,6 +50,8 @@
|
|||
accounts-data))
|
||||
:logout (fn []
|
||||
(.logout native-status))
|
||||
:generateAlias (fn [seed]
|
||||
(.generateAlias native-status seed))
|
||||
:generateAliasAndIdenticonAsync (fn [seed callback]
|
||||
(let [generated-identicon (.identicon native-status seed)
|
||||
generated-alias (.generateAlias native-status seed)]
|
||||
|
|
Loading…
Reference in New Issue