-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")))) |