Skip to content

Commit 37be08d

Browse files
committed
Fix permission screen & trailing zeros
status-im/status-go@c15f9e7...b7b7660 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
1 parent 3c4d27b commit 37be08d

File tree

6 files changed

+163
-175
lines changed

6 files changed

+163
-175
lines changed

src/status_im/config.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,5 @@
167167

168168
(def default-kdf-iterations 3200)
169169

170-
(def community-accounts-selection-enabled? (enabled? (get-config :ACCOUNT_SELECTION_ENABLED "0")))
170+
(def community-accounts-selection-enabled? true)
171171
(def fetch-messages-enabled? (enabled? (get-config :FETCH_MESSAGES_ENABLED "1")))

src/status_im/contexts/communities/overview/view.cljs

+60-44
Original file line numberDiff line numberDiff line change
@@ -110,66 +110,82 @@
110110
[rn/view
111111
[quo/icon :i/info {:no-color true}]]])
112112

113+
(defn- network-not-supported
114+
[]
115+
[quo/text (i18n/label :network-not-supported)])
116+
117+
(defn- request-access-button
118+
[id color]
119+
[quo/button
120+
{:on-press (if config/community-accounts-selection-enabled?
121+
#(rf/dispatch [:open-modal :community-account-selection
122+
{:community-id id}])
123+
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
124+
:accessibility-label :show-request-to-join-screen-button
125+
:customization-color color
126+
:icon-left :i/communities}
127+
(i18n/label :t/request-to-join)])
128+
113129
(defn- token-requirements
114-
[{:keys [id color]}]
130+
[{:keys [id color role-permissions?]}]
115131
(let [{:keys [can-request-access?
116-
number-of-hold-tokens tokens
132+
no-member-permission?
133+
tokens
134+
networks-not-supported?
117135
highest-permission-role]} (rf/sub [:community/token-gated-overview id])
118136
highest-role-text
119137
(i18n/label
120138
(communities.utils/role->translation-key highest-permission-role :t/member))]
121-
[rn/view {:style (style/token-gated-container)}
122-
[rn/view
123-
{:style {:padding-horizontal 12
124-
:flex-direction :row
125-
:align-items :center
126-
:justify-content :space-between
127-
:flex 1}}
128-
[quo/text {:weight :medium}
129-
(if can-request-access?
130-
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
131-
(i18n/label :t/you-not-eligible-to-join))]
132-
[info-button]]
133-
(when (pos? number-of-hold-tokens)
139+
(cond
140+
141+
networks-not-supported?
142+
[network-not-supported]
143+
144+
(or (not role-permissions?) no-member-permission?)
145+
[request-access-button id color]
146+
147+
:else
148+
[rn/view {:style (style/token-gated-container)}
149+
[rn/view
150+
{:style {:padding-horizontal 12
151+
:flex-direction :row
152+
:align-items :center
153+
:justify-content :space-between
154+
:flex 1}}
155+
[quo/text {:weight :medium}
156+
(if (and can-request-access? highest-permission-role)
157+
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
158+
(i18n/label :t/you-not-eligible-to-join))]
159+
[info-button]]
134160
[quo/text {:style {:padding-horizontal 12 :padding-bottom 18} :size :paragraph-2}
135161
(if can-request-access?
136-
(i18n/label :t/you-hold-number-of-hold-tokens-of-these
137-
{:number-of-hold-tokens number-of-hold-tokens})
138-
(i18n/label :t/you-must-hold))])
139-
[quo/token-requirement-list
140-
{:tokens tokens
141-
:padding? true}]
142-
[quo/button
143-
{:on-press (if config/community-accounts-selection-enabled?
144-
#(rf/dispatch [:open-modal :community-account-selection
145-
{:community-id id}])
146-
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
147-
:accessibility-label :join-community-button
148-
:customization-color color
149-
:container-style {:margin-horizontal 12 :margin-top 12 :margin-bottom 12}
150-
:disabled? (not can-request-access?)
151-
:icon-left (if can-request-access? :i/unlocked :i/locked)}
152-
(i18n/label :t/join-open-community)]]))
162+
(i18n/label :t/you-hodl)
163+
(i18n/label :t/you-must-hold))]
164+
[quo/token-requirement-list
165+
{:tokens tokens
166+
:padding? true}]
167+
[quo/button
168+
{:on-press (if config/community-accounts-selection-enabled?
169+
#(rf/dispatch [:open-modal :community-account-selection
170+
{:community-id id}])
171+
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
172+
:accessibility-label :join-community-button
173+
:customization-color color
174+
:container-style {:margin-horizontal 12 :margin-top 12 :margin-bottom 12}
175+
:disabled? (not can-request-access?)
176+
:icon-left (if can-request-access? :i/unlocked :i/locked)}
177+
(i18n/label :t/join-open-community)]])))
178+
153179

154180
(defn- join-community
155-
[{:keys [id color joined permissions role-permissions? can-join?] :as community}]
181+
[{:keys [id joined permissions role-permissions? can-join?] :as community}]
156182
(let [pending? (rf/sub [:communities/my-pending-request-to-join id])
157183
access-type (get-access-type (:access permissions))
158184
unknown-access? (= access-type :unknown-access)
159185
invite-only? (= access-type :invite-only)]
160186
[:<>
161187
(when-not (or joined pending? invite-only? unknown-access?)
162-
(if role-permissions?
163-
[token-requirements community]
164-
[quo/button
165-
{:on-press (if config/community-accounts-selection-enabled?
166-
#(rf/dispatch [:open-modal :community-account-selection
167-
{:community-id id}])
168-
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
169-
:accessibility-label :show-request-to-join-screen-button
170-
:customization-color color
171-
:icon-left :i/communities}
172-
(i18n/label :t/request-to-join)]))
188+
[token-requirements community])
173189
(when (not (or pending? role-permissions? can-join?))
174190
[quo/text
175191
{:size :paragraph-2

src/status_im/subs/communities.cljs

+30-46
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(ns status-im.subs.communities
22
(:require
33
[clojure.string :as string]
4-
[legacy.status-im.data-store.communities :as data-store]
54
[legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
65
[re-frame.core :as re-frame]
76
[status-im.constants :as constants]
7+
[status-im.contexts.wallet.common.utils :as wallet.utils]
88
[utils.i18n :as i18n]))
99

1010
(re-frame/reg-sub
@@ -298,58 +298,42 @@
298298
(fn [collapsed-categories [_ community-id]]
299299
(get collapsed-categories community-id)))
300300

301-
(defn- permission-id->permission-value
302-
[token-permissions permission-id]
303-
(get (into {} token-permissions) permission-id))
301+
302+
(defn token-requirement->token
303+
[checking-permissions?
304+
token-images
305+
{:keys [satisfied criteria]}]
306+
(let [sym (:symbol criteria)
307+
amount (:amount criteria)]
308+
{:symbol sym
309+
:sufficient? satisfied
310+
:loading? checking-permissions?
311+
:amount (wallet.utils/remove-trailing-zeroes amount)
312+
:img-src (get token-images sym)}))
304313

305314
(re-frame/reg-sub
306315
:community/token-gated-overview
307316
(fn [[_ community-id]]
308317
[(re-frame/subscribe [:communities/community community-id])])
309-
(fn [[{:keys [token-permissions-check token-permissions checking-permissions? token-images]}] _]
310-
(let [can-request-access? (:satisfied token-permissions-check)
311-
highest-permission-role
312-
(when can-request-access?
313-
(->> token-permissions-check
314-
:permissions
315-
(reduce-kv
316-
(fn [highest-permission-role permission-id {:keys [criteria]}]
317-
(if-let [permission-type
318-
(and (first criteria)
319-
(some #{(:type (permission-id->permission-value token-permissions
320-
permission-id))}
321-
constants/community-role-permissions))]
322-
(if highest-permission-role
323-
(min highest-permission-role permission-type)
324-
permission-type)
325-
highest-permission-role))
326-
nil)))
327-
highest-permission-role (if (and can-request-access? (nil? highest-permission-role))
328-
constants/community-token-permission-become-member
329-
highest-permission-role)]
318+
(fn [[{:keys [token-permissions-check checking-permissions? token-images]}] _]
319+
(let [highest-role (:highestRole token-permissions-check)
320+
networks-not-supported? (:networksNotSupported token-permissions-check)
321+
lowest-role (last (:roles token-permissions-check))
322+
highest-permission-role (:type highest-role)
323+
can-request-access? (and (boolean highest-permission-role) (not networks-not-supported?))]
330324
{:can-request-access? can-request-access?
331325
:highest-permission-role highest-permission-role
332-
:number-of-hold-tokens (reduce
333-
(fn [acc [_ {:keys [criteria]}]]
334-
(reduce #(+ %1 (if %2 1 0)) acc criteria))
335-
0
336-
(:permissions token-permissions-check))
337-
:tokens (->>
338-
token-permissions
339-
(filter (fn [[_ permission]]
340-
(data-store/role-permission? permission)))
341-
(map (fn [[perm-key {:keys [token_criteria]}]]
342-
(let [check-criteria (get-in token-permissions-check
343-
[:permissions perm-key :criteria])]
344-
(map
345-
(fn [{sym :symbol amount :amount} sufficient?]
346-
{:symbol sym
347-
:sufficient? (when (seq check-criteria) sufficient?)
348-
:loading? checking-permissions?
349-
:amount amount
350-
:img-src (get token-images sym)})
351-
token_criteria
352-
(or check-criteria token_criteria))))))})))
326+
:networks-not-supported? networks-not-supported?
327+
:no-member-permission? (and highest-permission-role
328+
(not (-> token-permissions-check :highestRole :criteria)))
329+
:tokens (map (fn [{:keys [tokenRequirement]}]
330+
(map
331+
(partial token-requirement->token
332+
checking-permissions?
333+
token-images)
334+
tokenRequirement))
335+
(or (:criteria highest-role)
336+
(:criteria lowest-role)))})))
353337

354338
(re-frame/reg-sub
355339
:community/images

0 commit comments

Comments
 (0)