diff --git a/src/quo/components/drawers/bottom_actions/style.cljs b/src/quo/components/drawers/bottom_actions/style.cljs index b462a152c3..9e958c69fe 100644 --- a/src/quo/components/drawers/bottom_actions/style.cljs +++ b/src/quo/components/drawers/bottom_actions/style.cljs @@ -21,12 +21,14 @@ (colors/theme-colors colors/white colors/neutral-95 theme))}) (defn buttons-container - [actions] - {:flex-direction (if (= actions :two-vertical-actions) :column :row) - :justify-content :space-around - :padding-vertical 12 - :gap 12 - :padding-horizontal 20}) + [actions container-style] + (merge + {:flex-direction (if (= actions :two-vertical-actions) :column :row) + :justify-content :space-around + :padding-vertical 12 + :gap 12 + :padding-horizontal 20} + container-style)) (def description-top {:flex-direction :row diff --git a/src/quo/components/drawers/bottom_actions/view.cljs b/src/quo/components/drawers/bottom_actions/view.cljs index 68de6073af..e3ef4ce46c 100644 --- a/src/quo/components/drawers/bottom_actions/view.cljs +++ b/src/quo/components/drawers/bottom_actions/view.cljs @@ -30,7 +30,8 @@ [:button-two-props {:optional true} [:maybe :map]] [:scroll? {: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]) (def ^:private role-icon @@ -42,7 +43,7 @@ (defn- view-internal [{: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 - context-tag-props]}] + buttons-container-style context-tag-props]}] (let [theme (quo.theme/use-theme)] [rn/view {:style (merge (style/container scroll? blur? theme) container-style)} @@ -72,7 +73,7 @@ :context (i18n/label (keyword "t" role))} 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) (= actions :two-vertical-actions)) [button/button diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index f9aad3c896..755e56d620 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -287,6 +287,7 @@ (def ^:const wallet-connect-supported-events #{"accountsChanged" "chainChanged"}) (def ^:const wallet-connect-session-proposal-event "session_proposal") (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 transaction-pending-type-wallet-connect-transfer "WalletConnectTransfer") diff --git a/src/status_im/contexts/shell/qr_reader/view.cljs b/src/status_im/contexts/shell/qr_reader/view.cljs index 3868e1b5cb..cf967d0b19 100644 --- a/src/status_im/contexts/shell/qr_reader/view.cljs +++ b/src/status_im/contexts/shell/qr_reader/view.cljs @@ -117,13 +117,14 @@ (defn- f-internal-view [] (let [{:keys [keyboard-shown]} (hooks/use-keyboard)] - [:<> - (when keyboard-shown - (rn/dismiss-keyboard!)) - [scan-qr-code/view - {:title (i18n/label :t/scan-qr) - :share-button? true - :on-success-scan on-qr-code-scanned}]])) + (rn/use-mount + (fn [] + (when keyboard-shown + (rn/dismiss-keyboard!)))) + [scan-qr-code/view + {:title (i18n/label :t/scan-qr) + :share-button? true + :on-success-scan on-qr-code-scanned}])) (defn view [] diff --git a/src/status_im/contexts/wallet/connected_dapps/view.cljs b/src/status_im/contexts/wallet/connected_dapps/view.cljs index b8408f95f7..01d7ad5cea 100644 --- a/src/status_im/contexts/wallet/connected_dapps/view.cljs +++ b/src/status_im/contexts/wallet/connected_dapps/view.cljs @@ -13,26 +13,26 @@ [utils.re-frame :as rf])) (defn- on-disconnect - [wallet-account {:keys [name topic]}] + [wallet-account {:keys [name topic pairing-topic]}] (rf/dispatch [:hide-bottom-sheet]) (rf/dispatch [:wallet-connect/disconnect-dapp - {:topic topic - :on-success (fn [] - (rf/dispatch [:wallet-connect/remove-pairing-by-topic topic]) - (rf/dispatch [:toasts/upsert - {:id :dapp-disconnect-success - :type :positive - :text (i18n/label :t/disconnect-dapp-success - {:dapp name - :account (:name wallet-account)})}])) - :on-fail (fn [] - (rf/dispatch [:toasts/upsert - {:id :dapp-disconnect-failure - :type :negative - :text (i18n/label :t/disconnect-dapp-fail - {:dapp name - :account (:name wallet-account)})}]))}])) + {:topic topic + :pairing-topic pairing-topic + :on-success (fn [] + (rf/dispatch [:toasts/upsert + {:id :dapp-disconnect-success + :type :positive + :text (i18n/label :t/disconnect-dapp-success + {:dapp name + :account (:name wallet-account)})}])) + :on-fail (fn [] + (rf/dispatch [:toasts/upsert + {:id :dapp-disconnect-failure + :type :negative + :text (i18n/label :t/disconnect-dapp-fail + {:dapp name + :account (:name wallet-account)})}]))}])) (defn- on-dapp-disconnect-press [wallet-account dapp] @@ -83,7 +83,8 @@ [] (let [{:keys [bottom]} (safe-area/get-insets) {: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)] [rn/view {:flex 1} [header @@ -91,7 +92,7 @@ :wallet-account wallet-account :on-close #(rf/dispatch [:navigate-back]) :on-add #(rf/dispatch [:navigate-to :screen/wallet.scan-dapp])}] - (if (empty? pairings) + (if (empty? sessions) [quo/empty-state {:title (i18n/label :t/no-dapps) :description (i18n/label :t/no-dapps-description) @@ -99,16 +100,16 @@ :container-style style/empty-container-style}] [rn/view (style/dapps-container bottom) [rn/flat-list - {:data pairings + {:data sessions :always-bounce-vertical false :content-container-style (style/dapps-list theme) - :render-fn (fn [{:keys [topic] - {:keys [icons name url]} :peerMetadata}] + :render-fn (fn [{:keys [topic pairingTopic name url iconUrl]}] [quo/dapp - {:dapp {:avatar (get icons 0) - :name name - :value url - :topic topic} + {:dapp {:avatar iconUrl + :name name + :value url + :topic topic + :pairing-topic pairingTopic} :accessibility-label (str "dapp-" topic) :state :default :action :icon diff --git a/src/status_im/contexts/wallet/wallet_connect/core.cljs b/src/status_im/contexts/wallet/wallet_connect/core.cljs index 5354f335dd..047ccaa190 100644 --- a/src/status_im/contexts/wallet/wallet_connect/core.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/core.cljs @@ -85,12 +85,34 @@ (defn required-networks-supported? [proposal supported-networks] - (let [required-networks (get-in proposal [:params :requiredNamespaces :eip155 :chains]) - supported-eip155 (set (map chain-id->eip155 supported-networks))] - (every? #(contains? supported-eip155 %) required-networks))) + (let [supported-namespaces #{:eip155} + required-namespaces (get-in proposal [:params :requiredNamespaces])] + (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 [db] (let [test-mode? (get-in db [:profile/profile :test-networks-enabled?]) networks (get-in db [:wallet :networks (if test-mode? :test :prod)])] (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}) diff --git a/src/status_im/contexts/wallet/wallet_connect/effects.cljs b/src/status_im/contexts/wallet/wallet_connect/effects.cljs index 40c12f6ef4..bbab603f33 100644 --- a/src/status_im/contexts/wallet/wallet_connect/effects.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/effects.cljs @@ -31,13 +31,6 @@ :event wc-event :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 :effects.wallet-connect/pair (fn [{:keys [web3-wallet url on-success on-fail]}] @@ -53,13 +46,6 @@ (promesa/then on-success) (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 :effects.wallet-connect/approve-session (fn [{:keys [web3-wallet proposal supported-namespaces on-success on-fail]}] @@ -74,6 +60,13 @@ (promesa/then on-success) (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 :effects.wallet-connect/sign-message (fn [{:keys [password address data rpc-method on-success on-error]}] diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index 51856c97da..bfc9d9e3ce 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -8,7 +8,8 @@ status-im.contexts.wallet.wallet-connect.responding-events [status-im.contexts.wallet.wallet-connect.utils :as wc-utils] [taoensso.timbre :as log] - [utils.i18n :as i18n])) + [utils.i18n :as i18n] + [utils.transforms :as types])) (rf/reg-event-fx :wallet-connect/init @@ -22,12 +23,7 @@ (fn [{:keys [db]} [web3-wallet]] {:db (assoc db :wallet-connect/web3-wallet web3-wallet) :fx [[:dispatch [:wallet-connect/register-event-listeners]] - [:effects.wallet-connect/fetch-pairings - {: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)]))}]]})) + [:dispatch [:wallet-connect/fetch-persisted-sessions]]]})) (rf/reg-event-fx :wallet-connect/register-event-listeners @@ -40,7 +36,11 @@ [:effects.wallet-connect/register-event-listener [web3-wallet 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 :wallet-connect/on-init-fail @@ -54,7 +54,10 @@ (fn [{:keys [db]} [proposal]] (log/info "Received Wallet Connect session proposal: " {:id (:id proposal)}) (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) session-networks (wallet-connect-core/proposal-networks-intersection proposal networks) @@ -65,9 +68,10 @@ :wallet-connect/current-proposal assoc :request proposal :session-networks session-networks - :address (-> without-watched - first - :address)) + :address (or current-viewing-address + (-> available-accounts + first + :address))) :fx [[:dispatch [:open-modal :screen/wallet.wallet-connect-session-proposal]]]} {:fx [[:dispatch @@ -85,9 +89,16 @@ (rf/reg-event-fx :wallet-connect/on-session-request - (fn [_ [event]] - (log/info "Received Wallet Connect session request: " event) - {:fx [[:dispatch [:wallet-connect/process-session-request event]]]})) + (fn [{:keys [db]} [event]] + (when (wallet-connect-core/event-should-be-handled? db 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 :wallet-connect/reset-current-session-proposal @@ -104,28 +115,18 @@ (fn [{:keys [db]}] {: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 :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)] {:fx [[:effects.wallet-connect/disconnect {:web3-wallet web3-wallet - :topic topic + :topic pairing-topic :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 :wallet-connect/pair @@ -137,15 +138,6 @@ :on-fail #(log/error "Failed to pair with dApp" {:error %}) :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 :wallet-connect/approve-session (fn [{:keys [db]}] @@ -204,10 +196,55 @@ {:version version}))}]]]} {: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 :wallet-connect/fetch-persisted-sessions-success (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 :wallet-connect/fetch-persisted-sessions @@ -218,7 +255,7 @@ ;; 0 means, return everything :params [0] :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 :wallet-connect/persist-session @@ -226,5 +263,22 @@ {:fx [[:json-rpc/call [{:method "wallet_addWalletConnectSession" :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" %)}]]]})) diff --git a/src/status_im/contexts/wallet/wallet_connect/modals/common/header/view.cljs b/src/status_im/contexts/wallet/wallet_connect/modals/common/header/view.cljs index 991949fcaa..5a13a0401e 100644 --- a/src/status_im/contexts/wallet/wallet_connect/modals/common/header/view.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/modals/common/header/view.cljs @@ -10,12 +10,12 @@ [quo/text {:size :heading-1 :weight :semi-bold} - (let [{:keys [name icons]} (:peerMetadata dapp)] + (let [{:keys [name iconUrl]} dapp] [rn/view {:style style/header-dapp-name} [quo/summary-tag {:type :dapp :label name - :image-source (first icons)}]]) + :image-source iconUrl}]]) (str " " label " ") (let [{:keys [emoji customization-color name]} account] [rn/view {:style style/header-account-name} diff --git a/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs b/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs index 838788576f..2a665fde6e 100644 --- a/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs @@ -132,7 +132,7 @@ :proposal current-proposal :on-success #(log/info "Wallet Connect session proposal rejected") :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 ;; But this needs to be solidified to ensure other cases: diff --git a/src/status_im/contexts/wallet/wallet_connect/session_proposal/style.cljs b/src/status_im/contexts/wallet/wallet_connect/session_proposal/style.cljs index b8438fb73d..a828d46a23 100644 --- a/src/status_im/contexts/wallet/wallet_connect/session_proposal/style.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/session_proposal/style.cljs @@ -6,12 +6,13 @@ :padding-top 12}) (def approval-note-container - {:margin-horizontal 20 - :padding 12 - :border-radius 16 - :border-width 1 - :border-color colors/neutral-10 - :background-color colors/neutral-2_5}) + {:margin-horizontal 20 + :padding-horizontal 16 + :padding-vertical 12 + :border-radius 16 + :border-width 1 + :border-color colors/neutral-10 + :background-color colors/neutral-2_5}) (def approval-note-title {:color colors/neutral-50 @@ -20,10 +21,8 @@ (def approval-note-li {:flex 1 :flex-direction :row - :align-items :center}) - -(def approval-li-spacer - {:width 8}) + :align-items :center + :gap 8}) (def account-switcher-title {:padding-horizontal 20}) @@ -31,3 +30,6 @@ (def account-switcher-list {:margin-top 8 :padding-horizontal 8}) + +(def footer-buttons-container + {:padding-horizontal 0}) diff --git a/src/status_im/contexts/wallet/wallet_connect/session_proposal/view.cljs b/src/status_im/contexts/wallet/wallet_connect/session_proposal/view.cljs index 3c953d686b..fab5752cf6 100644 --- a/src/status_im/contexts/wallet/wallet_connect/session_proposal/view.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/session_proposal/view.cljs @@ -33,16 +33,21 @@ 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} - [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})] (map-indexed (fn [idx label] ^{:key (str idx label)} [rn/view {:style style/approval-note-li} [quo/icon :i/bullet - {:color colors/neutral-50}] - [rn/view {:style style/approval-li-spacer}] - [quo/text label]]) + {:color colors/neutral-40}] + [quo/text + {:weight :regular + :size :paragraph-2} + label]]) labels)])) (defn- format-network-name @@ -57,16 +62,14 @@ (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])] [rn/view {:style style/account-switcher-list} - (for [account accounts] - ^{:key (-> account :address str)} + (for [{:keys [address] :as account} accounts] + ^{:key (str address)} [quo/account-item {:type :default - :state (if (and selected-address - (= (account :address) - selected-address)) + :state (if (= address selected-address) :selected :default) :account-props account @@ -101,12 +104,10 @@ (map format-network-name) (string/join ", ")) network-images (mapv :source session-networks) - data-item-common-props {:blur? false - :description :default - :card? false - :label :preview - :status :default - :size :large} + data-item-common-props {:blur? false + :card? false + :status :default + :size :large} account-data-item-props (assoc data-item-common-props :right-content {:type :accounts :size :size-32 @@ -116,9 +117,7 @@ :on-press show-account-switcher-bottom-sheet :title (i18n/label :t/account-title) :subtitle name - :icon-right? true - :right-icon :i/chevron-right - :icon-color colors/neutral-10) + :right-icon :i/chevron-right) networks-data-item-props (assoc data-item-common-props :right-content {:type :network :data network-images} @@ -136,18 +135,21 @@ [] (let [customization-color (rf/sub [:profile/customization-color])] [quo/bottom-actions - {:actions :two-actions - :button-two-label (i18n/label :t/decline) - :button-two-props {:type :grey - :accessibility-label :wc-deny-connection - :on-press #(do (rf/dispatch [:navigate-back]) - (rf/dispatch - [:wallet-connect/reject-session-proposal]))} - :button-one-label (i18n/label :t/connect) - :button-one-props {:customization-color customization-color - :type :primary - :accessibility-label :wc-connect - :on-press #(rf/dispatch [:wallet-connect/approve-session])}}])) + {:actions :two-actions + :buttons-container-style style/footer-buttons-container + :button-two-label (i18n/label :t/decline) + :button-two-props {:type :grey + :accessibility-label :wc-deny-connection + :on-press (fn [] + (rf/dispatch [:navigate-back]) + (rf/dispatch + [:wallet-connect/reject-session-proposal]))} + :button-one-label (i18n/label :t/connect) + :button-one-props {:customization-color customization-color + :type :primary + :accessibility-label :wc-connect + :on-press #(rf/dispatch + [:wallet-connect/approve-session])}}])) (defn- header [] diff --git a/src/status_im/contexts/wallet/wallet_connect/utils.cljs b/src/status_im/contexts/wallet/wallet_connect/utils.cljs index 736bab1d88..0f53bcc768 100644 --- a/src/status_im/contexts/wallet/wallet_connect/utils.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/utils.cljs @@ -11,14 +11,14 @@ (defn timestamp-expired? [expiry-timestamp] - (> (current-timestamp) expiry-timestamp)) + (when expiry-timestamp + (> (current-timestamp) expiry-timestamp))) (defn valid-wc-uri? [parsed-uri] - (let [{:keys [topic version expiryTimestamp]} parsed-uri] + (let [{:keys [topic version]} parsed-uri] (and (seq topic) - (number? version) - (number? expiryTimestamp)))) + (number? version)))) (defn valid-uri? "Check if the uri is in the wallet-connect format. diff --git a/src/status_im/subs/root.cljs b/src/status_im/subs/root.cljs index a364cd1a40..7e2051d06f 100644 --- a/src/status_im/subs/root.cljs +++ b/src/status_im/subs/root.cljs @@ -169,7 +169,7 @@ (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-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 (reg-root-key-sub :biometrics :biometrics) diff --git a/src/status_im/subs/wallet/wallet_connect.cljs b/src/status_im/subs/wallet/wallet_connect.cljs index 763bd8b8c1..da205dcee9 100644 --- a/src/status_im/subs/wallet/wallet_connect.cljs +++ b/src/status_im/subs/wallet/wallet_connect.cljs @@ -1,5 +1,6 @@ (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.networks :as networks] [status-im.contexts.wallet.wallet-connect.core :as wallet-connect-core] @@ -37,14 +38,24 @@ (rf/reg-sub :wallet-connect/current-request-dapp :<- [:wallet-connect/current-request] - :<- [:wallet-connect/pairings] - (fn [[request pairings]] + :<- [:wallet-connect/sessions] + (fn [[request sessions]] (let [dapp-url (get-in request [:event :verifyContext :verified :origin])] - (->> pairings - (filter (fn [pairing] - (= dapp-url (get-in pairing [:peerMetadata :url])))) + (->> sessions + (filter (fn [session] + (= dapp-url (get session :url)))) (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 :wallet-connect/current-request-network :<- [:wallet-connect/current-request]