diff --git a/src/status_im/config.cljs b/src/status_im/config.cljs index 7c3fc56b2b..bd59c5d0bc 100644 --- a/src/status_im/config.cljs +++ b/src/status_im/config.cljs @@ -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"))) diff --git a/src/status_im/contexts/communities/overview/view.cljs b/src/status_im/contexts/communities/overview/view.cljs index 1e26847a3a..9838660a3c 100644 --- a/src/status_im/contexts/communities/overview/view.cljs +++ b/src/status_im/contexts/communities/overview/view.cljs @@ -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 diff --git a/src/status_im/subs/communities.cljs b/src/status_im/subs/communities.cljs index 67e6bf618e..6cb531aeaf 100644 --- a/src/status_im/subs/communities.cljs +++ b/src/status_im/subs/communities.cljs @@ -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,42 @@ (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 :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)] + (fn [[{:keys [token-permissions-check checking-permissions? token-images]}] _] + (let [highest-role (:highestRole token-permissions-check) + networks-not-supported? (:networksNotSupported token-permissions-check) + lowest-role (last (:roles token-permissions-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 (-> token-permissions-check :highestRole :criteria))) + :tokens (map (fn [{:keys [tokenRequirement]}] + (map + (partial token-requirement->token + checking-permissions? + token-images) + tokenRequirement)) + (or (:criteria highest-role) + (:criteria lowest-role)))}))) (re-frame/reg-sub :community/images diff --git a/src/status_im/subs/communities_test.cljs b/src/status_im/subs/communities_test.cljs index 59078d9d10..9e197d5798 100644 --- a/src/status_im/subs/communities_test.cljs +++ b/src/status_im/subs/communities_test.cljs @@ -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 diff --git a/status-go-version.json b/status-go-version.json index 4aea2b0fc8..62d12bd5a4 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "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" } diff --git a/translations/en.json b/translations/en.json index 80d814309f..9f9c7acfe4 100644 --- a/translations/en.json +++ b/translations/en.json @@ -2266,6 +2266,8 @@ "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:", "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", "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.",