fix: rework wallet screen
This commit is contained in:
parent
1f7ae74b42
commit
1f6d272aa0
103 changed files with 2094 additions and 3892 deletions
|
|
@ -9,23 +9,46 @@ low(adapter).then(it => {
|
|||
db = it
|
||||
})
|
||||
|
||||
function saveConfig (config) {
|
||||
const currentState = db.getState()
|
||||
// TODO this should be _.assign
|
||||
// change after flattening of schema
|
||||
const newState = _.mergeWith((objValue, srcValue) => {
|
||||
if (_.isArray(objValue)) {
|
||||
return srcValue
|
||||
}
|
||||
}, currentState, config)
|
||||
function replace (array, index, value) {
|
||||
return array.slice(0, index).concat([value]).concat(array.slice(index + 1))
|
||||
}
|
||||
|
||||
function replaceOrAdd (accounts, account) {
|
||||
const index = _.findIndex(['code', account.code], accounts)
|
||||
return index !== -1 ? replace(accounts, index, account) : _.concat(accounts)(account)
|
||||
}
|
||||
|
||||
function saveAccounts (accountsToSave) {
|
||||
const currentState = db.getState() || {}
|
||||
const accounts = currentState.accounts || []
|
||||
|
||||
const newAccounts = _.reduce(replaceOrAdd)(accounts)(accountsToSave)
|
||||
|
||||
const newState = _.set('accounts', newAccounts, currentState)
|
||||
db.setState(newState)
|
||||
return db.write()
|
||||
.then(() => newState)
|
||||
.then(() => newState.accounts)
|
||||
}
|
||||
|
||||
function getAccounts () {
|
||||
const state = db.getState()
|
||||
return state ? state.accounts : null
|
||||
}
|
||||
|
||||
function saveConfig (config) {
|
||||
const currentState = db.getState() || {}
|
||||
const currentConfig = currentState.config || {}
|
||||
const newConfig = _.assign(currentConfig, config)
|
||||
|
||||
const newState = _.set('config', newConfig, currentState)
|
||||
db.setState(newState)
|
||||
return db.write()
|
||||
.then(() => newState.config)
|
||||
}
|
||||
|
||||
function getConfig () {
|
||||
return db.getState()
|
||||
const state = db.getState()
|
||||
return (state && state.config) || {}
|
||||
}
|
||||
|
||||
module.exports = { getConfig, saveConfig }
|
||||
module.exports = { getConfig, saveConfig, saveAccounts, getAccounts }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue