Reject wallet-connect request by dragging the modal down (#20763) (#20836)

* Reject wallet-connect request by dragging the modal down (#20763)

* Fix
This commit is contained in:
Alexander 2024-07-25 16:51:10 +02:00 committed by GitHub
parent 2ffbdac89e
commit 15a4219ef4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 54 additions and 45 deletions

View File

@ -76,6 +76,7 @@
(if (and (not-empty session-networks) required-networks-supported?)
{:db (update db
:wallet-connect/current-proposal assoc
:response-sent? false
:request proposal
:session-networks session-networks
:address (or current-viewing-address
@ -167,7 +168,8 @@
network-status (:network/status db)
expiry (get-in current-proposal [:params :expiryTimestamp])]
(if (= network-status :online)
{:fx [(if (wc-utils/timestamp-expired? expiry)
{:db (assoc-in db [:wallet-connect/current-proposal :response-sent?] true)
:fx [(if (wc-utils/timestamp-expired? expiry)
[:dispatch
[:toasts/upsert
{:id :wallet-connect-proposal-expired

View File

@ -7,6 +7,5 @@
[quo/page-nav
{:icon-name :i/close
:background :blur
:on-press #(do (rf/dispatch [:wallet-connect/dismiss-request-modal])
(rf/dispatch [:wallet-connect/reject-session-request]))
:on-press #(rf/dispatch [:wallet-connect/dismiss-request-modal])
:accessibility-label accessibility-label}])

View File

@ -22,6 +22,7 @@
network (rf/sub [:wallet-connect/current-request-network])
{:keys [max-fees-fiat-formatted
error-state]} (rf/sub [:wallet-connect/current-request-transaction-information])]
(rn/use-unmount #(rf/dispatch [:wallet-connect/on-request-modal-dismissed]))
[rn/view {:style (style/container bottom)}
[quo/gradient-cover {:customization-color customization-color}]
[page-nav/view

View File

@ -18,6 +18,7 @@
{:keys [customization-color]
:as account} (rf/sub [:wallet-connect/current-request-account-details])
dapp (rf/sub [:wallet-connect/current-request-dapp])]
(rn/use-unmount #(rf/dispatch [:wallet-connect/on-request-modal-dismissed]))
[rn/view {:style (style/container bottom)}
[quo/gradient-cover {:customization-color customization-color}]
[page-nav/view

View File

@ -21,6 +21,7 @@
network (rf/sub [:wallet-connect/current-request-network])
{:keys [max-fees-fiat-formatted
error-state]} (rf/sub [:wallet-connect/current-request-transaction-information])]
(rn/use-unmount #(rf/dispatch [:wallet-connect/on-request-modal-dismissed]))
[rn/view {:style (style/container bottom)}
[quo/gradient-cover {:customization-color customization-color}]
[page-nav/view

View File

@ -29,7 +29,9 @@
existing-event (get-in db [:wallet-connect/current-request :event])]
;; NOTE: make sure we don't show two requests at the same time
(when-not existing-event
{:db (assoc-in db [:wallet-connect/current-request :event] event)
{:db (-> db
(assoc-in [:wallet-connect/current-request :event] event)
(assoc-in [:wallet-connect/current-request :response-sent?] false))
:fx [(condp = method
constants/wallet-connect-eth-send-transaction-method
[:dispatch [:wallet-connect/process-eth-send-transaction]]
@ -191,4 +193,4 @@
:method method
:wallet-connect-event event
:event :wallet-connect/on-processing-error})
{:fx [[:dispatch [:wallet-connect/reject-session-request]]]})))
{:fx [[:dispatch [:wallet-connect/dismiss-request-modal]]]})))

View File

@ -106,31 +106,29 @@
:method method
:wallet-connect-event event
:event :wallet-connect/on-sign-error})
{:fx [[:dispatch [:wallet-connect/reject-session-request]]
[:dispatch [:wallet-connect/dismiss-request-modal]]]})))
{:fx [[:dispatch [:wallet-connect/dismiss-request-modal]]]})))
(rf/reg-event-fx
:wallet-connect/send-response
(fn [{:keys [db]} [{:keys [result error]}]]
(let [{:keys [id topic] :as event} (get-in db [:wallet-connect/current-request :event])
method (wallet-connect-core/get-request-method event)
web3-wallet (get db :wallet-connect/web3-wallet)]
{:fx [[:effects.wallet-connect/respond-session-request
{:web3-wallet web3-wallet
:topic topic
:id id
:result result
:error error
:on-error (fn [error]
(log/error "Failed to send Wallet Connect response"
{:error error
:method method
:event :wallet-connect/send-response
:wallet-connect-event event})
(rf/dispatch [:wallet-connect/reset-current-request]))
:on-success (fn []
(log/info "Successfully sent Wallet Connect response to dApp")
(rf/dispatch [:wallet-connect/reset-current-request]))}]]})))
(when-let [{:keys [id topic] :as event} (get-in db [:wallet-connect/current-request :event])]
(let [method (wallet-connect-core/get-request-method event)
web3-wallet (get db :wallet-connect/web3-wallet)]
{:db (assoc-in db [:wallet-connect/current-request :response-sent?] true)
:fx [[:effects.wallet-connect/respond-session-request
{:web3-wallet web3-wallet
:topic topic
:id id
:result result
:error error
:on-error (fn [error]
(log/error "Failed to send Wallet Connect response"
{:error error
:method method
:event :wallet-connect/send-response
:wallet-connect-event event}))
:on-success (fn []
(log/info "Successfully sent Wallet Connect response to dApp"))}]]}))))
(rf/reg-event-fx
:wallet-connect/dismiss-request-modal
@ -150,16 +148,18 @@
(rf/reg-event-fx
:wallet-connect/reject-session-proposal
(fn [{:keys [db]} _]
(let [web3-wallet (get db :wallet-connect/web3-wallet)
current-proposal (get-in db [:wallet-connect/current-proposal :request])]
{:fx [[:effects.wallet-connect/reject-session-proposal
{:web3-wallet web3-wallet
:proposal current-proposal
:on-success #(log/info "Wallet Connect session proposal rejected")
:on-error #(log/error "Wallet Connect unable to reject session proposal")}]
(let [web3-wallet (get db :wallet-connect/web3-wallet)
{:keys [request response-sent?]} (:wallet-connect/current-proposal db)]
{:fx [(when-not response-sent?
[:effects.wallet-connect/reject-session-proposal
{:web3-wallet web3-wallet
:proposal request
: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-proposal]]]})))
;; NOTE: Currently we only reject a session if the user rejected it
;; NOTE: Currently we only reject a session if the user dismissed a modal
;; without accepting the session first.
;; But this needs to be solidified to ensure other cases:
;; - Unsupported WC version
;; - Invalid params from dapps
@ -167,9 +167,11 @@
;; - Failed processing of request
;; - Failed "responding" (signing or sending message/transaction)
(rf/reg-event-fx
:wallet-connect/reject-session-request
(fn [_ _]
{:fx [[:dispatch
[:wallet-connect/send-response
{:error (wallet-connect/get-sdk-error
constants/wallet-connect-user-rejected-error-key)}]]]}))
:wallet-connect/on-request-modal-dismissed
(fn [{:keys [db]}]
{:fx [(when-not (get-in db [:wallet-connect/current-request :response-sent?])
[:dispatch
[:wallet-connect/send-response
{:error (wallet-connect/get-sdk-error
constants/wallet-connect-user-rejected-error-key)}]])
[:dispatch [:wallet-connect/reset-current-request]]]}))

View File

@ -148,10 +148,9 @@
: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]))}
:on-press #(rf/dispatch
[:dismiss-modal
:screen/wallet.wallet-connect-session-proposal])}
:button-one-label (i18n/label :t/connect)
:button-one-props {:customization-color customization-color
:type :primary
@ -165,11 +164,13 @@
{:type :no-title
:background :blur
:icon-name :i/close
:on-press (rn/use-callback #(rf/dispatch [:navigate-back]))
:on-press (rn/use-callback
#(rf/dispatch [:dismiss-modal :screen/wallet.wallet-connect-session-proposal]))
:accessibility-label :wc-session-proposal-top-bar}])
(defn view
[]
(rn/use-unmount #(rf/dispatch [:wallet-connect/reject-session-proposal]))
[floating-button-page/view
{:footer-container-padding 0
:header [header]