Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-signer
Commits
19c6c089
Commit
19c6c089
authored
Aug 06, 2018
by
fro
Browse files
do not delete anything on migrate
parent
7b164521
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/screens/Loading.js
View file @
19c6c089
...
...
@@ -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
,
save
Account
,
delet
eAccount
Old
}
from
'
../util/db
'
;
import
{
loadAccounts
,
load
Account
s_v1
,
sav
eAccount
}
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
'
})]
...
...
src/util/db.js
View file @
19c6c089
...
...
@@ -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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment