All files / @tech/intl persistency.js

21.43% Statements 3/14
0% Branches 0/2
0% Functions 0/2
21.43% Lines 3/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29          1x   1x                         1x                
import { NativeModules } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import { getDefaultLang } from './getDefaultLang';
import { LANG_PERSIST_KEY } from './constants';
 
const { Logger } = NativeModules;
 
export const retrieveLanguageAsync = async () => {
  try {
    const lang = await AsyncStorage.getItem(LANG_PERSIST_KEY);
    if (!lang) {
      return getDefaultLang();
    }
    return lang;
  } catch (error) {
    Logger.send(error.message);
    return 'en';
  }
};
 
export const persistLanguage = (lang) => {
  try {
    return AsyncStorage.setItem(LANG_PERSIST_KEY, lang);
  } catch (error) {
    Logger.send(error.message);
    return null;
  }
};