diff --git a/src/GWallet.Backend/Account.fs b/src/GWallet.Backend/Account.fs index c2da60a63..6f39dc7d4 100644 --- a/src/GWallet.Backend/Account.fs +++ b/src/GWallet.Backend/Account.fs @@ -17,6 +17,21 @@ type UnhandledCurrencyServerException(currency: Currency, module Account = + let private isInitialized (accounts: seq) = lazy( + Config.Init() + +#if !NATIVE_SEGWIT + let _readonlyUtxoAccounts = +#else + let readonlyUtxoAccounts = +#endif + accounts.Where(fun acc -> acc.Currency.IsUtxo()).OfType() +#if NATIVE_SEGWIT + UtxoCoin.Account.MigrateReadOnlyAccountsToNativeSegWit readonlyUtxoAccounts +#endif + () + ) + let private GetShowableBalanceAndImminentPaymentInternal (account: IAccount) (mode: ServerSelectionMode) (cancelSourceOption: Option) @@ -86,8 +101,6 @@ module Account = failwith <| SPrintF1 "Currency (%A) not supported for this API" currency let GetAllActiveAccounts(): seq = - Config.PropagateEthAccountInfoToMissingTokensAccounts() - let allCurrencies = Currency.GetAll() // uncomment this block below, manually, if when testing you need to go back to test the WelcomePage.xaml @@ -106,11 +119,9 @@ module Account = } let allAccounts = getAccountsOfKind [AccountKind.Normal; AccountKind.ReadOnly] -#if NATIVE_SEGWIT - let readonlyUtxoAccounts = - allAccounts.Where(fun acc -> acc.Currency.IsUtxo()).OfType() - UtxoCoin.Account.MigrateReadOnlyAccountsToNativeSegWit readonlyUtxoAccounts -#endif + + let _checkInit: unit = + (isInitialized allAccounts).Value allAccounts diff --git a/src/GWallet.Backend/Config.fs b/src/GWallet.Backend/Config.fs index 2d5927c7c..5bbf6a92c 100644 --- a/src/GWallet.Backend/Config.fs +++ b/src/GWallet.Backend/Config.fs @@ -127,26 +127,6 @@ module Config = | Some dir -> dir | None -> failwith "Unreachable, after invoking with createIfNotAlreadyExisting=true, it should return Some" - // In case a new token was added it will not have a config for an existing user - // we copy the eth configs to the new tokens config directory - let PropagateEthAccountInfoToMissingTokensAccounts() = - for accountKind in (AccountKind.All()) do - let ethConfigDir = GetConfigDir Currency.ETH accountKind - for token in Currency.GetAll() do - if token.IsEthToken() then - let maybeTokenConfigDir = GetConfigDirInternal token accountKind false - match maybeTokenConfigDir with - | Some _ -> - // already removed token account before - () - | None -> - // now create it if it wasn't there before - let tokenConfigDir = GetConfigDir token accountKind - for ethAccountFilePath in Directory.GetFiles ethConfigDir.FullName do - let newPath = ethAccountFilePath.Replace(ethConfigDir.FullName, tokenConfigDir.FullName) - if not (File.Exists newPath) then - File.Copy(ethAccountFilePath, newPath) - let GetAccountFilesWithCurrency (currency: Currency) (accountKind: AccountKind): seq = seq { for filePath in Directory.GetFiles (GetConfigDir currency accountKind).FullName do @@ -194,9 +174,26 @@ module Config = let RemoveReadOnlyAccount (account: ReadOnlyAccount): unit = RemoveAccount account - [] - let private NoInitMsg = "This function never really existed, but it's here to warn you that yes, configuration needs to be initialized (e.g. for migrations) but it's done in Account.GetAllActiveAccounts() so that it's done by all frontends seamlessly (not explicitly)" - - [] - let Init() = - failwith NoInitMsg + /// NOTE: the real initialization happens in Account.fs , see isInitialized + let internal Init() = + // In case a new token was added it will not have a config for an existing user + // we copy the eth configs to the new tokens config directory + let propagateEthAccountInfoToMissingTokensAccounts() = + for accountKind in (AccountKind.All()) do + let ethConfigDir = GetConfigDir Currency.ETH accountKind + for token in Currency.GetAll() do + if token.IsEthToken() then + let maybeTokenConfigDir = GetConfigDirInternal token accountKind false + match maybeTokenConfigDir with + | Some _ -> + // already removed token account before + () + | None -> + // now create it if it wasn't there before + let tokenConfigDir = GetConfigDir token accountKind + for ethAccountFilePath in Directory.GetFiles ethConfigDir.FullName do + let newPath = ethAccountFilePath.Replace(ethConfigDir.FullName, tokenConfigDir.FullName) + if not (File.Exists newPath) then + File.Copy(ethAccountFilePath, newPath) + + propagateEthAccountInfoToMissingTokensAccounts()