Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
// For debugging
// const storage = await AsyncStorage.multiGet(
// await AsyncStorage.getAllKeys(),
// )
// console.log(JSON.stringify(storage, null, 2))
const [
[, _auth],
[, _username],
[, _secret],
] = await AsyncStorage.multiGet([
STORAGE_KEYS.auth,
STORAGE_KEYS.username,
STORAGE_KEYS.secret,
]);
// console.log(_auth, _username, _secret)
setAuth(_auth);
setUsername(_username);
setSecret(_secret);
setReady(true);
})();
}, []);
export const getConnections = async (allKeys: string[]) => {
try {
const connectionKeys = allKeys.filter(
(val) =>
val !== 'userData' &&
!val.startsWith('App:') &&
!val.startsWith('store'),
);
console.log('connectionKeys', connectionKeys);
const storageValues = await AsyncStorage.multiGet(connectionKeys);
const connections = storageValues.map((val) => JSON.parse(val[1]));
// update redux store
store.dispatch(setConnections(connections));
store.dispatch(defaultSort());
// sort connections
} catch (err) {
err instanceof Error ? console.warn(err.message) : console.log(err);
throw new Error('unable to recover connections');
}
};
...getHeaders(uploadables),
Authorization: token
};
const response = await fetchWithRetries(GRAPHQL_URL, {
method: 'POST',
headers,
body,
fetchTimeout: 20000,
retryDelays: [ 1000, 3000, 5000 ]
});
const data = await handleData(response);
if (response.status === 401) {
await AsyncStorage.clear();
throw data.errors;
}
if (isMutation(request) && data.errors) {
throw data;
}
if (!data.data) {
await AsyncStorage.clear();
throw data.errors;
}
return data;
} catch (err) {
// eslint-disable-next-line
console.log('err: ', err);
handleChangeText = text => {
// save the value to the state email
const { onEmailChanged } = this.props;
this.setState({ email: text });
AsyncStorage.setItem(Constants.KEY_FIRST_RUN_EMAIL, text);
AsyncStorage.setItem(Constants.KEY_EMAIL_VERIFY_PENDING, 'true');
if (onEmailChanged) {
onEmailChanged(text);
}
};
if (validate) {
await Engine.context.KeyringController.exportSeedPhrase(password);
}
await AsyncStorage.setItem('@MetaMask:existingUser', 'true');
if (enabled) {
const authOptions = {
accessControl:
type === 'biometrics'
? SecureKeychain.ACCESS_CONTROL.BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE
: SecureKeychain.ACCESS_CONTROL.DEVICE_PASSCODE
};
await SecureKeychain.setGenericPassword('metamask-user', password, authOptions);
if (type === 'biometrics') {
await AsyncStorage.setItem('@MetaMask:biometryChoice', this.state.biometryType);
await AsyncStorage.removeItem('@MetaMask:passcodeChoice');
// If the user enables biometrics, we're trying to read the password
// immediately so we get the permission prompt
if (Platform.OS === 'ios') {
await SecureKeychain.getGenericPassword();
}
} else {
await AsyncStorage.setItem('@MetaMask:passcodeChoice', 'true');
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
}
} else {
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
await AsyncStorage.removeItem('@MetaMask:passcodeChoice');
}
this.props.passwordSet();
AsyncStorage.getItem('firstLaunchTime').then(startTime => {
if (startTime !== null && !isNaN(parseInt(startTime, 10))) {
// We don't need this value anymore once we've retrieved it
AsyncStorage.removeItem('firstLaunchTime');
// We know this is the first app launch because firstLaunchTime is set and it's a valid number
const start = parseInt(startTime, 10);
const now = moment().unix();
const delta = now - start;
AsyncStorage.getItem('firstLaunchSuspended').then(suspended => {
AsyncStorage.removeItem('firstLaunchSuspended');
const appSuspended = suspended === 'true';
if (NativeModules.Firebase) {
NativeModules.Firebase.track('first_run_time', {
total_seconds: delta,
app_suspended: appSuspended,
});
}
});
}
});
const loadNavigationState = async () => {
try {
const navState = JSON.parse(await AsyncStorage.getItem(NAV_STORE_KEY));
const didCrashLastOpen = JSON.parse(
await AsyncStorage.getItem(ERROR_STORE_KEY)
);
// Clear error saved state so that navigation persistence happens on next load
await AsyncStorage.setItem(ERROR_STORE_KEY, JSON.stringify(false));
// If the app crashed last time, don't restore nav state
log("DID CRASH?", didCrashLastOpen);
return didCrashLastOpen ? null : navState;
} catch (err) {
log("Error reading navigation and error state", err);
}
};
if (password === this.password) {
const biometryType = await SecureKeychain.getSupportedBiometryType();
if (biometryType) {
this.setState({ biometryType, biometryChoice: true });
}
const authOptions = {
accessControl: this.state.biometryChoice
? SecureKeychain.ACCESS_CONTROL.BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE
: SecureKeychain.ACCESS_CONTROL.DEVICE_PASSCODE
};
await SecureKeychain.setGenericPassword('metamask-user', password, authOptions);
if (!this.state.biometryChoice) {
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
} else {
// If the user enables biometrics, we're trying to read the password
// immediately so we get the permission prompt
try {
if (Platform.OS === 'ios') {
await SecureKeychain.getGenericPassword();
}
await AsyncStorage.setItem('@MetaMask:biometryChoice', this.state.biometryType);
} catch (e) {
Logger.error('User cancelled biometrics permission', e);
await AsyncStorage.removeItem('@MetaMask:biometryChoice');
}
}
}
try {
export function unsetUserLocally() {
// Remove token
AsyncStorage.removeItem('token')
AsyncStorage.removeItem('user')
}
static clearData = async () => {
await AsyncStorage.removeItem(DATA_SETTINGS);
await AsyncStorage.removeItem(DATA_PIN_HASH);
await AsyncStorage.removeItem(DATA_ASSETS);
await AsyncStorage.removeItem(DATA_PRICES);
await AsyncStorage.removeItem(DATA_PRICES_FETCHTIME);
// remove transactions
const keys = await AsyncStorage.getAllKeys();
for (let k = 0; k < keys.length; k += 1) {
const key = keys[k];
if (key.includes(DATA_ASSET_HIST)) {
await AsyncStorage.removeItem(key);
}
}
};