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.
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
is expected to be a valid re-frame event vector, and the event will be
dispatched with the transformed response conj'ed at the end.
called with the transformed response and id (request-id) as the argument.
When a vector, it is expected to be a valid re-frame event vector, and the event
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
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.
Default: nil.
@ -56,14 +58,14 @@
Note that on-error is optional, but if not provided, a default implementation
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 [])
on-error (or on-error
(on-error-retry call arg)
#(log/warn :json-rpc/error method :error % :params params))]
(native-module/call-private-rpc
(transforms/clj->json {:jsonrpc "2.0"
:id 1
:id (or id 1)
:method method
:params params})
(fn [raw-response]
@ -79,12 +81,13 @@
(rf/dispatch (conj on-error error))
(on-error error)))
(when on-success
(let [result (if js-response
(.-result response-js)
(transforms/js->clj (.-result response-js)))]
(let [result (if js-response
(.-result response-js)
(transforms/js->clj (.-result response-js)))
request-id (.-id response-js)]
(if (vector? on-success)
(rf/dispatch (conj on-success result))
(on-success result)))))))))))
(rf/dispatch (conj on-success result request-id))
(on-success result request-id)))))))))))
(re-frame/reg-fx
:json-rpc/call

View File

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