|
@@ -16,8 +16,9 @@ interface
|
|
|
|
|
|
uses
|
|
uses
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
|
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus,
|
|
- ExtCtrls, PairSplitter, Buttons, UVisualGrid, UCommon.UI, Generics.Collections, ULog,
|
|
|
|
- UAccounts, UDataSources, UNode, UCoreObjects, UCoreUtils, UCTRLNoAccount;
|
|
|
|
|
|
+ ExtCtrls, PairSplitter, Buttons, UVisualGrid, UCommon, UCommon.UI, Generics.Collections,
|
|
|
|
+ ULog, UAccounts, UDataSources, UNode, UCoreObjects, UCoreUtils, UCTRLNoAccount;
|
|
|
|
+
|
|
type
|
|
type
|
|
|
|
|
|
{ TCTRLWallet }
|
|
{ TCTRLWallet }
|
|
@@ -67,6 +68,7 @@ type
|
|
procedure miDelistAccountsFromSaleClick(Sender: TObject);
|
|
procedure miDelistAccountsFromSaleClick(Sender: TObject);
|
|
private
|
|
private
|
|
FNodeNotifyEvents: TNodeNotifyEvents;
|
|
FNodeNotifyEvents: TNodeNotifyEvents;
|
|
|
|
+ FBalanceUpdatedEvent : TThrottledEvent;
|
|
FAccountsMode: TCTRLWalletAccountsMode;
|
|
FAccountsMode: TCTRLWalletAccountsMode;
|
|
FOperationsMode: TCTRLWalletOperationsMode;
|
|
FOperationsMode: TCTRLWalletOperationsMode;
|
|
FOperationsHistory: TCTRLWalletOperationsHistory;
|
|
FOperationsHistory: TCTRLWalletOperationsHistory;
|
|
@@ -80,6 +82,7 @@ type
|
|
procedure SetOperationsMode(AMode: TCTRLWalletOperationsMode);
|
|
procedure SetOperationsMode(AMode: TCTRLWalletOperationsMode);
|
|
procedure SetOperationsHistory(AHistory: TCTRLWalletOperationsHistory);
|
|
procedure SetOperationsHistory(AHistory: TCTRLWalletOperationsHistory);
|
|
procedure RefreshMyAccountsCombo;
|
|
procedure RefreshMyAccountsCombo;
|
|
|
|
+ procedure RefreshBalances;
|
|
procedure RefreshTotals;
|
|
procedure RefreshTotals;
|
|
procedure RefreshAccountsGrid;
|
|
procedure RefreshAccountsGrid;
|
|
procedure RefreshOperationsGrid;
|
|
procedure RefreshOperationsGrid;
|
|
@@ -88,6 +91,7 @@ type
|
|
procedure ActivateFirstTime; override;
|
|
procedure ActivateFirstTime; override;
|
|
procedure OnPrivateKeysChanged(Sender: TObject);
|
|
procedure OnPrivateKeysChanged(Sender: TObject);
|
|
procedure OnUserKeyActivityDetected(Sender: TObject);
|
|
procedure OnUserKeyActivityDetected(Sender: TObject);
|
|
|
|
+ procedure OnUserBalanceChanged(Sender: TObject);
|
|
procedure OnNodeBlocksChanged(Sender: TObject);
|
|
procedure OnNodeBlocksChanged(Sender: TObject);
|
|
procedure OnNodeNewOperation(Sender: TObject);
|
|
procedure OnNodeNewOperation(Sender: TObject);
|
|
procedure OnAccountsSelected(Sender: TObject; constref ASelection: TVisualGridSelection);
|
|
procedure OnAccountsSelected(Sender: TObject; constref ASelection: TVisualGridSelection);
|
|
@@ -106,7 +110,7 @@ implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
UUserInterface, UCellRenderers, UBlockChain, UWallet, UCrypto,
|
|
UUserInterface, UCellRenderers, UBlockChain, UWallet, UCrypto,
|
|
- UCommon, UMemory, Generics.Defaults, UCommon.Data, UCommon.Collections, UWIZOperation;
|
|
|
|
|
|
+ UMemory, Generics.Defaults, UCommon.Data, UCommon.Collections, UWIZOperation;
|
|
|
|
|
|
{$R *.lfm}
|
|
{$R *.lfm}
|
|
|
|
|
|
@@ -124,6 +128,10 @@ begin
|
|
FNodeNotifyEvents.OnOperationsChanged := OnNodeNewOperation;
|
|
FNodeNotifyEvents.OnOperationsChanged := OnNodeNewOperation;
|
|
TWallet.Keys.OnChanged.Add(OnPrivateKeysChanged);
|
|
TWallet.Keys.OnChanged.Add(OnPrivateKeysChanged);
|
|
TWallet.Keys.AccountsKeyList.ClearAccountKeyChanges; // XXXXX CLEAR BUFFER on start
|
|
TWallet.Keys.AccountsKeyList.ClearAccountKeyChanges; // XXXXX CLEAR BUFFER on start
|
|
|
|
+ FBalanceUpdatedEvent := TThrottledEvent.Create(Self);
|
|
|
|
+ FBalanceUpdatedEvent.Mode := temNotifyOnEventBurstFinished;
|
|
|
|
+ FBalanceUpdatedEvent.Interval := TTimeSpan.FromSeconds(10);
|
|
|
|
+ FBalanceUpdatedEvent.Add(OnUserBalanceChanged);
|
|
|
|
|
|
// fields
|
|
// fields
|
|
FAccountsDataSource := TMyAccountsDataSource.Create(Self);
|
|
FAccountsDataSource := TMyAccountsDataSource.Create(Self);
|
|
@@ -316,8 +324,14 @@ begin
|
|
// add first time-init here
|
|
// add first time-init here
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TCTRLWallet.RefreshTotals;
|
|
|
|
|
|
+procedure TCTRLWallet.RefreshBalances;
|
|
|
|
+begin
|
|
|
|
+ FAccountsGrid.RefreshGrid;
|
|
|
|
+ FOperationsGrid.RefreshGrid;
|
|
|
|
+ // Note: RefreshTotals is called after FAccountsGrid finishes updating (since it uses it's internal data)
|
|
|
|
+end;
|
|
|
|
|
|
|
|
+procedure TCTRLWallet.RefreshTotals;
|
|
begin
|
|
begin
|
|
lblTotalPASC.Caption := TAccountComp.FormatMoney(FBalance.TotalPASC);
|
|
lblTotalPASC.Caption := TAccountComp.FormatMoney(FBalance.TotalPASC);
|
|
lblTotalPASA.Caption := Format('%d', [FBalance.TotalPASA]);
|
|
lblTotalPASA.Caption := Format('%d', [FBalance.TotalPASA]);
|
|
@@ -504,10 +518,17 @@ end;
|
|
|
|
|
|
procedure TCTRLWallet.OnUserKeyActivityDetected;
|
|
procedure TCTRLWallet.OnUserKeyActivityDetected;
|
|
begin
|
|
begin
|
|
-// if NOT TUserInterface.Node.HasBestKnownBlockchainTip then
|
|
|
|
-// exit; // node syncing
|
|
|
|
- FAccountsGrid.RefreshGrid;
|
|
|
|
- FOperationsGrid.RefreshGrid;
|
|
|
|
|
|
+ // This handler is called every time a block is downloaded. If we refreshed GUI here it would
|
|
|
|
+ // result in severe back-end blocking and slow-down, as the GUI refreshed on every block during
|
|
|
|
+ // a syncronization. As a result, we throttle the GUI refresh via FBalanceUpdatedEvent which
|
|
|
|
+ // waits until 5 seconds of idle before calling OnUserBalanceChanged which then updates GUI.
|
|
|
|
+ FBalanceUpdatedEvent.Notify;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TCTRLWallet.OnUserBalanceChanged(Sender: TObject);
|
|
|
|
+begin
|
|
|
|
+ // Invocation of this event hander is throttled by FBalanceUpdatedEvent.
|
|
|
|
+ RefreshBalances;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TCTRLWallet.OnNodeBlocksChanged(Sender: TObject);
|
|
procedure TCTRLWallet.OnNodeBlocksChanged(Sender: TObject);
|