Handle links in profile qr code scanner
Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
This commit is contained in:
parent
46ebda8eeb
commit
39cc56dd10
|
@ -1,6 +1,5 @@
|
||||||
(ns status-im.events
|
(ns status-im.events
|
||||||
(:require [clojure.string :as string]
|
(:require [re-frame.core :as re-frame]
|
||||||
[re-frame.core :as re-frame]
|
|
||||||
[status-im.bootnodes.core :as bootnodes]
|
[status-im.bootnodes.core :as bootnodes]
|
||||||
[status-im.browser.core :as browser]
|
[status-im.browser.core :as browser]
|
||||||
[status-im.browser.permissions :as browser.permissions]
|
[status-im.browser.permissions :as browser.permissions]
|
||||||
|
@ -13,7 +12,6 @@
|
||||||
[status-im.contact.core :as contact]
|
[status-im.contact.core :as contact]
|
||||||
[status-im.data-store.chats :as data-store.chats]
|
[status-im.data-store.chats :as data-store.chats]
|
||||||
[status-im.data-store.messages :as data-store.messages]
|
[status-im.data-store.messages :as data-store.messages]
|
||||||
[status-im.ethereum.core :as ethereum]
|
|
||||||
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
|
[status-im.ethereum.subscriptions :as ethereum.subscriptions]
|
||||||
[status-im.fleet.core :as fleet]
|
[status-im.fleet.core :as fleet]
|
||||||
[status-im.group-chats.core :as group-chats]
|
[status-im.group-chats.core :as group-chats]
|
||||||
|
@ -36,7 +34,6 @@
|
||||||
[status-im.transport.message.core :as transport.message]
|
[status-im.transport.message.core :as transport.message]
|
||||||
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]
|
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]
|
||||||
[status-im.ui.components.react :as react]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.ui.screens.add-new.new-chat.db :as new-chat.db]
|
|
||||||
[status-im.ui.screens.currency-settings.models
|
[status-im.ui.screens.currency-settings.models
|
||||||
:as
|
:as
|
||||||
currency-settings.models]
|
currency-settings.models]
|
||||||
|
@ -845,35 +842,6 @@
|
||||||
(fn [cofx [_ public-key]]
|
(fn [cofx [_ public-key]]
|
||||||
(contact.block/unblock-contact cofx public-key)))
|
(contact.block/unblock-contact cofx public-key)))
|
||||||
|
|
||||||
(defn get-validation-label [value]
|
|
||||||
(case value
|
|
||||||
:invalid
|
|
||||||
(i18n/label :t/use-valid-contact-code)
|
|
||||||
:yourself
|
|
||||||
(i18n/label :t/can-not-add-yourself)))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
|
||||||
:contact/qr-code-scanned
|
|
||||||
[(re-frame/inject-cofx :random-id-generator)]
|
|
||||||
(fn [{:keys [db] :as cofx} [_ contact-identity _]]
|
|
||||||
(let [public-key? (and (string? contact-identity)
|
|
||||||
(string/starts-with? contact-identity "0x"))
|
|
||||||
validation-result (new-chat.db/validate-pub-key db contact-identity)]
|
|
||||||
(cond
|
|
||||||
(and public-key? (not (some? validation-result)))
|
|
||||||
(chat/start-chat cofx contact-identity {:navigation-reset? true})
|
|
||||||
|
|
||||||
(and (not public-key?) (string? contact-identity))
|
|
||||||
(let [chain (ethereum/chain-keyword db)]
|
|
||||||
{:resolve-public-key {:chain chain
|
|
||||||
:contact-identity contact-identity
|
|
||||||
:cb #(re-frame/dispatch [:contact/qr-code-scanned %])}})
|
|
||||||
|
|
||||||
:else
|
|
||||||
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
|
|
||||||
:content (get-validation-label validation-result)
|
|
||||||
:on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}}))))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:contact.ui/start-group-chat-pressed
|
:contact.ui/start-group-chat-pressed
|
||||||
(fn [cofx _]
|
(fn [cofx _]
|
||||||
|
|
|
@ -54,11 +54,6 @@
|
||||||
[_ config]
|
[_ config]
|
||||||
{::navigate-reset config})
|
{::navigate-reset config})
|
||||||
|
|
||||||
(fx/defn navigate-to-clean
|
|
||||||
{:events [:navigate-to-clean]}
|
|
||||||
[cofx [_ view-id params]]
|
|
||||||
(navigate-to-cofx cofx view-id params))
|
|
||||||
|
|
||||||
(fx/defn navigate-replace
|
(fx/defn navigate-replace
|
||||||
{:events [:navigate-replace]}
|
{:events [:navigate-replace]}
|
||||||
[{:keys [db]} go-to-view-id screen-params]
|
[{:keys [db]} go-to-view-id screen-params]
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
|
[status-im.utils.universal-links.core :as ul]
|
||||||
[status-im.ethereum.ens :as ens]
|
[status-im.ethereum.ens :as ens]
|
||||||
[status-im.ethereum.resolver :as resolver]
|
[status-im.ethereum.resolver :as resolver]
|
||||||
[status-im.ui.screens.add-new.new-chat.db :as db]
|
[status-im.ui.screens.add-new.new-chat.db :as db]
|
||||||
[status-im.utils.handlers :as handlers]
|
[status-im.utils.handlers :as handlers]
|
||||||
[status-im.ethereum.stateofus :as stateofus]
|
[status-im.ethereum.stateofus :as stateofus]
|
||||||
[status-im.utils.random :as random]
|
[status-im.utils.random :as random]
|
||||||
[status-im.utils.utils :as utils]))
|
[status-im.utils.utils :as utils]
|
||||||
|
[status-im.utils.fx :as fx]
|
||||||
|
[status-im.chat.models :as chat]
|
||||||
|
[status-im.i18n :as i18n]))
|
||||||
|
|
||||||
(defn- ens-name-parse [contact-identity]
|
(defn- ens-name-parse [contact-identity]
|
||||||
(when (string? contact-identity)
|
(when (string? contact-identity)
|
||||||
|
@ -65,3 +69,34 @@
|
||||||
::new-chat-focus
|
::new-chat-focus
|
||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
{:db (dissoc db :contacts/new-identity)}))
|
{:db (dissoc db :contacts/new-identity)}))
|
||||||
|
|
||||||
|
(defn- get-validation-label [value]
|
||||||
|
(case value
|
||||||
|
:invalid
|
||||||
|
(i18n/label :t/use-valid-contact-code)
|
||||||
|
:yourself
|
||||||
|
(i18n/label :t/can-not-add-yourself)))
|
||||||
|
|
||||||
|
(fx/defn qr-code-scanned
|
||||||
|
{:events [:contact/qr-code-scanned]}
|
||||||
|
[{:keys [db] :as cofx} contact-identity]
|
||||||
|
(let [public-key? (and (string? contact-identity)
|
||||||
|
(string/starts-with? contact-identity "0x"))
|
||||||
|
validation-result (db/validate-pub-key db contact-identity)]
|
||||||
|
(cond
|
||||||
|
(and public-key? (not (some? validation-result)))
|
||||||
|
(chat/start-chat cofx contact-identity {:navigation-reset? true})
|
||||||
|
|
||||||
|
(and (string? contact-identity) (ul/match-url contact-identity ul/profile-regex))
|
||||||
|
(qr-code-scanned cofx (ul/match-url contact-identity ul/profile-regex))
|
||||||
|
|
||||||
|
(and (not public-key?) (string? contact-identity))
|
||||||
|
(let [chain (ethereum/chain-keyword db)]
|
||||||
|
{:resolve-public-key {:chain chain
|
||||||
|
:contact-identity contact-identity
|
||||||
|
:cb #(re-frame/dispatch [:contact/qr-code-scanned %])}})
|
||||||
|
|
||||||
|
:else
|
||||||
|
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
|
||||||
|
:content (get-validation-label validation-result)
|
||||||
|
:on-dismiss #(re-frame/dispatch [:navigate-to :home])}})))
|
||||||
|
|
Loading…
Reference in New Issue