💾 Persist Wallet Connect sessions (#20351)
* 💾 Add persist WC session events * ✅ Persistence works - Also moved closing of modal to approval stage
This commit is contained in:
parent
f133cd3d5d
commit
e9f98fcf85
|
@ -110,7 +110,7 @@
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet-connect/close-session-request
|
:wallet-connect/close-session-request
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
{:fx [[:dispatch [:navigate-back]]
|
{:fx [[:dispatch [:dismiss-modal :screen/wallet.wallet-connect-session-proposal]]
|
||||||
[:dispatch [:wallet-connect/reset-current-session-request]]]}))
|
[:dispatch [:wallet-connect/reset-current-session-request]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
|
@ -151,13 +151,20 @@
|
||||||
:supported-namespaces supported-namespaces
|
:supported-namespaces supported-namespaces
|
||||||
:on-success (fn []
|
:on-success (fn []
|
||||||
(log/info "Wallet Connect session approved")
|
(log/info "Wallet Connect session approved")
|
||||||
(rf/dispatch [:wallet-connect/reset-current-session-proposal]))
|
(let [metadata (-> current-proposal :params :proposer :metadata)]
|
||||||
|
(rf/dispatch [:wallet-connect/reset-current-session-proposal])
|
||||||
|
(rf/dispatch [:wallet-connect/persist-session
|
||||||
|
{:id (:id current-proposal)
|
||||||
|
:dapp-name (:name metadata)
|
||||||
|
:dapp-url (:url metadata)
|
||||||
|
:session-info current-proposal}])))
|
||||||
:on-fail (fn [error]
|
:on-fail (fn [error]
|
||||||
(log/error "Wallet Connect session approval failed"
|
(log/error "Wallet Connect session approval failed"
|
||||||
{:error error
|
{:error error
|
||||||
:event :wallet-connect/approve-session})
|
:event :wallet-connect/approve-session})
|
||||||
(rf/dispatch
|
(rf/dispatch
|
||||||
[:wallet-connect/reset-current-session-proposal]))}]]})))
|
[:wallet-connect/reset-current-session-proposal]))}]
|
||||||
|
[:dispatch [:dismiss-modal :screen/wallet.wallet-connect-session-proposal]]]})))
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet-connect/on-scan-connection
|
:wallet-connect/on-scan-connection
|
||||||
|
@ -185,5 +192,31 @@
|
||||||
{:version version})}]]]}
|
{:version version})}]]]}
|
||||||
|
|
||||||
:else
|
:else
|
||||||
{:fx [[:dispatch [:wallet-connect/pair scanned-text]]
|
{:fx [[:dispatch [:wallet-connect/pair scanned-text]]]}))))
|
||||||
[:dispatch [:dismiss-modal :screen/wallet.wallet-connect-session-proposal]]]}))))
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:wallet-connect/persist-session
|
||||||
|
(fn [_ [{:keys [id dapp-name dapp-url session-info]}]]
|
||||||
|
{:fx [[:json-rpc/call
|
||||||
|
[{:method "wakuext_addWalletConnectSession"
|
||||||
|
:params [{:id (str id)
|
||||||
|
:dappName dapp-name
|
||||||
|
:dappUrl dapp-url
|
||||||
|
:info (-> session-info
|
||||||
|
clj->js
|
||||||
|
js/JSON.stringify)}]
|
||||||
|
:on-success #(log/info "Wallet Connect session persisted")
|
||||||
|
:on-error #(log/info "Wallet Connect session persistence failed" %)}]]]}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:wallet-connect/fetch-persisted-sessions-success
|
||||||
|
(fn [{:keys [db]} [sessions]]
|
||||||
|
{:db (assoc db :wallet-connect/persisted-sessions sessions)}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:wallet-connect/fetch-persisted-sessions
|
||||||
|
(fn [_ _]
|
||||||
|
{:fx [[:json-rpc/call
|
||||||
|
[{:method "wakuext_getWalletConnectSession"
|
||||||
|
:on-success [:wallet-connect/fetch-persisted-sessions-success]
|
||||||
|
:on-error #(log/info "Wallet Connect fetch persisted sessions failed")}]]]}))
|
||||||
|
|
Loading…
Reference in New Issue