Compare commits

...
Author SHA1 Message Date
Andrea Maria Piana 009ba8f511 wip 2024-02-13 08:43:20 +00:00
Andrea Maria Piana 4fad90dfbc Fix permission screen & trailing zeros
https://github.com/status-im/status-go/compare/c15f9e73...b7b7660a

There were a few issues with the permission screen:
1) Wrong permission was displayed when able to join
2) If not able to join, we were showing both admin/member permissions
3) Trailing zeros in token amount
2024-02-13 08:18:26 +00:00
8 changed files with 207 additions and 207 deletions
+1 -1
View File
@@ -167,5 +167,5 @@
(def default-kdf-iterations 3200)
(def community-accounts-selection-enabled? (enabled? (get-config :ACCOUNT_SELECTION_ENABLED "0")))
(def community-accounts-selection-enabled? true)
(def fetch-messages-enabled? (enabled? (get-config :FETCH_MESSAGES_ENABLED "1")))
@@ -10,16 +10,16 @@
{:db (-> db
(assoc-in [:community-channels-permissions community-id]
(data-store/rpc->channel-permissions (:channels response)))
(assoc-in [:communities community-id :checking-all-channels-permissions?] false))}))
(assoc-in [:communities/channel-permissions-check community-id] false))}))
(rf/reg-event-fx :communities/check-all-community-channels-permissions-failed
(fn [{:keys [db]} [community-id]]
{:db (assoc-in db [:communities community-id :checking-all-channels-permissions?] false)}))
{:db (assoc-in db [:communities/channel-permissions-check community-id] false)}))
(rf/reg-event-fx :communities/check-all-community-channels-permissions
(fn [{:keys [db]} [community-id]]
(when (get-in db [:communities community-id])
{:db (assoc-in db [:communities community-id :checking-all-channels-permissions?] true)
{:db (assoc-in db [:communities/channel-permissions-check community-id] true)
:fx [[:json-rpc/call
[{:method "wakuext_checkAllCommunityChannelsPermissions"
:params [{:CommunityID community-id}]
@@ -38,21 +38,19 @@
(let [token-permissions-check (cond-> result
based-on-client-selection? (assoc :based-on-client-selection? true))]
{:db (-> db
(assoc-in [:communities community-id :checking-permissions?] false)
(assoc-in [:communities community-id :token-permissions-check]
token-permissions-check))})))
(assoc-in [:communities/permissions-check community-id] {:checking? false
:check token-permissions-check})
)})))
(rf/reg-event-fx :communities/check-permissions-to-join-community-failed
(fn [{:keys [db]} [community-id]]
{:db (assoc-in db [:communities community-id :checking-permissions?] false)}))
{:db (assoc-in db [:communities/permissions-check community-id :checking?] false)}))
(rf/reg-event-fx :communities/check-permissions-to-join-community
(fn [{:keys [db]} [community-id addresses based-on-client-selection?]]
(when-let [community (get-in db [:communities community-id])]
(when-not (:checking-permissions? community)
{:db (-> db
(assoc-in [:communities community-id :checking-permissions?] true)
(assoc-in [:communities community-id :can-request-access?] false))
{:db (assoc-in db [:communities/permissions-check community-id :checking?] true)
:json-rpc/call [{:method "wakuext_checkPermissionsToJoinCommunity"
:params [(cond-> {:communityId community-id}
addresses
@@ -110,66 +110,82 @@
[rn/view
[quo/icon :i/info {:no-color true}]]])
(defn- network-not-supported
[]
[quo/text (i18n/label :network-not-supported)])
(defn- request-access-button
[id color]
[quo/button
{:on-press (if config/community-accounts-selection-enabled?
#(rf/dispatch [:open-modal :community-account-selection
{:community-id id}])
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
:accessibility-label :show-request-to-join-screen-button
:customization-color color
:icon-left :i/communities}
(i18n/label :t/request-to-join)])
(defn- token-requirements
[{:keys [id color]}]
[{:keys [id color role-permissions?]}]
(let [{:keys [can-request-access?
number-of-hold-tokens tokens
no-member-permission?
tokens
networks-not-supported?
highest-permission-role]} (rf/sub [:community/token-gated-overview id])
highest-role-text
(i18n/label
(communities.utils/role->translation-key highest-permission-role :t/member))]
[rn/view {:style (style/token-gated-container)}
[rn/view
{:style {:padding-horizontal 12
:flex-direction :row
:align-items :center
:justify-content :space-between
:flex 1}}
[quo/text {:weight :medium}
(if can-request-access?
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
(i18n/label :t/you-not-eligible-to-join))]
[info-button]]
(when (pos? number-of-hold-tokens)
(cond
networks-not-supported?
[network-not-supported]
(or (not role-permissions?) no-member-permission?)
[request-access-button id color]
:else
[rn/view {:style (style/token-gated-container)}
[rn/view
{:style {:padding-horizontal 12
:flex-direction :row
:align-items :center
:justify-content :space-between
:flex 1}}
[quo/text {:weight :medium}
(if (and can-request-access? highest-permission-role)
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
(i18n/label :t/you-not-eligible-to-join))]
[info-button]]
[quo/text {:style {:padding-horizontal 12 :padding-bottom 18} :size :paragraph-2}
(if can-request-access?
(i18n/label :t/you-hold-number-of-hold-tokens-of-these
{:number-of-hold-tokens number-of-hold-tokens})
(i18n/label :t/you-must-hold))])
[quo/token-requirement-list
{:tokens tokens
:padding? true}]
[quo/button
{:on-press (if config/community-accounts-selection-enabled?
#(rf/dispatch [:open-modal :community-account-selection
{:community-id id}])
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
:accessibility-label :join-community-button
:customization-color color
:container-style {:margin-horizontal 12 :margin-top 12 :margin-bottom 12}
:disabled? (not can-request-access?)
:icon-left (if can-request-access? :i/unlocked :i/locked)}
(i18n/label :t/join-open-community)]]))
(i18n/label :t/you-hodl)
(i18n/label :t/you-must-hold))]
[quo/token-requirement-list
{:tokens tokens
:padding? true}]
[quo/button
{:on-press (if config/community-accounts-selection-enabled?
#(rf/dispatch [:open-modal :community-account-selection
{:community-id id}])
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
:accessibility-label :join-community-button
:customization-color color
:container-style {:margin-horizontal 12 :margin-top 12 :margin-bottom 12}
:disabled? (not can-request-access?)
:icon-left (if can-request-access? :i/unlocked :i/locked)}
(i18n/label :t/join-open-community)]])))
(defn- join-community
[{:keys [id color joined permissions role-permissions? can-join?] :as community}]
[{:keys [id joined permissions role-permissions? can-join?] :as community}]
(let [pending? (rf/sub [:communities/my-pending-request-to-join id])
access-type (get-access-type (:access permissions))
unknown-access? (= access-type :unknown-access)
invite-only? (= access-type :invite-only)]
[:<>
(when-not (or joined pending? invite-only? unknown-access?)
(if role-permissions?
[token-requirements community]
[quo/button
{:on-press (if config/community-accounts-selection-enabled?
#(rf/dispatch [:open-modal :community-account-selection
{:community-id id}])
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
:accessibility-label :show-request-to-join-screen-button
:customization-color color
:icon-left :i/communities}
(i18n/label :t/request-to-join)]))
[token-requirements community])
(when (not (or pending? role-permissions? can-join?))
[quo/text
{:size :paragraph-2
@@ -237,14 +253,16 @@
:description-accessibility-label :community-description}])
(defn- community-content
[{:keys [id]}]
[id]
(rf/dispatch [:communities/check-all-community-channels-permissions id])
(fn [{:keys [name description joined spectated images tags color id membership-permissions?]
:as community}
{:keys [on-category-layout
(fn [id {:keys [on-category-layout
collapsed?
on-first-channel-height-changed]}]
(let [joined-or-spectated (or joined spectated)
on-first-channel-height-changed] :as something}]
(let [{:keys [name description joined spectated images tags color id membership-permissions?]
:as community}
(rf/sub [:communities/community id])
joined-or-spectated (or joined spectated)
chats-by-category (rf/sub [:communities/categorized-channels id])]
[:<>
[rn/view {:style style/community-content-container}
@@ -295,20 +313,24 @@
(and (>= scroll-height (+ height first-channel-height))
category)))))
(defn- community-scroll-page
[{:keys [joined]}]
(let [scroll-height (reagent/atom 0)
categories-heights (reagent/atom {})
first-channel-height (reagent/atom 0)
;; We track the initial value of joined
;; as we open the page to avoid switching
;; from not collapsed to collapsed if the
;; user is on this page
initial-joined? joined]
(fn [{:keys [id name images] :as community}]
(defn- community-scroll-page
[id initial-joined? name images]
(let [scroll-height (reagent/atom 0)
categories-heights (reagent/atom {})
first-channel-height (reagent/atom 0)
on-category-layout (partial add-category-height categories-heights)
on-first-channel-height-changed (fn [height categories]
(swap! categories-heights select-keys categories)
(reset! first-channel-height height))]
(fn [id joined name images]
(let [cover {:uri (get-in images [:banner :uri])}
logo {:uri (get-in images [:thumbnail :uri])}
collapsed? (and initial-joined? (:joined community))
collapsed? (and initial-joined? joined)
overlay-shown? (boolean (:sheets (rf/sub [:bottom-sheet])))]
[scroll-page/scroll-page
{:cover-image cover
@@ -331,24 +353,22 @@
@first-channel-height
@categories-heights)}]}
[community-content
community
{:on-category-layout (partial add-category-height categories-heights)
id
{:on-category-layout on-category-layout
:collapsed? collapsed?
:on-first-channel-height-changed
;; Here we set the height of the component and we filter out the categories, as some
;; might have been removed.
(fn [height categories]
(swap! categories-heights select-keys categories)
(reset! first-channel-height height))}]]))))
on-first-channel-height-changed}]]))))
(defn- community-card-page-view
[id]
(let [{:keys [id joined]
(let [{:keys [id joined name images]
:as community} (rf/sub [:communities/community id])]
(when community
(when joined
(rf/dispatch [:activity-center.notifications/dismiss-community-overview id]))
[community-scroll-page community])))
[community-scroll-page id joined name images])))
(defn view
[id]
+39 -47
View File
@@ -1,10 +1,10 @@
(ns status-im.subs.communities
(:require
[clojure.string :as string]
[legacy.status-im.data-store.communities :as data-store]
[legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
[re-frame.core :as re-frame]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils :as wallet.utils]
[utils.i18n :as i18n]))
(re-frame/reg-sub
@@ -298,58 +298,50 @@
(fn [collapsed-categories [_ community-id]]
(get collapsed-categories community-id)))
(defn- permission-id->permission-value
[token-permissions permission-id]
(get (into {} token-permissions) permission-id))
(defn token-requirement->token
[checking-permissions?
token-images
{:keys [satisfied criteria]}]
(let [sym (:symbol criteria)
amount (:amount criteria)]
{:symbol sym
:sufficient? satisfied
:loading? checking-permissions?
:amount (wallet.utils/remove-trailing-zeroes amount)
:img-src (get token-images sym)}))
(re-frame/reg-sub
:communities/checking-permissions-by-id
:<- [:communities/permissions-check]
(fn [permissions [_ id]]
(get permissions id)))
(re-frame/reg-sub
:community/token-gated-overview
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])])
(fn [[{:keys [token-permissions-check token-permissions checking-permissions? token-images]}] _]
(let [can-request-access? (:satisfied token-permissions-check)
highest-permission-role
(when can-request-access?
(->> token-permissions-check
:permissions
(reduce-kv
(fn [highest-permission-role permission-id {:keys [criteria]}]
(if-let [permission-type
(and (first criteria)
(some #{(:type (permission-id->permission-value token-permissions
permission-id))}
constants/community-role-permissions))]
(if highest-permission-role
(min highest-permission-role permission-type)
permission-type)
highest-permission-role))
nil)))
highest-permission-role (if (and can-request-access? (nil? highest-permission-role))
constants/community-token-permission-become-member
highest-permission-role)]
[(re-frame/subscribe [:communities/community community-id])
(re-frame/subscribe [:communities/checking-permissions-by-id community-id])])
(fn [[{:keys [token-images]}
{:keys [checking? check]}] _]
(let [highest-role (:highestRole check)
networks-not-supported? (:networksNotSupported check)
lowest-role (last (:roles check))
highest-permission-role (:type highest-role)
can-request-access? (and (boolean highest-permission-role) (not networks-not-supported?))]
{:can-request-access? can-request-access?
:highest-permission-role highest-permission-role
:number-of-hold-tokens (reduce
(fn [acc [_ {:keys [criteria]}]]
(reduce #(+ %1 (if %2 1 0)) acc criteria))
0
(:permissions token-permissions-check))
:tokens (->>
token-permissions
(filter (fn [[_ permission]]
(data-store/role-permission? permission)))
(map (fn [[perm-key {:keys [token_criteria]}]]
(let [check-criteria (get-in token-permissions-check
[:permissions perm-key :criteria])]
(map
(fn [{sym :symbol amount :amount} sufficient?]
{:symbol sym
:sufficient? (when (seq check-criteria) sufficient?)
:loading? checking-permissions?
:amount amount
:img-src (get token-images sym)})
token_criteria
(or check-criteria token_criteria))))))})))
:networks-not-supported? networks-not-supported?
:no-member-permission? (and highest-permission-role
(not (-> check :highestRole :criteria)))
:tokens (map (fn [{:keys [tokenRequirement]}]
(map
(partial token-requirement->token
checking?
token-images)
tokenRequirement))
(or (:criteria highest-role)
(:criteria lowest-role)))})))
(re-frame/reg-sub
:community/images
+67 -81
View File
@@ -382,88 +382,74 @@
[sub-name]
(let
[checking-permissions? true
token-image-eth "data:image/jpeg;base64,/9j/2w"
community {:id community-id
:checking-permissions? checking-permissions?
:permissions {:access 3}
:highest-permission-role constants/community-token-permission-become-admin
:token-images {"ETH" token-image-eth}
:token-permissions [[:permission-id-01
{:id "permission-id-01"
:type constants/community-token-permission-can-view-channel
:token_criteria [{:contract_addresses {:5 "0x0"}
:type 1
:symbol "SNT"
:amount "0.002"
:decimals 18}]
:chat_ids [(str community-id
"89f98a1e-6776-4e5f-8626-8ab9f855253f")]}]
[:permission-id-02
{:id "permission-id-02"
:type constants/community-token-permission-become-admin
:token_criteria [{:contract_addresses {:5 "0x0"}
:type 1
:symbol "DAI"
:amount "5.0"
:decimals 18}]
:chat_ids [(str community-id
"89f98a1e-6776-4e5f-8626-8ab9f855253f")]}]
[:permission-id-03
{:id "permission-id-03"
:type constants/community-token-permission-become-member
:token_criteria [{:contract_addresses {:5 "0x0"}
:type 1
:symbol "ETH"
:amount "0.001"
:decimals 18}]}]]
:name "Community super name"
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f"
{:description "x"
:emoji "🎲"
:permissions {:access 1}
:color "#88B0FF"
:name "random"
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
:id "89f98a1e-6776-4e5f-8626-8ab9f855253f"
:position 4
:can-post? false
:members {"0x04" {"roles" [1]}}}
"a076358e-4638-470e-a3fb-584d0a542ce6"
{:description "General channel for the community"
:emoji "🐷 "
:permissions {:access 1}
:color "#4360DF"
:name "general"
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
:id "a076358e-4638-470e-a3fb-584d0a542ce6"
:position 0
:can-post? false
:members {"0x04" {"roles" [1]}}}}
:token-permissions-check {:satisfied true
:permissions
{:a3dd5b6b-d93b-452c-b22a-09a8f42ec566 {:criteria [true false
true]}}
:validCombinations
[{:address "0xd722eaa60dc73e334b588d34ba66a3b27e537783"
:chainIds nil}
{:address "0x738d3146831c5871fa15872b409e8f360e341784"
:chainIds [5 420]}]}
:members {"0x04" {"roles" [1]}}
:can-request-access? false
:outroMessage "bla"
:verified false}]
token-image-eth "data:image/jpeg;base64,/9j/2w"
community {:id community-id
:checking-permissions? checking-permissions?
:permissions {:access 3}
:highest-permission-role constants/community-token-permission-become-admin
:token-images {"ETH" token-image-eth}
:name "Community super name"
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f"
{:description "x"
:emoji "🎲"
:permissions {:access 1}
:color "#88B0FF"
:name "random"
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
:id "89f98a1e-6776-4e5f-8626-8ab9f855253f"
:position 4
:can-post? false
:members {"0x04" {"roles" [1]}}}
"a076358e-4638-470e-a3fb-584d0a542ce6"
{:description "General channel for the community"
:emoji "🐷 "
:permissions {:access 1}
:color "#4360DF"
:name "general"
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
:id "a076358e-4638-470e-a3fb-584d0a542ce6"
:position 0
:can-post? false
:members {"0x04" {"roles" [1]}}}}
:token-permissions-check
{:satisfied true
:highestRole {:type constants/community-token-permission-become-admin
:criteria [{:tokenRequirement [{:satisfied true
:criteria {:contract_addresses
{:5 "0x0"}
:type 1
:symbol "DAI"
:amount "5.0"
:decimals 18}}]}
{:tokenRequirement [{:satisfied false
:criteria {:type 1
:symbol "ETH"
:amount "0.002"
:decimals 18}}]}]}
:permissions
{:a3dd5b6b-d93b-452c-b22a-09a8f42ec566 {:criteria [true false
true]}}
:validCombinations
[{:address "0xd722eaa60dc73e334b588d34ba66a3b27e537783"
:chainIds nil}
{:address "0x738d3146831c5871fa15872b409e8f360e341784"
:chainIds [5 420]}]}
:members {"0x04" {"roles" [1]}}
:can-request-access? false
:outroMessage "bla"
:verified false}]
(swap! rf-db/app-db assoc-in [:communities community-id] community)
(is (match? {:can-request-access? true
:number-of-hold-tokens 2
:tokens [[{:symbol "DAI"
:amount "5.0"
:sufficient? nil
:loading? checking-permissions?}]
[{:symbol "ETH"
:amount "0.001"
:sufficient? nil
:loading? checking-permissions?
:img-src token-image-eth}]]}
(is (match? {:can-request-access? true
:tokens [[{:symbol "DAI"
:amount "5"
:sufficient? true
:loading? checking-permissions?}]
[{:symbol "ETH"
:amount "0.002"
:sufficient? false
:loading? checking-permissions?
:img-src token-image-eth}]]}
(rf/sub [sub-name community-id])))))
(h/deftest-sub :communities/airdrop-account
+2
View File
@@ -148,6 +148,8 @@
(reg-root-key-sub :communities/selected-tab :communities/selected-tab)
(reg-root-key-sub :contract-communities :contract-communities)
(reg-root-key-sub :communities/permissioned-balances :communities/permissioned-balances)
(reg-root-key-sub :communities/permissions-check :communities/permissions-check)
(reg-root-key-sub :communities/channel-permissions-check :communities/channel-permissions-check)
;;activity center
(reg-root-key-sub :activity-center :activity-center)
+3 -3
View File
@@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.174.3",
"commit-sha1": "c15f9e73654ed2f21887af680d7730dec5bec3e3",
"src-sha256": "09jvamavnkii2fikpz2a5d345aspfp5lzlg5lpymz7lyjif4qn1s"
"version": "chore/debug-token-permissions",
"commit-sha1": "b7b7660a534a01099e55ee0e4253f6a9531c7f02",
"src-sha256": "0nrmm3j9z6iwlr32mggd3xl63226drvvhrlrhrkgxcpgrgpixcfj"
}
+2
View File
@@ -2266,6 +2266,8 @@
"you-not-eligible-to-join": "Youre not eligible to join",
"you-hold-number-of-hold-tokens-of-these": "You hold {{number-of-hold-tokens}} of these:",
"addresses-dont-contain-tokens-needed": "These addresses dont contain tokens needed to join",
"you-hodl": "You hodl:",
"network-not-supported": "Networks not supported",
"token-gated-communities": "Token gated communities",
"read-more": "Read more",
"token-gated-communities-info": "Here will be something relevant about this topic. This will help the user get more context and therefore have a better understanding of it.",