From 4097aba39b60bd27c64aeb7a0d7943bc5e31de64 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 14 Mar 2023 11:40:38 +0100 Subject: [PATCH] Fetch details of user when adding a contact (#15070) * Fixes * Fixes * Final fixes * Lint fixes --- src/status_im/integration_test.cljs | 14 ++++--- src/status_im/profile/core.cljs | 21 ++-------- .../contexts/add_new_contact/events.cljs | 42 +++++++++++++------ .../contexts/add_new_contact/style.cljs | 41 ++++++++++++++++++ .../contexts/add_new_contact/views.cljs | 35 +++++++++++++++- status-go-version.json | 6 +-- translations/en.json | 1 + 7 files changed, 121 insertions(+), 39 deletions(-) diff --git a/src/status_im/integration_test.cljs b/src/status_im/integration_test.cljs index 6aea7460a2..a5dbd934bd 100644 --- a/src/status_im/integration_test.cljs +++ b/src/status_im/integration_test.cljs @@ -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))))))))))) diff --git a/src/status_im/profile/core.cljs b/src/status_im/profile/core.cljs index c58c24d290..27261aea3b 100644 --- a/src/status_im/profile/core.cljs +++ b/src/status_im/profile/core.cljs @@ -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]}))) diff --git a/src/status_im2/contexts/add_new_contact/events.cljs b/src/status_im2/contexts/add_new_contact/events.cljs index b876dca79c..f1afbdbd8f 100644 --- a/src/status_im2/contexts/add_new_contact/events.cljs +++ b/src/status_im2/contexts/add_new_contact/events.cljs @@ -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]} diff --git a/src/status_im2/contexts/add_new_contact/style.cljs b/src/status_im2/contexts/add_new_contact/style.cljs index ac90bfe71b..ed7c8adf7a 100644 --- a/src/status_im2/contexts/add_new_contact/style.cljs +++ b/src/status_im2/contexts/add_new_contact/style.cljs @@ -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 diff --git a/src/status_im2/contexts/add_new_contact/views.cljs b/src/status_im2/contexts/add_new_contact/views.cljs index 88333a040d..a1314f9bd0 100644 --- a/src/status_im2/contexts/add_new_contact/views.cljs +++ b/src/status_im2/contexts/add_new_contact/views.cljs @@ -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) diff --git a/status-go-version.json b/status-go-version.json index 8b5824858d..1327192a37 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.137.2", - "commit-sha1": "4d705ce1b2d16547e823ba0fc731f60a0e887e08", - "src-sha256": "1crblvx8027lk8yykb8hfnaj8a7n2xm4jch0c2grrpwfpcdxi4hg" + "version": "80d350ad5b8366966dd1aafe5622af172d7cce6b", + "commit-sha1": "80d350ad5b8366966dd1aafe5622af172d7cce6b", + "src-sha256": "0dcfrky9rky09fhzsk5krsj2khly6hwgmvilxzczi7vxny70xcha" } diff --git a/translations/en.json b/translations/en.json index c5ca90094e..f786be2e33 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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.",