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
(rf/dispatch [:chat.ui/show-profile public-key])
(rf-test/wait-for
[:contacts/contact-built]
(let [contact @(rf/subscribe [:contacts/current-contact])]
(is (= three-words-name (:primary-name contact))))
(logout!)
(rf-test/wait-for [::logout/logout-method]
(assert-logout))))))))))
[:contacts/build-contact]
(rf-test/wait-for
[:contacts/contact-built]
(let [contact @(rf/subscribe [:contacts/current-contact])]
(is (= three-words-name (:primary-name contact))))
(logout!)
(rf-test/wait-for [::logout/logout-method]
(assert-logout)))))))))))

View File

@ -2,7 +2,6 @@
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[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.react :as react]
[utils.re-frame :as rf]
@ -86,24 +85,12 @@
[_ 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
{:events [:chat.ui/show-profile]}
[{:keys [db]} identity ens-name]
(let [my-public-key (get-in db [:multiaccount :public-key])]
(when (not= my-public-key identity)
{:db (-> db
(assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name))
:json-rpc/call [{:method "wakuext_buildContact"
:params [identity]
:js-response true
:on-success #(rf/dispatch [:contacts/contact-built
identity
(data-store.contacts/<-rpc-js %)])}]})))
{:db (-> db
(assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name))
:dispatch [:contacts/build-contact identity true]})))

View File

@ -8,6 +8,7 @@
[status-im.native-module.core :as status]
[status-im2.navigation.events :as navigation]
[status-im2.utils.validators :as validators]
[status-im2.contexts.contacts.events :as data-store.contacts]
[status-im.utils.utils :as utils]))
(re-frame/reg-fx
@ -29,12 +30,9 @@
(defn fx-callbacks
[input ens-name]
{:on-success (fn [pubkey]
(rf/dispatch
[:contacts/set-new-identity-success
input ens-name pubkey]))
(rf/dispatch [:contacts/set-new-identity-success input ens-name pubkey]))
:on-error (fn [err]
(rf/dispatch
[:contacts/set-new-identity-error err input]))})
(rf/dispatch [:contacts/set-new-identity-error err input]))})
(defn identify-type
[input]
@ -87,15 +85,35 @@
:ens-name 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
{:events [:contacts/set-new-identity-success]}
[{:keys [db]} input ens-name pubkey]
{:db (assoc db
:contacts/new-identity
{:input input
:public-key pubkey
:ens-name ens-name
:state :valid})})
[{:keys [db] :as cofx} input ens-name pubkey]
(rf/merge cofx
{:db (assoc db
:contacts/new-identity
{:input input
:public-key pubkey
:ens-name ens-name
:state :valid})}
(build-contact pubkey false)))
(rf/defn set-new-identity-error
{:events [:contacts/set-new-identity-error]}

View File

@ -138,6 +138,47 @@
:icon true
: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
[state]
{:type :primary

View File

@ -6,11 +6,42 @@
[react-native.clipboard :as clipboard]
[status-im2.common.resources :as resources]
[status-im.qr-scanner.core :as qr-scanner]
[status-im.utils.utils :as utils]
[status-im2.contexts.add-new-contact.style :as style]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[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
[]
(let [{:keys [input public-key state error]} (rf/sub
@ -59,7 +90,9 @@
(when error?
[rn/view style/container-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
[quo/button
(merge (style/button-view-profile state)

View File

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

View File

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