Fix permission screen & trailing zeros
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
This commit is contained in:
parent
3c4d27b6ff
commit
37be08d2d7
|
@ -167,5 +167,5 @@
|
||||||
|
|
||||||
(def default-kdf-iterations 3200)
|
(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")))
|
(def fetch-messages-enabled? (enabled? (get-config :FETCH_MESSAGES_ENABLED "1")))
|
||||||
|
|
|
@ -110,14 +110,41 @@
|
||||||
[rn/view
|
[rn/view
|
||||||
[quo/icon :i/info {:no-color true}]]])
|
[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
|
(defn- token-requirements
|
||||||
[{:keys [id color]}]
|
[{:keys [id color role-permissions?]}]
|
||||||
(let [{:keys [can-request-access?
|
(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-permission-role]} (rf/sub [:community/token-gated-overview id])
|
||||||
highest-role-text
|
highest-role-text
|
||||||
(i18n/label
|
(i18n/label
|
||||||
(communities.utils/role->translation-key highest-permission-role :t/member))]
|
(communities.utils/role->translation-key highest-permission-role :t/member))]
|
||||||
|
(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 (style/token-gated-container)}
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style {:padding-horizontal 12
|
{:style {:padding-horizontal 12
|
||||||
|
@ -126,16 +153,14 @@
|
||||||
:justify-content :space-between
|
:justify-content :space-between
|
||||||
:flex 1}}
|
:flex 1}}
|
||||||
[quo/text {:weight :medium}
|
[quo/text {:weight :medium}
|
||||||
(if can-request-access?
|
(if (and can-request-access? highest-permission-role)
|
||||||
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
|
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
|
||||||
(i18n/label :t/you-not-eligible-to-join))]
|
(i18n/label :t/you-not-eligible-to-join))]
|
||||||
[info-button]]
|
[info-button]]
|
||||||
(when (pos? number-of-hold-tokens)
|
|
||||||
[quo/text {:style {:padding-horizontal 12 :padding-bottom 18} :size :paragraph-2}
|
[quo/text {:style {:padding-horizontal 12 :padding-bottom 18} :size :paragraph-2}
|
||||||
(if can-request-access?
|
(if can-request-access?
|
||||||
(i18n/label :t/you-hold-number-of-hold-tokens-of-these
|
(i18n/label :t/you-hodl)
|
||||||
{:number-of-hold-tokens number-of-hold-tokens})
|
(i18n/label :t/you-must-hold))]
|
||||||
(i18n/label :t/you-must-hold))])
|
|
||||||
[quo/token-requirement-list
|
[quo/token-requirement-list
|
||||||
{:tokens tokens
|
{:tokens tokens
|
||||||
:padding? true}]
|
:padding? true}]
|
||||||
|
@ -149,27 +174,18 @@
|
||||||
:container-style {:margin-horizontal 12 :margin-top 12 :margin-bottom 12}
|
:container-style {:margin-horizontal 12 :margin-top 12 :margin-bottom 12}
|
||||||
:disabled? (not can-request-access?)
|
:disabled? (not can-request-access?)
|
||||||
:icon-left (if can-request-access? :i/unlocked :i/locked)}
|
:icon-left (if can-request-access? :i/unlocked :i/locked)}
|
||||||
(i18n/label :t/join-open-community)]]))
|
(i18n/label :t/join-open-community)]])))
|
||||||
|
|
||||||
|
|
||||||
(defn- join-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])
|
(let [pending? (rf/sub [:communities/my-pending-request-to-join id])
|
||||||
access-type (get-access-type (:access permissions))
|
access-type (get-access-type (:access permissions))
|
||||||
unknown-access? (= access-type :unknown-access)
|
unknown-access? (= access-type :unknown-access)
|
||||||
invite-only? (= access-type :invite-only)]
|
invite-only? (= access-type :invite-only)]
|
||||||
[:<>
|
[:<>
|
||||||
(when-not (or joined pending? invite-only? unknown-access?)
|
(when-not (or joined pending? invite-only? unknown-access?)
|
||||||
(if role-permissions?
|
[token-requirements community])
|
||||||
[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)]))
|
|
||||||
(when (not (or pending? role-permissions? can-join?))
|
(when (not (or pending? role-permissions? can-join?))
|
||||||
[quo/text
|
[quo/text
|
||||||
{:size :paragraph-2
|
{:size :paragraph-2
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
(ns status-im.subs.communities
|
(ns status-im.subs.communities
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as string]
|
[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]
|
[legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
|
[status-im.contexts.wallet.common.utils :as wallet.utils]
|
||||||
[utils.i18n :as i18n]))
|
[utils.i18n :as i18n]))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
|
@ -298,58 +298,42 @@
|
||||||
(fn [collapsed-categories [_ community-id]]
|
(fn [collapsed-categories [_ community-id]]
|
||||||
(get collapsed-categories community-id)))
|
(get collapsed-categories community-id)))
|
||||||
|
|
||||||
(defn- permission-id->permission-value
|
|
||||||
[token-permissions permission-id]
|
(defn token-requirement->token
|
||||||
(get (into {} token-permissions) permission-id))
|
[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
|
(re-frame/reg-sub
|
||||||
:community/token-gated-overview
|
:community/token-gated-overview
|
||||||
(fn [[_ community-id]]
|
(fn [[_ community-id]]
|
||||||
[(re-frame/subscribe [:communities/community community-id])])
|
[(re-frame/subscribe [:communities/community community-id])])
|
||||||
(fn [[{:keys [token-permissions-check token-permissions checking-permissions? token-images]}] _]
|
(fn [[{:keys [token-permissions-check checking-permissions? token-images]}] _]
|
||||||
(let [can-request-access? (:satisfied token-permissions-check)
|
(let [highest-role (:highestRole token-permissions-check)
|
||||||
highest-permission-role
|
networks-not-supported? (:networksNotSupported token-permissions-check)
|
||||||
(when can-request-access?
|
lowest-role (last (:roles token-permissions-check))
|
||||||
(->> token-permissions-check
|
highest-permission-role (:type highest-role)
|
||||||
:permissions
|
can-request-access? (and (boolean highest-permission-role) (not networks-not-supported?))]
|
||||||
(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)]
|
|
||||||
{:can-request-access? can-request-access?
|
{:can-request-access? can-request-access?
|
||||||
:highest-permission-role highest-permission-role
|
:highest-permission-role highest-permission-role
|
||||||
:number-of-hold-tokens (reduce
|
:networks-not-supported? networks-not-supported?
|
||||||
(fn [acc [_ {:keys [criteria]}]]
|
:no-member-permission? (and highest-permission-role
|
||||||
(reduce #(+ %1 (if %2 1 0)) acc criteria))
|
(not (-> token-permissions-check :highestRole :criteria)))
|
||||||
0
|
:tokens (map (fn [{:keys [tokenRequirement]}]
|
||||||
(: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
|
(map
|
||||||
(fn [{sym :symbol amount :amount} sufficient?]
|
(partial token-requirement->token
|
||||||
{:symbol sym
|
checking-permissions?
|
||||||
:sufficient? (when (seq check-criteria) sufficient?)
|
token-images)
|
||||||
:loading? checking-permissions?
|
tokenRequirement))
|
||||||
:amount amount
|
(or (:criteria highest-role)
|
||||||
:img-src (get token-images sym)})
|
(:criteria lowest-role)))})))
|
||||||
token_criteria
|
|
||||||
(or check-criteria token_criteria))))))})))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:community/images
|
:community/images
|
||||||
|
|
|
@ -388,34 +388,6 @@
|
||||||
:permissions {:access 3}
|
:permissions {:access 3}
|
||||||
:highest-permission-role constants/community-token-permission-become-admin
|
:highest-permission-role constants/community-token-permission-become-admin
|
||||||
:token-images {"ETH" token-image-eth}
|
: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"
|
:name "Community super name"
|
||||||
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f"
|
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f"
|
||||||
{:description "x"
|
{:description "x"
|
||||||
|
@ -439,7 +411,22 @@
|
||||||
:position 0
|
:position 0
|
||||||
:can-post? false
|
:can-post? false
|
||||||
:members {"0x04" {"roles" [1]}}}}
|
:members {"0x04" {"roles" [1]}}}}
|
||||||
:token-permissions-check {:satisfied true
|
: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
|
:permissions
|
||||||
{:a3dd5b6b-d93b-452c-b22a-09a8f42ec566 {:criteria [true false
|
{:a3dd5b6b-d93b-452c-b22a-09a8f42ec566 {:criteria [true false
|
||||||
true]}}
|
true]}}
|
||||||
|
@ -454,14 +441,13 @@
|
||||||
:verified false}]
|
:verified false}]
|
||||||
(swap! rf-db/app-db assoc-in [:communities community-id] community)
|
(swap! rf-db/app-db assoc-in [:communities community-id] community)
|
||||||
(is (match? {:can-request-access? true
|
(is (match? {:can-request-access? true
|
||||||
:number-of-hold-tokens 2
|
|
||||||
:tokens [[{:symbol "DAI"
|
:tokens [[{:symbol "DAI"
|
||||||
:amount "5.0"
|
:amount "5"
|
||||||
:sufficient? nil
|
:sufficient? true
|
||||||
:loading? checking-permissions?}]
|
:loading? checking-permissions?}]
|
||||||
[{:symbol "ETH"
|
[{:symbol "ETH"
|
||||||
:amount "0.001"
|
:amount "0.002"
|
||||||
:sufficient? nil
|
:sufficient? false
|
||||||
:loading? checking-permissions?
|
:loading? checking-permissions?
|
||||||
:img-src token-image-eth}]]}
|
:img-src token-image-eth}]]}
|
||||||
(rf/sub [sub-name community-id])))))
|
(rf/sub [sub-name community-id])))))
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||||
"owner": "status-im",
|
"owner": "status-im",
|
||||||
"repo": "status-go",
|
"repo": "status-go",
|
||||||
"version": "v0.174.3",
|
"version": "chore/debug-token-permissions",
|
||||||
"commit-sha1": "c15f9e73654ed2f21887af680d7730dec5bec3e3",
|
"commit-sha1": "b7b7660a534a01099e55ee0e4253f6a9531c7f02",
|
||||||
"src-sha256": "09jvamavnkii2fikpz2a5d345aspfp5lzlg5lpymz7lyjif4qn1s"
|
"src-sha256": "0nrmm3j9z6iwlr32mggd3xl63226drvvhrlrhrkgxcpgrgpixcfj"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2266,6 +2266,8 @@
|
||||||
"you-not-eligible-to-join": "You’re not eligible to join",
|
"you-not-eligible-to-join": "You’re not eligible to join",
|
||||||
"you-hold-number-of-hold-tokens-of-these": "You hold {{number-of-hold-tokens}} of these:",
|
"you-hold-number-of-hold-tokens-of-these": "You hold {{number-of-hold-tokens}} of these:",
|
||||||
"addresses-dont-contain-tokens-needed": "These addresses don’t contain tokens needed to join",
|
"addresses-dont-contain-tokens-needed": "These addresses don’t contain tokens needed to join",
|
||||||
|
"you-hodl": "You hodl:",
|
||||||
|
"network-not-supported": "Networks not supported",
|
||||||
"token-gated-communities": "Token gated communities",
|
"token-gated-communities": "Token gated communities",
|
||||||
"read-more": "Read more",
|
"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.",
|
"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.",
|
||||||
|
|
Loading…
Reference in New Issue