Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fetchData() {
let value = null;
try {
AsyncStorage.getItem("@MYSUPERSTORE", (err, result) => {
if(result) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(JSON.parse(result)),
isLoading: false,
});
} else {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
try {
AsyncStorage.setItem("@MYSUPERSTORE", JSON.stringify(responseData));
} catch (err) {
//
}
this.setState({
reactNativePlugin._restorePayload = function() {
var AsyncStorage = require('react-native').AsyncStorage;
var promise = AsyncStorage.getItem(ASYNC_STORAGE_KEY).then(function(payload) {
return JSON.parse(payload);
})['catch'](function() {
return null;
});
// Make sure that we fetch ASAP.
var RCTAsyncSQLiteStorage = NativeModules.AsyncSQLiteDBStorage;
var RCTAsyncRocksDBStorage = NativeModules.AsyncRocksDBStorage;
var RCTAsyncFileStorage = NativeModules.AsyncLocalStorage;
var RCTAsyncStorage =
RCTAsyncRocksDBStorage || RCTAsyncSQLiteStorage || RCTAsyncFileStorage;
if (RCTAsyncStorage.multiGet) {
AsyncStorage.flushGetRequests();
}
return promise;
};
setupGuidance = async () => {
try {
const result = await AsyncStorage.getItem(this.guidanceCacheKey);
if (!result) {
this.setState({showGuidance: true});
AsyncStorage.setItem(this.guidanceCacheKey, JSON.stringify({}));
}
} catch (e) {
console.log(`[BeginnerGuidanceDecorator_${displayName}] setup guidance error: ${e}`);
}
};
async function read(key, deserializer) {
try {
let val = await AsyncStorage.getItem(key);
if (val !== null) {
let readValue = JSON.parse(val).map(serialized => {
return deserializer(serialized);
});
return readValue;
} else {
console.info(`${key} not found on disk.`);
return [];
}
} catch (error) {
console.warn("AsyncStorage error: ", error.message);
}
}
export function getUserToken() {
return AsyncStorage
.getItem('user')
.then(parseJson);
}
async _registerTokenCached(): Promise {
const { appId } = this._config;
const cacheKey = 'push_token' + appId;
return AsyncStorage.getItem(cacheKey).then(lastToken => {
if (lastToken) return true;
else return false;
});
}
componentDidMount() {
AsyncStorage.getItem('authData')
.then((state) => {
this.setState({
...JSON.parse(state),
checkedAuth: true,
});
});
}
return new Promise((resolve, reject) => {
AsyncStorage.getItem(SHOW_THUMBNAIL, (error, result) => {
if(!error && result){
if(result === 'true')
resolve(true);
else
resolve(false);
}else{
reject(true);
}
});
});
}
async joinGame(game_identifier){
game = await utils.joinGame(game_identifier,this.state.token,this.state.user);
if (game.error){
this.setState({errorLabel:game.error});
return;
}
let tutorialResponse = await AsyncStorage.getItem('@pokerBuddy:showTutorial');
let showTutorial = (tutorialResponse === null) ? true : (tutorialResponse==='true');
utils.resetToScreen(navigation,"GameView",{game: game,user: this.state.user,token:this.state.token,showTutorial:showTutorial});
}