Skip to content

Commit

Permalink
Added Launch Darkly for feature flag management DEV-557 (#195)
Browse files Browse the repository at this point in the history
* Catch machine status update failures

* Added Launch Darkly
  • Loading branch information
dsarfati authored Oct 1, 2019
1 parent 619d12b commit 0781499
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 17 deletions.
3 changes: 3 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ ID = "salad-web-app"
REACT_APP_AUTH0_CLIENT_ID='K8nT8zWF1Dyu9oqLJg5MTkpt9Aug3Ygt'
REACT_APP_SENTRY_DSN = "https://[email protected]/1424792"
REACT_APP_MIXPANEL_TOKEN = "68db9194f229525012624f3cf368921f"
REACT_APP_LAUNCH_DARKLY_ID='5d8e2d2d5c49cd07a94926c2'

[context.branch-deploy.environment]
REACT_APP_AUTH0_CLIENT_ID='K8nT8zWF1Dyu9oqLJg5MTkpt9Aug3Ygt'
REACT_APP_LAUNCH_DARKLY_ID='5d8e2d2d5c49cd07a94926c1'

# Deploy Preview context: all deploys resulting from a pull/merge request will
# inherit these settings.
[context.deploy-preview.environment]
REACT_APP_AUTH0_CLIENT_ID="OJ6ffJ2h4eYZr6HqswGF544WgqDcBn2h"
REACT_APP_LAUNCH_DARKLY_ID='5d8e2d2d5c49cd07a94926c1'
1 change: 1 addition & 0 deletions packages/web-app/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
REACT_APP_AUTH0_CLIENT_ID=OJ6ffJ2h4eYZr6HqswGF544WgqDcBn2h
REACT_APP_API_URL=https://app.salad.io/api/v1/
REACT_APP_BUILD=development
REACT_APP_LAUNCH_DARKLY_ID=5d8e2d2d5c49cd07a94926c1

REACT_APP_DEV_TOOLS=true
1 change: 1 addition & 0 deletions packages/web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"babel-loader": "8.0.5",
"classnames": "^2.2.6",
"final-form": "^4.12.0",
"launchdarkly-js-client-sdk": "^2.13.0",
"lorem-ipsum": "^1.0.6",
"mixpanel-browser": "^2.27.1",
"mobx": "^5.9.0",
Expand Down
25 changes: 18 additions & 7 deletions packages/web-app/src/FeatureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import featureFlags from './featureFlags.json'
import * as LDSdk from 'launchdarkly-js-client-sdk'
import { Config } from './config'

export const featureFlag = (flag: string): boolean => {
//@ts-ignore
if (featureFlags.hasOwnProperty(flag)) {
//@ts-ignore
return featureFlags[flag] === true
export class FeatureFlags {
private ldClient: LDSdk.LDClient | undefined

loadFeatureFlags = async (userId: string): Promise<void> => {
this.ldClient = LDSdk.initialize(Config.launchDarklyId, { key: userId })

await this.ldClient.waitUntilReady()
}

getBool = (key: string, defaultValue: boolean = false): boolean => {
if (this.ldClient) return this.ldClient.variation(key, defaultValue)
return defaultValue
}
return false
}

const instance = new FeatureFlags()

export { instance as featureFlags }
4 changes: 3 additions & 1 deletion packages/web-app/src/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReferralStore } from './modules/referral'
import { AnalyticsStore } from './modules/analytics'
import { NativeStore } from './modules/machine/NativeStore'
import { RefreshService } from './modules/data-refresh'
import { featureFlags } from './FeatureFlags'

//Forces all changes to state to be from an action
configure({ enforceActions: 'always' })
Expand Down Expand Up @@ -62,10 +63,11 @@ export class RootStore {

@action.bound
onLogin = flow(function*(this: RootStore) {
yield this.profile.loadProfile()
var profile = yield this.profile.loadProfile()
this.referral.loadReferralCode()
this.xp.refreshXp()
this.referral.loadCurrentReferral()
yield featureFlags.loadFeatureFlags(profile.id)

// Start a timer to keep checking for system information
this.machineInfoHeartbeat = setInterval(this.tryRegisterMachine, 20000)
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Config {
public readonly authRefreshRate: number = numberOrDefault('REACT_APP_AUTH_REFRESH_RATE', convertHours(4))

public readonly mixpanelToken?: string = optionalString('REACT_APP_MIXPANEL_TOKEN')

public readonly launchDarklyId: string = requiredString('REACT_APP_LAUNCH_DARKLY_ID')
public readonly sentryDSN?: string = optionalString('REACT_APP_SENTRY_DSN')

/** The current version of the terms of service */
Expand Down
3 changes: 0 additions & 3 deletions packages/web-app/src/featureFlags.json

This file was deleted.

5 changes: 3 additions & 2 deletions packages/web-app/src/modules/machine/NativeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import * as Storage from '../../Storage'
import { Config } from '../../config'
import { MachineInfo, MiningStatus } from './models'
import { AxiosInstance } from 'axios'

import { Machine } from './models/Machine'
import { featureFlag } from '../../FeatureFlags'
import { featureFlags } from '../../FeatureFlags'

const getMachineInfo = 'get-machine-info'
const setMachineInfo = 'set-machine-info'
Expand Down Expand Up @@ -319,7 +320,7 @@ export class NativeStore {
this.send(start, this.machineId)
} else {
let address = ''
if (featureFlag('miner.nicepool')) {
if (featureFlags.getBool('nice-hash-pool')) {
if (!this.minerId) {
throw new Error('MinerId not found. Check that the machine is valid first. Cannot start.')
}
Expand Down
2 changes: 2 additions & 0 deletions packages/web-app/src/modules/profile/ProfileStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ export class ProfileStore {
this.currentProfile = profile.data
} catch (err) {
console.error('Profile error: ', err)
this.currentProfile = undefined
this.store.routing.replace('/profile-error')
} finally {
this.isLoading = false
//TODO: Move the routing logic to the onLogin function so we can load all the data before showing the app
this.store.routing.replace('/')
}
return this.currentProfile
})

@action.bound
Expand Down
23 changes: 20 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3910,7 +3910,7 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=

base64-js@^1.0.2, base64-js@^1.2.0, base64-js@^1.2.3:
base64-js@1.3.0, base64-js@^1.0.2, base64-js@^1.2.0, base64-js@^1.2.3:
version "1.3.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.0.tgz#cab1e6118f051095e58b5281aea8c1cd22bfc0e3"
integrity sha512-ccav/yGvoa80BQDljCxsmmQ3Xvx60/UpBIij5QN21W3wBi/hhIC9OoO+KLpu9IJTS9j4DRVJ3aDDF9cMSoa2lw==
Expand Down Expand Up @@ -6757,7 +6757,7 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=

fast-deep-equal@^2.0.1:
fast-deep-equal@2.0.1, fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
Expand Down Expand Up @@ -9578,6 +9578,23 @@ latest-version@^3.0.0:
dependencies:
package-json "^4.0.0"

launchdarkly-js-client-sdk@^2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/launchdarkly-js-client-sdk/-/launchdarkly-js-client-sdk-2.13.0.tgz#f269966cd09461a8bae42159b53ec4ebf70e119e"
integrity sha512-KqMrKQidHR2O6XhZ++1QmLIwuSqhX+GNb48DGWcjWXRi35s/af3FbpVTx6Dh1KYl5K6wmOIgNVzKA3T4+m2m6g==
dependencies:
escape-string-regexp "1.0.5"
launchdarkly-js-sdk-common "^2.13.0"

launchdarkly-js-sdk-common@^2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/launchdarkly-js-sdk-common/-/launchdarkly-js-sdk-common-2.13.0.tgz#2df51b8a34c3de2895797e8e10cc6849480e6a18"
integrity sha512-Nhf+u9MSUzyDvTlbkdJXMJojL8M0dbm8S4rk3Nb8VsvYvLiANsDh6D58FPcl7I3n1NeeCprUk0us1y4QkO5TDQ==
dependencies:
base64-js "1.3.0"
fast-deep-equal "2.0.1"
uuid "3.3.2"

lazy-cache@^0.2.3:
version "0.2.7"
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-0.2.7.tgz#7feddf2dcb6edb77d11ef1d117ab5ffdf0ab1b65"
Expand Down Expand Up @@ -15445,7 +15462,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=

uuid@^3.0.1, uuid@^3.3.2:
uuid@3.3.2, uuid@^3.0.1, uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==
Expand Down

0 comments on commit 0781499

Please sign in to comment.