From c77936a127fa38450ef363afbfdd89931686a3fb 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 | 47 ++++++++++--------- 2 files changed, 25 insertions(+), 27 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..21bf5a83e 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,35 @@ 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:" + Console.WriteLine "Choose account to send funds to:" + Console.WriteLine() let btcAccounts = Account.GetAllActiveAccounts() |> Seq.filter (fun acc -> acc.Currency = currency) |> Seq.toList - 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" + | _ -> + btcAccounts |> List.iteri (fun i account -> + printfn "Account %d:" (i + 1) + printfn "Address=[ %s ]" account.PublicAddress + 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 chooseAccount() with | Some targetAccount -> @@ -409,10 +414,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 =