88@inject IWalletManager WalletManager
99@inject NavigationManager NavigationManager
1010@inject NodeDeployments NodeDeployments
11+ @inject Network Network
1112
1213@if (! NodeDeployments .GetFlags ().ScriptFlags .HasFlag (ScriptVerify .CheckColdStakeVerify ))
1314{
1415 <h2 >Cold staking is not activated </h2 >
1516 return ;
1617}
1718
18- <h2 >Cold staking wallets</ h2 >
19-
20- < p >Enable cold staking on an existing wallet.</ p >
21-
22- < hr />
23- < div class = " input-group mb-3 " >
24- < div class =" input-group-prepend " >
25- < span style = " min-width : 10 em " class = " input-group-text " id = " basic-addon1 " >Wallet Name:</ span >
26- </ div >
27- < input @bind = " WalletName " type = " text " class = " form-control " placeholder = " wallet name " />
19+ <div class = " d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom " >
20+ < h1 class = " h2 " >< strong >Cold Staking</ strong ></ h1 >
21+ < div class = " btn-toolbar mb-2 mb-md-0 " >
22+ @foreach ( var walletName in this . WalletManager . GetWalletsNames () ) {
23+ var coldStakingWalletEnabled = ColdStakingManager . GetColdStakingAccount ( this . WalletManager . GetWallet ( walletName ), true );
24+ if ( coldStakingWalletEnabled != null ) {} else {
25+ < button class = " btn btn-sm btn-primary " @onclick = " () => { NavigateToEnableWallet(); } " > Enable Cold Staking < / button >
26+ break ;
27+ }
28+ }
2829 </div >
29-
30- <div class =" input-group mb-3" >
31- <div class =" input-group-prepend" >
32- <span style =" min-width : 10em " class =" input-group-text" >Password:</span >
30+ </div >
31+ @{
32+ <div class =" row mb-3" >
33+ <div class =" col-xl-6 col-sm-6 grid-margin stretch-card" >
34+ <div class =" card" >
35+ <div class =" card-body" >
36+ <h5 >Main Balance </h5 >
37+ <div class =" row" >
38+ <div class =" col-12" >
39+ <div class =" d-flex align-items-center align-self-start" >
40+ <h3 class =" text-left" >@totalBalance().balance </h3 >
41+ <p class =" text-success ml-2 mb-0 font-weight-medium" >@this.Network.CoinTicker.ToUpper() </p >
42+ </div >
43+ </div >
44+ </div >
45+ <h6 class =" text-left text-muted font-weight-normal" >@totalUnconfirmedBalance().balance (unconfirmed )</h6 >
46+ </div >
3347 </div >
34- <input @bind =" Password" type =" password" class =" form-control" placeholder =" password" />
3548 </div >
36-
37- <div class =" input-group mb-3" >
38- <button class =" btn btn-info" @onclick =" CreateColdStakeAccount" >Create account</button >
49+ <div class =" col-xl-6 col-sm-6 grid-margin stretch-card" >
50+ <div class =" card" >
51+ <div class =" card-body" >
52+ <h5 >Cold Balance </h5 >
53+ <div class =" row" >
54+ <div class =" col-12" >
55+ <div class =" d-flex align-items-center align-self-start" >
56+ <h3 class =" text-left" >@totalBalance().coldBalance </h3 >
57+ <p class =" text-success ml-2 mb-0 font-weight-medium" >@this.Network.CoinTicker.ToUpper() </p >
58+ </div >
59+ </div >
60+ </div >
61+ <h6 class =" text-left text-muted font-weight-normal" >@totalUnconfirmedBalance().coldBalance (unconfirmed )</h6 >
62+ </div >
63+ </div >
3964 </div >
40- <hr />
41-
42- <p >Information about the deployed wallets.</p >
43-
44- @{
45- <table class =" table" >
46- <thead >
47- <tr >
48- <th >Wallet / Account </th >
49- <th >Confirmed balance </th >
50- <th >Unconfirmed balance </th >
51- <th >Action </th >
52- </tr >
53- </thead >
54- <tbody >
55- @{
56- foreach (var walletName in this .WalletManager .GetWalletsNames ())
57- {
58- var coldStakingAccount = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), true );
59- if (coldStakingAccount != null )
60- {
61- var coldAccountBalance = ColdStakingManager .GetBalances (walletName , coldStakingAccount .Name ).Single ();
62-
63- < tr title = " Withdraw" >
64- < td > @walletName < strong > / < / strong > @coldStakingAccount .Name < / td >
65- < td > @coldAccountBalance .AmountConfirmed < / td >
66- < td > @coldAccountBalance .AmountUnconfirmed < / td >
67- < td >
68- @if (coldAccountBalance .AmountConfirmed + coldAccountBalance .AmountUnconfirmed > 0 )
69- {
70- < button class = " btn btn-link btn-sm" @onclick = " () => { NavigateToWithdraw(walletName); }" > Withdraw < / button >
65+ </div >
66+
67+ <div class =" row " >
68+ <div class =" col-12 grid-margin" >
69+ <div class =" card" >
70+ <div class =" card-body" >
71+ <h4 class =" card-title" >Balances </h4 >
72+ <div class =" table-responsive" >
73+ <table class =" table table-border-bottom table-striped table-sm table-hover" >
74+ <thead class =" thead" >
75+ <tr >
76+ <th >Wallet </th >
77+ <th >Account balance </th >
78+ <th >Cold balance </th >
79+ <th >Hot balance </th >
80+ </tr >
81+ </thead >
82+ <tbody >
83+ @foreach ( var walletName in this .WalletManager .GetWalletsNames ()) {
84+
85+ var coldStakingWalletEnabled = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), true );
86+ if (coldStakingWalletEnabled != null ) {
87+ < tr @onclick = " () => { NavigateToColdStakeView(walletName); }" >
88+ < td > @walletName < / td >
89+ @foreach (var account in this .WalletManager .GetAccounts (walletName )) {
90+
91+ var accountBalance = this .WalletManager .GetBalances (walletName , account .Name ).Single ();
92+
93+ @if (@accountBalance .AmountUnconfirmed > 0 ) {
94+ < td > @accountBalance .AmountConfirmed (@accountBalance .AmountUnconfirmed )< / td >
95+ } else {
96+ < td > @accountBalance .AmountConfirmed < / td >
97+ }
98+
99+ var coldStakingAccount = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), true );
100+
101+ if (coldStakingAccount != null ) {
102+ var coldAccountBalance = ColdStakingManager .GetBalances (walletName , coldStakingAccount .Name ).Single ();
103+ @if (@coldAccountBalance .AmountUnconfirmed > 0 ) {
104+ < td > @coldAccountBalance .AmountConfirmed (@coldAccountBalance .AmountUnconfirmed )< / td >
105+ } else {
106+ < td > @coldAccountBalance .AmountConfirmed < / td >
107+ }
108+ }
109+
110+ var hotStakingAccount = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), false );
111+
112+ if (hotStakingAccount != null ) {
113+ var hotAccountBalance = ColdStakingManager .GetBalances (walletName , hotStakingAccount .Name ).Single ();
114+ @if (@hotAccountBalance .AmountUnconfirmed > 0 ) {
115+ < td > @hotAccountBalance .AmountConfirmed (@hotAccountBalance .AmountUnconfirmed )< / td >
116+ } else {
117+ < td > @hotAccountBalance .AmountConfirmed < / td >
118+ }
119+ }
71120 }
72- < / td >
73- < / tr >
74- }
75- else
76- {
77- <tr >
78- <td >@walletName </td >
79- <td >- </td >
80- <td >- </td >
81- <td >- </td >
82- </tr >
83- }
84-
85- var hotStakingAccount = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), false );
86- if (hotStakingAccount != null )
87- {
88- var hotAccountBalance = ColdStakingManager .GetBalances (walletName , hotStakingAccount .Name ).Single ();
89-
90- < tr >
91- < td > @walletName < strong > / < / strong > @hotStakingAccount .Name < / td >
92- < td > @hotAccountBalance .AmountConfirmed < / td >
93- < td > @hotAccountBalance .AmountUnconfirmed < / td >
94- < td >
95- < / td >
96- < / tr >
97- }
98- else
99- {
100- <tr >
101- <td >@walletName </td >
102- <td >- </td >
103- <td >- </td >
104- <td >- </td >
105- </tr >
106- }
107-
108- foreach (var account in this .WalletManager .GetAccounts (walletName ))
109- {
110- var accountBalance = this .WalletManager .GetBalances (walletName , account .Name ).Single ();
111-
112- <tr >
113- <td > @walletName <strong >/ </strong > @account.Name </td >
114- <td >@accountBalance.AmountConfirmed </td >
115- <td >@accountBalance.AmountUnconfirmed </td >
116- <td >
117- @if (accountBalance .AmountConfirmed + accountBalance .AmountUnconfirmed > 0 )
118- {
119- <button class =" btn btn-link btn-sm" @onclick =" () => { NavigateToSetup(walletName); }" >Delegate </button >
120- }
121- </td >
122- </tr >
123- }
124- }
125- }
126- </tbody >
127- </table >
121+ < / tr >
122+ }
123+ }
124+ </tbody >
125+ </table >
126+ </div >
127+ </div >
128+ </div >
129+ </div >
130+ </div >
128131}
129-
130132@code
131133{
132134 ColdStakingManager ColdStakingManager ;
133-
134135 string Alert { get ; set ; }
135-
136- private string WalletName { get ; set ; }
137-
138- private string Password { get ; set ; }
139-
140- public bool IsColdWalletAccount { get ; set ; }
141-
142136 protected override Task OnInitializedAsync ()
143137 {
144138 ColdStakingManager = this .WalletManager as ColdStakingManager ;
145139
146140 return Task .CompletedTask ;
147141 }
148-
149- private void CreateColdStakeAccount ()
142+ private (dynamic balance , dynamic coldBalance ) totalBalance ()
150143 {
151- if (string .IsNullOrEmpty (this .Password )) { this .Alert = " Please enter a password" ; return ; }
152- if (string .IsNullOrEmpty (this .WalletName )) { this .Alert = " Please enter a wallet name" ; return ; }
153- this .Alert = string .Empty ;
144+ dynamic balance = 0 ;
145+ dynamic coldBalance = 0 ;
146+ foreach (var walletName in this .WalletManager .GetWalletsNames ())
147+ {
148+ foreach (var account in this .WalletManager .GetAccounts (walletName ))
149+ {
150+ var accountBalance = this .WalletManager .GetBalances (walletName , account .Name ).Single ();
151+ balance = balance + accountBalance .AmountConfirmed ;
154152
155- this .ColdStakingManager .GetOrCreateColdStakingAccount (this .WalletName , true , this .Password );
156- this .ColdStakingManager .GetOrCreateColdStakingAccount (this .WalletName , false , this .Password );
153+ var coldStakingAccount = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), true );
154+ if (coldStakingAccount != null ) {
155+ var coldAccountBalance = ColdStakingManager .GetBalances (walletName , coldStakingAccount .Name ).Single ();
156+ coldBalance = coldBalance + coldAccountBalance .AmountConfirmed ;
157+ }
158+ }
159+ }
160+ return (balance ,coldBalance );
157161 }
158162
163+ private (dynamic balance , dynamic coldBalance ) totalUnconfirmedBalance ()
164+ {
165+ dynamic balance = 0 ;
166+ dynamic coldBalance = 0 ;
167+ foreach (var walletName in this .WalletManager .GetWalletsNames ())
168+ {
169+ foreach (var account in this .WalletManager .GetAccounts (walletName ))
170+ {
171+ var accountBalance = this .WalletManager .GetBalances (walletName , account .Name ).Single ();
172+ balance = balance + accountBalance .AmountUnconfirmed ;
173+
174+ var coldStakingAccount = ColdStakingManager .GetColdStakingAccount (this .WalletManager .GetWallet (walletName ), true );
175+ if (coldStakingAccount != null ) {
176+ var coldAccountBalance = ColdStakingManager .GetBalances (walletName , coldStakingAccount .Name ).Single ();
177+ coldBalance = coldBalance + coldAccountBalance .AmountUnconfirmed ;
178+ }
179+ }
180+ }
181+ return (balance ,coldBalance );
182+ }
183+ private void NavigateToEnableWallet ()
184+ {
185+ NavigationManager .NavigateTo (" coldstaking-enablewallet" );
186+ }
159187 private void NavigateToWithdraw (string walletName )
160188 {
161189 NavigationManager .NavigateTo (" coldstaking-withdraw/" + walletName );
165193 {
166194 NavigationManager .NavigateTo (" coldstaking-setup/" + walletName );
167195 }
196+ private void NavigateToDelegate (string walletName )
197+ {
198+ NavigationManager .NavigateTo (" coldstaking-delegate/" + walletName );
199+ }
200+ private void NavigateToColdStakeView (string walletName )
201+ {
202+ NavigationManager .NavigateTo (" coldstakeview/" + walletName + " /coldStakingColdAddresses" );
203+ }
168204}
0 commit comments