Commit 19c6c089 authored by fro's avatar fro
Browse files

do not delete anything on migrate

parent 7b164521
......@@ -21,7 +21,7 @@ import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
import { StackActions, NavigationActions } from 'react-navigation';
import { Subscribe } from 'unstated';
import { loadAccounts, saveAccount, deleteAccountOld } from '../util/db';
import { loadAccounts, loadAccounts_v1, saveAccount } from '../util/db';
import AccountsStore from '../stores/AccountsStore';
import colors from '../colors';
import { empty } from '../util/account';
......@@ -33,16 +33,16 @@ export default class Loading extends React.PureComponent {
};
async componentDidMount() {
const accounts = await loadAccounts();
let newAccounts = accounts;
// if we have an account with no associated chainId it means
// that we have to migrate accounts to the new format
if (accounts.length && accounts[0].chainId === undefined) {
newAccounts = accounts.map(empty).map(a => ({ ...a, v1recov: true }));
newAccounts.forEach(saveAccount);
// accounts.forEach(deleteAccountOld);
let accounts = await loadAccounts();
if (0 === accounts.length) {
// Try to migrate v1 accounts
const oldAccounts = await loadAccounts_v1();
accounts = oldAccounts.map(empty).map(a => ({ ...a, v1recov: true }));
accounts.forEach(saveAccount);
}
if (newAccounts.filter(a => !a.archived).length) {
if (accounts.filter(a => !a.archived).length) {
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Tabs' })]
......
......@@ -20,14 +20,27 @@ import SecureStorage from 'react-native-secure-storage';
import { AsyncStorage } from 'react-native';
import { accountId } from './account';
const accountsStore = {
const accountsStore_v1 = {
keychainService: 'accounts',
sharedPreferencesName: 'accounts'
};
const txStore = {
keychainService: 'transactions',
sharedPreferencesName: 'transactions'
export const deleteAccount_v1 = async account =>
SecureStorage.deleteItem(account.address, accountsStore_v1);
export async function loadAccounts_v1() {
if (!SecureStorage) {
return Promise.resolve([]);
}
return SecureStorage.getAllItems(accountsStore_v1).then(accounts =>
Object.values(accounts).map(account => JSON.parse(account))
);
}
const accountsStore = {
keychainService: 'accounts_v2',
sharedPreferencesName: 'accounts_v2'
};
function accountTxsKey({ address, networkType, chainId }) {
......@@ -38,9 +51,6 @@ function txKey(hash) {
return 'tx_' + hash;
}
export const deleteAccountOld = async account =>
SecureStorage.deleteItem(account.address, accountsStore);
export const deleteAccount = async account =>
SecureStorage.deleteItem(accountId(account), accountsStore);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment