From 75fa06c5bd7fe442b51dc896d5a8bd24dcdaec69 Mon Sep 17 00:00:00 2001 From: Dan Gershony Date: Sat, 6 Jun 2020 23:47:03 +0100 Subject: [PATCH] Create send max button and fee types (#148) * Create send max button and fee types * Fix some html * add max button and fee to cold staking * Add Max button * Add icons to buttons & improve tables * Add button icons * Fix xds fees * Show staking balance of hot accounts on staking UI * Improve UI Home Dashboard * Add network status to wallet page * Update Calculation for Wallet Sync * Revert xds min tx fee * change text for connection direction Co-authored-by: Hunter --- .../UI/Pages/ColdStake.razor | 30 +- .../UI/Pages/ColdStakeDelegate.razor | 55 ++-- .../UI/Pages/ColdStakeEnableWallet.razor | 6 - .../UI/Pages/ColdStakeSetup.razor | 186 ++++++------ .../UI/Pages/ColdStakeView.razor | 25 +- .../UI/Pages/ColdStakeWithdraw.razor | 18 +- .../UI/Pages/Stake.razor | 162 ++++++----- .../UI/Pages/Index.razor | 206 +++++++++---- .../UI/Shared/MainLayout.razor | 10 +- .../UI/Pages/WalletAccount.razor | 23 +- .../UI/Pages/WalletBroadcastTx.razor | 2 +- .../UI/Pages/WalletReceive.razor | 2 +- .../UI/Pages/WalletSend.razor | 273 ++++++++++-------- .../UI/Pages/Wallets.razor | 74 +++-- .../Xds/Blockcore.Networks.Xds/XdsMain.cs | 4 +- 15 files changed, 661 insertions(+), 415 deletions(-) diff --git a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStake.razor b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStake.razor index 032d7c4d2..2c84cafb0 100644 --- a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStake.razor +++ b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStake.razor @@ -69,14 +69,15 @@

Balances

-
+
- - - - + + + + + @@ -85,15 +86,15 @@ var coldStakingWalletEnabled = ColdStakingManager.GetColdStakingAccount(this.WalletManager.GetWallet(walletName), true); if (coldStakingWalletEnabled != null) { - + @foreach (var account in this.WalletManager.GetAccounts(walletName)) { var accountBalance = this.WalletManager.GetBalances(walletName, account.Name).Single(); @if (@accountBalance.AmountUnconfirmed >0) { - + } else { - + } var coldStakingAccount = ColdStakingManager.GetColdStakingAccount(this.WalletManager.GetWallet(walletName), true); @@ -101,9 +102,9 @@ if (coldStakingAccount != null) { var coldAccountBalance = ColdStakingManager.GetBalances(walletName, coldStakingAccount.Name).Single(); @if (@coldAccountBalance.AmountUnconfirmed >0) { - + } else { - + } } @@ -112,15 +113,18 @@ if (hotStakingAccount != null) { var hotAccountBalance = ColdStakingManager.GetBalances(walletName, hotStakingAccount.Name).Single(); @if (@hotAccountBalance.AmountUnconfirmed >0) { - + } else { - + } } } + } - } + }
WalletAccount balanceCold balanceHot balanceWALLETMAIN BALANCECOLD BALANCEHOT BALANCEDETAILS
@walletName@walletName@accountBalance.AmountConfirmed (@accountBalance.AmountUnconfirmed )@accountBalance.AmountConfirmed (@accountBalance.AmountUnconfirmed )@accountBalance.AmountConfirmed@accountBalance.AmountConfirmed@coldAccountBalance.AmountConfirmed (@coldAccountBalance.AmountUnconfirmed )@coldAccountBalance.AmountConfirmed (@coldAccountBalance.AmountUnconfirmed )@coldAccountBalance.AmountConfirmed@coldAccountBalance.AmountConfirmed@hotAccountBalance.AmountConfirmed (@hotAccountBalance.AmountUnconfirmed )@hotAccountBalance.AmountConfirmed (@hotAccountBalance.AmountUnconfirmed )@hotAccountBalance.AmountConfirmed@hotAccountBalance.AmountConfirmed + +
diff --git a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeDelegate.razor b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeDelegate.razor index e1e42b4c1..5418d860f 100644 --- a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeDelegate.razor +++ b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeDelegate.razor @@ -14,7 +14,7 @@ @inject NodeDeployments NodeDeployments
-

Delegate Staking From: @walletname

+

Delegate Staking from @walletname

@@ -40,7 +40,7 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0")
-
+
Cold Balance
@@ -57,7 +57,6 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0")
-
@@ -69,25 +68,25 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0")
-
-
- Amount: -
- -
- @this.Network.CoinTicker.ToUpper() -
+
+
+ Amount (@this.Network.CoinTicker.ToUpper()):
+ +
+ +
+
-
-
- Fee: -
- -
- Optional (default to low) -
+
+
+ Fee: +
+ +
+ Default to low
+
@@ -95,9 +94,10 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0")
+
- - + +
@Alert
@@ -147,12 +147,25 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0") } return Task.CompletedTask; } + public void SendMax() + { + var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0").Single(); + this.Amount = mainAccountBalance.AmountConfirmed.ToUnit(MoneyUnit.BTC); + + this.Amount = this.Amount - this.Fee; + } private void ChangePayToScript() { this.PayToScript = !this.PayToScript; } + public void MaxAmount() + { + var accountBalance = this.WalletManager.GetBalances(walletname, "account 0").Single(); + this.Amount = accountBalance.AmountConfirmed.ToDecimal(MoneyUnit.BTC) - this.Fee; + } + private async Task Setup() { if (string.IsNullOrEmpty(this.Password)) { this.Alert = "Please enter a password"; return; } diff --git a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeEnableWallet.razor b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeEnableWallet.razor index 7e451c254..48c20286a 100644 --- a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeEnableWallet.razor +++ b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeEnableWallet.razor @@ -9,12 +9,6 @@ @inject NavigationManager NavigationManager @inject NodeDeployments NodeDeployments -@if (!NodeDeployments.GetFlags().ScriptFlags.HasFlag(ScriptVerify.CheckColdStakeVerify)) -{ -

Cold staking is not activated

- return; -} -

Enable cold staking on an existing wallet

diff --git a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeSetup.razor b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeSetup.razor index d554a7ca3..c22521605 100644 --- a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeSetup.razor +++ b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeSetup.razor @@ -3,8 +3,10 @@ @using Blockcore.Features.ColdStaking @using Blockcore.Features.Wallet.Interfaces @using NBitcoin; -@using Blockcore.Interfaces @using Blockcore.Base.Deployments +@using Blockcore.Features.Wallet; +@using Blockcore.Features.Wallet.Types +@using Blockcore.Interfaces @inject IWalletManager WalletManager @inject NavigationManager NavigationManager @@ -14,121 +16,124 @@ @inject NodeDeployments NodeDeployments
-

Coldstaking setup for: @walletname

+

Cold Staking setup for @walletname

@{ -var accountBalance = this.WalletManager.GetBalances(walletname, "coldStakingColdAddresses").Single(); -var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0").Single(); - -
-
-
-
-
Main Balance
-
-
-
-

@mainAccountBalance.AmountConfirmed

-

@this.Network.CoinTicker.ToUpper()

+ var accountBalance = this.WalletManager.GetBalances(walletname, "coldStakingColdAddresses").Single(); + var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0").Single(); + +
+
+
+
+
Main Balance
+
+
+
+

@mainAccountBalance.AmountConfirmed

+

@this.Network.CoinTicker.ToUpper()

+
+
@mainAccountBalance.AmountUnconfirmed (unconfirmed)
-
@mainAccountBalance.AmountUnconfirmed (unconfirmed)
-
-
-
-
Cold Balance
-
-
-
-

@accountBalance.AmountConfirmed

-

@this.Network.CoinTicker.ToUpper()

+
+
+
Cold Balance
+
+
+
+

@accountBalance.AmountConfirmed

+

@this.Network.CoinTicker.ToUpper()

+
+
@accountBalance.AmountUnconfirmed (unconfirmed)
-
@accountBalance.AmountUnconfirmed (unconfirmed)
-
-//TODO: remove coldstake address -
-
-
-
-
-
- Cold Address: -
- -
- from: @walletname -
-
- -
-
- Hot Address: -
- +
+
+
+
-
-
- @{ - foreach (var walletName in this.WalletManager.GetWalletsNames().Where(w => w != walletname)) { - var coldStakingWalletEnabled = ColdStakingManager.GetColdStakingAccount(this.WalletManager.GetWallet(walletName), true); - if (coldStakingWalletEnabled != null) { - - } - } - } -
-
-
+ @*TODO: test removed coldstake address +
- Amount: + Amount(@this.Network.CoinTicker.ToUpper()):
- +
- @this.Network.CoinTicker.ToUpper() + from: @walletname
-
+
*@
-
- Fee: +
+ Hot Address:
- -
- Optional (default to low) + + +
+
+ @{ + foreach (var walletName in this.WalletManager.GetWalletsNames().Where(w => w != walletname)) + { + var coldStakingWalletEnabled = ColdStakingManager.GetColdStakingAccount(this.WalletManager.GetWallet(walletName), true); + if (coldStakingWalletEnabled != null) + { + + } + } + } +
+
+
+
+ Amount (@this.Network.CoinTicker.ToUpper()): +
+ +
+ +
-
-
-
- Password: +
+
+ Fee: +
+ +
+ Default to low +
- -
-
+ +
+
+ Password: +
+ +
+
-
-
-
@Alert
+
+
+
@Alert
+
-
} @code @@ -189,12 +194,31 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0") return; } } + public void SendMax() + { + var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0").Single(); + + this.Amount = mainAccountBalance.AmountConfirmed.ToUnit(MoneyUnit.BTC); + + this.Amount = this.Amount - this.Fee; + + if (this.PayToScript) + { + TxNullDataTemplate template = this.Network.StandardScriptsRegistry.GetScriptTemplates.OfType().First(); + + this.Amount = this.Amount - new Money(template.MinRequiredSatoshiFee, MoneyUnit.Satoshi).ToUnit(MoneyUnit.BTC); + } + } private void ChangePayToScript() { this.PayToScript = !this.PayToScript; } - + public void MaxAmount() + { + var accountBalance = this.WalletManager.GetBalances(walletname, "account 0").Single(); + this.Amount = accountBalance.AmountConfirmed.ToDecimal(MoneyUnit.BTC) - this.Fee; + } private async Task Setup() { if (string.IsNullOrEmpty(this.Password)) { this.Alert = "Please enter a password"; return; } diff --git a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeView.razor b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeView.razor index c889ab2dd..1bf5d437c 100644 --- a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeView.razor +++ b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeView.razor @@ -12,11 +12,14 @@ @{
-

Cold Staking Dashboard for @walletname

+

Cold Staking - @walletname

- - - + + +
@@ -70,10 +73,10 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle - - - - + + + + @@ -83,9 +86,9 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle { @* @onclick="() => { NavigateToViewTx(transaction.Id); }" *@ - - - + + + } } diff --git a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeWithdraw.razor b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeWithdraw.razor index 5fb8d94ec..8df939832 100644 --- a/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeWithdraw.razor +++ b/src/Features/Blockcore.Features.ColdStaking/UI/Pages/ColdStakeWithdraw.razor @@ -14,7 +14,7 @@ @inject NodeDeployments NodeDeployments
-

Cold Staking Withdrawal To: @walletname

+

Cold Staking withdrawal to @walletname

@@ -57,7 +57,6 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0") -
@@ -67,16 +66,16 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0") Address:
- +
- Amount: + Amount(@this.Network.CoinTicker.ToUpper()):
- @this.Network.CoinTicker.ToUpper() +
@@ -86,7 +85,7 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0")
- Optional (default to low) + Default to low
@@ -107,7 +106,6 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0") } - @code { ColdStakingManager ColdStakingManager; @@ -144,7 +142,11 @@ var mainAccountBalance = this.WalletManager.GetBalances(walletname, "account 0") this.Address = segwit ? result.Bech32Address : result.Address; } - + public void MaxAmount() + { + var accountBalance = this.WalletManager.GetBalances(walletname, "coldStakingColdAddresses").Single(); + this.Amount = accountBalance.AmountConfirmed.ToDecimal(MoneyUnit.BTC) - this.Fee; + } private async Task Withdraw() { if (string.IsNullOrEmpty(this.Password)) { this.Alert = "Please enter a password"; return; } diff --git a/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor b/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor index a0a6b25a3..f2e6a20dc 100644 --- a/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor +++ b/src/Features/Blockcore.Features.Miner/UI/Pages/Stake.razor @@ -17,12 +17,12 @@
-
+
Main Balance
-
+

@totalBalance()

@this.Network.CoinTicker.ToUpper()

@@ -34,6 +34,7 @@
+ @{ if (this.StakingEnabled) { @@ -48,50 +49,49 @@ Staking disabled
} - -
-
TYPEDATE/TIMEAMOUNTBLOCKTYPEDATE/TIMEAMOUNTBLOCK
@transaction.Type@String.Format("{0:f}", transaction.Timestamp)@transaction.Amount@transaction.ConfirmedInBlock@String.Format("{0:f}", transaction.Timestamp)@transaction.Amount@transaction.ConfirmedInBlock
- - - - - @* *@ - - - - @{ - foreach (var walletName in this.WalletManager.GetWalletsNames()) - { - foreach (var account in this.WalletManager.GetAccounts(walletName)) - { - var mainAccountBalance = this.WalletManager.GetBalances(walletName, account.Name).Single(); - - - - @if (@mainAccountBalance.AmountUnconfirmed >0) { - - } else { - - } - - @* var hotStakingAccount = ColdStakingManager.GetColdStakingAccount(this.WalletManager.GetWallet(walletName), false); - - if (hotStakingAccount != null) { - var hotAccountBalance = ColdStakingManager.GetBalances(walletName, hotStakingAccount.Name).Single(); - @if (@hotAccountBalance.AmountUnconfirmed >0) { - - } else { - - } - } *@ - - } - } - } - -
WalletMain balance (unconfirmed)Hot balance (unconfirmed)
@walletName@mainAccountBalance.AmountConfirmed (@mainAccountBalance.AmountUnconfirmed )@mainAccountBalance.AmountConfirmed@hotAccountBalance.AmountConfirmed (@hotAccountBalance.AmountUnconfirmed )@hotAccountBalance.AmountConfirmed
-
- +
+
+
+
+

Staking Wallets

+
+ + + + + + + + + @{ + foreach (var walletName in this.WalletManager.GetWalletsNames()) + { + var items = this.WalletManager.GetSpendableTransactionsInWalletForStaking(walletName, 0); + + var amountConfirmed = items.Where(s => s.Confirmations > 0).Sum(s => s.Transaction.Amount); + var amountUnconfirmed = items.Where(s => s.Confirmations <= 0).Sum(s => s.Transaction.Amount); + + + + @if (amountUnconfirmed > 0) + { + + } + else + { + + } + + + } + } + +
WALLETBALANCE (UNCONFIRMED)
@walletName@Money.Satoshis(amountConfirmed) (@Money.Satoshis(amountUnconfirmed))@Money.Satoshis(amountConfirmed)
+
+
+
+
+
if (!this.StakingEnabled) {
@@ -111,6 +111,31 @@
+ @*
+
+
+
+
+
+
+ Wallet Name: +
+ +
+
+
+ Password: +
+ +
+
+ +
+
+
+
+
+
*@ } else { @@ -118,7 +143,6 @@
} -
@Alert
@@ -126,7 +150,6 @@ @code { - string Alert { get; set; } private string WalletName { get; set; } @@ -137,6 +160,11 @@ private string StakingInfo { get; set; } + @* private string StakingWeight { get; set; } + private string NetworkWeight { get; set; } + private string StakingPercent { get; set; } + private string StakingTime { get; set; } *@ + protected override void OnInitialized() { this.LoadStats(); @@ -154,6 +182,11 @@ this.StakingInfo = $"Node staking with {new Money(model.Weight)} ({ourPercent:0.00} % of the network weight {new Money(model.NetStakeWeight)}), " + $"est. time to find new block is {TimeSpan.FromSeconds(model.ExpectedTime)}."; + + @* this.StakingWeight = $"{new Money(model.Weight)}"; + this.NetworkWeight = $"{new Money(model.NetStakeWeight)}"; + this.StakingPercent = $"{ourPercent:0.00}"; + this.StakingTime = $"{TimeSpan.FromSeconds(model.ExpectedTime)}"; *@ } else { @@ -176,32 +209,31 @@ private dynamic totalBalance() { dynamic balance = 0; - foreach (var walletName in this.WalletManager.GetWalletsNames()) - { - foreach (var account in this.WalletManager.GetAccounts(walletName)) - { - var accountBalance = this.WalletManager.GetBalances(walletName, account.Name).Single(); - balance = balance + accountBalance.AmountConfirmed; - } - } + foreach (var walletName in this.WalletManager.GetWalletsNames()) + { + var items = this.WalletManager.GetSpendableTransactionsInWalletForStaking(walletName, 1); + var amountConfirmed = items.Where(s => s.Confirmations > 0).Sum(s => s.Transaction.Amount); + + var accountBalance = Money.Satoshis(amountConfirmed); + balance = balance + accountBalance; + } return balance; } private dynamic totalUnconfirmedBalance() { dynamic balance = 0; - foreach (var walletName in this.WalletManager.GetWalletsNames()) - { - foreach (var account in this.WalletManager.GetAccounts(walletName)) - { - var accountBalance = this.WalletManager.GetBalances(walletName, account.Name).Single(); - balance = balance + accountBalance.AmountUnconfirmed; - } - } + foreach (var walletName in this.WalletManager.GetWalletsNames()) + { + var items = this.WalletManager.GetSpendableTransactionsInWalletForStaking(walletName, 0); + var amountConfirmed = items.Where(s => s.Confirmations <= 0).Sum(s => s.Transaction.Amount); + + var accountBalance = Money.Satoshis(amountConfirmed); + balance = balance + accountBalance; + } return balance; } - private void StartStaking() { if (string.IsNullOrEmpty(this.Password)) { this.Alert = "Please enter a password"; return; } diff --git a/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor b/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor index 88005f772..4fdf5b4ef 100644 --- a/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor +++ b/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor @@ -10,18 +10,23 @@ @inject NavigationManager NavigationManager
-

@this.Network.CoinTicker.ToUpper() Node

+

@this.Network.CoinTicker.ToUpper() Network

- -
- -
- - + +
+ +
+ +
-
@@ -29,70 +34,151 @@
@{ + if (this.InitialBlockDownloadState.IsInitialBlockDownload()) + { +

Currently processing the IBD (initial block download) & syncing your node with the network

+ } -if (this.InitialBlockDownloadState.IsInitialBlockDownload()) -{ -

Currently processing the IBD (initial block download) & syncing your node with the network

-} +
+
+
+
+
+
+
+

@this.Network.CoinTicker.ToUpper()

+

+
+
+
+
+ +
+
+
+
Network
+
+
+
+
+
+
+
+
+
+

@this.ConnectionManager.ConnectedPeers.Count()

+

+
+
+
+
+ +
+
+
+
Peers
+
+
+
+
+
+
+
+
+
+ @if (this.InitialBlockDownloadState.IsInitialBlockDownload()) + { + + } + else + { + + } +

+
+
+
+
+ +
+
+
+
Chain Synced
+
+
+
+
+
+
+
+
+
+

@this.ChainIndexer.Tip.Height

+

+
+
+
+
+ +
+
+
+
Network Height
+
+
+
+
-
-
-
-
-
- - - - - - - - - - - - - - - -
Connected peers:@this.ConnectionManager.ConnectedPeers.Count()
Current tip at height:@this.ChainIndexer.Tip.Height
Current tip Hash:@this.ChainIndexer.Tip.HashBlock
+
+
+
+
+
+ + + + + + + +
Current tip Hash:@this.ChainIndexer.Tip.HashBlock
+
-
-
-
-
-
-
- - - - - - - - - - - @foreach (var peer in this.ConnectionManager.ConnectedPeers) - { +
+
+
+
+
+
IP AddressInboundAgentVersion
+ - - - - + + + + - } - -
@peer.RemoteSocketEndpoint.ToString()@peer.Inbound@peer.PeerVersion?.UserAgent@peer.PeerVersion?.VersionIP ADDRESSCONNECTIONAGENTVERSION
+ + + @foreach (var peer in this.ConnectionManager.ConnectedPeers) + { + + @peer.RemoteSocketEndpoint.ToString() + @(peer.Inbound ? "Inbound" : "Outbound") + @peer.PeerVersion?.UserAgent + @peer.PeerVersion?.Version + + } + + +
-
} @code { @@ -118,4 +204,4 @@ if (this.InitialBlockDownloadState.IsInitialBlockDownload()) { NavigationManager.NavigateTo("logs"); } -} +} \ No newline at end of file diff --git a/src/Features/Blockcore.Features.NodeHost/UI/Shared/MainLayout.razor b/src/Features/Blockcore.Features.NodeHost/UI/Shared/MainLayout.razor index c06e01133..3fda61f89 100644 --- a/src/Features/Blockcore.Features.NodeHost/UI/Shared/MainLayout.razor +++ b/src/Features/Blockcore.Features.NodeHost/UI/Shared/MainLayout.razor @@ -5,16 +5,14 @@
+
+ @Body +
@* -
*@ - -
- @Body -
+
*@
\ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletAccount.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletAccount.razor index 3b9b5bb97..9d5dfa56f 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletAccount.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletAccount.razor @@ -13,10 +13,13 @@ var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Single();
-

Wallet Account: @walletname

+

Wallet - @walletname

- - + + +
@@ -50,10 +53,10 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle - - - - + + + + @@ -63,9 +66,9 @@ var model = WalletModelBuilder.GetHistory(this.WalletManager, Network, new Walle { @*@onclick="() => { NavigateToViewTx(transaction.Id); }" > *@ - - - + + + } } diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletBroadcastTx.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletBroadcastTx.razor index 092fb312f..a12f416cd 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletBroadcastTx.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletBroadcastTx.razor @@ -16,7 +16,7 @@
-

Broadcast Transaction from: @walletname

+

Broadcast Transaction from @walletname

diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletReceive.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletReceive.razor index 5cbb91524..79c76b37a 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletReceive.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletReceive.razor @@ -8,7 +8,7 @@ @inject NavigationManager NavigationManager
-

Receive to: @walletname

+

Receive to @walletname

diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletSend.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletSend.razor index 7714f2a4b..ff395abb2 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletSend.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletSend.razor @@ -15,109 +15,116 @@ @inject IBroadcasterManager BroadcasterManager @{ -
-

Send coins from: @walletname

-
- +
+

Send coins from @walletname

+
+ +
-
- -var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Single(); -
-
-
-
-
Main Balance
-
-
-
-

@accountBalance.AmountConfirmed

-

@this.Network.CoinTicker.ToUpper()

+ + var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Single(); +
+
+
+
+
Main Balance
+
+
+
+

@accountBalance.AmountConfirmed

+

@this.Network.CoinTicker.ToUpper()

+
+
@accountBalance.AmountUnconfirmed (unconfirmed)
-
@accountBalance.AmountUnconfirmed (unconfirmed)
-
- -
-
-
-
-
-
- To Address: -
- -
-
-
- Amount: -
- -
- @this.Network.CoinTicker.ToUpper() +
+
+
+
+
+
+ To Address: +
+
-
-
-
- Fee: +
+
+ Amount(@this.Network.CoinTicker.ToUpper()): +
+ +
+ +
- -
- + +
+
+ Fee: +
+ +
+ + + +
-
-
-
- Password: +
+
+ Password: +
+
- -
@if (IsSending) - { } + { + + } else - { } -
+ { + + } +
-
-
@Alert
-
- -
-
@Success
+
+
@Alert
+
+ +
+
@Success
+
-
-@* -// TODO add confirmation screeen -

Transaction Details

- -
-
-
-
-

Transaction hash: @SentTransactionHash

-
-
- Raw Transaction + @* + // TODO add confirmation screeen +

Transaction Details

+ +
+
+
+
+

Transaction hash: @SentTransactionHash

+
+
+ Raw Transaction +
+ +
-
-
-
-
*@ +
*@ } @code { @@ -145,7 +152,7 @@ var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Sin { this.Fee = new Money(this.Network.MinTxFee).ToDecimal(MoneyUnit.BTC); } - public void EstimateFee() + public void EstimateFee(FeeType feeType = FeeType.Low) { if (string.IsNullOrEmpty(this.Address)) { this.Alert = "Please enter a valid address"; return; } if (this.Amount == 0) { this.Alert = "Please enter the number of coins you want to send"; return; } @@ -161,22 +168,53 @@ var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Sin var context = new TransactionBuildContext(this.Network) { AccountReference = new WalletAccountReference(walletname, accountname), - FeeType = FeeType.Low, + FeeType = feeType, Recipients = recipients, Sign = false }; - this.Fee = this.WalletTransactionHandler.EstimateFee(context).ToDecimal(MoneyUnit.BTC); + try + { + this.Fee = this.WalletTransactionHandler.EstimateFee(context).ToDecimal(MoneyUnit.BTC); + } + catch (NBitcoin.NotEnoughFundsException nef) + { + if (nef.Missing is Money money) + { + var minFee = new Money(this.Network.MinTxFee).ToDecimal(MoneyUnit.BTC); + this.Fee = Math.Max(minFee, money.ToDecimal(MoneyUnit.BTC)); + } + else + { + this.Alert = nef.Message; + } + } + catch (Exception ex) + { + this.Alert = ex.Message; + } + } + public void SendMax() + { + if (string.IsNullOrEmpty(this.Address)) { this.Alert = "Please enter a valid address"; return; } + this.Alert = string.Empty; + + var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Single(); + + this.Amount = accountBalance.AmountConfirmed.ToUnit(MoneyUnit.BTC); + + this.EstimateFee(); + + this.Amount = this.Amount - this.Fee; } + private bool IsSending { get; set; } private async Task callSendCoins() { IsSending = true; StateHasChanged(); - await Task.Delay(1); - { - SendCoins(); - } + await Task.Delay(1); // flush changes + await SendCoins(); IsSending = false; StateHasChanged(); await Task.Delay(1); @@ -197,39 +235,48 @@ var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Sin return; } - var recipients = new List(); - recipients.Add(new Recipient + try { - ScriptPubKey = BitcoinAddress.Create(Address, this.Network).ScriptPubKey, - Amount = new Money(Amount, MoneyUnit.BTC) - }); - - var context = new TransactionBuildContext(this.Network) - { - AccountReference = new WalletAccountReference(walletname, accountname), - Shuffle = true, // We shuffle transaction outputs by default as it's better for anonymity. - WalletPassword = Password, - Recipients = recipients, - UseSegwitChangeAddress = recipients[0].ScriptPubKey.IsScriptType(ScriptType.Witness), - TransactionFee = new Money(this.Fee, MoneyUnit.BTC) - }; - - Transaction transactionResult = this.WalletTransactionHandler.BuildTransaction(context); - - this.SentTransactionHash = transactionResult.GetHash(); - this.TransactionHex = transactionResult.ToHex(this.Network.Consensus.ConsensusFactory); - - Transaction transaction = this.Network.CreateTransaction(this.TransactionHex); - - await this.BroadcasterManager.BroadcastTransactionAsync(transaction); - - var transactionBroadCastEntry = this.BroadcasterManager.GetTransaction(transaction.GetHash()); - - if (transactionBroadCastEntry.TransactionBroadcastState == TransactionBroadcastState.FailedBroadcast) + var recipients = new List(); + recipients.Add(new Recipient + { + ScriptPubKey = BitcoinAddress.Create(Address, this.Network).ScriptPubKey, + Amount = new Money(Amount, MoneyUnit.BTC) + }); + + var context = new TransactionBuildContext(this.Network) + { + AccountReference = new WalletAccountReference(walletname, accountname), + Shuffle = true, // We shuffle transaction outputs by default as it's better for anonymity. + WalletPassword = Password, + Recipients = recipients, + UseSegwitChangeAddress = recipients[0].ScriptPubKey.IsScriptType(ScriptType.Witness), + TransactionFee = new Money(this.Fee, MoneyUnit.BTC) + }; + + Transaction transactionResult = this.WalletTransactionHandler.BuildTransaction(context); + + this.SentTransactionHash = transactionResult.GetHash(); + this.TransactionHex = transactionResult.ToHex(this.Network.Consensus.ConsensusFactory); + + Transaction transaction = this.Network.CreateTransaction(this.TransactionHex); + + await this.BroadcasterManager.BroadcastTransactionAsync(transaction); + + var transactionBroadCastEntry = this.BroadcasterManager.GetTransaction(transaction.GetHash()); + + if (transactionBroadCastEntry.TransactionBroadcastState == TransactionBroadcastState.FailedBroadcast) + { + this.Alert = "An error occurred: " + transactionBroadCastEntry.ErrorMessage; + return; + } + } + catch (Exception ex) { - this.Alert = "An error occurred: " + transactionBroadCastEntry.ErrorMessage; + this.Alert = ex.Message; return; } + this.Success = "Coins sent."; NavigationManager.NavigateTo("walletaccount/" + walletname + "/" + accountname); diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor index 12980ec3e..e8624c9e8 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor @@ -11,19 +11,24 @@ @inject IBroadcasterManager BroadcasterManager @inject Network Network @inject IPooledTransaction PooledTransaction +@inject Blockcore.Interfaces.IInitialBlockDownloadState InitialBlockDownloadState @{
-

Wallet Details

+

Wallets

- - - - + + + +
-
+
Main Balance
@@ -39,21 +44,49 @@
+
+
+
+
Wallet Status
+
+
+
+

@this.WalletSyncManager.WalletTip.Height / @ChainIndexer.Height

+
+
+
+
+ @if (InSync()<100) { + + } else { + + } +
+
+
+ @if (InSync()<100) { +
Syncing - @InSync()%
+ } else { +
Synced
+ } +
+
+
-

Balances

-
+
TYPEDATE/TIMEAMOUNTBLOCKTYPEDATE/TIMEAMOUNTBLOCK
@transaction.Type@String.Format("{0:f}", transaction.Timestamp)@transaction.Amount@transaction.ConfirmedInBlock@String.Format("{0:f}", transaction.Timestamp)@transaction.Amount@transaction.ConfirmedInBlock
- - - + + + + @@ -63,11 +96,13 @@ foreach (var account in this.WalletManager.GetAccounts(walletName)) { var accountBalance = this.WalletManager.GetBalances(walletName, account.Name).Single(); - - - - + + + + } } @@ -75,7 +110,6 @@
WalletConfirmed balanceUnconfirmed balanceWALLETCONFIRMED BALANCEUNCONFIRMED BALANCEDETAILS
@walletName@accountBalance.AmountConfirmed@accountBalance.AmountUnconfirmed@walletName@accountBalance.AmountConfirmed@accountBalance.AmountUnconfirmed
-

Wallet Tip: @this.WalletSyncManager.WalletTip.Height / @ChainIndexer.Height

@@ -100,7 +134,6 @@ { this.WalletSyncManager.SyncFromHeight(1); } - private async Task Rebroadcast() { foreach (string walletName in this.WalletManager.GetWalletsNames()) @@ -156,4 +189,11 @@ return balance; } + private dynamic InSync() + { + dynamic syncPercent = 0; + syncPercent = (this.WalletSyncManager.WalletTip.Height / this.ChainIndexer.Height) * 100; + return syncPercent; + } + } \ No newline at end of file diff --git a/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs b/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs index 2b3dadead..0c4fc9a1b 100644 --- a/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs +++ b/src/Networks/Xds/Blockcore.Networks.Xds/XdsMain.cs @@ -45,8 +45,8 @@ public XdsMain() this.MaxTipAge = 2 * 60 * 60; this.MinTxFee = Money.Coins(0.00001m).Satoshi; this.MaxTxFee = Money.Coins(1).Satoshi; - this.FallbackFee = this.MinTxFee; - this.MinRelayTxFee = this.MinTxFee; + this.FallbackFee = Money.Coins(0.00001m).Satoshi; + this.MinRelayTxFee = Money.Coins(0.00001m).Satoshi; this.AbsoluteMinTxFee = Money.Coins(0.01m).Satoshi; var consensusFactory = new XdsConsensusFactory();