fix role is not updated correctly when unselecting accounts (#19636)

This commit is contained in:
Parvesh Monu 2024-04-17 16:21:32 +05:30 committed by GitHub
parent c0be0b7670
commit 8807a63989
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 29 deletions

View File

@ -40,13 +40,15 @@
params: sequence - A positional sequence of zero or more arguments. params: sequence - A positional sequence of zero or more arguments.
on-success/on-error: function/vector (optional) - When a function, it will be on-success/on-error: function/vector (optional) - When a function, it will be
called with the transformed response as the sole argument. When a vector, it called with the transformed response and id (request-id) as the argument.
is expected to be a valid re-frame event vector, and the event will be When a vector, it is expected to be a valid re-frame event vector, and the event
dispatched with the transformed response conj'ed at the end. will be dispatched with the transformed response and id conj'ed at the end.
js-response: boolean - When non-nil, the successful response will not be js-response: boolean - When non-nil, the successful response will not be
recursively converted to Clojure data structures. Default: nil. recursively converted to Clojure data structures. Default: nil.
id: (optional) - id passed while making the RPC call will be returned in response
number-of-retries: integer - The maximum number of retries in case of failure. number-of-retries: integer - The maximum number of retries in case of failure.
Default: nil. Default: nil.
@ -56,14 +58,14 @@
Note that on-error is optional, but if not provided, a default implementation Note that on-error is optional, but if not provided, a default implementation
will be used. will be used.
" "
[{:keys [method params on-success on-error js-response] :as arg}] [{:keys [method params on-success on-error js-response id] :as arg}]
(let [params (or params []) (let [params (or params [])
on-error (or on-error on-error (or on-error
(on-error-retry call arg) (on-error-retry call arg)
#(log/warn :json-rpc/error method :error % :params params))] #(log/warn :json-rpc/error method :error % :params params))]
(native-module/call-private-rpc (native-module/call-private-rpc
(transforms/clj->json {:jsonrpc "2.0" (transforms/clj->json {:jsonrpc "2.0"
:id 1 :id (or id 1)
:method method :method method
:params params}) :params params})
(fn [raw-response] (fn [raw-response]
@ -79,12 +81,13 @@
(rf/dispatch (conj on-error error)) (rf/dispatch (conj on-error error))
(on-error error))) (on-error error)))
(when on-success (when on-success
(let [result (if js-response (let [result (if js-response
(.-result response-js) (.-result response-js)
(transforms/js->clj (.-result response-js)))] (transforms/js->clj (.-result response-js)))
request-id (.-id response-js)]
(if (vector? on-success) (if (vector? on-success)
(rf/dispatch (conj on-success result)) (rf/dispatch (conj on-success result request-id))
(on-success result))))))))))) (on-success result request-id)))))))))))
(re-frame/reg-fx (re-frame/reg-fx
:json-rpc/call :json-rpc/call

View File

@ -73,19 +73,25 @@
(defn check-permissions-to-join-for-selection (defn check-permissions-to-join-for-selection
[{:keys [db]} [community-id addresses]] [{:keys [db]} [community-id addresses]]
(if (empty? addresses) (let [request-id (rand-int 10000000)]
;; When there are no addresses we can't just check permissions, otherwise (if (empty? addresses)
;; status-go will consider all possible addresses and the user will see the ;; When there are no addresses we can't just check permissions, otherwise
;; incorrect highest permission role. ;; status-go will consider all possible addresses and the user will see the
{:db (update db :communities/permissions-checks-for-selection dissoc community-id)} ;; incorrect highest permission role.
{:db (assoc-in db [:communities/permissions-checks-for-selection community-id :checking?] true) {:db (update db :communities/permissions-checks-for-selection dissoc community-id)}
:fx [[:json-rpc/call {:db (update-in db
[{:method :wakuext_checkPermissionsToJoinCommunity [:communities/permissions-checks-for-selection community-id]
:params [{:communityId community-id :addresses addresses}] assoc
:on-success [:communities/check-permissions-to-join-during-selection-success :checking? true
community-id] :latest-request-id request-id)
:on-error [:communities/check-permissions-to-join-during-selection-failure :fx [[:json-rpc/call
community-id addresses]}]]]})) [{:method :wakuext_checkPermissionsToJoinCommunity
:params [{:communityId community-id :addresses addresses}]
:id request-id
:on-success [:communities/check-permissions-to-join-during-selection-success
community-id]
:on-error [:communities/check-permissions-to-join-during-selection-failure
community-id addresses]}]]]})))
;; This event should be used to check permissions temporarily because it won't ;; This event should be used to check permissions temporarily because it won't
;; mutate the state `:communities/permissions-check` (used by many other ;; mutate the state `:communities/permissions-check` (used by many other
@ -94,12 +100,14 @@
check-permissions-to-join-for-selection) check-permissions-to-join-for-selection)
(rf/reg-event-fx :communities/check-permissions-to-join-during-selection-success (rf/reg-event-fx :communities/check-permissions-to-join-during-selection-success
(fn [{:keys [db]} [community-id result]] (fn [{:keys [db]} [community-id result request-id]]
{:db (assoc-in db (when (= (get-in db [:communities/permissions-checks-for-selection community-id :latest-request-id])
[:communities/permissions-checks-for-selection community-id] request-id)
{:checking? false {:db (assoc-in db
:based-on-client-selection? true [:communities/permissions-checks-for-selection community-id]
:check result})})) {:checking? false
:based-on-client-selection? true
:check result})})))
(rf/reg-event-fx :communities/check-permissions-to-join-during-selection-failure (rf/reg-event-fx :communities/check-permissions-to-join-during-selection-failure
(fn [_ [community-id addresses error]] (fn [_ [community-id addresses error]]