Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3cfbfe9f2 | ||
|
|
ddf2a9420d | ||
|
|
4351ca6372 | ||
|
|
01b3b633cd | ||
|
|
28f72674ff | ||
|
|
e24d423ae7 | ||
|
|
499b4a213c | ||
|
|
ac9fc3feb1 | ||
|
|
1e80c4abdd | ||
|
|
6fbbc9de23 | ||
|
|
e05923d430 | ||
|
|
bfbf065edf | ||
|
|
4b9d559d77 | ||
|
|
b8adc68eb0 |
@@ -9,7 +9,7 @@
|
||||
[:size {:optional true} [:maybe [:enum :size-24 :size-32]]]
|
||||
[:blur? {:optional true} [:maybe :boolean]]
|
||||
[:theme :schema.common/theme]
|
||||
[:collectible-img-src :schema.common/image-source]
|
||||
[:collectible-img-src [:maybe :schema.common/image-source :string]]
|
||||
[:collectible-name :string]
|
||||
[:collectible-id :string]]]]
|
||||
[:collectible-id {:optional true} [:maybe :string]]]]]
|
||||
:any])
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
(:require [quo.core :as quo]
|
||||
[react-native.core :as rn]
|
||||
[react-native.gesture :as gesture]
|
||||
[status-im.common.not-implemented :as not-implemented]
|
||||
[status-im.common.resources :as resources]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.communities.actions.addresses-for-permissions.style :as style]
|
||||
[status-im.contexts.communities.actions.detail-token-gating.view :as detail-token-gating]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.re-frame :as rf]))
|
||||
@@ -57,7 +57,9 @@
|
||||
|
||||
(defn view
|
||||
[{:keys [scroll-enabled? on-scroll]}]
|
||||
(let [{id :community-id} (rf/sub [:get-screen-params])]
|
||||
(let [{id :community-id} (rf/sub [:get-screen-params])
|
||||
token-permissions (rf/sub [:community/token-permissions id])]
|
||||
|
||||
(rf/dispatch [:communities/get-permissioned-balances id])
|
||||
(fn []
|
||||
(let [{:keys [name color images]} (rf/sub [:communities/community id])
|
||||
@@ -69,15 +71,16 @@
|
||||
unsaved-address-changes? (rf/sub [:communities/unsaved-address-changes? id])]
|
||||
[rn/safe-area-view {:style style/container}
|
||||
[quo/drawer-top
|
||||
{:type :context-tag
|
||||
:title (i18n/label :t/addresses-for-permissions)
|
||||
:context-tag-type :community
|
||||
:community-name name
|
||||
:button-icon :i/info
|
||||
:button-type :grey
|
||||
:on-button-press not-implemented/alert
|
||||
:community-logo (get-in images [:thumbnail :uri])
|
||||
:customization-color color}]
|
||||
(cond-> {:type :context-tag
|
||||
:title (i18n/label :t/addresses-for-permissions)
|
||||
:context-tag-type :community
|
||||
:community-name name
|
||||
:community-logo (get-in images [:thumbnail :uri])
|
||||
:customization-color color}
|
||||
(seq token-permissions)
|
||||
(assoc
|
||||
:button-icon :i/info
|
||||
:on-button-press #(rf/dispatch [:show-bottom-sheet {:content detail-token-gating/view}])))]
|
||||
|
||||
[quo/category
|
||||
{:list-type :settings
|
||||
@@ -131,4 +134,3 @@
|
||||
(not highest-permission-role) (i18n/label
|
||||
:t/addresses-dont-contain-tokens-needed)
|
||||
:else nil)}]]))))
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
(ns status-im.contexts.communities.actions.detail-token-gating.style)
|
||||
|
||||
(def container
|
||||
{:flex 1
|
||||
:background-color :white})
|
||||
|
||||
(def role-container
|
||||
{:flex-direction :row
|
||||
:padding-horizontal 22
|
||||
:margin-bottom 8})
|
||||
|
||||
(def permission-text
|
||||
{:flex-direction :column
|
||||
:margin-top 12})
|
||||
@@ -0,0 +1,69 @@
|
||||
(ns status-im.contexts.communities.actions.detail-token-gating.view
|
||||
(:require
|
||||
[quo.core :as quo]
|
||||
[react-native.core :as rn]
|
||||
[status-im.contexts.communities.actions.detail-token-gating.style :as style]
|
||||
[status-im.contexts.communities.utils :as communities.utils]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn filter-tokens
|
||||
[token-permissions permission-types]
|
||||
(mapcat (fn [permission-type]
|
||||
(get token-permissions permission-type))
|
||||
permission-types))
|
||||
|
||||
(defn get-token-role
|
||||
[token-permissions]
|
||||
(->> token-permissions
|
||||
(remove (fn [[level _]] (#{5 6} level))) ; Exclude levels 5 and 6, focusing on token roles
|
||||
(filter (fn [[_ requests]] (some :sufficient? (first requests))))
|
||||
(map first)
|
||||
(reduce max)))
|
||||
|
||||
(defn view
|
||||
[]
|
||||
(let [{id :community-id} (rf/sub [:get-screen-params])
|
||||
{:keys [highest-permission-role can-request-access?]}
|
||||
(rf/sub [:community/token-gated-overview id])
|
||||
token-permissions (rf/sub [:community/token-permissions id])
|
||||
tokens (filter-tokens token-permissions [1 2 3])
|
||||
collectible (filter-tokens token-permissions [5 6])
|
||||
collectible-name (:symbol (first (first collectible)))
|
||||
collectible-img (:img-src (first (first collectible)))
|
||||
has-collectible (get first (first collectible) :sufficient?)
|
||||
role (get-token-role token-permissions)
|
||||
highest-role-text (i18n/label
|
||||
(communities.utils/role->translation-key highest-permission-role
|
||||
:t/token-master))
|
||||
member-role-text (i18n/label
|
||||
(communities.utils/role->translation-key role :t/member))
|
||||
selected-addresses (rf/sub [:communities/selected-permission-addresses id])]
|
||||
|
||||
[rn/view {:style style/container}
|
||||
(when (and has-collectible (seq selected-addresses))
|
||||
[rn/view
|
||||
{:style style/role-container}
|
||||
[rn/view {:style {:flex-direction :column}}
|
||||
[quo/text {:weight :medium}
|
||||
(i18n/label :t/you-eligible-to-join-as {:role highest-role-text})]
|
||||
[quo/text {:style {:padding-bottom 18} :size :paragraph-2}
|
||||
(if can-request-access?
|
||||
(i18n/label :t/you-hodl)
|
||||
(i18n/label :t/you-must-hold))]
|
||||
[rn/view {:style {:align-items :flex-start}}
|
||||
[quo/collectible-tag
|
||||
{:size :size-24
|
||||
:collectible-name collectible-name
|
||||
:options (if has-collectible :hold false)
|
||||
:collectible-img-src collectible-img}]]]])
|
||||
[rn/view
|
||||
{:style style/role-container}
|
||||
[rn/view {:style style/permission-text}
|
||||
[quo/text {:weight :medium}
|
||||
(i18n/label :t/you-eligible-to-join-as {:role member-role-text})]
|
||||
[quo/text {:style {:padding-bottom 18} :size :paragraph-2}
|
||||
(if can-request-access?
|
||||
(i18n/label :t/you-hodl)
|
||||
(i18n/label :t/you-must-hold))]
|
||||
[quo/token-requirement-list {:tokens tokens}]]]]))
|
||||
@@ -15,6 +15,7 @@
|
||||
[status-im.contexts.communities.actions.addresses-for-permissions.view :as
|
||||
addresses-for-permissions]
|
||||
[status-im.contexts.communities.actions.airdrop-addresses.view :as airdrop-addresses]
|
||||
[status-im.contexts.communities.actions.detail-token-gating.view :as detail-token-gating]
|
||||
[status-im.contexts.communities.actions.request-to-join.view :as join-menu]
|
||||
[status-im.contexts.communities.actions.share-community-channel.view :as share-community-channel]
|
||||
[status-im.contexts.communities.discover.view :as communities.discover]
|
||||
@@ -132,6 +133,10 @@
|
||||
:options {:sheet? true}
|
||||
:component airdrop-addresses/view}
|
||||
|
||||
{:name :detail-token-gating
|
||||
:options {:sheet? true}
|
||||
:component detail-token-gating/view}
|
||||
|
||||
{:name :lightbox
|
||||
:options options/lightbox
|
||||
:component lightbox/lightbox}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[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] ;; [re-frame.db :as rf-db]
|
||||
[status-im.common.resources :as resources]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.wallet.common.utils :as wallet.utils]
|
||||
[utils.i18n :as i18n]))
|
||||
@@ -406,3 +407,40 @@
|
||||
(re-frame/subscribe [:communities/airdrop-address community-id])])
|
||||
(fn [[accounts airdrop-address]]
|
||||
(first (filter #(= (:address %) airdrop-address) accounts))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:communities/checking-all-channels-permissions?
|
||||
(fn [db [_ community-id]]
|
||||
(get-in db [:communities community-id])))
|
||||
|
||||
(re-frame/reg-sub :community/token-permissions
|
||||
(fn [[_ community-id]]
|
||||
[(re-frame/subscribe [:communities/community community-id])
|
||||
(re-frame/subscribe [:communities/checking-permissions-by-id community-id])])
|
||||
(fn [[{:keys [token-permissions token-images]} permissions-check] _]
|
||||
(let [mock-images (when (and (contains? token-permissions 5)
|
||||
(contains? token-permissions 6))
|
||||
(resources/mock-images :collectible))
|
||||
permissions (get-in permissions-check [:check :permissions])]
|
||||
|
||||
(->> token-permissions
|
||||
(map second)
|
||||
(map
|
||||
(fn [token-permission]
|
||||
(let [token-id (keyword (:id token-permission))
|
||||
token-requirements (get permissions token-id)
|
||||
satisfied-criteria (get token-requirements :tokenRequirement)]
|
||||
(map-indexed (fn [idx criterion]
|
||||
(let [sym (:symbol criterion)
|
||||
type (:type token-permission)]
|
||||
{:symbol sym
|
||||
:permission-type type
|
||||
:amount (wallet.utils/remove-trailing-zeroes (:amount
|
||||
criterion))
|
||||
:sufficient? (get-in satisfied-criteria [idx :satisfied] false)
|
||||
:img-src (if (= type 2)
|
||||
(or (get mock-images sym)
|
||||
(get token-images sym))
|
||||
(get token-images sym))}))
|
||||
(:token_criteria token-permission)))))
|
||||
(group-by (comp :permission-type first))))))
|
||||
|
||||
@@ -496,3 +496,426 @@
|
||||
:network-preferences-names #{}
|
||||
:name "account3"}]
|
||||
(rf/sub [sub-name community-id])))))
|
||||
|
||||
;; (h/deftest-sub :communities/token-permissions
|
||||
;; [sub-name]
|
||||
;; (testing "returns token permissions grouped by role"
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities
|
||||
;; {"0x1" {:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
;; {:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
;; :type 2
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:5 "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
;; :11155111 "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
;; :type 1
|
||||
;; :symbol "STT"
|
||||
;; :amount "1.0000000000000000"
|
||||
;; :decimals 18}]}]
|
||||
;; [:6872cfb4-9122-4d39-b58c-5dff441f94d4
|
||||
;; {:id "6872cfb4-9122-4d39-b58c-5dff441f94d4"
|
||||
;; :type 6
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:420 "0x98C28243BeFD84f5B83BA49fE843e6Cbd9a55AD4"}
|
||||
;; :type 2
|
||||
;; :symbol "OWNPER"
|
||||
;; :name "Owner-Permission Drawer"
|
||||
;; :amount "1"}]
|
||||
;; :is_private true}]
|
||||
;; [:730c3fd3-3fcf-4d48-934a-b175b571c5fe
|
||||
;; {:id "730c3fd3-3fcf-4d48-934a-b175b571c5fe"
|
||||
;; :type 2
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:5 "0x0000000000000000000000000000000000000000"
|
||||
;; :420 "0x0000000000000000000000000000000000000000"
|
||||
;; :421613 "0x0000000000000000000000000000000000000000"
|
||||
;; :421614 "0x0000000000000000000000000000000000000000"
|
||||
;; :11155111 "0x0000000000000000000000000000000000000000"}
|
||||
;; :type 1
|
||||
;; :symbol "ETH"
|
||||
;; :amount "1.0000000000000000"
|
||||
;; :decimals 18}]}]
|
||||
;; [:75a6c876-7be4-4830-a82b-b672986329da
|
||||
;; {:id "75a6c876-7be4-4830-a82b-b672986329da"
|
||||
;; :type 5
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:420 "0x2334ab535D0146d4a78C24894Cdc0C466cF3159e"}
|
||||
;; :type 2
|
||||
;; :symbol "TMPER"
|
||||
;; :name "TMaster-Permission Drawer"
|
||||
;; :amount "1"}]
|
||||
;; :is_private true}]]}})
|
||||
;; (is
|
||||
;; (match?
|
||||
;; {2 [[{:symbol "STT" :amount "1" :sufficient? true :loading? false :img-src nil}]
|
||||
;; [{:symbol "ETH" :amount "1" :sufficient? true :loading? false :img-src nil}]]
|
||||
;; 5
|
||||
;; [[{:symbol "TMPER"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? false
|
||||
;; :img-src
|
||||
;; "data:image/jpeg;base64,/path/to/jpeg"}]]
|
||||
;; 6
|
||||
;; [[{:symbol "OWNPER"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? false
|
||||
;; :img-src
|
||||
;; "data:image/jpeg;base64,/path/to/jpeg"}]]}
|
||||
;; (rf/sub [sub-name])))))
|
||||
|
||||
;; (h/deftest-sub :communities/token-permissions
|
||||
;; [sub-name]
|
||||
;; (testing "returns token permissions grouped by role"
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities
|
||||
;; {"0x1" {:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
;; {:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
;; :type 2
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:5 "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
;; :11155111 "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
;; :type 1
|
||||
;; :symbol "STT"
|
||||
;; :amount "1.0000000000000000"
|
||||
;; :decimals 18}]}]
|
||||
;; [:6872cfb4-9122-4d39-b58c-5dff441f94d4
|
||||
;; {:id "6872cfb4-9122-4d39-b58c-5dff441f94d4"
|
||||
;; :type 6
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:420 "0x98C28243BeFD84f5B83BA49fE843e6Cbd9a55AD4"}
|
||||
;; :type 2
|
||||
;; :symbol "OWNPER"
|
||||
;; :name "Owner-Permission Drawer"
|
||||
;; :amount "1"}]
|
||||
;; :is_private true}]
|
||||
;; [:730c3fd3-3fcf-4d48-934a-b175b571c5fe
|
||||
;; {:id "730c3fd3-3fcf-4d48-934a-b175b571c5fe"
|
||||
;; :type 2
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:5 "0x0000000000000000000000000000000000000000"
|
||||
;; :420 "0x0000000000000000000000000000000000000000"
|
||||
;; :421613 "0x0000000000000000000000000000000000000000"
|
||||
;; :421614 "0x0000000000000000000000000000000000000000"
|
||||
;; :11155111 "0x0000000000000000000000000000000000000000"}
|
||||
;; :type 1
|
||||
;; :symbol "ETH"
|
||||
;; :amount "1.0000000000000000"
|
||||
;; :decimals 18}]}]
|
||||
;; [:75a6c876-7be4-4830-a82b-b672986329da
|
||||
;; {:id "75a6c876-7be4-4830-a82b-b672986329da"
|
||||
;; :type 5
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:420 "0x2334ab535D0146d4a78C24894Cdc0C466cF3159e"}
|
||||
;; :type 2
|
||||
;; :symbol "TMPER"
|
||||
;; :name "TMaster-Permission Drawer"
|
||||
;; :amount "1"}]
|
||||
;; :is_private true}]]}})
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities/checking-permissions-by-id
|
||||
;; {"0x1" {:check {:permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a" {:tokenRequirement
|
||||
;; [{:satisfied true}]}
|
||||
;; "6872cfb4-9122-4d39-b58c-5dff441f94d4" {:tokenRequirement
|
||||
;; [{:satisfied true}]}
|
||||
;; "730c3fd3-3fcf-4d48-934a-b175b571c5fe" {:tokenRequirement
|
||||
;; [{:satisfied true}]}
|
||||
;; "75a6c876-7be4-4830-a82b-b672986329da" {:tokenRequirement
|
||||
;; [{:satisfied true}]}}}}})
|
||||
;; (is
|
||||
;; (match?
|
||||
;; {2 [[{:symbol "STT"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? false
|
||||
;; :img-src nil}]
|
||||
;; [{:symbol "ETH"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? false
|
||||
;; :img-src nil}]]
|
||||
;; 5
|
||||
;; [[{:symbol "TMPER"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? false
|
||||
;; :img-src "path/to/jpeg"}]]
|
||||
;; 6
|
||||
;; [[{:symbol "OWNPER"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? false
|
||||
;; :img-src "path/to/jpeg"}]]})
|
||||
;; (rf/sub [sub-name community-id]))))
|
||||
|
||||
;; (h/deftest-sub :community/token-permissions
|
||||
;; [sub-name]
|
||||
;; (testing "returns token permissions grouped by type with correct attributes"
|
||||
;; (js/console.log "We here guys")
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities
|
||||
;; {"0x1" {:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
;; {:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
;; :type 2
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:5
|
||||
;; "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
;; :11155111
|
||||
;; "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
;; :type 1
|
||||
;; :symbol "STT"
|
||||
;; :amount "1.0000000000000000"
|
||||
;; :decimals 18}]}]]}})
|
||||
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities/checking-permissions-by-id
|
||||
;; {:checking? false
|
||||
;; :check {:satisfied true
|
||||
;; :permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a" {:tokenRequirement
|
||||
;; [{:satisfied
|
||||
;; true}]}}}})
|
||||
;; (is (match?
|
||||
;; {2 [[{:symbol "STT"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :loading? ""
|
||||
;; :img-src ""}]]}
|
||||
;; (rf/sub [sub-name community-id])))))
|
||||
|
||||
;; (h/deftest-sub :community/token-permissions
|
||||
;; [sub-name]
|
||||
;; (testing "returns token permissions grouped by type with correct attributes"
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities
|
||||
;; {"0x1" {:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
;; {:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
;; :type 2
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:5 "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
;; 11155111 "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
;; :type 1
|
||||
;; :symbol "STT"
|
||||
;; :amount "1.0000000000000000"
|
||||
;; :decimals 18}]}]
|
||||
;; [:6872cfb4-9122-4d39-b58c-5dff441f94d4
|
||||
;; {:id "6872cfb4-9122-4d39-b58c-5dff441f94d4"
|
||||
;; :type 6
|
||||
;; :token_criteria
|
||||
;; [{:contract_addresses
|
||||
;; {:420 "0x98C28243BeFD84f5B83BA49fE843e6Cbd9a55AD4"}
|
||||
;; :type 2
|
||||
;; :symbol "OWNPER"
|
||||
;; :name "Owner-Permission Drawer"
|
||||
;; :amount "1"}]
|
||||
;; :is_private true}]]
|
||||
;; :token-images {"OWNPER" "path/to/jpeg"}}})
|
||||
|
||||
;; (swap! rf-db/app-db assoc
|
||||
;; :communities/checking-permissions-by-id
|
||||
;; {:checking? false
|
||||
;; :check {:satisfied true
|
||||
;; :permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a" {:tokenRequirement
|
||||
;; [{:satisfied true}]}}}})
|
||||
;; (is (match? {2 [[{:symbol "STT"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :img-src nil}]]
|
||||
;; 6 [[{:symbol "OWNPER"
|
||||
;; :amount "1"
|
||||
;; :sufficient? true
|
||||
;; :img-src "path/to/jpeg"}]]}
|
||||
;; (rf/sub [sub-name community-id])))))
|
||||
|
||||
(h/deftest-sub :community/token-permissions
|
||||
[sub-name]
|
||||
(testing "returns token permissions grouped by type with correct attributes"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities
|
||||
{community-id
|
||||
{:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
{:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
:type 2
|
||||
:token_criteria
|
||||
[{:contract_addresses
|
||||
{:5 "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
11155111 "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
:type 1
|
||||
:symbol "STT"
|
||||
:amount "1.0000000000000000"
|
||||
:decimals 18}]}]
|
||||
[:6872cfb4-9122-4d39-b58c-5dff441f94d4
|
||||
{:id "6872cfb4-9122-4d39-b58c-5dff441f94d4"
|
||||
:type 6
|
||||
:token_criteria
|
||||
[{:contract_addresses
|
||||
{:420 "0x98C28243BeFD84f5B83BA49fE843e6Cbd9a55AD4"}
|
||||
:type 2
|
||||
:symbol "OWNPER"
|
||||
:name "Owner-Permission Drawer"
|
||||
:amount "1"}]
|
||||
:is_private true}]]
|
||||
:token-images {"OWNPER" "path/to/jpeg"}}})
|
||||
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/permissions-check
|
||||
{community-id {:checking? false
|
||||
:check {:satisfied true
|
||||
:permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
{:tokenRequirement
|
||||
[{:satisfied true}]}}}}})
|
||||
|
||||
(is (match? {2 [[{:symbol "STT"
|
||||
:amount "1"
|
||||
:permission-type 2
|
||||
:sufficient? true
|
||||
:img-src nil}]]
|
||||
6 [[{:symbol "OWNPER"
|
||||
:permission-type 6
|
||||
:amount "1"
|
||||
:sufficient? false
|
||||
:img-src "path/to/jpeg"}]]}
|
||||
(rf/sub [sub-name community-id]))))
|
||||
|
||||
(testing "returns empty because theres no token permissions setted"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities
|
||||
{community-id
|
||||
{:token-permissions nil
|
||||
:token-images nil}})
|
||||
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/permissions-check
|
||||
{community-id {:checking? false
|
||||
:check {:satisfied true
|
||||
:permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
{:tokenRequirement
|
||||
[{:satisfied true}]}}}}})
|
||||
|
||||
(is (match? {}
|
||||
(rf/sub [sub-name community-id]))))
|
||||
|
||||
|
||||
(testing "returns tokens and images when no collectibles exist, with 'satisfied' set to true"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities
|
||||
{community-id
|
||||
{:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
{:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
:type 2
|
||||
:token_criteria
|
||||
[{:contract_addresses
|
||||
{:5 "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
11155111 "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
:type 1
|
||||
:symbol "STT"
|
||||
:amount "1.0000000000000000"
|
||||
:decimals 18}]}]
|
||||
[:730c3fd3-3fcf-4d48-934a-b175b571c5fe
|
||||
{:id "730c3fd3-3fcf-4d48-934a-b175b571c5fe"
|
||||
:type 2
|
||||
:token_criteria
|
||||
[{:contract_addresses
|
||||
{:5 "0x0000000000000000000000000000000000000000"
|
||||
:420 "0x0000000000000000000000000000000000000000"
|
||||
:421613 "0x0000000000000000000000000000000000000000"
|
||||
:421614 "0x0000000000000000000000000000000000000000"
|
||||
:11155111 "0x0000000000000000000000000000000000000000"}
|
||||
:type 1
|
||||
:symbol "ETH"
|
||||
:amount "1.0000000000000000"
|
||||
:decimals 18}]}]]
|
||||
:token-images {"STT" "path/to/jpeg" "ETH" "path/to/jpeg"}}})
|
||||
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/permissions-check
|
||||
{community-id {:checking? false
|
||||
:check {:satisfied true
|
||||
:permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
{:tokenRequirement
|
||||
[{:satisfied true}]}
|
||||
"730c3fd3-3fcf-4d48-934a-b175b571c5fe"
|
||||
{:tokenRequirement
|
||||
[{:satisfied true}]}}}}})
|
||||
|
||||
(is (match?
|
||||
{2 [[{:symbol "STT"
|
||||
:amount "1"
|
||||
:permission-type 2
|
||||
:sufficient? true
|
||||
:img-src "path/to/jpeg"}]
|
||||
[{:symbol "ETH"
|
||||
:amount "1"
|
||||
:sufficient? true
|
||||
:permission-type 2
|
||||
:img-src "path/to/jpeg"}]]}
|
||||
(rf/sub [sub-name community-id]))))
|
||||
|
||||
(testing "returns tokens and images when no collectibles exist, with 'satisfied' set to false"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities
|
||||
{community-id
|
||||
{:token-permissions [[:1cfb5618-5e6a-4695-a91c-19e7e4f0af3a
|
||||
{:id "1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
:type 2
|
||||
:token_criteria
|
||||
[{:contract_addresses
|
||||
{:5 "0x3d6afaa395c31fcd391fe3d562e75fe9e8ec7e6a"
|
||||
11155111 "0xe452027cdef746c7cd3db31cb700428b16cd8e51"}
|
||||
:type 1
|
||||
:symbol "STT"
|
||||
:amount "1.0000000000000000"
|
||||
:decimals 18}]}]
|
||||
[:730c3fd3-3fcf-4d48-934a-b175b571c5fe
|
||||
{:id "730c3fd3-3fcf-4d48-934a-b175b571c5fe"
|
||||
:type 2
|
||||
:token_criteria
|
||||
[{:contract_addresses
|
||||
{:5 "0x0000000000000000000000000000000000000000"
|
||||
:420 "0x0000000000000000000000000000000000000000"
|
||||
:421613 "0x0000000000000000000000000000000000000000"
|
||||
:421614 "0x0000000000000000000000000000000000000000"
|
||||
:11155111 "0x0000000000000000000000000000000000000000"}
|
||||
:type 1
|
||||
:symbol "ETH"
|
||||
:amount "1.0000000000000000"
|
||||
:decimals 18}]}]]
|
||||
:token-images {"STT" "path/to/jpeg" "ETH" "path/to/jpeg"}}})
|
||||
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/permissions-check
|
||||
{community-id {:checking? false
|
||||
:check {:satisfied true
|
||||
:permissions {"1cfb5618-5e6a-4695-a91c-19e7e4f0af3a"
|
||||
{:tokenRequirement
|
||||
[{:satisfied false}]}
|
||||
"730c3fd3-3fcf-4d48-934a-b175b571c5fe"
|
||||
{:tokenRequirement
|
||||
[{:satisfied false}]}}}}})
|
||||
|
||||
(is (match?
|
||||
{2 [[{:symbol "STT"
|
||||
:amount "1"
|
||||
:permission-type 2
|
||||
:sufficient? false
|
||||
:img-src "path/to/jpeg"}]
|
||||
[{:symbol "ETH"
|
||||
:amount "1"
|
||||
:sufficient? false
|
||||
:permission-type 2
|
||||
:img-src "path/to/jpeg"}]]}
|
||||
(rf/sub [sub-name community-id])))))
|
||||
|
||||
(comment
|
||||
(require 'cljs.test)
|
||||
(cljs.test/test-var #'status-im.subs.communities-test/community-token-permissions-test))
|
||||
|
||||
Reference in New Issue
Block a user