Skip to content

Commit

Permalink
fix: adapted to latest standard-auth changes
Browse files Browse the repository at this point in the history
  • Loading branch information
clauxx committed Jan 6, 2025
1 parent d5b3e24 commit 7f300d3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
[:auth-button-label {:optional true} [:maybe string?]]
[:auth-button-icon-left {:optional true} [:maybe keyword?]]
[:blur? {:optional true} [:maybe boolean?]]
[:theme {:optional true} [:maybe :schema.common/theme]]
[:keycard-supported? {:optional true} [:maybe boolean?]]])
[:theme {:optional true} [:maybe :schema.common/theme]]])

(def ?authorize
[:=>
Expand Down
12 changes: 12 additions & 0 deletions src/status_im/contexts/keycard/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@
args
:on-success (get-on-success args)
:on-failure (get-on-failure args)))

(defn keycard-address?
[keypairs address]
(some (fn [keypair]
(->> keypair
:keycards
(some (fn [keycard]
(-> keycard
:accounts-addresses
set
(contains? address))))))
(vals keypairs)))
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [re-frame.core :as rf]
[react-native.wallet-connect :as wallet-connect]
[status-im.constants :as constants]
[status-im.contexts.keycard.utils :as keycard]
[status-im.contexts.wallet.wallet-connect.utils.data-store :as
data-store]
[status-im.contexts.wallet.wallet-connect.utils.uri :as uri]
Expand All @@ -10,25 +11,13 @@
[utils.i18n :as i18n]
[utils.transforms :as transforms]))

(defn- keycard-account?
[keypairs address]
(some (fn [keypair]
(->> keypair
:keycards
(some (fn [keycard]
(-> keycard
:accounts-addresses
set
(contains? address))))))
(vals keypairs)))

(rf/reg-event-fx
:wallet-connect/authorized-signing
(fn [{:keys [db]} [password]]
(let [prepared-hash (get-in db [:wallet-connect/current-request :prepared-hash])
address (get-in db [:wallet-connect/current-request :address])
keycard-sign? (-> (get-in db [:wallet :keypairs])
(keycard-account? address))
(keycard/keycard-address? address))
on-success #(rf/dispatch [:wallet-connect/respond (hex/prefix-hex %)])
on-fail #(rf/dispatch [:wallet-connect/on-sign-error %])]
(if keycard-sign?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
[{:keys [warning-label slide-button-text error-state]} & children]
(let [{:keys [customization-color]} (rf/sub [:wallet-connect/current-request-account-details])
offline? (rf/sub [:network/offline?])
theme (quo.theme/use-theme)]
theme (quo.theme/use-theme)
sign-on-keycard? (rf/sub [:wallet-connect/sign-on-keycard?])]
[:<>
(when (or offline? error-state)
[quo/alert-banner
Expand All @@ -45,10 +46,11 @@
[standard-authentication/slide-button
{:size :size-48
:track-text slide-button-text
:keycard-supported? true
:disabled? (or offline? error-state)
:customization-color customization-color
:on-auth-success on-auth-success
:on-complete (when sign-on-keycard?
#(on-auth-success ""))
:auth-button-label (i18n/label :t/confirm)}]]
[rn/view {:style style/warning-container}
[quo/text
Expand Down
8 changes: 8 additions & 0 deletions src/status_im/subs/wallet/dapps/requests.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns status-im.subs.wallet.dapps.requests
(:require [re-frame.core :as rf]
[status-im.contexts.keycard.utils :as keycard]
[status-im.contexts.wallet.common.utils :as wallet-utils]
[status-im.contexts.wallet.wallet-connect.utils.data-store :as
data-store]
Expand Down Expand Up @@ -59,3 +60,10 @@
:wallet-connect/typed-data-request?
:<- [:wallet-connect/current-request-method]
typed-data/typed-data-request?)

(rf/reg-sub
:wallet-connect/sign-on-keycard?
:<- [:wallet/keypairs]
:<- [:wallet-connect/current-request-address]
(fn [[keypairs address]]
(keycard/keycard-address? keypairs address)))

0 comments on commit 7f300d3

Please sign in to comment.