BlueWallet/screen/wallets/walletMigrate.js
Igor Korsakov 6f581a2f2e
Eject (#126)
* OPS: randombytes work
* OPS: porting to RN android: added prompt, refactoring
* OPS: better android prompt
* FIX: scan qr callback
* FIX: correct fee sat calculation for HD & classic segwit wallets
* FIX: Fixed height for button in empty transaction list
* FIX: keyboard issue on fee selection modal
* FIX: slow QR code generation for HD backup screen
* ADD: wallet reorder
* FIX: TypeError: undefined is not an object (evaluating 'recommendedFees.halfHourFee') #133
* FIX: android appstore link
* OPS: Code to Migrate Expo json
* REF: renamed blitzhub to lndhub
* OPS: Migration: move expo files instead of parsing
* FIX: lndhub uri usage
* FIX: no security alert on android (it was ios specific)
* REF: better tx list rendering and sorting
* ADD: verify tx on coinb.in
* FIX: Tap to dismiss is not working #137
* REF: Removed Wallet gradients duplication.
* REF: about screen
* FIX: bech32 qr scan in send screen
* FIX: better bip21 handling
* Use of dayjs for transaction details
* REF: QR code content follows BIP21
* ADD: fee in local currency when send
* FIX: Refresh wallet info on page focus
2018-12-11 22:52:46 +00:00

95 lines
3.5 KiB
JavaScript

import React, { Component } from 'react';
import { View, ActivityIndicator, AsyncStorage } from 'react-native';
import PropTypes from 'prop-types';
import RNFS from 'react-native-fs';
const expoDataDirectory = RNFS.DocumentDirectoryPath + '/ExponentExperienceData/%40overtorment%2Fbluewallet/RCTAsyncLocalStorage';
export default class WalletMigrate extends Component {
componentDidMount() {
this.migrateDataFromExpo();
}
migrationComplete() {
console.log('Migration was successful. Exiting migration...');
this.props.onComplete();
}
// Migrate Document directory from Expo
async migrateDataFromExpo() {
const expoDirectoryExists = await RNFS.exists(RNFS.DocumentDirectoryPath + '/ExponentExperienceData');
if (!expoDirectoryExists) {
console.log('Expo data was previously migrated. Exiting migration...');
this.migrationComplete();
return;
}
try {
await RNFS.unlink(RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1');
console.log('/RCTAsyncLocalStorage_V1 has been deleted. Continuing...');
} catch (error) {
console.log(error);
console.log('/RCTAsyncLocalStorage_V1 does not exist. Continuing...');
}
try {
await RNFS.copyFile(expoDataDirectory, RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1');
} catch (error) {
console.log('An error was encountered when trying to copy Expo data to /RCTAsyncLocalStorage_V1. Exiting migration...');
console.log(error);
}
try {
await RNFS.unlink(RNFS.DocumentDirectoryPath + '/RCTAsyncLocalStorage_V1/.DS_Store');
} catch (error) {
console.log('An error was encountered when trying to delete .DS_Store. Continuing migration...');
console.log(error);
}
const files = await RNFS.readDir(expoDataDirectory);
for (const file of files) {
try {
if (file.isFile()) {
if (file.name === 'manifest.json') {
const manifestFile = await RNFS.readFile(file.path);
const manifestFileParsed = JSON.parse(manifestFile);
if (manifestFileParsed.hasOwnProperty('data')) {
if (typeof manifestFileParsed.data === 'string') {
await AsyncStorage.setItem('data', manifestFileParsed.data);
}
}
if (manifestFileParsed.hasOwnProperty('data_encrypted')) {
if (typeof manifestFileParsed.data_encrypted === 'string') {
await AsyncStorage.setItem('data_encrypted', manifestFileParsed.data_encrypted);
}
}
} else if (file.name !== 'manifest.json') {
const manifestFile = await RNFS.readFile(file.path);
const manifestFileParsed = JSON.parse(manifestFile);
if (typeof manifestFileParsed === 'object') await AsyncStorage.setItem('data', JSON.stringify(manifestFileParsed));
}
}
} catch (error) {
console.log(error);
}
}
try {
await RNFS.unlink(RNFS.DocumentDirectoryPath + '/ExponentExperienceData');
console.log('Deleted /ExponentExperienceData.');
} catch (error) {
console.log('An error was encountered when trying to delete /ExponentExperienceData. Exiting migration...');
console.log(error);
}
this.migrationComplete();
}
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignContent: 'center' }}>
<ActivityIndicator />
</View>
);
}
}
WalletMigrate.propTypes = {
onComplete: PropTypes.func,
};