Skip to content

Commit

Permalink
🧰 Fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shivekkhurana committed Jun 3, 2024
1 parent b3403a5 commit 70f399f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 68 deletions.
32 changes: 3 additions & 29 deletions src/status_im/contexts/shell/qr_reader/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
[_]
false)

(defn wallet-connect-code?
[scanned-text]
(string/starts-with? scanned-text "wc:"))

(defn url?
[scanned-text]
(url/url? scanned-text))
Expand All @@ -71,31 +67,9 @@

(defn- handle-wallet-connect
[scanned-text]
(let [parsed-uri (wallet-connect/parse-uri scanned-text)
version (-> parsed-uri :version)
expired? (wc-utils/timestamp-expired? (-> parsed-uri :expiryTimestamp))
version-supported? (wc-utils/version-supported? version)]

(cond
expired?
(debounce/debounce-and-dispatch
[:toasts/upsert
{:type :negative
:theme :dark
:text (i18n/label :t/wallet-connect-qr-expired)}]
300)

(not version-supported?)
(debounce/debounce-and-dispatch
[:toasts/upsert
{:type :negative
:theme :dark
:text (i18n/label :t/wallet-connect-version-not-supported
{:version version})}]
300)

:else
(debounce/debounce-and-dispatch [:wallet-connect/pair scanned-text] 300))))
(debounce/debounce-and-dispatch
[:wallet-connect/potential-connection-uri-scanned scanned-text]
300))

(defn on-qr-code-scanned
[scanned-text]
Expand Down
22 changes: 10 additions & 12 deletions src/status_im/contexts/wallet/common/scan_account/view.cljs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(ns status-im.contexts.wallet.common.scan-account.view
(:require
[clojure.string :as string]
[status-im.common.scan-qr-code.view :as scan-qr-code]
[status-im.constants :as constants]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[clojure.string :as string]
[status-im.common.scan-qr-code.view :as scan-qr-code]
[status-im.constants :as constants]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(def ^:private supported-networks #{:eth :arb1 :oeth})

Expand All @@ -30,12 +30,10 @@
{:title (i18n/label :t/scan-qr)
:subtitle (i18n/label :t/scan-an-account-qr-code)
:error-message (i18n/label :t/oops-this-qr-does-not-contain-an-address)
:validate-fn (fn [scanned-text]
(contains-supported-address? scanned-text))
:validate-fn #(contains-supported-address? %)
:on-success-scan (fn [result]
(let [address (extract-address result)]
(when on-result (on-result address))
(when address
(debounce/debounce-and-dispatch
[:wallet/scan-address-success address]
300))))}]))
(debounce/debounce-and-dispatch
[:wallet/scan-address-success address]
300)))}]))
40 changes: 36 additions & 4 deletions src/status_im/contexts/wallet/wallet_connect/events.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(ns status-im.contexts.wallet.wallet-connect.events
(:require [re-frame.core :as rf]
[react-native.wallet-connect :as wallet-connect]
[status-im.constants :as constants]
status-im.contexts.wallet.wallet-connect.effects
[taoensso.timbre :as log]))
[status-im.contexts.wallet.wallet-connect.utils :as wc-utils]
[taoensso.timbre :as log]
[utils.i18n :as i18n]))

(rf/reg-event-fx
:wallet-connect/init
Expand Down Expand Up @@ -36,9 +39,9 @@
(rf/reg-event-fx
:wallet-connect/on-session-proposal
(fn [{:keys [db]} [proposal]]
{:db (assoc db :wallet-connect/current-proposal proposal)
:open-modal-fx [:screen/wallet.wallet-connect-session-proposal
(:theme db)]}))
{:db (assoc db :wallet-connect/current-proposal proposal)
:fx [[:dispatch
[:open-modal :screen/wallet.wallet-connect-session-proposal]]]}))

(rf/reg-event-fx
:wallet-connect/reset-current-session
Expand Down Expand Up @@ -89,3 +92,32 @@
{:error error
:event :wallet-connect/approve-session})
(rf/dispatch [:wallet-connect/reset-current-session]))}]]})))

(rf/reg-event-fx
:wallet-connect/potential-connection-uri-scanned
(fn [_ [scanned-text]]
(let [parsed-uri (wallet-connect/parse-uri scanned-text)
version (:version parsed-uri)
expired? (-> parsed-uri
:expiryTimestamp
wc-utils/timestamp-expired?)
version-supported? (wc-utils/version-supported? version)]
(cond
expired?
{:fx [[:dispatch
[:toasts/upsert
{:type :negative
:theme :dark
:text (i18n/label :t/wallet-connect-qr-expired)}]]]}

(not version-supported?)
{:fx [[:dispatch
[:toasts/upsert
{:type :negative
:theme :dark
:text (i18n/label :t/wallet-connect-version-not-supported
{:version version})}]]]}

:else
{:fx [[:dispatch [:wallet-connect/pair scanned-text]]
[:dispatch [:dismiss-modal :screen/wallet.wallet-connect-session-proposal]]]}))))
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
(ns status-im.contexts.wallet.wallet-connect.session-proposal.style
(:require [quo.foundations.colors :as colors]))

(def container
{})

(def dapp-avatar
{:padding-horizontal 20
:padding-top 12})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
(ns status-im.contexts.wallet.wallet-connect.session-proposal.view
(:require
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme]
[react-native.core :as rn]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.contexts.wallet.wallet-connect.session-proposal.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme]
[react-native.core :as rn]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.contexts.wallet.wallet-connect.session-proposal.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn- dapp-metadata
[]
(let [proposer (rf/sub [:wallet-connect/session-proposer])
metadata (-> proposer :metadata)
icon (-> metadata :icons first)
dapp-name (-> metadata :name)
url (-> metadata :url)]
(let [proposer (rf/sub [:wallet-connect/session-proposer])
{:keys [icons name url]} (:metadata proposer)]
[:<>
[rn/view {:style style/dapp-avatar}
[quo/user-avatar
{:profile-picture icon
{:profile-picture (first icons)
:size :big}]]
[quo/page-top
{:title dapp-name
{:title name
:description :context-tag
:context-tag {:type :icon
:size 32
Expand All @@ -35,7 +32,7 @@
labels [(i18n/label :t/check-your-account-balance-and-activity)
(i18n/label :t/request-txns-and-message-signing)]]
[rn/view {:style style/approval-note-container}
[rn/text {:style style/approval-note-title}
[quo/text {:style style/approval-note-title}
(i18n/label :t/dapp-will-be-able-to {:dapp-name dapp-name})]
(map-indexed
(fn [idx label]
Expand All @@ -44,7 +41,7 @@
[quo/icon :i/bullet
{:color colors/neutral-50}]
[rn/view {:style style/approval-li-spacer}]
[rn/text label]])
[quo/text label]])
labels)]))

(defn- accounts-data-item
Expand Down Expand Up @@ -116,7 +113,6 @@
:header [header]
:footer [footer]}
[rn/view
{:style style/container}
[dapp-metadata]
[accounts-data-item]
[networks-data-item]
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/contexts/wallet/wallet_connect/utils.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns status-im.contexts.wallet.wallet-connect.utils
(:require [react-native.wallet-connect :refer [parse-uri]]))
(:require [react-native.wallet-connect :as wallet-connect]))

(defn version-supported?
[version]
Expand All @@ -25,5 +25,5 @@
At this stage, the uri might be expired or from an unsupported version"
[s]
(-> s
parse-uri
wallet-connect/parse-uri
valid-wc-uri?))

0 comments on commit 70f399f

Please sign in to comment.