From db04387230451891904d59ab0e6e0f553afd4d04 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 22 Jul 2024 11:29:46 +0200 Subject: [PATCH] WIP: addressed comments --- .../UtxoCoin/ImportedAccount.fs | 5 +- src/GWallet.Frontend.Console/Program.fs | 52 +++++++++---------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs b/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs index ffbd6e856..735278253 100644 --- a/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs +++ b/src/GWallet.Backend/UtxoCoin/ImportedAccount.fs @@ -9,13 +9,11 @@ type ImportedAccount(mnemonic: string) = let firstReceivingAddressKey = rootKey.Derive(0u).Derive(0u) let firstReceivingAddressPubKey = firstReceivingAddressKey.GetPublicKey().ToHex() let publicAddress = firstReceivingAddressKey.GetPublicKey().GetAddress(ScriptPubKeyType.Segwit, Network.Main).ToString() - - do ignore firstReceivingAddressPubKey interface IAccount with member self.Currency = Currency.BTC member self.PublicAddress = publicAddress -#if !LEGACY_FRAMEWORK + member self.GetTotalBalance() = async { let! maybeBalance = @@ -32,4 +30,3 @@ type ImportedAccount(mnemonic: string) = destinationAccount.PublicAddress amount firstReceivingAddressKey.PrivateKey -#endif \ No newline at end of file diff --git a/src/GWallet.Frontend.Console/Program.fs b/src/GWallet.Frontend.Console/Program.fs index e68af4887..3d2455ffe 100644 --- a/src/GWallet.Frontend.Console/Program.fs +++ b/src/GWallet.Frontend.Console/Program.fs @@ -351,7 +351,6 @@ module Program = () let TransferFundsFromWalletUsingMenmonic() = -#if !LEGACY_FRAMEWORK let rec askForMnemonic() : UtxoCoin.ImportedAccount = Console.WriteLine "Enter mnemonic seed phrase (12, 15, 18, 21 or 24 words):" let mnemonic = Console.ReadLine() @@ -373,29 +372,32 @@ module Program = printfn "Balance on imported account: %s BTC" (balance.ToString()) let rec chooseAccount() = - Console.WriteLine "Choose account to send funds to" - Console.WriteLine "Available accounts:" - let btcAccounts = - Account.GetAllActiveAccounts() - |> Seq.filter (fun acc -> acc.Currency = currency) - |> Seq.toList + Console.WriteLine "Choose account to send funds to:" + Console.WriteLine() + let allAccounts = Account.GetAllActiveAccounts() |> Seq.toList + let btcAccounts = allAccounts |> List.filter (fun acc -> acc.Currency = currency) - UserInteraction.DisplayAccountStatuses(WhichAccount.All btcAccounts) - |> Async.RunSynchronously - |> Seq.iter Console.WriteLine - - Console.Write("Write the account number (or 0 to cancel): ") - let accountNumber = Console.ReadLine() - match Int32.TryParse(accountNumber) with - | false, _ -> chooseAccount() - | true, 0 -> None - | true, accountParsed -> - let theAccountChosen = - try - Some btcAccounts.[accountParsed - 1] - with - | _ -> chooseAccount() - theAccountChosen + match btcAccounts with + | [ singleAccount ] -> Some singleAccount + | [] -> failwith "No BTC accounts found" + | _ -> + for account in btcAccounts do + UserInteraction.DisplayAccountStatuses(WhichAccount.MatchingWith account) + |> Async.RunSynchronously + |> Seq.iter Console.WriteLine + + Console.Write("Write the account number (or 0 to cancel): ") + let accountNumber = Console.ReadLine() + match Int32.TryParse(accountNumber) with + | false, _ -> chooseAccount() + | true, 0 -> None + | true, accountParsed -> + let theAccountChosen = + try + Some allAccounts.[accountParsed - 1] + with + | _ -> chooseAccount() + theAccountChosen match chooseAccount() with | Some targetAccount -> @@ -409,10 +411,6 @@ module Program = let uri = BlockExplorer.GetTransaction currency txId printfn "Transaction successful:\n%s" (uri.ToString()) | None -> () -#else - let x = UtxoCoin.ImportedAccount "" - ignore x -#endif let WalletOptions(): unit = let rec AskWalletOption(): GenericWalletOption =