Skip to content

Commit 9aa96a0

Browse files
[#20150] fix: reviewer's feedback
1 parent d5fa666 commit 9aa96a0

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

src/status_im/common/router.cljs

+8-5
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
[path]
3939
(map #(str % path) status-web-urls))
4040

41-
4241
(def handled-schemes (set (into uri-schemes status-web-urls)))
4342

43+
(defn wc-normalize-uri
44+
[uri]
45+
(if (string/includes? uri "//wc:") (string/replace-first uri "/?" "?") uri))
46+
4447
(def group-chat-extractor
4548
{[#"(.*)" :params] {"" :group-chat
4649
"/" :group-chat}})
@@ -96,16 +99,16 @@
9699
(if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
97100

98101
;;bidi has issue to detect wc regex with /?, couldn't fine any other workaround
99-
normalize-url
100-
(if (string/includes? uri "//wc:") (string/replace-first uri "/?" "?") uri-without-equal-in-path)
102+
normalize-uri
103+
(wc-normalize-uri uri-without-equal-in-path)
101104

102105
;; fragment is the one after `#`, usually user-id, ens-name, community-id
103106
fragment (parse-fragment uri)
104107
ens? (utils.ens/is-valid-eth-name? fragment)
105108
compressed-key? (validators/valid-compressed-key? fragment)
106109

107110
{:keys [handler route-params query-params] :as parsed}
108-
(assoc (bidi/match-route routes normalize-url)
111+
(assoc (bidi/match-route routes normalize-uri)
109112
:uri uri
110113
:query-params (parse-query-params uri))]
111114
(cond-> parsed
@@ -148,7 +151,7 @@
148151
(assoc-in [:route-params :uri]
149152
(if (get query-params "uri")
150153
(get query-params "uri")
151-
(remove-scheme normalize-url))))))
154+
(remove-scheme normalize-uri))))))
152155

153156
(defn match-contact-async
154157
[chain {:keys [user-id ens-name]} callback]

src/status_im/contexts/wallet/wallet_connect/core.cljs

+2-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@
5959
(filter (fn [session]
6060
(= (utils.string/remove-trailing-slash dapp-url)
6161
(utils.string/remove-trailing-slash (get session :url)))))
62-
(first))))
62+
first)))
6363

6464
(defn get-dapp-redirect-url
6565
[session]
66-
(let [peer-metadata (get-in session [:peer :metadata])]
67-
(get-in peer-metadata [:redirect :native])))
66+
(get-in session [:peer :metadata :redirect :native]))
6867

6968
(defn get-db-current-request-params
7069
[db]

src/status_im/contexts/wallet/wallet_connect/events.cljs

+11-7
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,17 @@
317317
(rf/reg-event-fx
318318
:wallet-connect/persist-session
319319
(fn [_ [session-info]]
320-
{:fx [[:json-rpc/call
321-
[{:method "wallet_addWalletConnectSession"
322-
:params [(js/JSON.stringify session-info)]
323-
:on-success (fn []
324-
(log/info "Wallet Connect session persisted")
325-
(rf/dispatch [:wallet-connect/fetch-persisted-sessions]))
326-
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]}))
320+
(let [redirect-url (-> session-info
321+
(js->clj :keywordize-keys true)
322+
(wallet-connect-core/get-dapp-redirect-url))]
323+
{:fx [[:json-rpc/call
324+
[{:method "wallet_addWalletConnectSession"
325+
:params [(js/JSON.stringify session-info)]
326+
:on-success (fn []
327+
(log/info "Wallet Connect session persisted")
328+
(rf/dispatch [:wallet-connect/fetch-persisted-sessions])
329+
(rf/dispatch [:wallet-connect/redirect-to-dapp redirect-url]))
330+
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]})))
327331

328332
(rf/reg-event-fx
329333
:wallet-connect/disconnect-session

src/status_im/contexts/wallet/wallet_connect/responding_events.cljs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns status-im.contexts.wallet.wallet-connect.responding-events
22
(:require [re-frame.core :as rf]
3-
[react-native.platform :as platform]
43
[react-native.wallet-connect :as wallet-connect]
54
[status-im.constants :as constants]
65
[status-im.contexts.wallet.wallet-connect.core :as wallet-connect-core]
@@ -134,18 +133,19 @@
134133
:event :wallet-connect/send-response
135134
:wallet-connect-event event}))
136135
:on-success (fn []
137-
(when platform/android?
138-
(rf/dispatch [:wallet-connect/redirect-to-dapp]))
136+
(rf/dispatch [:wallet-connect/redirect-to-dapp])
139137
(log/info "Successfully sent Wallet Connect response to dApp"))}]]}))))
140138

141139
(rf/reg-event-fx
142140
:wallet-connect/redirect-to-dapp
143-
(fn [{:keys [db]} _]
144-
(let [current-request (get db :wallet-connect/current-request)
145-
sessions (get db :wallet-connect/sessions)
146-
dapp (wallet-connect-core/get-current-request-dapp current-request sessions)
147-
session (transforms/json->clj (dapp :sessionJson))
148-
redirect-url (wallet-connect-core/get-dapp-redirect-url session)]
141+
(fn [{:keys [db]} [url]]
142+
(let [redirect-url (or url
143+
(->> (get db :wallet-connect/current-request)
144+
(wallet-connect-core/get-current-request-dapp
145+
(get db :wallet-connect/sessions))
146+
:sessionJson
147+
transforms/json->clj
148+
wallet-connect-core/get-dapp-redirect-url))]
149149
{:fx [[:open-url redirect-url]]})))
150150

151151
(rf/reg-event-fx

0 commit comments

Comments
 (0)