diff --git a/src/status_im/contexts/wallet/wallet_connect/events.cljs b/src/status_im/contexts/wallet/wallet_connect/events.cljs index 48e5491cdf..a1a212aabe 100644 --- a/src/status_im/contexts/wallet/wallet_connect/events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/events.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/wallet_connect/modals/common/page_nav/view.cljs b/src/status_im/contexts/wallet/wallet_connect/modals/common/page_nav/view.cljs index 0a35fb8778..13f2c2be9f 100644 --- a/src/status_im/contexts/wallet/wallet_connect/modals/common/page_nav/view.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/modals/common/page_nav/view.cljs @@ -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}]) diff --git a/src/status_im/contexts/wallet/wallet_connect/modals/send_transaction/view.cljs b/src/status_im/contexts/wallet/wallet_connect/modals/send_transaction/view.cljs index 746fb5f84a..9546a59c39 100644 --- a/src/status_im/contexts/wallet/wallet_connect/modals/send_transaction/view.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/modals/send_transaction/view.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/wallet_connect/modals/sign_message/view.cljs b/src/status_im/contexts/wallet/wallet_connect/modals/sign_message/view.cljs index 32b802d8c5..b3a3a4a93a 100644 --- a/src/status_im/contexts/wallet/wallet_connect/modals/sign_message/view.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/modals/sign_message/view.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/wallet_connect/modals/sign_transaction/view.cljs b/src/status_im/contexts/wallet/wallet_connect/modals/sign_transaction/view.cljs index 9e348a9cca..3aa090401c 100644 --- a/src/status_im/contexts/wallet/wallet_connect/modals/sign_transaction/view.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/modals/sign_transaction/view.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs b/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs index f432ee7c2e..32df348ceb 100644 --- a/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/processing_events.cljs @@ -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]]]}))) 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 f4381fe14b..a615a97a68 100644 --- a/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs +++ b/src/status_im/contexts/wallet/wallet_connect/responding_events.cljs @@ -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]]]})) 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 8e321bc067..c989eb515b 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 @@ -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]