Skip to content

Commit

Permalink
refactor(mosip#618): [Vijay|Alka] refactor storage method and variabl…
Browse files Browse the repository at this point in the history
…e name to follow convention
  • Loading branch information
vijay151096 committed Apr 10, 2023
1 parent 247d930 commit 5da9609
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { SUPPORTED_LANGUAGES } from '../i18n';
import { I18nManager, View } from 'react-native';
import { Picker } from './ui/Picker';
import { setDataToStorage } from '../storage';
import { setDataToStorage } from '../shared/storage';
import { useTranslation } from 'react-i18next';
import i18next from 'i18next';
import RNRestart from 'react-native-restart';
Expand Down
2 changes: 1 addition & 1 deletion i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ar from './locales/ara.json';
import hi from './locales/hin.json';
import kn from './locales/kan.json';
import ta from './locales/tam.json';
import { getDataFromStorage } from './storage';
import { getDataFromStorage } from './shared/storage';

const resources = { en, fil, ar, hi, kn, ta };
import { iso6393To1 } from 'iso-639-3';
Expand Down
2 changes: 1 addition & 1 deletion machines/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
clearDataFromStorage,
getDataFromStorage,
setDataToStorage,
} from '../storage';
} from '../shared/storage';
import binaryToBase64 from 'react-native/Libraries/Utilities/binaryToBase64';
import { EventFrom, Receiver, sendParent, send, sendUpdate } from 'xstate';
import { createModel } from 'xstate/lib/model';
Expand Down
2 changes: 1 addition & 1 deletion shared/commonprops/commonProps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { request } from '../request';
import { getDataFromStorage, setDataToStorage } from '../../storage';
import { getDataFromStorage, setDataToStorage } from '../storage';
import { init } from 'mosip-inji-face-sdk';

const COMMON_PROPS_KEY: string =
Expand Down
12 changes: 6 additions & 6 deletions storage.ts → shared/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MMKVLoader } from 'react-native-mmkv-storage';
import { VC_ITEM_STORE_KEY_REGEX } from './shared/constants';
import { VC_ITEM_STORE_KEY_REGEX } from './constants';
import {
DocumentDirectoryPath,
readDir,
Expand All @@ -9,17 +9,17 @@ import {
} from 'react-native-fs';

const MMKV = new MMKVLoader().initialize();
let regExp = new RegExp(VC_ITEM_STORE_KEY_REGEX);
let vcKeyRegExp = new RegExp(VC_ITEM_STORE_KEY_REGEX);
export const getDataFromStorage = async (key: string) => {
if (regExp.exec(key)) {
if (vcKeyRegExp.exec(key)) {
const path = getFilePath(key);
return await readFile(path, 'utf8');
}
return await MMKV.getItem(key);
};

export const setDataToStorage = async (key: string, data: string) => {
if (regExp.exec(key)) {
if (vcKeyRegExp.exec(key)) {
const path = getFilePath(key);
return await writeFile(path, data, 'utf8');
}
Expand All @@ -32,11 +32,11 @@ export const clearDataFromStorage = async () => {
MMKV.clearStore();
};

const getFileNameFrom = (key) => {
const getFileName = (key: string) => {
return key.split(':').join('_');
};

const getFilePath = (key: string) => {
let fileName = getFileNameFrom(key);
let fileName = getFileName(key);
return `${DocumentDirectoryPath}/${fileName}.txt`;
};

0 comments on commit 5da9609

Please sign in to comment.