Use quo/bottom-actions component in addresses for permissions screen (#18863)

This commit is contained in:
Ajay Sivan 2024-02-19 20:36:35 +05:30 committed by GitHub
parent d77033e346
commit 678bc548ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 58 deletions

View File

@ -1,16 +1,3 @@
(ns status-im.contexts.communities.actions.addresses-for-permissions.style) (ns status-im.contexts.communities.actions.addresses-for-permissions.style)
(def container {:flex 1}) (def container {:flex 1})
(def buttons
{:flex-direction :row
:gap 12
:padding-horizontal 20
:padding-vertical 12})
(def highest-role
{:flex-direction :row
:gap 4
:justify-content :center
:align-items :center
:margin-bottom 8})

View File

@ -1,17 +1,24 @@
(ns status-im.contexts.communities.actions.addresses-for-permissions.view (ns status-im.contexts.communities.actions.addresses-for-permissions.view
(:require [quo.core :as quo] (:require [quo.core :as quo]
[quo.foundations.colors :as colors]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.gesture :as gesture] [react-native.gesture :as gesture]
[status-im.common.not-implemented :as not-implemented] [status-im.common.not-implemented :as not-implemented]
[status-im.common.resources :as resources] [status-im.common.resources :as resources]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.communities.actions.addresses-for-permissions.style :as style] [status-im.contexts.communities.actions.addresses-for-permissions.style :as style]
[status-im.contexts.communities.utils :as communities.utils]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.money :as money] [utils.money :as money]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn- role-keyword
[role]
(condp = role
constants/community-token-permission-become-token-owner :token-owner
constants/community-token-permission-become-token-master :token-master
constants/community-token-permission-become-admin :admin
constants/community-token-permission-become-member :member
nil))
(defn- balances->components-props (defn- balances->components-props
[balances] [balances]
(for [{:keys [amount decimals type name] :as balance} balances] (for [{:keys [amount decimals type name] :as balance} balances]
@ -58,10 +65,7 @@
accounts (rf/sub [:wallet/accounts-without-watched-accounts]) accounts (rf/sub [:wallet/accounts-without-watched-accounts])
selected-addresses (rf/sub [:communities/selected-permission-addresses id]) selected-addresses (rf/sub [:communities/selected-permission-addresses id])
share-all-addresses? (rf/sub [:communities/share-all-addresses? id]) share-all-addresses? (rf/sub [:communities/share-all-addresses? id])
unsaved-address-changes? (rf/sub [:communities/unsaved-address-changes? id]) unsaved-address-changes? (rf/sub [:communities/unsaved-address-changes? id])]
highest-role-text (when highest-permission-role
(i18n/label (communities.utils/role->translation-key
highest-permission-role)))]
[rn/safe-area-view {:style style/container} [rn/safe-area-view {:style style/container}
[quo/drawer-top [quo/drawer-top
{:type :context-tag {:type :context-tag
@ -97,42 +101,31 @@
:key-fn :address :key-fn :address
:data accounts}] :data accounts}]
(if (and highest-permission-role (seq selected-addresses)) [quo/bottom-actions
[rn/view {:actions :two-actions
{:style style/highest-role} :button-one-label (i18n/label :t/confirm-changes)
[quo/text :button-one-props {:customization-color color
{:size :paragraph-2 :disabled? (or (empty? selected-addresses)
:style {:color colors/neutral-50}} (not highest-permission-role)
(i18n/label :t/eligible-to-join-as)] (not unsaved-address-changes?))
[quo/context-tag :on-press (fn []
{:type :icon (rf/dispatch
:icon :i/members [:communities/update-previous-permission-addresses
:size 24 id])
:context highest-role-text}]] (rf/dispatch [:navigate-back]))}
[quo/info-message :button-two-label (i18n/label :t/cancel)
{:type :error :button-two-props {:type :grey
:size :default :on-press (fn []
:icon :i/info (rf/dispatch
:style {:justify-content :center}} [:communities/reset-selected-permission-addresses id])
(if (empty? selected-addresses) (rf/dispatch [:navigate-back]))}
(i18n/label :t/no-addresses-selected) :description (if (or (empty? selected-addresses)
(i18n/label :t/addresses-dont-contain-tokens-needed))]) (not highest-permission-role))
:top-error
[rn/view {:style style/buttons} :top)
[quo/button :role (role-keyword highest-permission-role)
{:type :grey :error-message (cond
:container-style {:flex 1} (empty? selected-addresses) (i18n/label :t/no-addresses-selected)
:on-press (fn [] (not highest-permission-role) (i18n/label
(rf/dispatch [:communities/reset-selected-permission-addresses id]) :t/addresses-dont-contain-tokens-needed)
(rf/dispatch [:navigate-back]))} :else nil)}]]))))
(i18n/label :t/cancel)]
[quo/button
{:container-style {:flex 1}
:customization-color color
:disabled? (or (empty? selected-addresses)
(not highest-permission-role)
(not unsaved-address-changes?))
:on-press (fn []
(rf/dispatch [:communities/update-previous-permission-addresses id])
(rf/dispatch [:navigate-back]))}
(i18n/label :t/confirm-changes)]]]))))