Merge branch 'main' of https://git.ambigrat.com/shenyan/physical-expo
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import type { UserProfile } from "@/types/api";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
|
||||
const STORAGE_KEYS = {
|
||||
ACCESS_TOKEN: "access_token",
|
||||
REFRESH_TOKEN: "refresh_token",
|
||||
USER: "user",
|
||||
ODDS_SETTINGS: "odds_settings",
|
||||
};
|
||||
|
||||
export interface OddsSettings {
|
||||
enabled: boolean;
|
||||
selectedBookmakers: string[];
|
||||
}
|
||||
|
||||
export const storage = {
|
||||
async setAccessToken(token: string): Promise<void> {
|
||||
await AsyncStorage.setItem(STORAGE_KEYS.ACCESS_TOKEN, token);
|
||||
@@ -38,11 +44,29 @@ export const storage = {
|
||||
}
|
||||
},
|
||||
|
||||
async setOddsSettings(settings: OddsSettings): Promise<void> {
|
||||
await AsyncStorage.setItem(
|
||||
STORAGE_KEYS.ODDS_SETTINGS,
|
||||
JSON.stringify(settings),
|
||||
);
|
||||
},
|
||||
|
||||
async getOddsSettings(): Promise<OddsSettings> {
|
||||
const settingsStr = await AsyncStorage.getItem(STORAGE_KEYS.ODDS_SETTINGS);
|
||||
if (!settingsStr) return { enabled: false, selectedBookmakers: [] };
|
||||
try {
|
||||
return JSON.parse(settingsStr) as OddsSettings;
|
||||
} catch {
|
||||
return { enabled: false, selectedBookmakers: [] };
|
||||
}
|
||||
},
|
||||
|
||||
async clear(): Promise<void> {
|
||||
await AsyncStorage.multiRemove([
|
||||
STORAGE_KEYS.ACCESS_TOKEN,
|
||||
STORAGE_KEYS.REFRESH_TOKEN,
|
||||
STORAGE_KEYS.USER,
|
||||
STORAGE_KEYS.ODDS_SETTINGS,
|
||||
]);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user