Fetch details of user when adding a contact (#15070)

* Fixes

* Fixes

* Final fixes

* Lint fixes
This commit is contained in:
Alexander 2023-03-14 11:40:38 +01:00 committed by GitHub
parent 64dde1c9d1
commit 4097aba39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 39 deletions

View File

@ -336,9 +336,11 @@
;; click 'view profile' button ;; click 'view profile' button
(rf/dispatch [:chat.ui/show-profile public-key]) (rf/dispatch [:chat.ui/show-profile public-key])
(rf-test/wait-for (rf-test/wait-for
[:contacts/contact-built] [:contacts/build-contact]
(let [contact @(rf/subscribe [:contacts/current-contact])] (rf-test/wait-for
(is (= three-words-name (:primary-name contact)))) [:contacts/contact-built]
(logout!) (let [contact @(rf/subscribe [:contacts/current-contact])]
(rf-test/wait-for [::logout/logout-method] (is (= three-words-name (:primary-name contact))))
(assert-logout)))))))))) (logout!)
(rf-test/wait-for [::logout/logout-method]
(assert-logout)))))))))))

View File

@ -2,7 +2,6 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im2.contexts.contacts.events :as data-store.contacts]
[status-im.ui.components.list-selection :as list-selection] [status-im.ui.components.list-selection :as list-selection]
[status-im.ui.components.react :as react] [status-im.ui.components.react :as react]
[utils.re-frame :as rf] [utils.re-frame :as rf]
@ -86,24 +85,12 @@
[_ value] [_ value]
{:profile/share-profile-link value}) {:profile/share-profile-link value})
(rf/defn contact-built
{:events [:contacts/contact-built]}
[{:keys [db]} identity contact]
{:db (assoc-in db [:contacts/contacts identity] contact)
:dispatch [:open-modal :profile]})
(rf/defn show-profile (rf/defn show-profile
{:events [:chat.ui/show-profile]} {:events [:chat.ui/show-profile]}
[{:keys [db]} identity ens-name] [{:keys [db]} identity ens-name]
(let [my-public-key (get-in db [:multiaccount :public-key])] (let [my-public-key (get-in db [:multiaccount :public-key])]
(when (not= my-public-key identity) (when (not= my-public-key identity)
{:db (-> db {:db (-> db
(assoc :contacts/identity identity) (assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name)) (assoc :contacts/ens-name ens-name))
:json-rpc/call [{:method "wakuext_buildContact" :dispatch [:contacts/build-contact identity true]})))
:params [identity]
:js-response true
:on-success #(rf/dispatch [:contacts/contact-built
identity
(data-store.contacts/<-rpc-js %)])}]})))

View File

@ -8,6 +8,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[status-im2.utils.validators :as validators] [status-im2.utils.validators :as validators]
[status-im2.contexts.contacts.events :as data-store.contacts]
[status-im.utils.utils :as utils])) [status-im.utils.utils :as utils]))
(re-frame/reg-fx (re-frame/reg-fx
@ -29,12 +30,9 @@
(defn fx-callbacks (defn fx-callbacks
[input ens-name] [input ens-name]
{:on-success (fn [pubkey] {:on-success (fn [pubkey]
(rf/dispatch (rf/dispatch [:contacts/set-new-identity-success input ens-name pubkey]))
[:contacts/set-new-identity-success
input ens-name pubkey]))
:on-error (fn [err] :on-error (fn [err]
(rf/dispatch (rf/dispatch [:contacts/set-new-identity-error err input]))})
[:contacts/set-new-identity-error err input]))})
(defn identify-type (defn identify-type
[input] [input]
@ -87,15 +85,35 @@
:ens-name ens-name} :ens-name ens-name}
(fx-callbacks id ens-name))}))) (fx-callbacks id ens-name))})))
(rf/defn build-contact
{:events [:contacts/build-contact]}
[_ pubkey open-profile-modal?]
{:json-rpc/call [{:method "wakuext_buildContact"
:params [pubkey]
:js-response true
:on-success #(rf/dispatch [:contacts/contact-built
pubkey
open-profile-modal?
(data-store.contacts/<-rpc-js %)])}]})
(rf/defn contact-built
{:events [:contacts/contact-built]}
[{:keys [db]} pubkey open-profile-modal? contact]
(merge {:db (assoc-in db [:contacts/contacts pubkey] contact)}
(when open-profile-modal?
{:dispatch [:open-modal :profile]})))
(rf/defn set-new-identity-success (rf/defn set-new-identity-success
{:events [:contacts/set-new-identity-success]} {:events [:contacts/set-new-identity-success]}
[{:keys [db]} input ens-name pubkey] [{:keys [db] :as cofx} input ens-name pubkey]
{:db (assoc db (rf/merge cofx
:contacts/new-identity {:db (assoc db
{:input input :contacts/new-identity
:public-key pubkey {:input input
:ens-name ens-name :public-key pubkey
:state :valid})}) :ens-name ens-name
:state :valid})}
(build-contact pubkey false)))
(rf/defn set-new-identity-error (rf/defn set-new-identity-error
{:events [:contacts/set-new-identity-error]} {:events [:contacts/set-new-identity-error]}

View File

@ -138,6 +138,47 @@
:icon true :icon true
:size 40}) :size 40})
(def found-user
{:padding-top 16
:flex-direction :column
:align-self :stretch})
(defn found-user-container
[]
{:flex-direction :row
:align-items :center
:padding-top 8
:padding-left 12
:padding-right 12
:padding-bottom 8
:color (colors/theme-colors
colors/black
colors/white)
:background-color (colors/theme-colors
colors/white
colors/neutral-95)
:border-width 1
:border-radius 12
:border-color (colors/theme-colors
colors/neutral-20
colors/neutral-80)})
(def found-user-text
{:margin-left 8
:flex-direction :column})
(defn found-user-display-name
[]
{:color (colors/theme-colors
colors/black
colors/white)})
(defn found-user-key
[]
{:color (colors/theme-colors
colors/neutral-50
colors/neutral-40)})
(defn button-view-profile (defn button-view-profile
[state] [state]
{:type :primary {:type :primary

View File

@ -6,11 +6,42 @@
[react-native.clipboard :as clipboard] [react-native.clipboard :as clipboard]
[status-im2.common.resources :as resources] [status-im2.common.resources :as resources]
[status-im.qr-scanner.core :as qr-scanner] [status-im.qr-scanner.core :as qr-scanner]
[status-im.utils.utils :as utils]
[status-im2.contexts.add-new-contact.style :as style] [status-im2.contexts.add-new-contact.style :as style]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn found-contact
[public-key]
(let [{:keys [primary-name
compressed-key
identicon
images]} (rf/sub [:contacts/contact-by-identity public-key])
profile-picture (-> (or (:thumbnail images) (:large images) (first images))
(get :uri identicon))]
(when primary-name
[rn/view style/found-user
[quo/text (style/text-description)
(i18n/label :t/user-found)]
[rn/view (style/found-user-container)
[quo/user-avatar
{:full-name primary-name
:profile-picture profile-picture
:size :small
:status-indicator? false}]
[rn/view style/found-user-text
[quo/text
{:weight :semi-bold
:size :paragraph-1
:style (style/found-user-display-name)}
primary-name]
[quo/text
{:weight :regular
:size :paragraph-2
:style (style/found-user-key)}
(utils/get-shortened-address compressed-key)]]]])))
(defn new-contact (defn new-contact
[] []
(let [{:keys [input public-key state error]} (rf/sub (let [{:keys [input public-key state error]} (rf/sub
@ -59,7 +90,9 @@
(when error? (when error?
[rn/view style/container-error [rn/view style/container-error
[quo/icon :i/alert style/icon-error] [quo/icon :i/alert style/icon-error]
[quo/text style/text-error (i18n/label :t/not-a-chatkey)]])] [quo/text style/text-error (i18n/label :t/not-a-chatkey)]])
(when (= state :valid)
[found-contact public-key])]
[rn/view [rn/view
[quo/button [quo/button
(merge (style/button-view-profile state) (merge (style/button-view-profile state)

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.137.2", "version": "80d350ad5b8366966dd1aafe5622af172d7cce6b",
"commit-sha1": "4d705ce1b2d16547e823ba0fc731f60a0e887e08", "commit-sha1": "80d350ad5b8366966dd1aafe5622af172d7cce6b",
"src-sha256": "1crblvx8027lk8yykb8hfnaj8a7n2xm4jch0c2grrpwfpcdxi4hg" "src-sha256": "0dcfrky9rky09fhzsk5krsj2khly6hwgmvilxzczi7vxny70xcha"
} }

View File

@ -576,6 +576,7 @@
"password-placeholder": "Password...", "password-placeholder": "Password...",
"confirm-password-placeholder": "Confirm your password...", "confirm-password-placeholder": "Confirm your password...",
"ens-or-chat-key": "ENS or Chat key", "ens-or-chat-key": "ENS or Chat key",
"user-found": "User found",
"enter-pin": "Enter 6-digit passcode", "enter-pin": "Enter 6-digit passcode",
"enter-puk-code": "Enter PUK code", "enter-puk-code": "Enter PUK code",
"enter-puk-code-description": "6-digit passcode has been blocked.\n Please enter PUK code to unblock passcode.", "enter-puk-code-description": "6-digit passcode has been blocked.\n Please enter PUK code to unblock passcode.",