Add management for wallet connect sessions
This commit is contained in:
parent
78b0bf0bda
commit
2c1bfcd092
Binary file not shown.
After Width: | Height: | Size: 861 B |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
|
@ -25,6 +25,7 @@
|
|||
[status-im.utils.types :as types]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.wallet.core :as wallet]
|
||||
[status-im.wallet-connect-legacy.core :as wallet-connect-legacy]
|
||||
[status-im.wallet.prices :as prices]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.data-store.invitations :as data-store.invitations]
|
||||
|
@ -88,13 +89,6 @@
|
|||
#(re-frame/dispatch [:wallet-connect/client-init %])
|
||||
#(log/error "[wallet-connect]" %))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::initialize-wallet-connect
|
||||
(fn []
|
||||
(async-storage/get-item
|
||||
:wallet-connect-enabled?
|
||||
#(re-frame/dispatch [:multiaccounts.ui/switch-wallet-connect-enabled %]))))
|
||||
|
||||
(defn rpc->accounts [accounts]
|
||||
(reduce (fn [acc {:keys [chat type wallet] :as account}]
|
||||
(if chat
|
||||
|
@ -169,7 +163,8 @@
|
|||
(transactions/get-fetched-transfers))
|
||||
(when (ethereum/binance-chain? db)
|
||||
(wallet/request-current-block-update))
|
||||
(prices/update-prices)))
|
||||
(prices/update-prices)
|
||||
(wallet-connect-legacy/get-connector-session-from-db)))
|
||||
|
||||
(fx/defn login
|
||||
{:events [:multiaccounts.login.ui/password-input-submitted]}
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
[cofx]
|
||||
;; we need to disable notifications before starting the logout process
|
||||
(fx/merge cofx
|
||||
{:dispatch-later [{:ms 100
|
||||
{:dispatch [:wallet-connect-legacy/clean-up-sessions]
|
||||
:dispatch-later [{:ms 100
|
||||
:dispatch [::logout-method
|
||||
{:auth-method keychain/auth-method-none
|
||||
:logout? true}]}]}
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
current-fleet
|
||||
webview-debug
|
||||
new-ui-enabled?
|
||||
mutual-contact-requests-enabled?
|
||||
wallet-connect-enabled?]}]
|
||||
mutual-contact-requests-enabled?]}]
|
||||
(keep
|
||||
identity
|
||||
[{:size :small
|
||||
|
@ -118,15 +117,6 @@
|
|||
[:multiaccounts.ui/switch-mutual-contact-requests-enabled (not mutual-contact-requests-enabled?)])
|
||||
:accessory :switch
|
||||
:active mutual-contact-requests-enabled?}
|
||||
{:size :small
|
||||
:title (i18n/label :t/wallet-connect)
|
||||
:accessibility-label :wallet-connect-settings-switch
|
||||
:container-margin-bottom 8
|
||||
:on-press
|
||||
#(re-frame/dispatch
|
||||
[:multiaccounts.ui/switch-wallet-connect-enabled (not wallet-connect-enabled?)])
|
||||
:accessory :switch
|
||||
:active wallet-connect-enabled?}
|
||||
{:size :small
|
||||
:title (i18n/label :t/new-ui)
|
||||
:accessibility-label :new-ui-toggle
|
||||
|
@ -152,8 +142,7 @@
|
|||
transactions-management-enabled? [:wallet/transactions-management-enabled?]
|
||||
current-log-level [:log-level/current-log-level]
|
||||
current-fleet [:fleets/current-fleet]
|
||||
mutual-contact-requests-enabled? [:mutual-contact-requests/enabled?]
|
||||
wallet-connect-enabled? [:wallet-connect/enabled?]]
|
||||
mutual-contact-requests-enabled? [:mutual-contact-requests/enabled?]]
|
||||
[list/flat-list
|
||||
{:data (flat-list-data
|
||||
{:network-name network-name
|
||||
|
@ -166,7 +155,6 @@
|
|||
:waku-bloom-filter-mode waku-bloom-filter-mode
|
||||
:webview-debug webview-debug
|
||||
:new-ui-enabled? @config/new-ui-enabled?
|
||||
:mutual-contact-requests-enabled? mutual-contact-requests-enabled?
|
||||
:wallet-connect-enabled? wallet-connect-enabled?})
|
||||
:mutual-contact-requests-enabled? mutual-contact-requests-enabled?})
|
||||
:key-fn (fn [_ i] (str i))
|
||||
:render-fn render-item}]))
|
||||
|
|
|
@ -119,6 +119,7 @@
|
|||
[status-im.ui.screens.wallet.send.views :as wallet.send]
|
||||
[quo2.screens.main :as quo2.preview]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.ui.screens.wallet.manage-connections.views :as manage-all-connections]
|
||||
[status-im.navigation2.screens :as navigation2.screens]))
|
||||
;[quo2.foundations.colors :as quo2.colors]))
|
||||
|
||||
|
@ -880,6 +881,11 @@
|
|||
;;TODO move to popover?
|
||||
:component key-storage.views/storage}
|
||||
|
||||
{:name :show-all-connections
|
||||
:insets {:bottom true}
|
||||
:options {:topBar {:title {:text (i18n/label :all-connections)}}}
|
||||
:component manage-all-connections/views}
|
||||
|
||||
;; BUG REPORT
|
||||
{:name :bug-report
|
||||
:options {:topBar {:visible false}}
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
:accessibility-label :wallet-manage-assets
|
||||
:on-press #(hide-sheet-and-dispatch
|
||||
[:navigate-to :wallet-settings-assets])}]
|
||||
[quo/list-item
|
||||
{:theme :accent
|
||||
:title (i18n/label :t/wallet-manage-app-connections)
|
||||
:icon :main-icons/manage-connections
|
||||
:accessibility-label :wallet-manage-app-connections
|
||||
:on-press #(hide-sheet-and-dispatch
|
||||
[:navigate-to :show-all-connections])}]
|
||||
[quo/list-item
|
||||
{:theme :accent
|
||||
:title (i18n/label :t/scan-tokens)
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
(ns status-im.ui.screens.wallet.manage-connections.styles
|
||||
(:require [quo.design-system.colors :as colors]))
|
||||
|
||||
(def dapp-icon
|
||||
{:width 30
|
||||
:height 30
|
||||
:resize-mode :cover
|
||||
:margin 10
|
||||
:border-radius 15
|
||||
:border-width 2
|
||||
:padding 10})
|
||||
|
||||
(def app-row
|
||||
{:flex-direction :row
|
||||
:margin-vertical 8
|
||||
:align-items :center})
|
||||
|
||||
(def app-column
|
||||
{:flex-direction :column
|
||||
:max-width 160
|
||||
:justify-content :center})
|
||||
|
||||
(def dapp-name
|
||||
{:font-size 15})
|
||||
|
||||
(def dapp-url
|
||||
{:font-size 15
|
||||
:opacity 0.5})
|
||||
|
||||
(def selected-account
|
||||
{:font-size 13
|
||||
:color colors/white})
|
||||
|
||||
(defn selected-account-container [account-background-color]
|
||||
{:background-color account-background-color
|
||||
:padding-horizontal 10
|
||||
:justify-content :center
|
||||
:flex-direction :row
|
||||
:align-items :center
|
||||
:border-radius 40
|
||||
:height 26})
|
||||
|
||||
(def delete-icon-container
|
||||
{:margin-horizontal 10})
|
|
@ -0,0 +1,52 @@
|
|||
(ns status-im.ui.screens.wallet.manage-connections.views
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[quo.react-native :as rn]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.screens.wallet.manage-connections.styles :as styles]
|
||||
[quo.core :as quo]
|
||||
[quo.design-system.colors :as colors]
|
||||
[status-im.ui.components.icons.icons :as icons]
|
||||
[status-im.utils.utils :as utils]))
|
||||
|
||||
(defn print-session-info [session]
|
||||
(let [peer-meta (get-in session [:params 0 :peerMeta])
|
||||
peer-id (get-in session [:params 0 :peerId])
|
||||
name (get peer-meta :name)
|
||||
url (get peer-meta :url)
|
||||
account (get-in session [:params 0 :accounts 0])
|
||||
icons (get peer-meta :icons)
|
||||
icon-uri (first (status-im.utils.utils/exclude-svg-resources icons))
|
||||
visible-accounts @(re-frame/subscribe [:visible-accounts-without-watch-only])
|
||||
selected-account (first (filter
|
||||
#(= account
|
||||
(:address %))
|
||||
visible-accounts))]
|
||||
^{:key peer-id}
|
||||
[rn/view
|
||||
[:<>
|
||||
[rn/view {:style styles/app-row}
|
||||
[react/image {:style styles/dapp-icon :source {:uri icon-uri}}]
|
||||
[rn/view {:style styles/app-column}
|
||||
[quo/text {:style styles/dapp-name} name]
|
||||
[quo/text {:style styles/dapp-url} url]]
|
||||
|
||||
[rn/view {:flex-direction :row
|
||||
:position :absolute
|
||||
:right 10
|
||||
:align-items :center}
|
||||
[rn/touchable-opacity {:style styles/delete-icon-container
|
||||
:on-press #(re-frame/dispatch [:wallet-connect-legacy/disconnect session])}
|
||||
|
||||
[icons/icon :icons/delete {:width 20
|
||||
:height 20
|
||||
:container-style {:elevation 3}
|
||||
:color colors/red}]]
|
||||
|
||||
(when selected-account ;; The account might not be available in theory, if deleted
|
||||
[rn/view {:style (styles/selected-account-container (:color selected-account))}
|
||||
[rn/text {:style styles/selected-account} (:name selected-account)]])]]]]))
|
||||
|
||||
(defn views []
|
||||
(let [legacy-sessions @(re-frame/subscribe [:wallet-connect-legacy/sessions])]
|
||||
[rn/view {:margin-top 10}
|
||||
(doall (map print-session-info legacy-sessions))]))
|
|
@ -3,6 +3,7 @@
|
|||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.i18n.i18n :as i18n]
|
||||
[status-im.utils.utils :as status.utils]
|
||||
[status-im.utils.security]
|
||||
[quo.design-system.colors :as colors]
|
||||
[quo.core :as quo]
|
||||
|
@ -81,7 +82,8 @@
|
|||
{:keys [peerMeta]} (first params)
|
||||
{:keys [accounts]} (if (= wc-version constants/wallet-connect-version-1) (first params) state)
|
||||
{:keys [name icons]} (if (= wc-version constants/wallet-connect-version-1) peerMeta metadata)
|
||||
icon-uri (when (and icons (pos? (count icons))) (first icons))
|
||||
filtered-icons (status.utils/exclude-svg-resources icons)
|
||||
icon-uri (when (and filtered-icons (pos? (count filtered-icons))) (first filtered-icons))
|
||||
address (if (= wc-version constants/wallet-connect-version-1) (first accounts) (last (string/split (first accounts) #":")))
|
||||
account (first (filter #(= (:address %) address) visible-accounts))
|
||||
selected-account-atom (reagent/atom account)]
|
||||
|
@ -89,7 +91,7 @@
|
|||
[react/view (styles/proposal-sheet-header)
|
||||
[quo/text {:weight :bold
|
||||
:size :large}
|
||||
(i18n/label :t/connection-request)]]
|
||||
(i18n/label :t/successful-connection)]]
|
||||
[react/image {:style (styles/dapp-logo)
|
||||
:source {:uri icon-uri}}]
|
||||
[react/view styles/sheet-body-container
|
||||
|
@ -137,7 +139,8 @@
|
|||
{:keys [peerMeta]} (first params)
|
||||
{:keys [accounts]} (if (= wc-version constants/wallet-connect-version-1) (first params) state)
|
||||
{:keys [name icons url]} (if (= wc-version constants/wallet-connect-version-1) peerMeta metadata)
|
||||
icon-uri (when (and icons (pos? (count icons))) (first icons))
|
||||
filtered-icons (status-im.utils.utils/exclude-svg-resources icons)
|
||||
icon-uri (when (and filtered-icons (pos? (count filtered-icons))) (first filtered-icons))
|
||||
address (if (= wc-version constants/wallet-connect-version-1) (first accounts) (last (string/split (first accounts) #":")))
|
||||
account (first (filter #(= (:address %) address) visible-accounts))
|
||||
selected-account-atom (reagent/atom account)]
|
||||
|
@ -167,7 +170,8 @@
|
|||
(defview session-proposal-sheet [{:keys [name icons wc-version]}]
|
||||
(letsubs [visible-accounts [:visible-accounts-without-watch-only]
|
||||
dapps-account [:dapps-account]]
|
||||
(let [icon-uri (when (and icons (> (count icons) 0)) (first icons))
|
||||
(let [filtered-icons (status-im.utils.utils/exclude-svg-resources icons)
|
||||
icon-uri (when (and filtered-icons (> (count filtered-icons) 0)) (first filtered-icons))
|
||||
selected-account-atom (reagent/atom dapps-account)]
|
||||
[react/view (styles/proposal-sheet-container)
|
||||
[react/view (styles/proposal-sheet-header)
|
||||
|
|
|
@ -131,3 +131,9 @@
|
|||
(defn safe-replace [s m r]
|
||||
(when (string? s)
|
||||
(string/replace s m r)))
|
||||
|
||||
(defn svg? [some-string]
|
||||
(string/ends-with? some-string ".svg"))
|
||||
|
||||
(defn exclude-svg-resources [lst]
|
||||
(remove svg? lst))
|
||||
|
|
|
@ -5,4 +5,9 @@
|
|||
(defn create-connector [uri]
|
||||
(WalletConnect.
|
||||
(clj->js {:uri uri
|
||||
:clientMeta config/default-wallet-connect-metadata})))
|
||||
:clientMeta config/default-wallet-connect-metadata})))
|
||||
|
||||
(defn create-connector-from-session [session]
|
||||
(WalletConnect.
|
||||
(clj->js {:session session
|
||||
:clientMeta config/default-wallet-connect-metadata})))
|
||||
|
|
|
@ -8,22 +8,9 @@
|
|||
[status-im.utils.wallet-connect :as wallet-connect]
|
||||
[status-im.browser.core :as browser]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.async-storage.core :as async-storage]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.types :as types]))
|
||||
|
||||
(fx/defn switch-wallet-connect-enabled
|
||||
{:events [:multiaccounts.ui/switch-wallet-connect-enabled]}
|
||||
[{:keys [db]} enabled?]
|
||||
(merge
|
||||
{::async-storage/set! {:wallet-connect-enabled? enabled?}
|
||||
:db (cond-> db
|
||||
(not enabled?)
|
||||
(dissoc :wallet-connect/client)
|
||||
:always
|
||||
(assoc :wallet-connect/enabled? enabled?))}
|
||||
(when enabled? {:wc-2-init nil})))
|
||||
|
||||
(fx/defn proposal-handler
|
||||
{:events [:wallet-connect/proposal]}
|
||||
[{:keys [db] :as cofx} request-event]
|
||||
|
@ -196,13 +183,10 @@
|
|||
(fx/defn pair-session
|
||||
{:events [:wallet-connect/pair]}
|
||||
[{:keys [db]} {:keys [data]}]
|
||||
(let [client (get db :wallet-connect/client)
|
||||
wallet-connect-enabled? (get db :wallet-connect/enabled?)]
|
||||
(merge
|
||||
{:dispatch [:navigate-back]}
|
||||
(when wallet-connect-enabled?
|
||||
{:db (assoc db :wallet-connect/scanned-uri data)
|
||||
:wc-2-pair [client data]}))))
|
||||
(let [client (get db :wallet-connect/client)]
|
||||
{:db (assoc db :wallet-connect/scanned-uri data)
|
||||
:dispatch [:navigate-back]
|
||||
:wc-2-pair [client data]}))
|
||||
|
||||
(fx/defn wallet-connect-client-initate
|
||||
{:events [:wallet-connect/client-init]}
|
||||
|
|
|
@ -7,19 +7,71 @@
|
|||
[status-im.utils.wallet-connect-legacy :as wallet-connect-legacy]
|
||||
[status-im.browser.core :as browser]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.ethereum.json-rpc :as json-rpc]
|
||||
[status-im.utils.types :as types]))
|
||||
|
||||
(defn subscribe-to-session [^js connector]
|
||||
(.on connector "session_request" (fn [err payload]
|
||||
(if err
|
||||
(log/error "session request error" err)
|
||||
(re-frame/dispatch [:wallet-connect-legacy/proposal payload connector]))))
|
||||
(.on connector "disconnect" (fn [err]
|
||||
;; We pull the peer-id from the object we set it on
|
||||
(let [peer-id (or (.-connectedPeerId connector)
|
||||
(.-peerId connector))]
|
||||
(if err
|
||||
(log/error "wallet connect error" err)
|
||||
(re-frame/dispatch [:wallet-connect-legacy/disconnect-by-peer-id peer-id])))))
|
||||
(.on connector "connect" (fn [err payload]
|
||||
(if err
|
||||
(log/error "connect error" err)
|
||||
(let [peer-id (get-in (types/js->clj payload) [:params 0 :peerId])]
|
||||
;; This is extremely ugly. But.
|
||||
;; Above in `disconnect` we don't have access to `peerId`
|
||||
;; since it's not passed in the parameters, and it's cleared
|
||||
;; from the connector object (I think by the library itself)
|
||||
;; so we can't tell which peer-id we want to disconnect, and
|
||||
;; therefore we can't remove it from the dabase.
|
||||
;; So we set it on the connector object, and pull it back in
|
||||
;; the disconnect event. May Rich Hickey have mercy on me.
|
||||
(set! (.. connector -connectedPeerId) peer-id)
|
||||
(re-frame/dispatch [:wallet-connect-legacy/created payload])))))
|
||||
(.on connector "call_request" (fn [err payload]
|
||||
(log/info "CALL REQUEST" (.-connectedPeerId connector))
|
||||
(if err
|
||||
(log/error "call request error" err)
|
||||
(re-frame/dispatch [:wallet-connect-legacy/request-received (types/js->clj payload) connector]))))
|
||||
(.on connector "session_update" (fn [err payload]
|
||||
(if err
|
||||
(log/error "session update error" err)
|
||||
(re-frame/dispatch [:wallet-connect-legacy/update-sessions (types/js->clj payload) connector])))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-subscribe-to-events
|
||||
(fn [^js connector]
|
||||
(.on connector "session_request" (fn [_ payload]
|
||||
(re-frame/dispatch [:wallet-connect-legacy/proposal payload connector])))
|
||||
(.on connector "connect" (fn [_ payload]
|
||||
(re-frame/dispatch [:wallet-connect-legacy/created payload])))
|
||||
(.on connector "call_request" (fn [_ payload]
|
||||
(re-frame/dispatch [:wallet-connect-legacy/request-received (types/js->clj payload) connector])))
|
||||
(.on connector "session_update" (fn [_ payload]
|
||||
(re-frame/dispatch [:wallet-connect-legacy/update-sessions (types/js->clj payload) connector])))))
|
||||
subscribe-to-session)
|
||||
|
||||
(re-frame/reg-fx
|
||||
:initialize-wc-sessions
|
||||
(fn [[chain-id sessions]]
|
||||
(let [clj-sessions
|
||||
(doall
|
||||
(map
|
||||
(fn [^js session]
|
||||
(let [connector (wallet-connect-legacy/create-connector-from-session session)]
|
||||
;; Update session so we are sure it's on the same network
|
||||
(.updateSession connector (clj->js {:chainId chain-id
|
||||
:accounts (.-accounts session)}))
|
||||
;; Set the peerId
|
||||
(set! (.. connector -connectedPeerId) (.-peerId session))
|
||||
(subscribe-to-session connector)
|
||||
{:wc-version constants/wallet-connect-version-1
|
||||
:params [{:peerId (.-peerId session)
|
||||
:peerMeta (types/js->clj (.-peerMeta session))
|
||||
:chainId (.-chainId session)
|
||||
:accounts (types/js->clj (.-accounts session))}]
|
||||
:connector connector}))
|
||||
sessions))]
|
||||
(re-frame/dispatch [::subscribed-to-multiple-sessions clj-sessions]))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-approve-session
|
||||
|
@ -31,6 +83,21 @@
|
|||
(fn [^js connector]
|
||||
(.rejectSession connector)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-reject-request
|
||||
(fn [[^js connector request-id message]]
|
||||
(.rejectRequest connector (clj->js {:id request-id :error {:message message}}))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-clean-up-sessions
|
||||
(fn [^js connectors]
|
||||
(doseq [^js connector connectors]
|
||||
(.off connector "session_request")
|
||||
(.off connector "disconnect")
|
||||
(.off connector "connect")
|
||||
(.off connector "call_request")
|
||||
(.off connector "session_update"))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-update-session
|
||||
(fn [[^js connector chain-id address]]
|
||||
|
@ -39,8 +106,16 @@
|
|||
(re-frame/reg-fx
|
||||
:wc-1-kill-session
|
||||
(fn [^js connector]
|
||||
(log/debug "Kill wc session")
|
||||
(.killSession connector)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-kill-sessions
|
||||
(fn [^js connectors]
|
||||
(log/debug "Kill wc sessions")
|
||||
(doseq [connector connectors]
|
||||
(.killSession connector))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:wc-1-approve-request
|
||||
(fn [[^js connector response]]
|
||||
|
@ -59,25 +134,45 @@
|
|||
{:db (assoc db :wallet-connect-legacy/proposal-connector connector :wallet-connect-legacy/proposal-chain-id chain-id :wallet-connect/proposal-metadata metadata)
|
||||
:show-wallet-connect-sheet nil}))
|
||||
|
||||
(fx/defn clean-up-sessions
|
||||
{:events [:wallet-connect-legacy/clean-up-sessions]}
|
||||
[{:keys [db]}]
|
||||
(let [connectors (map
|
||||
:connector
|
||||
(:wallet-connect-legacy/sessions db))]
|
||||
{:wc-1-clean-up-sessions connectors}))
|
||||
|
||||
(fx/defn session-connected
|
||||
{:events [:wallet-connect-legacy/created]}
|
||||
[{:keys [db]} session]
|
||||
(let [connector (get db :wallet-connect-legacy/proposal-connector)
|
||||
session (merge (types/js->clj session) {:wc-version constants/wallet-connect-version-1
|
||||
:connector connector})
|
||||
params (first (:params session))
|
||||
metadata (:peerMeta params)
|
||||
account (first (:accounts params))
|
||||
sessions (get db :wallet-connect-legacy/sessions)
|
||||
updated-sessions (if sessions (conj sessions session) [session])]
|
||||
(log/debug "[wallet connect 1.0] session created - " session)
|
||||
session (assoc (types/js->clj session)
|
||||
:wc-version constants/wallet-connect-version-1
|
||||
:connector connector)
|
||||
info (.stringify js/JSON (.-session connector))
|
||||
peer-id (get-in session [:params 0 :peerId])
|
||||
dapp-name (get-in session [:params 0 :peerMeta :name])
|
||||
dapp-url (get-in session [:params 0 :peerMeta :url])]
|
||||
{:show-wallet-connect-success-sheet nil
|
||||
:db (assoc db :wallet-connect/session-connected session :wallet-connect-legacy/sessions updated-sessions)}))
|
||||
:db (-> db
|
||||
(assoc :wallet-connect/session-connected session)
|
||||
(update :wallet-connect-legacy/sessions
|
||||
conj
|
||||
session))
|
||||
::json-rpc/call [{:method "wakuext_addWalletConnectSession"
|
||||
:params [{:id peer-id
|
||||
:info info
|
||||
:dappName dapp-name
|
||||
:dappUrl dapp-url}]
|
||||
:on-success #(log/info "wakuext_addWalletConnectSession success call back , data =>" %)
|
||||
:on-error #(log/error "wakuext_addWalletConnectSession error call back , data =>" %)}]}))
|
||||
|
||||
(fx/defn manage-app
|
||||
{:events [:wallet-connect-legacy/manage-app]}
|
||||
[{:keys [db]} session]
|
||||
{:db (assoc db :wallet-connect/session-managed session :wallet-connect/showing-app-management-sheet? true)
|
||||
{:db (assoc db
|
||||
:wallet-connect/session-managed session
|
||||
:wallet-connect/showing-app-management-sheet? true)
|
||||
:show-wallet-connect-app-management-sheet nil})
|
||||
|
||||
(fx/defn request-handler
|
||||
|
@ -127,28 +222,45 @@
|
|||
:wc-1-update-session [connector chain-id address]
|
||||
:db (assoc db :wallet-connect/showing-app-management-sheet? false)}))
|
||||
|
||||
(fx/defn disconnect-by-peer-id
|
||||
{:events [:wallet-connect-legacy/disconnect-by-peer-id]}
|
||||
[{:keys [db]} peer-id]
|
||||
(let [sessions (get db :wallet-connect-legacy/sessions)]
|
||||
{:db (-> db
|
||||
(assoc :wallet-connect-legacy/sessions (filter #(not= peer-id (get-in % [:params 0 :peerId])) sessions))
|
||||
(dissoc :wallet-connect/session-managed)
|
||||
(dissoc :wallet-connect/session-connected))
|
||||
::json-rpc/call [{:method "wakuext_destroyWalletConnectSession"
|
||||
:params [peer-id]
|
||||
:on-success #(log/debug "wakuext_destroyWalletConnectSession success call back , data ===>" %)
|
||||
:on-error #(log/debug "wakuext_destroyWalletConnectSession error call back , data ===>" %)}]}))
|
||||
|
||||
(fx/defn disconnect-session
|
||||
{:events [:wallet-connect-legacy/disconnect]}
|
||||
[{:keys [db]} session]
|
||||
(let [sessions (get db :wallet-connect-legacy/sessions)
|
||||
connector (:connector session)]
|
||||
connector (:connector session)
|
||||
peer-id (get-in session [:params 0 :peerId])]
|
||||
{:hide-wallet-connect-app-management-sheet nil
|
||||
:hide-wallet-connect-success-sheet nil
|
||||
:wc-1-kill-session connector
|
||||
:db (-> db
|
||||
(assoc :wallet-connect-legacy/sessions (filter #(not= (:connector %) connector) sessions))
|
||||
(dissoc :wallet-connect/session-managed))}))
|
||||
(dissoc :wallet-connect/session-managed)
|
||||
(dissoc :wallet-connect/session-connected))
|
||||
::json-rpc/call [{:method "wakuext_destroyWalletConnectSession"
|
||||
:params [peer-id]
|
||||
:on-success #(log/debug "wakuext_destroyWalletConnectSession success call back , data ===>" %)
|
||||
:on-error #(log/debug "wakuext_destroyWalletConnectSession error call back , data ===>" %)}]}))
|
||||
|
||||
(fx/defn pair-session
|
||||
{:events [:wallet-connect-legacy/pair]}
|
||||
[{:keys [db]} {:keys [data]}]
|
||||
(let [connector (wallet-connect-legacy/create-connector data)
|
||||
wallet-connect-enabled? (get db :wallet-connect/enabled?)]
|
||||
(merge
|
||||
{:dispatch [:navigate-back]}
|
||||
(when wallet-connect-enabled?
|
||||
{:db (assoc db :wallet-connect-legacy/scanned-uri data)
|
||||
:wc-1-subscribe-to-events connector}))))
|
||||
(log/debug "uri received ===> ")
|
||||
(let [connector (wallet-connect-legacy/create-connector data)]
|
||||
{:db (assoc db :wallet-connect-legacy/scanned-uri data)
|
||||
:dispatch [:navigate-back]
|
||||
:wc-1-subscribe-to-events connector}))
|
||||
|
||||
(fx/defn update-sessions
|
||||
{:events [:wallet-connect-legacy/update-sessions]}
|
||||
|
@ -169,6 +281,11 @@
|
|||
{:db (assoc db :wallet-connect-legacy/response response)
|
||||
:wc-1-approve-request [connector response]}))
|
||||
|
||||
(fx/defn wallet-connect-legacy-transaction-error
|
||||
{:events [:wallet-connect-legacy.dapp/transaction-on-error]}
|
||||
[{:keys [db]} message-id connector message]
|
||||
{:wc-1-reject-request [connector message-id message]})
|
||||
|
||||
(fx/defn wallet-connect-legacy-send-async
|
||||
[{:keys [db] :as cofx} {:keys [method params id] :as payload} message-id connector]
|
||||
(let [message? (browser/web3-sign-message? method)
|
||||
|
@ -177,6 +294,7 @@
|
|||
linked-address (get-in session [:params 0 :accounts 0])
|
||||
accounts (get-in cofx [:db :multiaccount/visible-accounts])
|
||||
typed? (and (not= constants/web3-personal-sign method) (not= constants/web3-eth-sign method))]
|
||||
|
||||
(if (or message? (= constants/web3-send-transaction method))
|
||||
(let [[address data] (cond (and (= method constants/web3-keycard-sign-typed-data)
|
||||
(not (vector? params)))
|
||||
|
@ -211,3 +329,26 @@
|
|||
[{:keys [db] :as cofx} payload connector]
|
||||
(let [{:keys [id]} payload]
|
||||
(wallet-connect-legacy-send-async-read-only cofx payload id connector)))
|
||||
|
||||
(fx/defn subscribed-to-multiple-sessions
|
||||
{:events [::subscribed-to-multiple-sessions]}
|
||||
[{:keys [db]} sessions]
|
||||
{:db (assoc db :wallet-connect-legacy/sessions sessions)})
|
||||
|
||||
(fx/defn sync-app-db-with-wc-sessions
|
||||
{:events [:sync-wallet-connect-app-sessions]}
|
||||
[{:keys [db]} session-data]
|
||||
(let [chain-id (get-in db [:networks/networks (:networks/current-network db) :config :NetworkId])
|
||||
sessions (->> session-data
|
||||
(map :info)
|
||||
(map js/JSON.parse)
|
||||
(filter #(.-connected %)))] ; filter out non-connected-sessions
|
||||
(when chain-id
|
||||
{:initialize-wc-sessions [chain-id sessions]})))
|
||||
|
||||
(fx/defn get-connector-session-from-db
|
||||
{:events [:get-connector-session-from-db]}
|
||||
[_]
|
||||
{::json-rpc/call [{:method "wakuext_getWalletConnectSession"
|
||||
:on-success #(re-frame/dispatch [:sync-wallet-connect-app-sessions %])
|
||||
:on-error #(log/debug "wakuext_getWalletConnectSession error call back , data ===>" %)}]})
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "v0.104.2",
|
||||
"commit-sha1": "0135cc155baea9f8d61619a109869d1d9cf681c1",
|
||||
"src-sha256": "16phivml5yhayp4hhsrb71i7spd9vm3z7bhy11vbfi9b4vp8nmvb"
|
||||
"version": "v0.105.1",
|
||||
"commit-sha1": "924820c14af829a941744c0de9658485a8599a17",
|
||||
"src-sha256": "1hqdil8bi3ziky9n1aqkcdl1pgis1yknzs8zlpww89xadh39dfxa"
|
||||
}
|
||||
|
|
|
@ -1743,6 +1743,7 @@
|
|||
"wallet-manage-app-connections": "Manage app connections",
|
||||
"connection-request": "Connection Request",
|
||||
"disconnect": "Disconnect",
|
||||
"app-connections": "App connections",
|
||||
"new-ui": "New UI",
|
||||
"send-contact-request-message": "To start a chat you need to become contacts",
|
||||
"contact-request": "Contact request",
|
||||
|
@ -1756,8 +1757,9 @@
|
|||
"contact-request-pending": "Pending...",
|
||||
"removed-from-contacts": "Removed from contacts",
|
||||
"mutual-contact-requests": "Mutual contact requests",
|
||||
"pending": "Pending",
|
||||
"negative": "Negative",
|
||||
"positive": "Positive",
|
||||
"public": "Public"
|
||||
"public": "Public",
|
||||
"successful-connection": "Successful Connection",
|
||||
"all-connections": "All Connections"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue