Skip to content

Commit

Permalink
Last fixes for scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx committed Feb 7, 2024
1 parent cd3b934 commit b13a907
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 73 deletions.
9 changes: 5 additions & 4 deletions src/legacy/status_im/profile/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@
{:db (-> db
(assoc :contacts/identity identity)
(assoc :contacts/ens-name ens-name))
:dispatch [:contacts/build-contact {:pubkey identity
:ens ens-name
:success-fn (fn [_]
{:dispatch [:open-modal :profile]})}]}
:dispatch [:contacts/build-contact
{:pubkey identity
:ens ens-name
:success-fn (fn [_]
{:dispatch [:open-modal :profile]})}]}
{:dispatch [:navigate-to :my-profile]})))
5 changes: 3 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,16 @@
: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 {:input 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
3 changes: 2 additions & 1 deletion src/status_im/common/router.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

(def web-urls (map #(str % web2-domain "/") web-prefixes))

(defn path-urls [path]
(defn path-urls
[path]
(map #(str % path) web-urls))

(def handled-schemes (set (into uri-schemes web-urls)))
Expand Down
57 changes: 28 additions & 29 deletions src/status_im/contexts/chat/home/add_new_contact/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
status-im.contexts.chat.home.add-new-contact.effects
[utils.ens.stateofus :as stateofus]
[utils.ethereum.chain :as chain]
[utils.re-frame :as rf]
[utils.string :as utils.string]))

(defn init-contact
Expand Down Expand Up @@ -99,35 +98,35 @@
init-contact
validate-contact)]
(case state
:empty {:db (dissoc db :contacts/new-identity)}
:empty {:db (dissoc db :contacts/new-identity)}
(:valid :invalid) {:db (assoc db :contacts/new-identity contact)}
:decompress-key {:db (assoc db :contacts/new-identity contact)
:serialization/decompress-public-key
{:compressed-key id
:on-success
#(re-frame/dispatch [:contacts/set-new-identity-success
{:input input
:pubkey %
:build-success-fn build-success-fn}])
:on-error
#(re-frame/dispatch [:contacts/set-new-identity-error
{:input input
:pubkey %
:failure-fn failure-fn}])}}
: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
#(re-frame/dispatch [:contacts/set-new-identity-success
{:input input
:pubkey %
:build-success-fn build-success-fn}])
:on-error
#(re-frame/dispatch [:contacts/set-new-identity-error
{:input input
:pubkey %
:failure-fn failure-fn}])}})))
:decompress-key {:db (assoc db :contacts/new-identity contact)
:serialization/decompress-public-key
{:compressed-key id
:on-success
#(re-frame/dispatch [:contacts/set-new-identity-success
{:input input
:pubkey %
:build-success-fn build-success-fn}])
:on-error
#(re-frame/dispatch [:contacts/set-new-identity-error
{:input input
:pubkey %
:failure-fn failure-fn}])}}
: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
#(re-frame/dispatch [:contacts/set-new-identity-success
{:input input
:pubkey %
:build-success-fn build-success-fn}])
:on-error
#(re-frame/dispatch [:contacts/set-new-identity-error
{:input input
:pubkey %
:failure-fn failure-fn}])}})))

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

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

(defn view
[]
Expand Down
17 changes: 9 additions & 8 deletions src/status_im/contexts/chat/home/add_new_contact/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
paste-on-input #(clipboard/get-string
(fn [clipboard-text]
(reset! input-value clipboard-text)
(rf/dispatch [:contacts/set-new-identity {:input clipboard-text}])))]
(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 Down Expand Up @@ -88,18 +89,18 @@
:on-change-text (fn [new-text]
(reset! input-value new-text)
(as-> [:contacts/set-new-identity {:input new-text}] $
(if (string/blank? scanned)
(debounce/debounce-and-dispatch $ 600)
(rf/dispatch-sync $))))}]
(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 @@ -111,7 +112,7 @@
(defn new-contact
[]
(let [{:keys [public-key ens state msg] :as i} (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 @@ -120,7 +121,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
64 changes: 37 additions & 27 deletions src/status_im/contexts/shell/qr_reader/view.cljs
Original file line number Diff line number Diff line change
@@ -1,70 +1,80 @@
(ns status-im.contexts.shell.qr-reader.view
(:require
[clojure.string :as string]
[re-frame.core :as rf]
[react-native.core :as rn]
[react-native.hooks :as hooks]
[status-im.common.router :as router]
[status-im.common.scan-qr-code.view :as scan-qr-code]
[status-im.common.validators :as validators]
[status-im.contexts.communities.events]
[status-im.contexts.wallet.common.validation :as wallet-validation]
[utils.debounce :as debounce]
[utils.i18n :as i18n]))

(def invalid-qr-toast {:type :negative
:theme :dark
:text (i18n/label :t/invalid-qr)})
(def invalid-qr-toast
{:type :negative
:theme :dark
:text (i18n/label :t/invalid-qr)})

(defn- text-for-path? [text path]
(defn- text-for-url-path?
[text path]
(some #(string/starts-with? text %) (router/path-urls path)))

(defn- extract-id
[scanned-text]
(let [index (string/index-of scanned-text "#")]
(subs scanned-text (inc index))))

(defn legacy-eth-address?
(defn eth-address?
[scanned-text]
(wallet-validation/eth-address? scanned-text))

(defn pairing-qr-code?
[scanned-text]
false)

(defn load-and-show-profile [address]
(defn load-and-show-profile
[address]
(debounce/debounce-and-dispatch
[:contacts/set-new-identity
{:input address
:build-success-fn (fn [{:keys [public-key ens-name]}]
{:dispatch-n [[:chat.ui/show-profile public-key ens-name]
[:contacts/clear-new-identity]]})
:failure-fn (fn []
{:dispatch [:toasts/upsert invalid-qr-toast]})}]
300))

(defn show-invalid-qr-toast []
[:contacts/set-new-identity
{:input address
:build-success-fn (fn [{:keys [public-key ens-name]}]
{:dispatch-n [[:chat.ui/show-profile public-key ens-name]
[:contacts/clear-new-identity]]})
:failure-fn (fn []
{:dispatch [:toasts/upsert invalid-qr-toast]})}]
300))

(defn show-invalid-qr-toast
[]
(debounce/debounce-and-dispatch
[:toasts/upsert invalid-qr-toast] 300))
[:toasts/upsert invalid-qr-toast]
300))

(defn on-qr-code-scanned [scanned-text]
(defn on-qr-code-scanned
[scanned-text]
(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)
(text-for-url-path? scanned-text router/community-with-data-path)
;; TODO(alwx): community link, to be implemented
nil

(text-for-path? scanned-text router/channel-path)
(text-for-url-path? scanned-text router/channel-path)
;; TODO(alwx): channel link, to be implemented
nil

(text-for-path? scanned-text router/user-with-data-path)
(text-for-url-path? scanned-text router/user-with-data-path)
(load-and-show-profile address)

(legacy-eth-address? scanned-text)
;; :wallet/scan-address-success
(or (validators/valid-public-key? scanned-text)
(validators/valid-compressed-key? scanned-text))
(load-and-show-profile scanned-text)

(eth-address? scanned-text)
(debounce/debounce-and-dispatch [:navigate-to :wallet-accounts address] 300)

(pairing-qr-code? scanned-text)
;; :syncing/input-connection-string-for-bootstrapping
;; TODO(alwx): pairing link, to be implemented
nil

:else
Expand All @@ -82,4 +92,4 @@

(defn view
[]
[:f> f-internal-view])
[:f> f-internal-view])
2 changes: 1 addition & 1 deletion src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
[status-im.contexts.profile.settings.view :as settings]
[status-im.contexts.shell.activity-center.view :as activity-center]
[status-im.contexts.shell.jump-to.view :as shell]
[status-im.contexts.shell.share.view :as share]
[status-im.contexts.shell.qr-reader.view :as shell-qr-reader]
[status-im.contexts.shell.share.view :as share]
[status-im.contexts.syncing.find-sync-code.view :as find-sync-code]
[status-im.contexts.syncing.how-to-pair.view :as how-to-pair]
[status-im.contexts.syncing.scan-sync-code-page.view :as scan-sync-code-page]
Expand Down

0 comments on commit b13a907

Please sign in to comment.