Skip to content

Commit

Permalink
Scan profile path
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx committed Feb 7, 2024
1 parent 1ef4692 commit aa90878
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 42 deletions.
5 changes: 4 additions & 1 deletion src/legacy/status_im/profile/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@
{:db (-> db
(assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name))
:dispatch [:contacts/build-contact identity ens-name true]}
:dispatch [:contacts/build-contact {:pubkey identity
:ens ens-name
:success-fn (fn [contact]
{:dispatch [:open-modal :profile]})}]}
{:dispatch [:navigate-to :my-profile]})))
4 changes: 2 additions & 2 deletions src/legacy/status_im/ui/screens/wallet/recipient/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
:on-change (fn [text]
(re-frame/dispatch [:wallet-legacy/search-recipient-filter-changed text])
(re-frame/dispatch [:set-in [:contacts/new-identity :state] :searching])
(debounce/debounce-and-dispatch [:contacts/set-new-identity text] 300))}]]))
(debounce/debounce-and-dispatch [:contacts/set-new-identity {:input text}] 300))}]]))

(defn section
[_ _ _]
(let [opened? (reagent/atom false)]
(fn [title cnt content]
[react/view {:padding-vertical 8}
[list.item/list-item
{:title title
{:title title
:on-press #(swap! opened? not)
:accessory
[react/view {:flex-direction :row :align-items :center}
Expand Down
47 changes: 23 additions & 24 deletions src/status_im/contexts/chat/home/add_new_contact/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@

(def validate-contact (comp ->state ->type ->id))

(defn dispatcher [event input] (fn [arg] (rf/dispatch [event input arg])))

(defn set-new-identity
[{:keys [db]} [input]]
[{:keys [db]} [{:keys [input build-success-fn]}]]
(let [user-public-key (get-in db [:profile/profile :public-key])
{:keys [input id ens state]
:as contact} (-> {:user-public-key user-public-key
Expand All @@ -105,48 +103,49 @@
:serialization/decompress-public-key
{:compressed-key id
:on-success
(dispatcher :contacts/set-new-identity-success input)
#(rf/dispatch [:contacts/set-new-identity-success input % build-success-fn])
:on-error
(dispatcher :contacts/set-new-identity-error input)}}
#(rf/dispatch [:contacts/set-new-identity-error input %])}}
:resolve-ens {:db (assoc db :contacts/new-identity contact)
:effects.contacts/resolve-public-key-from-ens
{:chain-id (chain/chain-id db)
:ens ens
:on-success
(dispatcher :contacts/set-new-identity-success input)
#(rf/dispatch [:contacts/set-new-identity-success input % build-success-fn])
:on-error
(dispatcher :contacts/set-new-identity-error input)}})))
#(rf/dispatch [:contacts/set-new-identity-error input %])}})))

(re-frame/reg-event-fx :contacts/set-new-identity set-new-identity)

(rf/defn build-contact
{:events [:contacts/build-contact]}
[_ pubkey ens open-profile-modal?]
[_ {:keys [pubkey ens success-fn]}]
(js/console.log "ALWX ens" ens)
{:json-rpc/call [{:method "wakuext_buildContact"
:params [{:publicKey pubkey
:ENSName ens}]
: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]
:on-success #(rf/dispatch [:contacts/build-contact-success
{:pubkey pubkey
:contact (data-store.contacts/<-rpc-js %)
:success-fn success-fn}])}]})

(rf/defn build-contact-success
{:events [:contacts/build-contact-success]}
[{:keys [db]} {:keys [pubkey contact success-fn]}]
(merge {:db (assoc-in db [:contacts/contacts pubkey] contact)}
(when open-profile-modal?
{:dispatch [:open-modal :profile]})))
(when success-fn
(success-fn contact))))

(rf/defn set-new-identity-success
{:events [:contacts/set-new-identity-success]}
[{:keys [db]} input pubkey]
[{:keys [db]} input pubkey build-success-fn]
(let [contact (get-in db [:contacts/new-identity])]
(when (= (:input contact) input)
(rf/merge {:db (assoc db
:contacts/new-identity
(->state (assoc contact :public-key pubkey)))}
(build-contact pubkey (:ens contact) false)))))
(rf/merge {:db (assoc db :contacts/new-identity (->state (assoc contact :public-key pubkey)))}
(build-contact {:pubkey pubkey
:ens (:ens contact)
:success-fn build-success-fn})))))

(rf/defn set-new-identity-error
{:events [:contacts/set-new-identity-error]}
Expand All @@ -171,4 +170,4 @@
(rf/defn set-new-identity-reconnected
[{:keys [db]}]
(let [input (get-in db [:contacts/new-identity :input])]
(rf/dispatch [:contacts/set-new-identity input])))
(rf/dispatch [:contacts/set-new-identity {:input input}])))
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

(deftest set-new-identity-test
(with-redefs [events/dispatcher (fn [& args] args)]
(are [i edb] (match? (events/set-new-identity {:db db} i nil) edb)
(are [i edb] (match? (events/set-new-identity {:db db} [{:input i}]) edb)

"" {:db db}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
(rn/dismiss-keyboard!))
[scan-qr-code/view
{:title (i18n/label :t/scan-qr)
:on-success-scan #(debounce/debounce-and-dispatch [:contacts/set-new-identity % %] 300)}]]))
:on-success-scan #(debounce/debounce-and-dispatch [:contacts/set-new-identity {:input %}] 300)}]]))

(defn view
[]
Expand Down
19 changes: 10 additions & 9 deletions src/status_im/contexts/chat/home/add_new_contact/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
[quo/text (style/text-title) (i18n/label :t/add-a-contact)]
[quo/text (style/text-subtitle) (i18n/label :t/find-your-friends)]])

;; TODO(alwx): check why it is not filled
(defn- search-input
[]
(reagent/with-let [input-value (reagent/atom nil)
Expand All @@ -59,7 +60,7 @@
paste-on-input #(clipboard/get-string
(fn [clipboard-text]
(reset! input-value clipboard-text)
(rf/dispatch [:contacts/set-new-identity clipboard-text nil])))]
(rf/dispatch [:contacts/set-new-identity {:input clipboard-text}])))]
(let [{:keys [scanned]} (rf/sub [:contacts/new-identity])
empty-input? (and (string/blank? @input-value)
(string/blank? scanned))]
Expand All @@ -86,19 +87,19 @@
:value (or scanned @input-value)
:on-change-text (fn [new-text]
(reset! input-value new-text)
(as-> [:contacts/set-new-identity new-text nil] $
(if (string/blank? scanned)
(debounce/debounce-and-dispatch $ 600)
(rf/dispatch-sync $))))}]
(as-> [:contacts/set-new-identity {:input new-text}] $
(if (string/blank? scanned)
(debounce/debounce-and-dispatch $ 600)
(rf/dispatch-sync $))))}]
[rn/view {:style style/scan-button-container}
[quo/button
{:type :outline
:icon-only? true
:size 40
:on-press #(rf/dispatch [:open-modal :scan-profile-qr-code])}
:i/scan]]])
(finally
(rf/dispatch [:contacts/clear-new-identity]))))
(finally
(rf/dispatch [:contacts/clear-new-identity]))))

(defn- invalid-text
[message]
Expand All @@ -110,7 +111,7 @@
(defn new-contact
[]
(let [{:keys [public-key ens state msg]} (rf/sub [:contacts/new-identity])
customization-color (rf/sub [:profile/customization-color])]
customization-color (rf/sub [:profile/customization-color])]
[rn/keyboard-avoiding-view {:style {:flex 1}}
[rn/touchable-without-feedback {:on-press rn/dismiss-keyboard!}
[rn/view {:style (style/container-outer)}
Expand All @@ -119,7 +120,7 @@
[search-input]
(case state
:invalid [invalid-text msg]
:valid [found-contact public-key]
:valid [found-contact public-key]
nil)]
[quo/button
{:type :primary
Expand Down
7 changes: 5 additions & 2 deletions src/status_im/contexts/shell/qr_reader/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
(let [address (extract-id scanned-text)]
(cond
(text-for-path? scanned-text router/community-with-data-path)
(debounce/debounce-and-dispatch [:communities/navigate-to-community-overview address] 300)
nil
;;(debounce/debounce-and-dispatch [:communities/navigate-to-community-overview address] 300)

(text-for-path? scanned-text router/channel-path)
nil

(text-for-path? scanned-text router/user-with-data-path)
(debounce/debounce-and-dispatch [:contacts/set-new-identity address] 300)
(debounce/debounce-and-dispatch [:contacts/set-new-identity {:input address
:build-success-fn (fn [{:keys [public-key ens-name] :as contact}]
{:dispatch-n [[:chat.ui/show-profile public-key ens-name]]})}] 300)

(legacy-eth-address? scanned-text)
;; :wallet/scan-address-success
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/integration_test/chat_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
(h/with-app-initialized
(h/with-account
;; search for contact using compressed key
(rf/dispatch [:contacts/set-new-identity compressed-key])
(rf/dispatch [:contacts/set-new-identity {:input compressed-key}])
(rf-test/wait-for
[:contacts/set-new-identity-success]
(let [new-identity @(rf/subscribe [:contacts/new-identity])]
Expand All @@ -89,7 +89,7 @@
(rf-test/wait-for
[:contacts/build-contact]
(rf-test/wait-for
[:contacts/contact-built]
[:contacts/build-contact-success]
(let [contact @(rf/subscribe [:contacts/current-contact])]
(is (= primary-name (:primary-name contact))))
(h/logout)
Expand Down

0 comments on commit aa90878

Please sign in to comment.