forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet-ext: set up experimentation framework (MystenLabs#4988)
- Loading branch information
Showing
6 changed files
with
74 additions
and
14 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
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,42 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { GrowthBook } from '@growthbook/growthbook'; | ||
|
||
const GROWTHBOOK_API_KEY = | ||
process.env.GROWTH_BOOK_API_KEY ?? 'key_dev_dc2872e15e0c5f95'; | ||
|
||
export default class FeatureGating { | ||
#growthBook: GrowthBook; | ||
|
||
constructor() { | ||
// Create a GrowthBook context | ||
this.#growthBook = new GrowthBook(); | ||
} | ||
|
||
public async init() { | ||
// Load feature definitions | ||
await fetch( | ||
`https://cdn.growthbook.io/api/features/${GROWTHBOOK_API_KEY}` | ||
) | ||
.then((res) => { | ||
if (res.ok) { | ||
return res.json(); | ||
} | ||
throw new Error(res.statusText); | ||
}) | ||
.then((parsed) => { | ||
this.#growthBook.setFeatures(parsed.features); | ||
}) | ||
.catch(() => { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`Failed to fetch feature definitions from GrowthBook with API_KEY ${process.env.GROWTH_BOOK_API_KEY}` | ||
); | ||
}); | ||
} | ||
|
||
public isOn(featureName: string): boolean { | ||
return this.#growthBook.isOn(featureName); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.