Skip to content

Commit

Permalink
fix reading remote config
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalkishor1991 committed Mar 31, 2024
1 parent 38fe68f commit 6efa574
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion android/app/src/main/java/app/croma/CromaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion libs/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 };
8 changes: 3 additions & 5 deletions screens/ChatSessionScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions screens/ProVersionScreen.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down

0 comments on commit 6efa574

Please sign in to comment.