start adding payment
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { Platform } from "react-native";
|
||||
import {
|
||||
getReactNativePersistence,
|
||||
initializeAuth,
|
||||
@@ -9,6 +10,26 @@ import "firebase/compat/firestore";
|
||||
import "firebase/compat/functions";
|
||||
import "firebase/compat/storage";
|
||||
|
||||
const functionsInstances = {};
|
||||
const emulatorConfigured = {};
|
||||
const emulatorHost = Platform.OS === "web" ? "localhost" : "192.168.1.146";
|
||||
|
||||
const configureFunctionsEmulator = (instance, regionKey = "us-central1") => {
|
||||
if (!__DEV__ || !instance?.useEmulator || emulatorConfigured[regionKey]) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
instance.useEmulator(emulatorHost, 5001);
|
||||
emulatorConfigured[regionKey] = true;
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
`[firebase] Unable to set functions emulator for region ${regionKey}`,
|
||||
error?.message,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const firebaseConfig = {
|
||||
apiKey: "AIzaSyCuHJHdwVN_F-VmUG4Hd7bGiMRqj6rPlLo",
|
||||
authDomain: "musicland-d33f9.firebaseapp.com",
|
||||
@@ -29,6 +50,9 @@ if (!firebase?.apps?.filter(({ name_ }) => name_ === "[DEFAULT]").length) {
|
||||
// if (__DEV__) {
|
||||
// firebase.functions().useEmulator("localhost", 5001);
|
||||
// }
|
||||
const defaultFunctions = firebase.functions();
|
||||
functionsInstances["us-central1"] = defaultFunctions;
|
||||
configureFunctionsEmulator(defaultFunctions, "us-central1");
|
||||
console.log("Firebase init");
|
||||
}
|
||||
|
||||
@@ -57,4 +81,18 @@ export const reportsRef = firestore.collection("reports");
|
||||
export const { arrayUnion, arrayRemove, increment, serverTimestamp } =
|
||||
firebase.firestore.FieldValue;
|
||||
|
||||
export const getFunctionsClient = (region = "us-central1") => {
|
||||
const regionKey = region || "us-central1";
|
||||
|
||||
if (!functionsInstances[regionKey]) {
|
||||
functionsInstances[regionKey] = firebase.app().functions(regionKey);
|
||||
}
|
||||
|
||||
const instance = functionsInstances[regionKey];
|
||||
|
||||
configureFunctionsEmulator(instance, regionKey);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
export default firebase;
|
||||
|
||||
Reference in New Issue
Block a user