diff --git a/android/app/src/main/java/app/croma/CromaModule.java b/android/app/src/main/java/app/croma/CromaModule.java index 447d23139..e00e25b7b 100644 --- a/android/app/src/main/java/app/croma/CromaModule.java +++ b/android/app/src/main/java/app/croma/CromaModule.java @@ -56,7 +56,8 @@ public String getName() { @ReactMethod public void getConfigString(String key, Promise promise) { - promise.resolve(BuildConfig.DEBUG ? "true" : firebaseRemoteConfig.getString(key)); + // https://console.firebase.google.com/u/0/project/croma-a6256/config/env/firebase + promise.resolve( firebaseRemoteConfig.getString(key)); } @ReactMethod diff --git a/libs/Helpers.js b/libs/Helpers.js index 6b3d96d8b..a77165b6f 100644 --- a/libs/Helpers.js +++ b/libs/Helpers.js @@ -3,6 +3,11 @@ import * as RNIap from 'react-native-iap'; import { requestPurchase, getProducts } from 'react-native-iap'; import { sendClientErrorAsync } from '../network/errors'; +const readRemoteConfig = async (key) => { + // Native module always returns string. So, we need to convert it to boolean. + return (await NativeModules.CromaModule.getConfigString(key)) == 'true'; +}; + const productSku = function () { //return 'local_test1'; return Platform.OS === 'android' ? 'croma_pro' : 'app_croma'; @@ -161,4 +166,4 @@ export function extractHexColors(text) { return Object.values(combinedHexMap); } -export { logEvent, sendClientError, purchase, notifyMessage, initPurchase }; +export { logEvent, sendClientError, purchase, notifyMessage, initPurchase, readRemoteConfig }; diff --git a/screens/ChatSessionScreen.js b/screens/ChatSessionScreen.js index 1d1aba1c1..407497ded 100644 --- a/screens/ChatSessionScreen.js +++ b/screens/ChatSessionScreen.js @@ -10,9 +10,9 @@ import { ImageBackground } from 'react-native'; import Colors from '../constants/Colors'; -import React, { useState, useEffect, useRef, NativeModules } from 'react'; +import React, { useState, useEffect, useRef } from 'react'; import { material } from 'react-native-typography'; -import { logEvent } from '../libs/Helpers'; +import { logEvent, readRemoteConfig } from '../libs/Helpers'; import ChatCard from '../components/ChatCard'; import LoginScreen from './LoginScreen'; import useUserData from '../hooks/getUserData'; @@ -52,9 +52,7 @@ const ChatSessionScreen = (props) => { const fetchData = async () => { if (!canUserCreateChat && !isUserDataLoading) { if (userData && !isPro) { - setCanUserCreateChat( - await NativeModules.CromaModule.getConfigString('ai_behind_pro_version') - ); + setCanUserCreateChat(await readRemoteConfig('ai_behind_pro_version')); } if (isPro && userData) { setCanUserCreateChat(true); diff --git a/screens/ProVersionScreen.js b/screens/ProVersionScreen.js index 88c5e7f01..f69334129 100644 --- a/screens/ProVersionScreen.js +++ b/screens/ProVersionScreen.js @@ -1,9 +1,9 @@ import React, { useEffect, useState } from 'react'; -import { ScrollView, StyleSheet, Text, ActivityIndicator, NativeModules } from 'react-native'; +import { ScrollView, StyleSheet, Text, ActivityIndicator } from 'react-native'; import { View } from 'react-native-animatable'; import CromaButton from '../components/CromaButton'; import { CromaContext } from '../store/store'; -import { purchase, logEvent } from '../libs/Helpers'; +import { purchase, logEvent, readRemoteConfig } from '../libs/Helpers'; import { material } from 'react-native-typography'; import { initPurchase } from '../libs/Helpers'; import { useTranslation } from 'react-i18next'; @@ -18,7 +18,7 @@ export default function ProScreen() { }; useEffect(() => { const fetchData = async () => { - setAiBehindFF(await NativeModules.CromaModule.getConfigString('ai_behind_pro_version')); + setAiBehindFF(await readRemoteConfig('ai_behind_pro_version')); setLoading(false); }; fetchData();