From 361ee5662f5bfac56b75ea276ed3677e47f5e5c7 Mon Sep 17 00:00:00 2001 From: Niloofar Sadeghi <93518187+niloofar-deriv@users.noreply.github.com> Date: Thu, 29 Aug 2024 18:13:34 +0800 Subject: [PATCH] Niloofar / Added a condition to ensure that Growthbook is fully loaded before assigning or using any feature flags (#16642) * fix: growthbook not loaded correctly * chore: removed logges --- .../App/Components/Layout/Header/signup-button.jsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/src/App/Components/Layout/Header/signup-button.jsx b/packages/core/src/App/Components/Layout/Header/signup-button.jsx index 3beb08e3c7f7..37f086e7cb14 100644 --- a/packages/core/src/App/Components/Layout/Header/signup-button.jsx +++ b/packages/core/src/App/Components/Layout/Header/signup-button.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { Button } from '@deriv/components'; import { redirectToSignUp, mobileOSDetectAsync, isSafari } from '@deriv/shared'; @@ -6,11 +6,18 @@ import { localize } from '@deriv/translations'; import { useGrowthbookGetFeatureValue } from '@deriv/hooks'; const SignupButton = ({ className }) => { - const [trigger_os_signup] = useGrowthbookGetFeatureValue({ + const [redirect_to_os_signup, setRedirectToOSSignup] = useState(false); + const [trigger_os_signup, isGBLoaded] = useGrowthbookGetFeatureValue({ featureFlag: 'trigger_os_signup', defaultValue: false, }); + useEffect(() => { + if (isGBLoaded) { + setRedirectToOSSignup(trigger_os_signup); + } + }, [isGBLoaded, trigger_os_signup]); + const handleOutSystemsRedirection = () => { switch (process.env.NODE_ENV) { case 'production': @@ -25,7 +32,7 @@ const SignupButton = ({ className }) => { const handleSignup = async () => { const os = await mobileOSDetectAsync(); - if (trigger_os_signup) { + if (redirect_to_os_signup) { if (os === 'iOS' || isSafari()) { redirectToSignUp(); } else window.open(handleOutSystemsRedirection());