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,66 +110,82 @@
|
||||||
[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))]
|
||||||
[rn/view {:style (style/token-gated-container)}
|
(cond
|
||||||
[rn/view
|
|
||||||
{:style {:padding-horizontal 12
|
networks-not-supported?
|
||||||
:flex-direction :row
|
[network-not-supported]
|
||||||
:align-items :center
|
|
||||||
:justify-content :space-between
|
(or (not role-permissions?) no-member-permission?)
|
||||||
:flex 1}}
|
[request-access-button id color]
|
||||||
[quo/text {:weight :medium}
|
|
||||||
(if can-request-access?
|
:else
|
||||||
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})
|
[rn/view {:style (style/token-gated-container)}
|
||||||
(i18n/label :t/you-not-eligible-to-join))]
|
[rn/view
|
||||||
[info-button]]
|
{:style {:padding-horizontal 12
|
||||||
(when (pos? number-of-hold-tokens)
|
: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}
|
[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}]
|
[quo/button
|
||||||
[quo/button
|
{:on-press (if config/community-accounts-selection-enabled?
|
||||||
{:on-press (if config/community-accounts-selection-enabled?
|
#(rf/dispatch [:open-modal :community-account-selection
|
||||||
#(rf/dispatch [:open-modal :community-account-selection
|
{:community-id id}])
|
||||||
{:community-id id}])
|
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
|
||||||
#(rf/dispatch [:open-modal :community-requests-to-join {:id id}]))
|
:accessibility-label :join-community-button
|
||||||
:accessibility-label :join-community-button
|
:customization-color color
|
||||||
:customization-color color
|
: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))
|
(map
|
||||||
:tokens (->>
|
(partial token-requirement->token
|
||||||
token-permissions
|
checking-permissions?
|
||||||
(filter (fn [[_ permission]]
|
token-images)
|
||||||
(data-store/role-permission? permission)))
|
tokenRequirement))
|
||||||
(map (fn [[perm-key {:keys [token_criteria]}]]
|
(or (:criteria highest-role)
|
||||||
(let [check-criteria (get-in token-permissions-check
|
(:criteria lowest-role)))})))
|
||||||
[: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))))))})))
|
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:community/images
|
:community/images
|
||||||
|
|
|
@ -382,88 +382,74 @@
|
||||||
[sub-name]
|
[sub-name]
|
||||||
(let
|
(let
|
||||||
[checking-permissions? true
|
[checking-permissions? true
|
||||||
token-image-eth "data:image/jpeg;base64,/9j/2w"
|
token-image-eth "data:image/jpeg;base64,/9j/2w"
|
||||||
community {:id community-id
|
community {:id community-id
|
||||||
:checking-permissions? checking-permissions?
|
:checking-permissions? checking-permissions?
|
||||||
: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
|
:name "Community super name"
|
||||||
{:id "permission-id-01"
|
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f"
|
||||||
:type constants/community-token-permission-can-view-channel
|
{:description "x"
|
||||||
:token_criteria [{:contract_addresses {:5 "0x0"}
|
:emoji "🎲"
|
||||||
:type 1
|
:permissions {:access 1}
|
||||||
:symbol "SNT"
|
:color "#88B0FF"
|
||||||
:amount "0.002"
|
:name "random"
|
||||||
:decimals 18}]
|
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
|
||||||
:chat_ids [(str community-id
|
:id "89f98a1e-6776-4e5f-8626-8ab9f855253f"
|
||||||
"89f98a1e-6776-4e5f-8626-8ab9f855253f")]}]
|
:position 4
|
||||||
[:permission-id-02
|
:can-post? false
|
||||||
{:id "permission-id-02"
|
:members {"0x04" {"roles" [1]}}}
|
||||||
:type constants/community-token-permission-become-admin
|
"a076358e-4638-470e-a3fb-584d0a542ce6"
|
||||||
:token_criteria [{:contract_addresses {:5 "0x0"}
|
{:description "General channel for the community"
|
||||||
:type 1
|
:emoji "🐷 "
|
||||||
:symbol "DAI"
|
:permissions {:access 1}
|
||||||
:amount "5.0"
|
:color "#4360DF"
|
||||||
:decimals 18}]
|
:name "general"
|
||||||
:chat_ids [(str community-id
|
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
|
||||||
"89f98a1e-6776-4e5f-8626-8ab9f855253f")]}]
|
:id "a076358e-4638-470e-a3fb-584d0a542ce6"
|
||||||
[:permission-id-03
|
:position 0
|
||||||
{:id "permission-id-03"
|
:can-post? false
|
||||||
:type constants/community-token-permission-become-member
|
:members {"0x04" {"roles" [1]}}}}
|
||||||
:token_criteria [{:contract_addresses {:5 "0x0"}
|
:token-permissions-check
|
||||||
:type 1
|
{:satisfied true
|
||||||
:symbol "ETH"
|
:highestRole {:type constants/community-token-permission-become-admin
|
||||||
:amount "0.001"
|
:criteria [{:tokenRequirement [{:satisfied true
|
||||||
:decimals 18}]}]]
|
:criteria {:contract_addresses
|
||||||
:name "Community super name"
|
{:5 "0x0"}
|
||||||
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f"
|
:type 1
|
||||||
{:description "x"
|
:symbol "DAI"
|
||||||
:emoji "🎲"
|
:amount "5.0"
|
||||||
:permissions {:access 1}
|
:decimals 18}}]}
|
||||||
:color "#88B0FF"
|
{:tokenRequirement [{:satisfied false
|
||||||
:name "random"
|
:criteria {:type 1
|
||||||
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
|
:symbol "ETH"
|
||||||
:id "89f98a1e-6776-4e5f-8626-8ab9f855253f"
|
:amount "0.002"
|
||||||
:position 4
|
:decimals 18}}]}]}
|
||||||
:can-post? false
|
|
||||||
:members {"0x04" {"roles" [1]}}}
|
:permissions
|
||||||
"a076358e-4638-470e-a3fb-584d0a542ce6"
|
{:a3dd5b6b-d93b-452c-b22a-09a8f42ec566 {:criteria [true false
|
||||||
{:description "General channel for the community"
|
true]}}
|
||||||
:emoji "🐷 "
|
:validCombinations
|
||||||
:permissions {:access 1}
|
[{:address "0xd722eaa60dc73e334b588d34ba66a3b27e537783"
|
||||||
:color "#4360DF"
|
:chainIds nil}
|
||||||
:name "general"
|
{:address "0x738d3146831c5871fa15872b409e8f360e341784"
|
||||||
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
|
:chainIds [5 420]}]}
|
||||||
:id "a076358e-4638-470e-a3fb-584d0a542ce6"
|
:members {"0x04" {"roles" [1]}}
|
||||||
:position 0
|
:can-request-access? false
|
||||||
:can-post? false
|
:outroMessage "bla"
|
||||||
:members {"0x04" {"roles" [1]}}}}
|
:verified false}]
|
||||||
: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}]
|
|
||||||
(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"
|
||||||
:amount "5.0"
|
:sufficient? true
|
||||||
:sufficient? nil
|
:loading? checking-permissions?}]
|
||||||
:loading? checking-permissions?}]
|
[{:symbol "ETH"
|
||||||
[{:symbol "ETH"
|
:amount "0.002"
|
||||||
:amount "0.001"
|
:sufficient? false
|
||||||
:sufficient? nil
|
: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])))))
|
||||||
|
|
||||||
(h/deftest-sub :communities/airdrop-account
|
(h/deftest-sub :communities/airdrop-account
|
||||||
|
|
|
@ -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