Skip to content

Commit

Permalink
two
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Son89 committed Jan 29, 2024
1 parent 70d47de commit 602547f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
4 changes: 0 additions & 4 deletions src/status_im/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,3 @@

(def community-accounts-selection-enabled? false)
(def fetch-messages-enabled? (enabled? (get-config :FETCH_MESSAGES_ENABLED "1")))

(def wallet-feature-flags
{:edit-default-keypair false
:bridge-token false})
5 changes: 5 additions & 0 deletions src/status_im/contexts/preview/feature_flags/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns status-im.contexts.preview.feature-flags.style)

(def container
{:flex 1
:margin-left 20})
39 changes: 22 additions & 17 deletions src/status_im/contexts/preview/feature_flags/view.cljs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(ns status-im.contexts.preview.feature-flags.view
(:require
[clojure.string :as string]
[quo.core :as quo]
[re-frame.core :as rf]
[react-native.core :as rn]
[status-im.contexts.preview.feature-flags.style :as style]
[status-im.feature-flags :as ff]))

(defn view
Expand All @@ -14,21 +16,24 @@
:title "Features Flags"
:icon-name :i/arrow-left
:on-press #(rf/dispatch [:navigate-back])}]
(for [[context-name context-flags] (ff/feature-flags)]
^{:key (str context-name)}
[rn/view
{:flex 1
:margin-left 20}
[quo/text {:color :black} (name context-name)]
(doall
(for [context-name ff/feature-flags-categories]
(let [context-flags (filter (fn [[k]]
(string/includes? (str k) context-name))
(ff/feature-flags))]
^{:key (str context-name)}
[rn/view {:style style/container}
[quo/text
context-name]
(doall
(for [i (range (count context-flags))]
(let [[flag] (nth context-flags i)]
^{:key (str context-name flag i)}
[rn/view {:style {:flex-direction :row}}
[quo/selectors
{:type :toggle
:checked? (ff/enabled? flag)
:container-style {:margin-right 8}
:on-change #(ff/update-flag flag)}]
[quo/text (second (string/split (name flag) "."))]])))])))])

(for [[flag _v] context-flags]
^{:key (str context-name flag)}

[rn/view {:flex-direction :row}
(prn (ff/get-flag context-name flag))
[quo/selectors
{:type :toggle
:checked? (ff/get-flag context-name flag)
:container-style {:margin-right 8}
:on-change #(ff/update-flag context-name flag)}]
[quo/text {:color :black} (name flag)]])])])
3 changes: 1 addition & 2 deletions src/status_im/contexts/wallet/account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
:receive-action #(rf/dispatch [:open-modal :wallet-share-address {:status :receive}])
:buy-action #(rf/dispatch [:show-bottom-sheet
{:content buy-drawer}])
:bridge-action #(ff/alert :wallet
:bridge-token
:bridge-action #(ff/alert :status-im.feature-flags/wallet.bridge-token
(fn [] (rf/dispatch [:open-modal :wallet-bridge])))}])
[quo/tabs
{:style style/tabs
Expand Down
3 changes: 1 addition & 2 deletions src/status_im/contexts/wallet/create_account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
:size :xxs
:customization-color account-color}
:action :button
:action-props {:on-press #(ff/alert :wallet
:edit-default-keypair
:action-props {:on-press #(ff/alert :status-im.feature-flags/wallet.edit-default-keypair
(fn []
(rf/dispatch [:navigate-to :wallet-select-keypair])))
:button-text (i18n/label :t/edit)
Expand Down
37 changes: 22 additions & 15 deletions src/status_im/feature_flags.cljs
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
(ns status-im.feature-flags
(:require
[clojure.string :as string]
[react-native.config :as config]
[reagent.core :as reagent]))

(defn- enabled? [v] (= "1" v))
(defn- enabled-in-env?
[k]
(= "1" (config/get-config k)))

(defn check-env [k] (enabled? (config/get-config k)))

(def ^:private feature-flags-config
(defonce ^:private feature-flags-config
(reagent/atom
{:wallet
{:edit-default-keypair (check-env :DEV_FF_EDIT_DEFAULT_KEYPAIR)
:bridge-token (check-env :DEV_FF_BRIDGE_TOKEN)}}))
{::wallet.edit-default-keypair (enabled-in-env? :FLAG_EDIT_DEFAULT_KEYPAIR_ENABLED)
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)}))

(defn feature-flags [] @feature-flags-config)

(defn get-flag
[section flag]
(get-in (feature-flags) [section flag]))
(def feature-flags-categories
(set (map
(fn [k]
(first (string/split (str (name k)) ".")))
(keys @feature-flags-config))))

(defn enabled?
[flag]
(get-in (feature-flags) [flag]))

(defn update-flag
[section flag]
[flag]
(swap! feature-flags-config
(fn [a]
(update-in a [section flag] not))))
update-in
[flag]
not))

(defn alert
[context flag action]
(if (get-flag context flag)
[flag action]
(if (enabled? flag)
(action)
(js/alert (str flag " is currently feature flagged off"))))

0 comments on commit 602547f

Please sign in to comment.