feat: add ident ring for login profile picture (#15942)

This commit is contained in:
yqrashawn 2023-05-23 14:10:01 +08:00 committed by GitHub
parent d1941fe002
commit 2191f68883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 92 additions and 18 deletions

View File

@ -73,11 +73,10 @@
:shell? true}]))
(defn profile-card
[{:keys [name key-uid customization-color keycard-pairing last-index set-hide-profiles]
:as multiaccount}
[{:keys [name key-uid customization-color keycard-pairing last-index set-hide-profiles]}
index]
(let [last-item? (= last-index index)
profile-picture (:uri (first (:images multiaccount)))]
profile-picture (rf/sub [:multiaccounts/login-profiles-picture key-uid])]
[quo/profile-card
{:name name
:login-card? true
@ -176,10 +175,10 @@
(defn login-section
[{:keys [set-show-profiles]}]
(let [{:keys [name customization-color error processing password]
:as multiaccount} (rf/sub [:multiaccounts/login])
sign-in-enabled? (rf/sub [:sign-in-enabled?])
profile-picture (:uri (first (:images multiaccount)))]
(let [{:keys [key-uid name customization-color error
processing password]} (rf/sub [:multiaccounts/login])
sign-in-enabled? (rf/sub [:sign-in-enabled?])
profile-picture (rf/sub [:multiaccounts/login-profiles-picture key-uid])]
[rn/keyboard-avoiding-view
{:style style/login-container
:keyboardVerticalOffset (- (safe-area/get-bottom))}

View File

@ -1,13 +1,13 @@
(ns status-im2.subs.multiaccount
(:require [cljs.spec.alpha :as spec]
[clojure.string :as string]
[quo2.theme :as theme]
[re-frame.core :as re-frame]
[status-im.ethereum.core :as ethereum]
[status-im.fleet.core :as fleet]
[status-im.multiaccounts.db :as multiaccounts.db]
[utils.image-server :as image-server]
[utils.security.core :as security]
[quo2.theme :as theme]))
[utils.security.core :as security]))
(re-frame/reg-sub
:multiaccount/public-key
@ -214,11 +214,12 @@
images (reduce (fn [acc current]
(let [key-uid (:keyUid current)
image-name (:type current)
uri (image-server/get-account-image-uri port
public-key
image-name
key-uid
theme)]
uri (image-server/get-account-image-uri {:port port
:public-key public-key
:image-name image-name
:key-uid key-uid
:theme theme
:ring? true})]
(conj acc (assoc current :uri uri))))
[]
images)]

View File

@ -1,7 +1,9 @@
(ns status-im2.subs.onboarding
(:require [re-frame.core :as re-frame]
(:require [quo2.theme :as theme]
[re-frame.core :as re-frame]
[status-im.multiaccounts.recover.core :as recover]
[status-im2.constants :as constants]))
[status-im2.constants :as constants]
[utils.image-server :as image-server]))
(re-frame/reg-sub
:intro-wizard
@ -48,6 +50,22 @@
(fn [[intro-wizard multiaccounts]]
(recover/existing-account? (:root-key intro-wizard) multiaccounts)))
(re-frame/reg-sub
:multiaccounts/login-profiles-picture
:<- [:multiaccounts/multiaccounts]
:<- [:mediaserver/port]
(fn [[multiaccounts port] [_ target-key-uid]]
(let [image-name (-> multiaccounts
(get-in [target-key-uid :images])
first
:type)]
(when image-name
(image-server/get-account-image-uri {:port port
:image-name image-name
:key-uid target-key-uid
:theme (theme/get-theme)
:ring? true})))))
(defn login-ma-keycard-pairing
"Compute the keycard-pairing value of the multiaccount selected for login"
[db _]

View File

@ -0,0 +1,38 @@
(ns status-im2.subs.onboarding-test
(:require [cljs.test :as t]
[quo2.theme :as theme]
[re-frame.db :as rf-db]
status-im2.subs.onboarding
[test-helpers.unit :as h]
[utils.image-server :as image-server]
[utils.re-frame :as rf]))
(def key-uid "0x1")
(def port "mediaserver-port")
(def cur-theme :current-theme)
(h/deftest-sub :multiaccounts/login-profiles-picture
[sub-name]
(with-redefs [image-server/get-account-image-uri identity
theme/get-theme (constantly cur-theme)]
(t/testing "nil when no images"
(swap! rf-db/app-db assoc :multiaccounts/multiaccounts {key-uid {}})
(t/is (nil? (rf/sub [sub-name key-uid]))))
(t/testing "nil when no key-uid"
(swap! rf-db/app-db assoc :multiaccounts/multiaccounts {key-uid {}})
(t/is (nil? (rf/sub [sub-name "0x2"]))))
(t/testing "result from image-server/get-account-image-uri"
(swap!
rf-db/app-db
assoc
:multiaccounts/multiaccounts {key-uid {:images [{:type "large"}
{:type "thumbnail"}]}}
:mediaserver/port port)
(t/is (= (rf/sub [sub-name key-uid])
{:port port
:image-name "large"
:key-uid key-uid
:theme cur-theme
:ring? true})))))

View File

@ -26,7 +26,7 @@
4))
(defn get-account-image-uri
[port public-key image-name key-uid theme]
[{:keys [port public-key image-name key-uid theme ring?]}]
(str image-server-uri-prefix
port
account-images-action
@ -40,7 +40,8 @@
(current-theme-index theme)
"&clock="
(timestamp)
"&addRing=1"))
"&addRing="
(if ring? 1 0)))
(defn get-contact-image-uri
[port public-key image-name clock theme]

View File

@ -0,0 +1,17 @@
(ns utils.image-server-test
(:require [cljs.test :as t]
[utils.image-server :as sut]))
(t/deftest get-account-image-uri
(with-redefs
[sut/current-theme-index identity
sut/timestamp (constantly "timestamp")]
(t/is
(=
(sut/get-account-image-uri {:port "port"
:public-key "public-key"
:image-name "image-name"
:key-uid "key-uid"
:theme "theme"
:ring? true})
"https://localhost:port/accountImages?publicKey=public-key&keyUid=key-uid&imageName=image-name&theme=theme&clock=timestamp&addRing=1"))))