A pack of bugfixes for the user story "Connect to dApps" (#20711)

This commit is contained in:
Alexander 2024-07-18 14:57:53 +02:00 committed by GitHub
parent 2b0847ef76
commit 9f84a7b912
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 247 additions and 157 deletions

View File

@ -21,12 +21,14 @@
(colors/theme-colors colors/white colors/neutral-95 theme))}) (colors/theme-colors colors/white colors/neutral-95 theme))})
(defn buttons-container (defn buttons-container
[actions] [actions container-style]
{:flex-direction (if (= actions :two-vertical-actions) :column :row) (merge
:justify-content :space-around {:flex-direction (if (= actions :two-vertical-actions) :column :row)
:padding-vertical 12 :justify-content :space-around
:gap 12 :padding-vertical 12
:padding-horizontal 20}) :gap 12
:padding-horizontal 20}
container-style))
(def description-top (def description-top
{:flex-direction :row {:flex-direction :row

View File

@ -30,7 +30,8 @@
[:button-two-props {:optional true} [:maybe :map]] [:button-two-props {:optional true} [:maybe :map]]
[:scroll? {:optional true} [:maybe :boolean]] [:scroll? {:optional true} [:maybe :boolean]]
[:blur? {:optional true} [:maybe :boolean]] [:blur? {:optional true} [:maybe :boolean]]
[:container-style {:optional true} [:maybe :map]]]]] [:container-style {:optional true} [:maybe :map]]
[:buttons-container-style {:optional true} [:maybe :map]]]]]
:any]) :any])
(def ^:private role-icon (def ^:private role-icon
@ -42,7 +43,7 @@
(defn- view-internal (defn- view-internal
[{:keys [actions description description-text description-top-text error-message role button-one-label [{:keys [actions description description-text description-top-text error-message role button-one-label
button-two-label blur? button-one-props button-two-props scroll? container-style button-two-label blur? button-one-props button-two-props scroll? container-style
context-tag-props]}] buttons-container-style context-tag-props]}]
(let [theme (quo.theme/use-theme)] (let [theme (quo.theme/use-theme)]
[rn/view [rn/view
{:style (merge (style/container scroll? blur? theme) container-style)} {:style (merge (style/container scroll? blur? theme) container-style)}
@ -72,7 +73,7 @@
:context (i18n/label (keyword "t" role))} :context (i18n/label (keyword "t" role))}
context-tag-props)]]) context-tag-props)]])
[rn/view {:style (style/buttons-container actions)} [rn/view {:style (style/buttons-container actions buttons-container-style)}
(when (or (= actions :two-actions) (when (or (= actions :two-actions)
(= actions :two-vertical-actions)) (= actions :two-vertical-actions))
[button/button [button/button

View File

@ -287,6 +287,7 @@
(def ^:const wallet-connect-supported-events #{"accountsChanged" "chainChanged"}) (def ^:const wallet-connect-supported-events #{"accountsChanged" "chainChanged"})
(def ^:const wallet-connect-session-proposal-event "session_proposal") (def ^:const wallet-connect-session-proposal-event "session_proposal")
(def ^:const wallet-connect-session-request-event "session_request") (def ^:const wallet-connect-session-request-event "session_request")
(def ^:const wallet-connect-session-delete-event "session_delete")
(def ^:const wallet-connect-user-rejected-error-key "USER_REJECTED") (def ^:const wallet-connect-user-rejected-error-key "USER_REJECTED")
(def ^:const transaction-pending-type-wallet-connect-transfer "WalletConnectTransfer") (def ^:const transaction-pending-type-wallet-connect-transfer "WalletConnectTransfer")

View File

@ -117,13 +117,14 @@
(defn- f-internal-view (defn- f-internal-view
[] []
(let [{:keys [keyboard-shown]} (hooks/use-keyboard)] (let [{:keys [keyboard-shown]} (hooks/use-keyboard)]
[:<> (rn/use-mount
(when keyboard-shown (fn []
(rn/dismiss-keyboard!)) (when keyboard-shown
[scan-qr-code/view (rn/dismiss-keyboard!))))
{:title (i18n/label :t/scan-qr) [scan-qr-code/view
:share-button? true {:title (i18n/label :t/scan-qr)
:on-success-scan on-qr-code-scanned}]])) :share-button? true
:on-success-scan on-qr-code-scanned}]))
(defn view (defn view
[] []

View File

@ -13,26 +13,26 @@
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn- on-disconnect (defn- on-disconnect
[wallet-account {:keys [name topic]}] [wallet-account {:keys [name topic pairing-topic]}]
(rf/dispatch [:hide-bottom-sheet]) (rf/dispatch [:hide-bottom-sheet])
(rf/dispatch (rf/dispatch
[:wallet-connect/disconnect-dapp [:wallet-connect/disconnect-dapp
{:topic topic {:topic topic
:on-success (fn [] :pairing-topic pairing-topic
(rf/dispatch [:wallet-connect/remove-pairing-by-topic topic]) :on-success (fn []
(rf/dispatch [:toasts/upsert (rf/dispatch [:toasts/upsert
{:id :dapp-disconnect-success {:id :dapp-disconnect-success
:type :positive :type :positive
:text (i18n/label :t/disconnect-dapp-success :text (i18n/label :t/disconnect-dapp-success
{:dapp name {:dapp name
:account (:name wallet-account)})}])) :account (:name wallet-account)})}]))
:on-fail (fn [] :on-fail (fn []
(rf/dispatch [:toasts/upsert (rf/dispatch [:toasts/upsert
{:id :dapp-disconnect-failure {:id :dapp-disconnect-failure
:type :negative :type :negative
:text (i18n/label :t/disconnect-dapp-fail :text (i18n/label :t/disconnect-dapp-fail
{:dapp name {:dapp name
:account (:name wallet-account)})}]))}])) :account (:name wallet-account)})}]))}]))
(defn- on-dapp-disconnect-press (defn- on-dapp-disconnect-press
[wallet-account dapp] [wallet-account dapp]
@ -83,7 +83,8 @@
[] []
(let [{:keys [bottom]} (safe-area/get-insets) (let [{:keys [bottom]} (safe-area/get-insets)
{:keys [color] :as wallet-account} (rf/sub [:wallet/current-viewing-account]) {:keys [color] :as wallet-account} (rf/sub [:wallet/current-viewing-account])
pairings (rf/sub [:wallet-connect/pairings]) sessions (rf/sub
[:wallet-connect/sessions-for-current-account])
theme (quo.theme/use-theme)] theme (quo.theme/use-theme)]
[rn/view {:flex 1} [rn/view {:flex 1}
[header [header
@ -91,7 +92,7 @@
:wallet-account wallet-account :wallet-account wallet-account
:on-close #(rf/dispatch [:navigate-back]) :on-close #(rf/dispatch [:navigate-back])
:on-add #(rf/dispatch [:navigate-to :screen/wallet.scan-dapp])}] :on-add #(rf/dispatch [:navigate-to :screen/wallet.scan-dapp])}]
(if (empty? pairings) (if (empty? sessions)
[quo/empty-state [quo/empty-state
{:title (i18n/label :t/no-dapps) {:title (i18n/label :t/no-dapps)
:description (i18n/label :t/no-dapps-description) :description (i18n/label :t/no-dapps-description)
@ -99,16 +100,16 @@
:container-style style/empty-container-style}] :container-style style/empty-container-style}]
[rn/view (style/dapps-container bottom) [rn/view (style/dapps-container bottom)
[rn/flat-list [rn/flat-list
{:data pairings {:data sessions
:always-bounce-vertical false :always-bounce-vertical false
:content-container-style (style/dapps-list theme) :content-container-style (style/dapps-list theme)
:render-fn (fn [{:keys [topic] :render-fn (fn [{:keys [topic pairingTopic name url iconUrl]}]
{:keys [icons name url]} :peerMetadata}]
[quo/dapp [quo/dapp
{:dapp {:avatar (get icons 0) {:dapp {:avatar iconUrl
:name name :name name
:value url :value url
:topic topic} :topic topic
:pairing-topic pairingTopic}
:accessibility-label (str "dapp-" topic) :accessibility-label (str "dapp-" topic)
:state :default :state :default
:action :icon :action :icon

View File

@ -85,12 +85,34 @@
(defn required-networks-supported? (defn required-networks-supported?
[proposal supported-networks] [proposal supported-networks]
(let [required-networks (get-in proposal [:params :requiredNamespaces :eip155 :chains]) (let [supported-namespaces #{:eip155}
supported-eip155 (set (map chain-id->eip155 supported-networks))] required-namespaces (get-in proposal [:params :requiredNamespaces])]
(every? #(contains? supported-eip155 %) required-networks))) (when (every? #(contains? supported-namespaces %)
(keys required-namespaces))
(let [required-networks (get-in required-namespaces [:eip155 :chains])
supported-eip155 (set (map chain-id->eip155 supported-networks))]
(every? #(contains? supported-eip155 %)
required-networks)))))
(defn get-networks-by-mode (defn get-networks-by-mode
[db] [db]
(let [test-mode? (get-in db [:profile/profile :test-networks-enabled?]) (let [test-mode? (get-in db [:profile/profile :test-networks-enabled?])
networks (get-in db [:wallet :networks (if test-mode? :test :prod)])] networks (get-in db [:wallet :networks (if test-mode? :test :prod)])]
(mapv #(-> % :chain-id) networks))) (mapv #(-> % :chain-id) networks)))
(defn event-should-be-handled?
[db {:keys [topic]}]
(some #(= topic %)
(map :topic (:wallet-connect/sessions db))))
(defn sdk-session->db-session
[{:keys [topic expiry pairingTopic] :as session}]
{:topic topic
:expiry expiry
:sessionJson (transforms/clj->json session)
:pairingTopic pairingTopic
:name (get-in session [:peer :metadata :name])
:iconUrl (get-in session [:peer :metadata :icons 0])
:url (get-in session [:peer :metadata :url])
:accounts (get-in session [:namespaces :eip155 :accounts])
:disconnected false})

View File

@ -31,13 +31,6 @@
:event wc-event :event wc-event
:handler handler}))) :handler handler})))
(rf/reg-fx
:effects.wallet-connect/fetch-pairings
(fn [{:keys [web3-wallet on-success on-fail]}]
(-> (wallet-connect/get-pairings web3-wallet)
(promesa/then on-success)
(promesa/catch on-fail))))
(rf/reg-fx (rf/reg-fx
:effects.wallet-connect/pair :effects.wallet-connect/pair
(fn [{:keys [web3-wallet url on-success on-fail]}] (fn [{:keys [web3-wallet url on-success on-fail]}]
@ -53,13 +46,6 @@
(promesa/then on-success) (promesa/then on-success)
(promesa/catch on-fail)))) (promesa/catch on-fail))))
(rf/reg-fx
:effects.wallet-connect/fetch-active-sessions
(fn [{:keys [web3-wallet on-success on-fail]}]
(-> (wallet-connect/get-active-sessions web3-wallet)
(promesa/then on-success)
(promesa/catch on-fail))))
(rf/reg-fx (rf/reg-fx
:effects.wallet-connect/approve-session :effects.wallet-connect/approve-session
(fn [{:keys [web3-wallet proposal supported-namespaces on-success on-fail]}] (fn [{:keys [web3-wallet proposal supported-namespaces on-success on-fail]}]
@ -74,6 +60,13 @@
(promesa/then on-success) (promesa/then on-success)
(promesa/catch on-fail))))) (promesa/catch on-fail)))))
(rf/reg-fx
:effects.wallet-connect/fetch-active-sessions
(fn [{:keys [web3-wallet on-success on-fail]}]
(-> (wallet-connect/get-active-sessions web3-wallet)
(promesa/then on-success)
(promesa/catch on-fail))))
(rf/reg-fx (rf/reg-fx
:effects.wallet-connect/sign-message :effects.wallet-connect/sign-message
(fn [{:keys [password address data rpc-method on-success on-error]}] (fn [{:keys [password address data rpc-method on-success on-error]}]

View File

@ -8,7 +8,8 @@
status-im.contexts.wallet.wallet-connect.responding-events status-im.contexts.wallet.wallet-connect.responding-events
[status-im.contexts.wallet.wallet-connect.utils :as wc-utils] [status-im.contexts.wallet.wallet-connect.utils :as wc-utils]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.i18n :as i18n])) [utils.i18n :as i18n]
[utils.transforms :as types]))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/init :wallet-connect/init
@ -22,12 +23,7 @@
(fn [{:keys [db]} [web3-wallet]] (fn [{:keys [db]} [web3-wallet]]
{:db (assoc db :wallet-connect/web3-wallet web3-wallet) {:db (assoc db :wallet-connect/web3-wallet web3-wallet)
:fx [[:dispatch [:wallet-connect/register-event-listeners]] :fx [[:dispatch [:wallet-connect/register-event-listeners]]
[:effects.wallet-connect/fetch-pairings [:dispatch [:wallet-connect/fetch-persisted-sessions]]]}))
{:web3-wallet web3-wallet
:on-fail #(log/error "Failed to get dApp pairings" {:error %})
:on-success (fn [data]
(rf/dispatch [:wallet-connect/set-pairings
(js->clj data :keywordize-keys true)]))}]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/register-event-listeners :wallet-connect/register-event-listeners
@ -40,7 +36,11 @@
[:effects.wallet-connect/register-event-listener [:effects.wallet-connect/register-event-listener
[web3-wallet [web3-wallet
constants/wallet-connect-session-request-event constants/wallet-connect-session-request-event
#(rf/dispatch [:wallet-connect/on-session-request %])]]]}))) #(rf/dispatch [:wallet-connect/on-session-request %])]]
[:effects.wallet-connect/register-event-listener
[web3-wallet
constants/wallet-connect-session-delete-event
#(rf/dispatch [:wallet-connect/on-session-delete %])]]]})))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/on-init-fail :wallet-connect/on-init-fail
@ -54,7 +54,10 @@
(fn [{:keys [db]} [proposal]] (fn [{:keys [db]} [proposal]]
(log/info "Received Wallet Connect session proposal: " {:id (:id proposal)}) (log/info "Received Wallet Connect session proposal: " {:id (:id proposal)})
(let [accounts (get-in db [:wallet :accounts]) (let [accounts (get-in db [:wallet :accounts])
without-watched (remove :watch-only? (vals accounts)) current-viewing-address (get-in db [:wallet :current-viewing-account-address])
available-accounts (filter #(and (:operable? %)
(not (:watch-only? %)))
(vals accounts))
networks (wallet-connect-core/get-networks-by-mode db) networks (wallet-connect-core/get-networks-by-mode db)
session-networks (wallet-connect-core/proposal-networks-intersection proposal session-networks (wallet-connect-core/proposal-networks-intersection proposal
networks) networks)
@ -65,9 +68,10 @@
:wallet-connect/current-proposal assoc :wallet-connect/current-proposal assoc
:request proposal :request proposal
:session-networks session-networks :session-networks session-networks
:address (-> without-watched :address (or current-viewing-address
first (-> available-accounts
:address)) first
:address)))
:fx [[:dispatch :fx [[:dispatch
[:open-modal :screen/wallet.wallet-connect-session-proposal]]]} [:open-modal :screen/wallet.wallet-connect-session-proposal]]]}
{:fx [[:dispatch {:fx [[:dispatch
@ -85,9 +89,16 @@
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/on-session-request :wallet-connect/on-session-request
(fn [_ [event]] (fn [{:keys [db]} [event]]
(log/info "Received Wallet Connect session request: " event) (when (wallet-connect-core/event-should-be-handled? db event)
{:fx [[:dispatch [:wallet-connect/process-session-request event]]]})) {:fx [[:dispatch [:wallet-connect/process-session-request event]]]})))
(rf/reg-event-fx
:wallet-connect/on-session-delete
(fn [{:keys [db]} [{:keys [topic] :as event}]]
(when (wallet-connect-core/event-should-be-handled? db event)
(log/info "Received Wallet Connect session delete: " event)
{:fx [[:dispatch [:wallet-connect/disconnect-session topic]]]})))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/reset-current-session-proposal :wallet-connect/reset-current-session-proposal
@ -104,28 +115,18 @@
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (dissoc db :wallet-connect/current-request)})) {:db (dissoc db :wallet-connect/current-request)}))
(rf/reg-event-fx
:wallet-connect/set-pairings
(fn [{:keys [db]} [pairings]]
{:db (assoc db :wallet-connect/pairings pairings)}))
(rf/reg-event-fx
:wallet-connect/remove-pairing-by-topic
(fn [{:keys [db]} [topic]]
{:db (update db
:wallet-connect/pairings
(fn [pairings]
(remove #(= (:topic %) topic) pairings)))}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/disconnect-dapp :wallet-connect/disconnect-dapp
(fn [{:keys [db]} [{:keys [topic on-success on-fail]}]] (fn [{:keys [db]} [{:keys [pairing-topic on-success on-fail]}]]
(let [web3-wallet (get db :wallet-connect/web3-wallet)] (let [web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/disconnect {:fx [[:effects.wallet-connect/disconnect
{:web3-wallet web3-wallet {:web3-wallet web3-wallet
:topic topic :topic pairing-topic
:on-fail on-fail :on-fail on-fail
:on-success on-success}]]}))) :on-success (fn []
(rf/dispatch [:wallet-connect/disconnect-session pairing-topic])
(when on-success
(on-success)))}]]})))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/pair :wallet-connect/pair
@ -137,15 +138,6 @@
:on-fail #(log/error "Failed to pair with dApp" {:error %}) :on-fail #(log/error "Failed to pair with dApp" {:error %})
:on-success #(log/info "dApp paired successfully")}]]}))) :on-success #(log/info "dApp paired successfully")}]]})))
(rf/reg-event-fx
:wallet-connect/fetch-active-sessions
(fn [{:keys [db]}]
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/fetch-active-sessions
{:web3-wallet web3-wallet
:on-fail #(log/error "Failed to get active sessions" {:error %})
:on-success #(log/info "Got active sessions successfully" {:sessions %})}]]})))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/approve-session :wallet-connect/approve-session
(fn [{:keys [db]}] (fn [{:keys [db]}]
@ -204,10 +196,55 @@
{:version version}))}]]]} {:version version}))}]]]}
{:fx [[:dispatch [:wallet-connect/pair scanned-text]]]})))) {:fx [[:dispatch [:wallet-connect/pair scanned-text]]]}))))
;; We first load sessions from database, then we initiate a call to Wallet Connect SDK and
;; then replace the list we have stored in the database with the one that came from the SDK.
;; In addition to that, we also update the backend state by marking sessions that are not
;; active anymore by calling `:wallet-connect/disconnect-session`.
(rf/reg-event-fx
:wallet-connect/fetch-active-sessions-success
(fn [{:keys [db now]} [sessions]]
(let [persisted-sessions (:wallet-connect/sessions db)
sessions (->> (js->clj sessions :keywordize-keys true)
vals
(map wallet-connect-core/sdk-session->db-session))
expired-sessions (remove
(fn [{:keys [expiry]}]
(> expiry (/ now 1000)))
persisted-sessions)]
{:fx (mapv (fn [{:keys [pairingTopic]}]
[:wallet-connect/disconnect-session pairingTopic])
expired-sessions)
:db (assoc db :wallet-connect/sessions sessions)})))
(rf/reg-event-fx
:wallet-connect/fetch-active-sessions
(fn [{:keys [db]}]
(let [web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/fetch-active-sessions
{:web3-wallet web3-wallet
:on-fail #(log/error "Failed to get active sessions" {:error %})
:on-success #(rf/dispatch [:wallet-connect/fetch-active-sessions-success %])}]]})))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/fetch-persisted-sessions-success :wallet-connect/fetch-persisted-sessions-success
(fn [{:keys [db]} [sessions]] (fn [{:keys [db]} [sessions]]
{:db (assoc db :wallet-connect/persisted-sessions sessions)})) (let [sessions' (mapv (fn [{:keys [sessionJson] :as session}]
(assoc session
:accounts
(-> sessionJson
types/json->clj
:namespaces
:eip155
:accounts)))
sessions)]
{:fx [[:dispatch [:wallet-connect/fetch-active-sessions]]]
:db (assoc db :wallet-connect/sessions sessions')})))
(rf/reg-event-fx
:wallet-connect/fetch-persisted-sessions-fail
(fn [_ [error]]
(log/info "Wallet Connect fetch persisted sessions failed" error)
{:fx [[:dispatch [:wallet-connect/fetch-active-sessions]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/fetch-persisted-sessions :wallet-connect/fetch-persisted-sessions
@ -218,7 +255,7 @@
;; 0 means, return everything ;; 0 means, return everything
:params [0] :params [0]
:on-success [:wallet-connect/fetch-persisted-sessions-success] :on-success [:wallet-connect/fetch-persisted-sessions-success]
:on-error #(log/info "Wallet Connect fetch persisted sessions failed" %)}]]]})) :on-error [:wallet-connect/fetch-persisted-sessions-fail]}]]]}))
(rf/reg-event-fx (rf/reg-event-fx
:wallet-connect/persist-session :wallet-connect/persist-session
@ -226,5 +263,22 @@
{:fx [[:json-rpc/call {:fx [[:json-rpc/call
[{:method "wallet_addWalletConnectSession" [{:method "wallet_addWalletConnectSession"
:params [(js/JSON.stringify session-info)] :params [(js/JSON.stringify session-info)]
:on-success #(log/info "Wallet Connect session persisted") :on-success (fn []
(log/info "Wallet Connect session persisted")
(rf/dispatch [:wallet-connect/fetch-persisted-sessions]))
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]}))
(rf/reg-event-fx
:wallet-connect/disconnect-session
(fn [{:keys [db]} [pairing-topic]]
{:db (update db
:wallet-connect/sessions
(fn [sessions]
(->> sessions
(remove #(= (:pairingTopic %) pairing-topic))
(into []))))
:fx [[:json-rpc/call
[{:method "wallet_disconnectWalletConnectSession"
:params [pairing-topic]
:on-success #(log/info "Wallet Connect session disconnected")
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]})) :on-error #(log/info "Wallet Connect session persistence failed" %)}]]]}))

View File

@ -10,12 +10,12 @@
[quo/text [quo/text
{:size :heading-1 {:size :heading-1
:weight :semi-bold} :weight :semi-bold}
(let [{:keys [name icons]} (:peerMetadata dapp)] (let [{:keys [name iconUrl]} dapp]
[rn/view {:style style/header-dapp-name} [rn/view {:style style/header-dapp-name}
[quo/summary-tag [quo/summary-tag
{:type :dapp {:type :dapp
:label name :label name
:image-source (first icons)}]]) :image-source iconUrl}]])
(str " " label " ") (str " " label " ")
(let [{:keys [emoji customization-color name]} account] (let [{:keys [emoji customization-color name]} account]
[rn/view {:style style/header-account-name} [rn/view {:style style/header-account-name}

View File

@ -132,7 +132,7 @@
:proposal current-proposal :proposal current-proposal
:on-success #(log/info "Wallet Connect session proposal rejected") :on-success #(log/info "Wallet Connect session proposal rejected")
:on-error #(log/error "Wallet Connect unable to reject session proposal")}] :on-error #(log/error "Wallet Connect unable to reject session proposal")}]
[:dispatch [:wallet-connect/reset-current-session]]]}))) [:dispatch [:wallet-connect/reset-current-session-proposal]]]})))
;; NOTE: Currently we only reject a session if the user rejected it ;; NOTE: Currently we only reject a session if the user rejected it
;; But this needs to be solidified to ensure other cases: ;; But this needs to be solidified to ensure other cases:

View File

@ -6,12 +6,13 @@
:padding-top 12}) :padding-top 12})
(def approval-note-container (def approval-note-container
{:margin-horizontal 20 {:margin-horizontal 20
:padding 12 :padding-horizontal 16
:border-radius 16 :padding-vertical 12
:border-width 1 :border-radius 16
:border-color colors/neutral-10 :border-width 1
:background-color colors/neutral-2_5}) :border-color colors/neutral-10
:background-color colors/neutral-2_5})
(def approval-note-title (def approval-note-title
{:color colors/neutral-50 {:color colors/neutral-50
@ -20,10 +21,8 @@
(def approval-note-li (def approval-note-li
{:flex 1 {:flex 1
:flex-direction :row :flex-direction :row
:align-items :center}) :align-items :center
:gap 8})
(def approval-li-spacer
{:width 8})
(def account-switcher-title (def account-switcher-title
{:padding-horizontal 20}) {:padding-horizontal 20})
@ -31,3 +30,6 @@
(def account-switcher-list (def account-switcher-list
{:margin-top 8 {:margin-top 8
:padding-horizontal 8}) :padding-horizontal 8})
(def footer-buttons-container
{:padding-horizontal 0})

View File

@ -33,16 +33,21 @@
labels [(i18n/label :t/check-your-account-balance-and-activity) labels [(i18n/label :t/check-your-account-balance-and-activity)
(i18n/label :t/request-txns-and-message-signing)]] (i18n/label :t/request-txns-and-message-signing)]]
[rn/view {:style style/approval-note-container} [rn/view {:style style/approval-note-container}
[quo/text {:style style/approval-note-title} [quo/text
{:style style/approval-note-title
:weight :regular
:size :paragraph-2}
(i18n/label :t/dapp-will-be-able-to {:dapp-name dapp-name})] (i18n/label :t/dapp-will-be-able-to {:dapp-name dapp-name})]
(map-indexed (map-indexed
(fn [idx label] (fn [idx label]
^{:key (str idx label)} ^{:key (str idx label)}
[rn/view {:style style/approval-note-li} [rn/view {:style style/approval-note-li}
[quo/icon :i/bullet [quo/icon :i/bullet
{:color colors/neutral-50}] {:color colors/neutral-40}]
[rn/view {:style style/approval-li-spacer}] [quo/text
[quo/text label]]) {:weight :regular
:size :paragraph-2}
label]])
labels)])) labels)]))
(defn- format-network-name (defn- format-network-name
@ -57,16 +62,14 @@
(defn- accounts-list (defn- accounts-list
[] []
(let [accounts (rf/sub [:wallet/accounts-without-watched-accounts]) (let [accounts (rf/sub [:wallet/operable-accounts-without-watched-accounts])
selected-address (rf/sub [:wallet-connect/current-proposal-address])] selected-address (rf/sub [:wallet-connect/current-proposal-address])]
[rn/view {:style style/account-switcher-list} [rn/view {:style style/account-switcher-list}
(for [account accounts] (for [{:keys [address] :as account} accounts]
^{:key (-> account :address str)} ^{:key (str address)}
[quo/account-item [quo/account-item
{:type :default {:type :default
:state (if (and selected-address :state (if (= address selected-address)
(= (account :address)
selected-address))
:selected :selected
:default) :default)
:account-props account :account-props account
@ -101,12 +104,10 @@
(map format-network-name) (map format-network-name)
(string/join ", ")) (string/join ", "))
network-images (mapv :source session-networks) network-images (mapv :source session-networks)
data-item-common-props {:blur? false data-item-common-props {:blur? false
:description :default :card? false
:card? false :status :default
:label :preview :size :large}
:status :default
:size :large}
account-data-item-props (assoc data-item-common-props account-data-item-props (assoc data-item-common-props
:right-content {:type :accounts :right-content {:type :accounts
:size :size-32 :size :size-32
@ -116,9 +117,7 @@
:on-press show-account-switcher-bottom-sheet :on-press show-account-switcher-bottom-sheet
:title (i18n/label :t/account-title) :title (i18n/label :t/account-title)
:subtitle name :subtitle name
:icon-right? true :right-icon :i/chevron-right)
:right-icon :i/chevron-right
:icon-color colors/neutral-10)
networks-data-item-props (assoc data-item-common-props networks-data-item-props (assoc data-item-common-props
:right-content {:type :network :right-content {:type :network
:data network-images} :data network-images}
@ -136,18 +135,21 @@
[] []
(let [customization-color (rf/sub [:profile/customization-color])] (let [customization-color (rf/sub [:profile/customization-color])]
[quo/bottom-actions [quo/bottom-actions
{:actions :two-actions {:actions :two-actions
:button-two-label (i18n/label :t/decline) :buttons-container-style style/footer-buttons-container
:button-two-props {:type :grey :button-two-label (i18n/label :t/decline)
:accessibility-label :wc-deny-connection :button-two-props {:type :grey
:on-press #(do (rf/dispatch [:navigate-back]) :accessibility-label :wc-deny-connection
(rf/dispatch :on-press (fn []
[:wallet-connect/reject-session-proposal]))} (rf/dispatch [:navigate-back])
:button-one-label (i18n/label :t/connect) (rf/dispatch
:button-one-props {:customization-color customization-color [:wallet-connect/reject-session-proposal]))}
:type :primary :button-one-label (i18n/label :t/connect)
:accessibility-label :wc-connect :button-one-props {:customization-color customization-color
:on-press #(rf/dispatch [:wallet-connect/approve-session])}}])) :type :primary
:accessibility-label :wc-connect
:on-press #(rf/dispatch
[:wallet-connect/approve-session])}}]))
(defn- header (defn- header
[] []

View File

@ -11,14 +11,14 @@
(defn timestamp-expired? (defn timestamp-expired?
[expiry-timestamp] [expiry-timestamp]
(> (current-timestamp) expiry-timestamp)) (when expiry-timestamp
(> (current-timestamp) expiry-timestamp)))
(defn valid-wc-uri? (defn valid-wc-uri?
[parsed-uri] [parsed-uri]
(let [{:keys [topic version expiryTimestamp]} parsed-uri] (let [{:keys [topic version]} parsed-uri]
(and (seq topic) (and (seq topic)
(number? version) (number? version))))
(number? expiryTimestamp))))
(defn valid-uri? (defn valid-uri?
"Check if the uri is in the wallet-connect format. "Check if the uri is in the wallet-connect format.

View File

@ -169,7 +169,7 @@
(reg-root-key-sub :wallet-connect/web3-wallet :wallet-connect/web3-wallet) (reg-root-key-sub :wallet-connect/web3-wallet :wallet-connect/web3-wallet)
(reg-root-key-sub :wallet-connect/current-proposal :wallet-connect/current-proposal) (reg-root-key-sub :wallet-connect/current-proposal :wallet-connect/current-proposal)
(reg-root-key-sub :wallet-connect/current-request :wallet-connect/current-request) (reg-root-key-sub :wallet-connect/current-request :wallet-connect/current-request)
(reg-root-key-sub :wallet-connect/pairings :wallet-connect/pairings) (reg-root-key-sub :wallet-connect/sessions :wallet-connect/sessions)
;;biometrics ;;biometrics
(reg-root-key-sub :biometrics :biometrics) (reg-root-key-sub :biometrics :biometrics)

View File

@ -1,5 +1,6 @@
(ns status-im.subs.wallet.wallet-connect (ns status-im.subs.wallet.wallet-connect
(:require [re-frame.core :as rf] (:require [clojure.string :as string]
[re-frame.core :as rf]
[status-im.contexts.wallet.common.utils :as wallet-utils] [status-im.contexts.wallet.common.utils :as wallet-utils]
[status-im.contexts.wallet.common.utils.networks :as networks] [status-im.contexts.wallet.common.utils.networks :as networks]
[status-im.contexts.wallet.wallet-connect.core :as wallet-connect-core] [status-im.contexts.wallet.wallet-connect.core :as wallet-connect-core]
@ -37,14 +38,24 @@
(rf/reg-sub (rf/reg-sub
:wallet-connect/current-request-dapp :wallet-connect/current-request-dapp
:<- [:wallet-connect/current-request] :<- [:wallet-connect/current-request]
:<- [:wallet-connect/pairings] :<- [:wallet-connect/sessions]
(fn [[request pairings]] (fn [[request sessions]]
(let [dapp-url (get-in request [:event :verifyContext :verified :origin])] (let [dapp-url (get-in request [:event :verifyContext :verified :origin])]
(->> pairings (->> sessions
(filter (fn [pairing] (filter (fn [session]
(= dapp-url (get-in pairing [:peerMetadata :url])))) (= dapp-url (get session :url))))
(first))))) (first)))))
(rf/reg-sub
:wallet-connect/sessions-for-current-account
:<- [:wallet-connect/sessions]
:<- [:wallet/current-viewing-account-address]
(fn [[sessions address]]
(filter
(fn [{:keys [accounts]}]
(some #(string/includes? % address) accounts))
sessions)))
(rf/reg-sub (rf/reg-sub
:wallet-connect/current-request-network :wallet-connect/current-request-network
:<- [:wallet-connect/current-request] :<- [:wallet-connect/current-request]