Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
chore: why they do this
Browse files Browse the repository at this point in the history
  • Loading branch information
yashim-deriv committed Jun 20, 2024
1 parent c29098a commit 137a3a1
Showing 1 changed file with 1 addition and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,7 @@
import { useState, useEffect } from 'react'
import { initializeApp } from 'firebase/app'
import { getDatabase, ref, onValue } from 'firebase/database'
// import useRegion from 'components/hooks/use-region'
import featuresConfig from '../../../static/appConfig'

const thirdPartyFlagsConfig = {
databaseURL: process.env.GATSBY_DATABASE_URL,
}

const useThirdPartyFlags = (featurePath) => {
const [data, setData] = useState(featuresConfig)
const [feature, setFeature] = useState(null)

useEffect(() => {
const app = initializeApp(thirdPartyFlagsConfig, 'thirdPartyFlagsConfig')
const db = getDatabase(app)

// let fetchedData = featuresConfig
const starCountRef = ref(db, 'remote_config/deriv-com')
const flagsData = onValue(
starCountRef,
(snapshot) => {
setData(snapshot.val())
},
(error) => {
console.error(error)
},
)
return flagsData
}, [])

useEffect(() => {
const pathParts = featurePath.split('.')
let currentFeature = data
for (const part of pathParts) {
if (currentFeature[part] === undefined) {
return // Feature path does not exist
}
currentFeature = currentFeature[part]
}
if (typeof currentFeature === 'object') {
setFeature(currentFeature)
} else {
if (featurePath === 'maintenance_mode_content') {
setFeature(currentFeature)
} else {
setFeature(Boolean(currentFeature))
}
}
}, [data, featurePath])

return feature
return featurePath ? featuresConfig : featuresConfig
}

export default useThirdPartyFlags

0 comments on commit 137a3a1

Please sign in to comment.