const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
const { getAllCryptoCurrencies } = require('../lib/new-config-manager.js')
const { utils: coinUtils } = require('lamassu-coins')
const _ = require('lodash/fp')

exports.up = function (next) {
  loadLatest()
    .then(settings => {
      const newSettings = {}
      const activeCryptos = getAllCryptoCurrencies(settings.config)
      if (_.head(activeCryptos)) {
        _.map(crypto => {
          const defaultUnit = _.head(_.keys(coinUtils.getCryptoCurrency(crypto).units))
          newSettings[`wallets_${crypto}_cryptoUnits`] = defaultUnit
          return newSettings
        }, activeCryptos)
      }
      return saveConfig(newSettings)
    })
    .then(() => next())
    .catch(err => {
      console.log(err.message)
      return next(err)
    })
}

exports.down = function (next) {
  next()
}

@@ -77,35 +77,42 @@
 st %7B get
-All
 Crypto
-Currencies
+sFromWalletNamespace
  %7D = req
@@ -368,27 +368,34 @@
  get
-All
 Crypto
-Currencies
+sFromWalletNamespace
 (set
@@ -418,23 +418,17 @@
     if (
-_.head(
+!
 activeCr
@@ -436,15 +436,42 @@
 ptos
-)) %7B%0A  
+.length) return Promise.resolve()%0A
     
@@ -486,26 +486,24 @@
 crypto =%3E %7B%0A
-  
         cons
@@ -584,18 +584,16 @@
         
-  
 newSetti
@@ -643,18 +643,16 @@
 ultUnit%0A
-  
         
@@ -676,18 +676,16 @@
 s%0A      
-  
 %7D, activ
@@ -698,16 +698,8 @@
 os)%0A
-      %7D%0A
     

replace getAllCryptoCurrencies function