Browse Source

Refactor: cleanup prior refactoring

Herman Schoenfeld 7 years ago
parent
commit
dacf1feb54

+ 14 - 14
Units/Forms/UFRMAccountExplorer.lfm

@@ -1,11 +1,11 @@
 object FRMAccountExplorer: TFRMAccountExplorer
-  Left = 264
+  Left = 135
   Height = 471
-  Top = 67
-  Width = 816
+  Top = 14
+  Width = 868
   Caption = 'Accounts Explorer'
   ClientHeight = 451
-  ClientWidth = 816
+  ClientWidth = 868
   Menu = meAccountExplorerMenu
   OnCreate = FormCreate
   OnDestroy = FormDestroy
@@ -20,11 +20,11 @@ object FRMAccountExplorer: TFRMAccountExplorer
     Left = 0
     Height = 66
     Top = 0
-    Width = 816
+    Width = 868
     Align = alTop
     BevelOuter = bvNone
     ClientHeight = 66
-    ClientWidth = 816
+    ClientWidth = 868
     TabOrder = 0
     object Label18: TLabel
       Left = 11
@@ -245,7 +245,7 @@ object FRMAccountExplorer: TFRMAccountExplorer
     Left = 385
     Height = 385
     Top = 66
-    Width = 431
+    Width = 483
     ActivePage = tsMultiSelectAccounts
     Align = alClient
     TabIndex = 1
@@ -272,13 +272,13 @@ object FRMAccountExplorer: TFRMAccountExplorer
     object tsMultiSelectAccounts: TTabSheet
       Caption = 'Selected accounts for massive operations'
       ClientHeight = 357
-      ClientWidth = 423
+      ClientWidth = 475
       ImageIndex = 1
       object dgSelectedAccounts: TDrawGrid
         Left = 41
         Height = 300
         Top = 31
-        Width = 273
+        Width = 325
         Align = alLeft
         Anchors = [akTop, akLeft, akRight, akBottom]
         ExtendedSelect = False
@@ -291,11 +291,11 @@ object FRMAccountExplorer: TFRMAccountExplorer
         Left = 0
         Height = 31
         Top = 0
-        Width = 423
+        Width = 475
         Align = alTop
         BevelOuter = bvNone
         ClientHeight = 31
-        ClientWidth = 423
+        ClientWidth = 475
         Font.Color = clWindowText
         Font.Height = -13
         Font.Name = 'Tahoma'
@@ -315,11 +315,11 @@ object FRMAccountExplorer: TFRMAccountExplorer
         Left = 0
         Height = 26
         Top = 331
-        Width = 423
+        Width = 475
         Align = alBottom
         BevelOuter = bvNone
         ClientHeight = 26
-        ClientWidth = 423
+        ClientWidth = 475
         TabOrder = 2
         object Label20: TLabel
           Left = 41
@@ -398,7 +398,7 @@ object FRMAccountExplorer: TFRMAccountExplorer
         end
       end
       object bbSelectedAccountsOperation: TBitBtn
-        Left = 320
+        Left = 372
         Height = 61
         Top = 31
         Width = 75

+ 111 - 161
Units/Forms/UFRMAccountExplorer.pas

@@ -168,15 +168,15 @@ type
     procedure sbSelectedAccountsAddClick(Sender: TObject);
     procedure sbSelectedAccountsDelAllClick(Sender: TObject);
     procedure sbSelectedAccountsDelClick(Sender: TObject);
-    procedure UpdateAccounts(RefreshData : Boolean);
-    procedure OnSelectedAccountsGridUpdated(Sender: TObject);
+    procedure RefreshAccountsGrid(RefreshData : Boolean);
+    procedure RefreshMyKeysCombo;
+    procedure OnAccountsSelectedGridUpdated(Sender: TObject);
   private
     { private declarations }
-    FUpdating : boolean;
-    FAccountsGrid : TAccountsGrid;  //HS
-    FOperationsAccountGrid : TOperationsGrid; // HS
-    FSelectedAccountsGrid : TAccountsGrid; //HS
-    FOrderedAccountsKeyList : TOrderedAccountKeysList; //HS
+    FAccountsGrid : TAccountsGrid;
+    FAccountOperationsGrid : TOperationsGrid;
+    FAccountsSelectedGrid : TAccountsGrid;
+    FOrderedAccountsKeyList : TOrderedAccountKeysList;
     FMinAccountBalance : Int64;
     FMaxAccountBalance : Int64;
     Procedure FillAccountInformation(Const Strings : TStrings; Const AccountNumber : Cardinal);
@@ -188,7 +188,6 @@ type
     procedure Refresh;
   end;
 
-
 implementation
 
 {$R *.lfm}
@@ -209,20 +208,22 @@ begin
   FAccountsGrid.DrawGrid := dgAccounts;
   FAccountsGrid.Node := TUserInterface.Node;
   FAccountsGrid.AllowMultiSelect := True;
-  FSelectedAccountsGrid := TAccountsGrid.Create(Self);
-  FSelectedAccountsGrid.DrawGrid :=dgSelectedAccounts;
-  FSelectedAccountsGrid.Node := TUserInterface.Node;
-  FSelectedAccountsGrid.OnUpdated := OnSelectedAccountsGridUpdated;
-  FOperationsAccountGrid := TOperationsGrid.Create(Self);
-  FOperationsAccountGrid.DrawGrid := dgAccountOperations;
-  FOperationsAccountGrid.Node := TUserInterface.Node;
-  FOperationsAccountGrid.MustShowAlwaysAnAccount := true;
+  FAccountsSelectedGrid := TAccountsGrid.Create(Self);
+  FAccountsSelectedGrid.DrawGrid :=dgSelectedAccounts;
+  FAccountsSelectedGrid.Node := TUserInterface.Node;
+  FAccountsSelectedGrid.OnUpdated := OnAccountsSelectedGridUpdated;
+  FAccountOperationsGrid := TOperationsGrid.Create(Self);
+  FAccountOperationsGrid.DrawGrid := dgAccountOperations;
+  FAccountOperationsGrid.Node := TUserInterface.Node;
+  FAccountOperationsGrid.MustShowAlwaysAnAccount := true;
   pcAccountsOptions.ActivePage := tsAccountOperations;
 
+  // Get account list from SafeBox
+  FOrderedAccountsKeyList := TOrderedAccountKeysList.Create(TUserInterface.Node.Bank.SafeBox,false);
+
   // Subscribe to wallet events
   TUserInterface.WalletKeys.OnChanged.Add(OnPrivateKeysChanged);
-
-  FUpdating := false;
+  Refresh;
 end;
 
 procedure TFRMAccountExplorer.FormDestroy(Sender: TObject);
@@ -231,9 +232,9 @@ begin
   TUserInterface.WalletKeys.OnChanged.Remove(OnPrivateKeysChanged);
 
   // Nullify fields
-  FOperationsAccountGrid.Node := Nil;
+  FAccountOperationsGrid.Node := Nil;
   FAccountsGrid.Node := Nil;
-  FSelectedAccountsGrid.Node := Nil;
+  FAccountsSelectedGrid.Node := Nil;
   FAccountsGrid.Node := Nil;
 
   // Note: grids themselves are collected with Self (TComponent dependency)
@@ -244,44 +245,11 @@ end;
 {%region Form methods}
 
 procedure TFRMAccountExplorer.Refresh;
-Var i,last_i : Integer;
-  wk : TWalletKey;
-  s : AnsiString;
 begin
-  If (Not Assigned(FOrderedAccountsKeyList)) And (Assigned(TUserInterface.Node)) Then begin
-    FOrderedAccountsKeyList := TOrderedAccountKeysList.Create(TUserInterface.Node.Bank.SafeBox,false);
-  end;
-  if (cbMyPrivateKeys.ItemIndex>=0) then last_i := PtrInt(cbMyPrivateKeys.Items.Objects[cbMyPrivateKeys.ItemIndex])
-  else last_i := -1;
-  cbMyPrivateKeys.items.BeginUpdate;
-  Try
-    cbMyPrivateKeys.Items.Clear;
-    For i:=0 to TUserInterface.WalletKeys.Count-1 do begin
-      wk := TUserInterface.WalletKeys.Key[i];
-      if assigned(FOrderedAccountsKeyList) then begin
-        FOrderedAccountsKeyList.AddAccountKey(wk.AccountKey);
-      end;
-      if (wk.Name='') then begin
-        s := 'Sha256='+TCrypto.ToHexaString( TCrypto.DoSha256( TAccountComp.AccountKey2RawString(wk.AccountKey) ) );
-      end else begin
-        s := wk.Name;
-      end;
-      if Not Assigned(wk.PrivateKey) then s := s + '(*)';
-      cbMyPrivateKeys.Items.AddObject(s,TObject(i));
-    end;
-    cbMyPrivateKeys.Sorted := true;
-    cbMyPrivateKeys.Sorted := false;
-    cbMyPrivateKeys.Items.InsertObject(0,'(All my private keys)',TObject(-1));
-  Finally
-    cbMyPrivateKeys.Items.EndUpdate;
-  End;
-  last_i := cbMyPrivateKeys.Items.IndexOfObject(TObject(last_i));
-  if last_i<0 then last_i := 0;
-  if cbMyPrivateKeys.Items.Count>last_i then cbMyPrivateKeys.ItemIndex := last_i
-  else if cbMyPrivateKeys.Items.Count>=0 then cbMyPrivateKeys.ItemIndex := 0;
+  RefreshAccountsGrid(true);
+  RefreshMyKeysCombo;
 end;
 
-
 {%endregion}
 
 {%region For auxillary methods}
@@ -349,7 +317,7 @@ begin
   end;
 end;
 
-procedure TFRMAccountExplorer.UpdateAccounts(RefreshData : Boolean);
+procedure TFRMAccountExplorer.RefreshAccountsGrid(RefreshData : Boolean);
 Var accl : TOrderedCardinalList;
   l : TOrderedCardinalList;
   i,j,k : Integer;
@@ -357,7 +325,6 @@ Var accl : TOrderedCardinalList;
   applyfilter : Boolean;
   acc : TAccount;
 begin
-//  with FRMWallet do begin
   If Not Assigned(FOrderedAccountsKeyList) Then exit;
   if Not RefreshData then begin
     dgAccounts.Invalidate;
@@ -420,42 +387,69 @@ begin
   // Show Totals:
   lblAccountsBalance.Caption := TAccountComp.FormatMoney(FAccountsGrid.AccountsBalance);
   OnSelectedAccountChanged;
-//  end
 end;
 
-function TFRMAccountExplorer.DoUpdateAccountsFilter: Boolean;
-Var bmin,bmax:Int64;
-  doupd : Boolean;
+procedure TFRMAccountExplorer.RefreshMyKeysCombo;
+Var i,last_i : Integer;
+  wk : TWalletKey;
+  s : AnsiString;
 begin
-//  with FRMWallet do
-//  begin
-  if FUpdating then exit;
-  FUpdating := true;
+  cbMyPrivateKeys.Enabled := cbExploreMyAccounts.Checked;
+  if (cbMyPrivateKeys.ItemIndex>=0) then last_i := PtrInt(cbMyPrivateKeys.Items.Objects[cbMyPrivateKeys.ItemIndex])
+  else last_i := -1;
+  cbMyPrivateKeys.items.BeginUpdate;
   Try
-    If Not TAccountComp.TxtToMoney(ebFilterAccountByBalanceMin.Text,bmin) then bmin := 0;
-    If not TAccountComp.TxtToMoney(ebFilterAccountByBalanceMax.Text,bmax) then bmax := CT_MaxWalletAmount;
-    if (bmax<bmin) or (bmax=0) then bmax := CT_MaxWalletAmount;
-    if bmin>bmax then bmin := 0;
-    doupd := (bmin<>FMinAccountBalance) Or (bmax<>FMaxAccountBalance);
-    FMinAccountBalance := bmin;
-    FMaxAccountBalance := bmax;
-    if bmin>0 then
-      ebFilterAccountByBalanceMin.Text:=TAccountComp.FormatMoney(bmin)
-    else ebFilterAccountByBalanceMin.Text := '';
-    if bmax<CT_MaxWalletAmount then
-      ebFilterAccountByBalanceMax.Text := TAccountComp.FormatMoney(bmax)
-    else ebFilterAccountByBalanceMax.Text := '';
-    if cbFilterAccounts.Checked then begin
-      ebFilterAccountByBalanceMin.ParentFont := true;
-      ebFilterAccountByBalanceMax.ParentFont := true;
-    end else begin
-      ebFilterAccountByBalanceMin.font.Color := clDkGray;
-      ebFilterAccountByBalanceMax.font.Color := clDkGray;
+    cbMyPrivateKeys.Items.Clear;
+    For i:=0 to TUserInterface.WalletKeys.Count-1 do begin
+      wk := TUserInterface.WalletKeys.Key[i];
+      if assigned(FOrderedAccountsKeyList) then begin
+        FOrderedAccountsKeyList.AddAccountKey(wk.AccountKey);
+      end;
+      if (wk.Name='') then begin
+        s := 'Sha256='+TCrypto.ToHexaString( TCrypto.DoSha256( TAccountComp.AccountKey2RawString(wk.AccountKey) ) );
+      end else begin
+        s := wk.Name;
+      end;
+      if Not Assigned(wk.PrivateKey) then s := s + '(*)';
+      cbMyPrivateKeys.Items.AddObject(s,TObject(i));
     end;
+    cbMyPrivateKeys.Sorted := true;
+    cbMyPrivateKeys.Sorted := false;
+    cbMyPrivateKeys.Items.InsertObject(0,'(All my private keys)',TObject(-1));
   Finally
-    FUpdating := false;
+    cbMyPrivateKeys.Items.EndUpdate;
   End;
-  if doupd then UpdateAccounts(true);
+  last_i := cbMyPrivateKeys.Items.IndexOfObject(TObject(last_i));
+  if last_i<0 then last_i := 0;
+  if cbMyPrivateKeys.Items.Count>last_i then cbMyPrivateKeys.ItemIndex := last_i
+  else if cbMyPrivateKeys.Items.Count>=0 then cbMyPrivateKeys.ItemIndex := 0;
+end;
+
+function TFRMAccountExplorer.DoUpdateAccountsFilter: Boolean;
+Var bmin,bmax:Int64;
+  doupd : Boolean;
+begin
+  If Not TAccountComp.TxtToMoney(ebFilterAccountByBalanceMin.Text,bmin) then bmin := 0;
+  If not TAccountComp.TxtToMoney(ebFilterAccountByBalanceMax.Text,bmax) then bmax := CT_MaxWalletAmount;
+  if (bmax<bmin) or (bmax=0) then bmax := CT_MaxWalletAmount;
+  if bmin>bmax then bmin := 0;
+  doupd := (bmin<>FMinAccountBalance) Or (bmax<>FMaxAccountBalance);
+  FMinAccountBalance := bmin;
+  FMaxAccountBalance := bmax;
+  if bmin>0 then
+    ebFilterAccountByBalanceMin.Text:=TAccountComp.FormatMoney(bmin)
+  else ebFilterAccountByBalanceMin.Text := '';
+  if bmax<CT_MaxWalletAmount then
+    ebFilterAccountByBalanceMax.Text := TAccountComp.FormatMoney(bmax)
+  else ebFilterAccountByBalanceMax.Text := '';
+  if cbFilterAccounts.Checked then begin
+    ebFilterAccountByBalanceMin.ParentFont := true;
+    ebFilterAccountByBalanceMax.ParentFont := true;
+  end else begin
+    ebFilterAccountByBalanceMin.font.Color := clDkGray;
+    ebFilterAccountByBalanceMax.font.Color := clDkGray;
+  end;
+  if doupd then RefreshAccountsGrid(true);
   Result := doupd;
   //end;
 end;
@@ -473,7 +467,7 @@ procedure TFRMAccountExplorer.OnSelectedAccountChanged;
 Var accn : Int64;
 begin
   accn := FAccountsGrid.AccountNumber(dgAccounts.Row);
-  FOperationsAccountGrid.AccountNumber := accn;
+  FAccountOperationsGrid.AccountNumber := accn;
 end;
 
 {%endregion}
@@ -482,22 +476,19 @@ end;
 
 procedure TFRMAccountExplorer.cbExploreMyAccountsChange(Sender: TObject);
 begin
-//  with FRMWallet do
-//  begin
-    cbMyPrivateKeys.Enabled := cbExploreMyAccounts.Checked;
-    UpdateAccounts(true);
+    RefreshAccountsGrid(true);
+    RefreshMyKeysCombo;
     OnSelectedAccountChanged;
-//  end;
 end;
 
 procedure TFRMAccountExplorer.cbFilterAccountsChange(Sender: TObject);
 begin
-  If not DoUpdateAccountsFilter then UpdateAccounts(true);
+  If not DoUpdateAccountsFilter then RefreshAccountsGrid(true);
 end;
 
 procedure TFRMAccountExplorer.cbMyPrivateKeysChange(Sender: TObject);
 begin
-  UpdateAccounts(true);
+  RefreshAccountsGrid(true);
 end;
 
 {%endregion}
@@ -519,7 +510,7 @@ end;
 
 procedure TFRMAccountExplorer.bbAccountsRefreshClick(Sender: TObject);
 begin
-  UpdateAccounts(true);
+  RefreshAccountsGrid(true);
 end;
 
 procedure TFRMAccountExplorer.sbSelectedAccountsAddAllClick(Sender: TObject);
@@ -530,14 +521,14 @@ begin
 //  begin
   lsource := FAccountsGrid.LockAccountsList;
   Try
-    ltarget := FSelectedAccountsGrid.LockAccountsList;
+    ltarget := FAccountsSelectedGrid.LockAccountsList;
     Try
       for i := 0 to lsource.Count-1 do begin
         if TUserInterface.WalletKeys.IndexOfAccountKey(TUserInterface.Node.Bank.SafeBox.Account(lsource.Get(i)).accountInfo.accountKey)<0 then raise Exception.Create(Format('You cannot operate with account %d because private key not found in your wallet',[lsource.Get(i)]));
         ltarget.Add(lsource.Get(i));
       end;
     Finally
-      FSelectedAccountsGrid.UnlockAccountsList;
+      FAccountsSelectedGrid.UnlockAccountsList;
     End;
   Finally
     FAccountsGrid.UnlockAccountsList;
@@ -551,15 +542,13 @@ Var l, selected : TOrderedCardinalList;
   an : Int64;
   i : Integer;
 begin
-//  with FRMWallet do
-//  begin
   an := FAccountsGrid.AccountNumber(dgAccounts.Row);
   if (an<0) then raise Exception.Create('No account selected');
   if TUserInterface.WalletKeys.IndexOfAccountKey(TUserInterface.Node.Bank.SafeBox.Account(an).accountInfo.accountkey)<0 then
     raise Exception.Create(Format('You cannot add %s account because private key not found in your wallet.'#10+#10+'You''re not the owner!',
       [TAccountComp.AccountNumberToAccountTxtNumber(an)]));
   // Add
-  l := FSelectedAccountsGrid.LockAccountsList;
+  l := FAccountsSelectedGrid.LockAccountsList;
   selected := TOrderedCardinalList.Create;
   Try
     FAccountsGrid.SelectedAccounts(selected);
@@ -568,19 +557,18 @@ begin
     end;
   Finally
     selected.Free;
-    FSelectedAccountsGrid.UnlockAccountsList;
+    FAccountsSelectedGrid.UnlockAccountsList;
   End;
-//  end;
 end;
 
 procedure TFRMAccountExplorer.sbSelectedAccountsDelAllClick(Sender: TObject);
 Var l : TOrderedCardinalList;
 begin
-  l := FSelectedAccountsGrid.LockAccountsList;
+  l := FAccountsSelectedGrid.LockAccountsList;
   try
     l.Clear;
   finally
-    FSelectedAccountsGrid.UnlockAccountsList;
+    FAccountsSelectedGrid.UnlockAccountsList;
   end;
 end;
 
@@ -588,32 +576,27 @@ procedure TFRMAccountExplorer.sbSelectedAccountsDelClick(Sender: TObject);
 Var an : Int64;
   l : TOrderedCardinalList;
 begin
-//  with FRMWallet do
-//  begin
-  l := FSelectedAccountsGrid.LockAccountsList;
+  l := FAccountsSelectedGrid.LockAccountsList;
   try
-    an := FSelectedAccountsGrid.AccountNumber(dgSelectedAccounts.Row);
+    an := FAccountsSelectedGrid.AccountNumber(dgSelectedAccounts.Row);
     if an>=0 then l.Remove(an);
   finally
-    FSelectedAccountsGrid.UnlockAccountsList;
+    FAccountsSelectedGrid.UnlockAccountsList;
   end;
-//  end;
 end;
 
 procedure TFRMAccountExplorer.bbSelectedAccountsOperationClick(Sender: TObject);
 var l : TOrderedCardinalList;
 begin
-//  with FRMWallet do
-//  begin
   TUserInterface.CheckNodeIsReady;
-  if FSelectedAccountsGrid.AccountsCount<=0 then raise Exception.Create('Must select at least 1 account');
+  if FAccountsSelectedGrid.AccountsCount<=0 then raise Exception.Create('Must select at least 1 account');
   With TFRMOperation.Create(Self) do
   Try
-    l := FSelectedAccountsGrid.LockAccountsList;
+    l := FAccountsSelectedGrid.LockAccountsList;
     try
       SenderAccounts.CopyFrom(l);
     finally
-      FSelectedAccountsGrid.UnlockAccountsList;
+      FAccountsSelectedGrid.UnlockAccountsList;
     end;
     DefaultFee := TUserInterface.AppParams.ParamByName[CT_PARAM_DefaultFee].GetAsInt64(0);
     WalletKeys := TUserInterface.WalletKeys;
@@ -621,7 +604,6 @@ begin
   Finally
     Free;
   End;
-//  end;
 end;
 
 procedure TFRMAccountExplorer.sbSearchAccountClick(Sender: TObject);
@@ -659,7 +641,6 @@ begin
     ebFindAccountNumber.Font.Color := clDkGray;
   end else if TAccountComp.AccountTxtNumberToAccountNumber(ebFindAccountNumber.Text,an) then begin
     ebFindAccountNumber.Color := clWindow;
-    //HS if FRMWallet.FAccountsGrid.MoveRowToAccount(an) then begin
     if FAccountsGrid.MoveRowToAccount(an) then begin
       ebFindAccountNumber.Font.Color := clWindowText;
     end else begin
@@ -683,8 +664,7 @@ end;
 
 procedure TFRMAccountExplorer.dgAccountOperationsClick(Sender: TObject);
 begin
-//  with FRMWallet do
-  FOperationsAccountGrid.ShowModalDecoder(TUserInterface.WalletKeys,TUserInterface.AppParams);
+  TUserInterface.ShowOperationInfoDialog(Self, FAccountOperationsGrid.SelectedOperation);
 end;
 
 procedure TFRMAccountExplorer.dgAccountsClick(Sender: TObject);
@@ -692,10 +672,10 @@ begin
   OnSelectedAccountChanged;
 end;
 
-procedure TFRMAccountExplorer.OnSelectedAccountsGridUpdated(Sender: TObject);
+procedure TFRMAccountExplorer.OnAccountsSelectedGridUpdated(Sender: TObject);
 begin
-  lblSelectedAccountsCount.Caption := Inttostr(FSelectedAccountsGrid.AccountsCount);
-  lblSelectedAccountsBalance.Caption := TAccountComp.FormatMoney( FSelectedAccountsGrid.AccountsBalance );
+  lblSelectedAccountsCount.Caption := Inttostr(FAccountsSelectedGrid.AccountsCount);
+  lblSelectedAccountsBalance.Caption := TAccountComp.FormatMoney( FAccountsSelectedGrid.AccountsBalance );
 end;
 
 {%endregion}
@@ -721,7 +701,6 @@ Var an  : Cardinal;
   an64 : Int64;
   start : TAccount;
 begin
-//  with FWallet do begin
     an64 := FAccountsGrid.AccountNumber(dgAccounts.Row);
     if an64<0 then an := TUserInterface.Node.Bank.SafeBox.AccountsCount-1
     else an := an64;
@@ -734,7 +713,6 @@ begin
     if (TUserInterface.Node.Bank.SafeBox.Account(an).balance>start.balance) then FAccountsGrid.MoveRowToAccount(an)
     else raise Exception.Create('Not found any account lower than '+TAccountComp.AccountNumberToAccountTxtNumber(start.account)+' with balance higher than '+
       TAccountComp.FormatMoney(start.balance));
-//    end;
 end;
 
 procedure TFRMAccountExplorer.miFindNextAccountWithHighBalanceClick(Sender: TObject);
@@ -742,7 +720,6 @@ Var an  : Cardinal;
   an64 : Int64;
   start : TAccount;
 begin
-//  with FRMWallet do begin
   an64 := FAccountsGrid.AccountNumber(dgAccounts.Row);
   if an64<0 then an := 0
   else an := an64;
@@ -755,47 +732,28 @@ begin
   if (an<TUserInterface.Node.Bank.SafeBox.AccountsCount) then FAccountsGrid.MoveRowToAccount(an)
   else raise Exception.Create('Not found any account higher than '+TAccountComp.AccountNumberToAccountTxtNumber(start.account)+' with balance higher than '+
     TAccountComp.FormatMoney(start.balance));
-//  end;
 end;
 
 procedure TFRMAccountExplorer.miAccountInformationClick(Sender: TObject);
 Var F : TFRMMemoText;
   accn : Int64 =-1;
   title : String;
-  //account : TAccount;
   strings : TStrings;
   i : Integer;
   opr : TOperationResume;
 begin
-//  with FRMWallet do begin
   accn := -1;
   title := '';
   strings := TStringList.Create;
   try
     opr := CT_TOperationResume_NUL;
-    //HS
-    ////AntonB if PageControl.ActivePage=tsOperations then begin
-    //  if not (FOperationsExplorerGrid.DrawGrid = nil) then begin
-    //  i := FOperationsExplorerGrid.DrawGrid.Row;
-    //  if (i>0) and (i<=FOperationsExplorerGrid.OperationsResume.Count) then begin
-    //    opr := FOperationsExplorerGrid.OperationsResume.OperationResume[i-1];
-    //  end;
-    //AntonB end else if PageControl.ActivePage=tsPendingOperations then begin
-    //  end else if not (FPendingOperationsGrid.DrawGrid = nil) then begin
-    //  i := FPendingOperationsGrid.DrawGrid.Row;
-    //  if (i>0) and (i<=FPendingOperationsGrid.OperationsResume.Count) then begin
-    //    opr := FPendingOperationsGrid.OperationsResume.OperationResume[i-1];
-    //  end;
-    //end else //if PageControl.ActivePage=tsMyAccounts then
-    begin
-      accn := FAccountsGrid.AccountNumber(dgAccounts.Row);
-      if accn<0 then raise Exception.Create('Select an account');
-      FillAccountInformation(strings,accn);
-      title := 'Account '+TAccountComp.AccountNumberToAccountTxtNumber(accn)+' info';
-      i := FOperationsAccountGrid.DrawGrid.Row;
-      if (i>0) and (i<=FOperationsAccountGrid.OperationsResume.Count) then begin
-        opr := FOperationsAccountGrid.OperationsResume.OperationResume[i-1];
-      end;
+    accn := FAccountsGrid.AccountNumber(dgAccounts.Row);
+    if accn<0 then raise Exception.Create('Select an account');
+    FillAccountInformation(strings,accn);
+    title := 'Account '+TAccountComp.AccountNumberToAccountTxtNumber(accn)+' info';
+    i := FAccountOperationsGrid.DrawGrid.Row;
+    if (i>0) and (i<=FAccountOperationsGrid.OperationsResume.Count) then begin
+      opr := FAccountOperationsGrid.OperationsResume.OperationResume[i-1];
     end;
     If (opr.valid) then begin
       if accn>=0 then strings.Add('')
@@ -803,18 +761,10 @@ begin
       strings.Add('Operation info:');
       FillOperationInformation(strings,opr);
     end else if accn<0 then Raise Exception.Create('No info available');
-    F := TFRMMemoText.Create(Self);
-    Try
-      F.Caption := title;
-      F.Memo.Lines.Assign(strings);
-      F.ShowModal;
-    Finally
-      F.Free;
-    End;
+    TUserInterface.ShowMemoText(Self, title, strings);
   finally
     strings.free;
   end;
-//  end;
 end;
 
 procedure TFRMAccountExplorer.miAddAccountToSelectedClick(Sender: TObject);
@@ -826,7 +776,7 @@ end;
 
 procedure TFRMAccountExplorer.miDecodePayloadClick(Sender: TObject);
 begin
-  FOperationsAccountGrid.ShowModalDecoder(TUserInterface.WalletKeys,TUserInterface.AppParams);
+  TUserInterface.ShowOperationInfoDialog(Self, FAccountOperationsGrid.SelectedOperation.OperationHash);
 end;
 
 procedure TFRMAccountExplorer.miRemoveAccountFromSelectedClick(Sender: TObject);

+ 8 - 27
Units/Forms/UFRMOperationExplorer.pas

@@ -5,10 +5,8 @@ unit UFRMOperationExplorer;
 interface
 
 uses
-    LCLIntf, LCLType,
-    SysUtils, Controls, Forms,
-    Dialogs, ExtCtrls, StdCtrls,
-    Grids, Menus, Classes, UGridUtils, UConst;
+    LCLIntf, LCLType, SysUtils, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Grids, Menus, Classes,
+    UCommonUI, UGridUtils, UConst;
 
 type
 
@@ -40,9 +38,6 @@ type
     { public declarations }
   end;
 
-var
-  FRMOperationExplorer: TFRMOperationExplorer = nil;
-
 implementation
 
 {$R *.lfm}
@@ -67,30 +62,17 @@ end;
 
 procedure TFRMOperationExplorer.miDecodePayloadClick(Sender: TObject);
 begin
-  // TODO - move ShowModalDecoder to TUserInterface
-  FOperationsExplorerGrid.ShowModalDecoder(TUserInterface.WalletKeys, TUserInterface.AppParams);
+  TUserInterface.ShowOperationInfoDialog(Self, '');
 end;
 
 procedure TFRMOperationExplorer.miFindOperationByOpHashClick(Sender: TObject);
 var
-  FRM : TFRMPayloadDecoder;
-  oph : String;
+  ophash : String;
 begin
-  //TODO - refactor out with TUserInterface.ShowOperationInfoDialog(oph);
-  oph := '';
-  if Not InputQuery('Search operation by OpHash','Insert Operation Hash value (OpHash)',oph) then exit;
-  FRM := TFRMPayloadDecoder.Create(Self);
-  try
-    FRM.Init(CT_TOperationResume_NUL, TUserInterface.WalletKeys,TUserInterface.AppParams);
-    FRM.DoFind(oph);
-    FRM.ShowModal;
-
+  if Not InputQuery('Search operation by OpHash','Insert Operation Hash value (OpHash)',ophash)
+    then exit;
 
-
-  finally
-
-    FRM.Free;
-  end;
+  TUserInterface.ShowOperationInfoDialog(Self, ophash);
 end;
 
 procedure TFRMOperationExplorer.ebFilterOperationsAccountExit(Sender: TObject);
@@ -113,8 +95,7 @@ end;
 
 procedure TFRMOperationExplorer.dgOperationsExplorerClick(Sender: TObject);
 begin
-  //with FRMWallet do
-    FOperationsExplorerGrid.ShowModalDecoder(TUserInterface.WalletKeys, TUserInterface.AppParams);
+  TUserInterface.ShowOperationInfoDialog(Self, FOperationsExplorerGrid.SelectedOperation);
 end;
 
 procedure TFRMOperationExplorer.ebFilterOperationsAccountKeyPress(Sender: TObject; var Key: Char);

+ 6 - 2
Units/Forms/UFRMPendingOperations.pas

@@ -59,17 +59,21 @@ end;
 
 procedure TFRMPendingOperations.miDecodePayLoadClick(Sender: TObject);
 begin
-  FPendingOperationsGrid.ShowModalDecoder(TUserInterface.WalletKeys,TUserInterface.AppParams);
+  TUserInterface.ShowOperationInfoDialog(self, FPendingOperationsGrid.SelectedOperation);
 end;
 
 procedure TFRMPendingOperations.miFindOperationbyOpHashClick(Sender: TObject);
+var ophash:AnsiString;
 begin
+  if Not TUserInterface.AskUserEnterString(Self, 'Search operation by OpHash','Insert Operation Hash value (OpHash)',ophash)
+    then exit;
 
+  TUserInterface.ShowOperationInfoDialog(Self, ophash);
 end;
 
 procedure TFRMPendingOperations.dgPendingOperationsDblClick(Sender: TObject);
 begin
-   FPendingOperationsGrid.ShowModalDecoder(TUserInterface.WalletKeys, TUserInterface.AppParams);
+  TUserInterface.ShowOperationInfoDialog(Self, FPendingOperationsGrid.SelectedOperation.OperationHash);
 end;
 
 end.

+ 59 - 12
Units/Forms/UUserInterface.pas

@@ -7,15 +7,14 @@ interface
 uses
   SysUtils, Classes, Forms, Controls, Windows, ExtCtrls,
   UCommonUI,
-  UAccounts, UNode, UWalletKeys, UAppParams, UConst, UFolderHelper, UGridUtils, URPC, UPoolMining, ULog, UThread, UNetProtocol, UCrypto,
-  UFRMWallet, UFRMSyncronizationDialog, UFRMAccountExplorer, UFRMPendingOperations, UFRMOperation,
+  UBlockChain, UAccounts, UNode, UWalletKeys, UAppParams, UConst, UFolderHelper, UGridUtils, URPC, UPoolMining, ULog, UThread, UNetProtocol, UCrypto,
+  UFRMWallet, UFRMSyncronizationDialog, UFRMAccountExplorer, UFRMOperationExplorer, UFRMPendingOperations, UFRMOperation,
   UFRMLogs, UFRMMessages, UFRMNodes, UFRMBlockExplorer, UFRMWalletKeys;
 
 type
   { Forward Declarations }
   TLoadSafeBoxThread = class;
 
-
   { TMinerPrivateKey }
 
   TMinerPrivateKey = (mpk_NewEachTime, mpk_Random, mpk_Selected);
@@ -31,7 +30,7 @@ type
       FSyncronizationDialog : TFRMSyncronizationDialog; static;
       FAccountExplorer : TFRMAccountExplorer; static;
       FPendingOperationForm : TFRMPendingOperations; static;
-      FOperationsExplorerForm : TFRMOperation; static;
+      FOperationsExplorerForm : TFRMOperationExplorer; static;
       FBlockExplorerForm : TFRMBlockExplorer; static;
       FLogsForm : TFRMLogs; static;
       FNodesForm : TFRMNodes; static;
@@ -102,14 +101,18 @@ type
       // Show Dialogs
       class procedure ShowAboutBox(parentForm : TForm);
       class procedure ShowOptionsDialog(parentForm: TForm);
+      class procedure ShowOperationInfoDialog(parentForm: TForm; const ophash : AnsiString);
+      class procedure ShowOperationInfoDialog(parentForm: TForm; const operation : TOperationResume); overload;
       class procedure ShowNewOperationDialog(parentForm : TForm; accounts : TOrderedCardinalList; defaultFee : Cardinal);
       class procedure ShowSyncronizationDialog(parentForm : TForm);
       class procedure ShowWalletKeysDialog(parentForm : TForm);
       class procedure ShowSeedNodesDialog(parentForm : TForm);
       class procedure ShowAccountInformationDialog(parentForm : TForm; account : UInt64);
       class procedure ShowPrivateKeysDialog(parentForm: TForm);
+      class procedure ShowMemoText(parentForm: TForm; const ATitle : AnsiString; text : TStrings);
       class procedure UnlockWallet(parentForm: TForm;  walletKeys : TWalletKeys);
       class procedure ChangeWalletPassword(parentForm: TForm; walletKeys : TWalletKeys);
+      class function AskUserEnterString(parentForm: TForm; const ACaption, APrompt : String; var Value : String) : Boolean;
 
       // Show sub-forms
       class procedure ShowAccountExplorer;
@@ -130,7 +133,10 @@ type
 
 implementation
 
-uses Dialogs, UCommon, UOpenSSL, UFileStorage, UTime, UFRMAbout, UFRMNodesIp, UFRMPascalCoinWalletConfig ;
+uses
+  Dialogs,
+  UFRMAbout, UFRMNodesIp, UFRMPascalCoinWalletConfig, UFRMPayloadDecoder, UFRMMemoText,
+  UOpenSSL, UFileStorage, UTime, UCommon;
 
 {%region UI Lifecyle}
 
@@ -406,6 +412,30 @@ begin
   end;
 end;
 
+class procedure TUserInterface.ShowOperationInfoDialog(parentForm: TForm; const ophash: AnsiString);
+begin
+  with TFRMPayloadDecoder.Create(parentForm) do
+  try
+    Init(CT_TOperationResume_NUL, TUserInterface.WalletKeys,TUserInterface.AppParams);
+    if ophash <> '' then
+      DoFind(ophash);
+    ShowModal;
+  finally
+    Free;
+  end;
+end;
+
+class procedure TUserInterface.ShowOperationInfoDialog(parentForm: TForm; const operation : TOperationResume); overload;
+begin
+  with TFRMPayloadDecoder.Create(parentForm) do
+  try
+    Init(operation, TUserInterface.WalletKeys,TUserInterface.AppParams);
+    ShowModal;
+  finally
+    Free;
+  end;
+end;
+
 // TODO - refactor with accounts as ARRAY
 class procedure TUserInterface.ShowNewOperationDialog(parentForm : TForm; accounts : TOrderedCardinalList; defaultFee : Cardinal);
 begin
@@ -539,12 +569,25 @@ begin
   Try
     FRM.WalletKeys := FWalletKeys;
     FRM.ShowModal;
-    //UpdatePrivateKeys; // Should receive event from FWalletKeys.OnChanged subscription
   Finally
     FRM.Free;
   End;
 end;
 
+class procedure TUserInterface.ShowMemoText(parentForm: TForm; const ATitle : AnsiString; text : TStrings);
+begin
+  with TFRMMemoText.Create(parentForm) do begin
+    try
+      Caption := ATitle;
+      Memo.Lines.Assign(text);
+      ShowModal;
+    finally
+      Free;
+    end;
+  end;
+end;
+
+
 class procedure TUserInterface.ChangeWalletPassword(parentForm: TForm; walletKeys : TWalletKeys);
 Var s,s2 : String;
 begin
@@ -560,7 +603,11 @@ begin
     'Please note that your new password is "'+s+'"'+#10+#10+
     '(If you lose this password, you will lose your wallet forever!)'),
     PChar(Application.Title),MB_ICONWARNING+MB_OK);
-  //UpdateWalletKeys;
+end;
+
+class function TUserInterface.AskUserEnterString(parentForm: TForm; const ACaption, APrompt : String; var Value : String) : Boolean;
+begin
+  Result := InputQuery(ACaption, APrompt, Value);
 end;
 
 class procedure TUserInterface.UnlockWallet(parentForm: TForm; walletKeys : TWalletKeys);
@@ -589,8 +636,8 @@ begin
        FAccountExplorer.CloseAction:= caFree;
        FAccountExplorer.OnDestroyed:= Self.OnSubFormDestroyed;
        FAccountExplorer.SetSubFormCoordinate(FAccountExplorer);
-    end;
-    FAccountExplorer.Refresh;
+    end else
+      FAccountExplorer.Refresh;
     FAccountExplorer.Show;
   finally
     FUILock.Release;
@@ -618,7 +665,7 @@ begin
   try
     FUILock.Acquire;
     if not Assigned(FOperationsExplorerForm) then begin
-      FOperationsExplorerForm := TFRMOperation.Create(FWallet);
+      FOperationsExplorerForm := TFRMOperationExplorer.Create(FWallet);
       FOperationsExplorerForm.CloseAction:= caFree;
       FOperationsExplorerForm.OnDestroyed:= Self.OnSubFormDestroyed;
       FWallet.SetSubFormCoordinate(FOperationsExplorerForm);
@@ -887,7 +934,7 @@ begin
   FUILock.Acquire;
   Try
     if Assigned(FAccountExplorer) then
-      FAccountExplorer.UpdateAccounts(true);
+      FAccountExplorer.RefreshAccountsGrid(true);
   finally
     FUILock.Release;
   end;
@@ -899,7 +946,7 @@ begin
   try
     try
       if Assigned(FAccountExplorer) then
-        FAccountExplorer.UpdateAccounts(false);
+        FAccountExplorer.RefreshAccountsGrid(false);
       FSyncronizationDialog.UpdateBlockChainState;
     except
       On E:Exception do begin

+ 2 - 2
Units/PascalCoin/config.inc

@@ -28,8 +28,8 @@
   {.$DEFINE Synapse_OpenSSLv10}
   {.$DEFINE Synapse_OpenSSLv11}
 
-  {.$DEFINE PRODUCTION}
-  {$DEFINE TESTNET}
+  {$DEFINE PRODUCTION}
+  {.$DEFINE TESTNET}
 
   // For GUI: Allows to show average time on blockchain explorer
   {.$DEFINE SHOW_AVERAGE_TIME_STATS}

+ 20 - 22
Units/Utils/UGridUtils.pas

@@ -95,22 +95,23 @@ Type
     procedure SetBlockEnd(const Value: Int64);
     procedure SetBlockStart(const Value: Int64);
     procedure SetMustShowAlwaysAnAccount(const Value: Boolean);
+    function GetSelectedOperation : TOperationResume;
   protected
     procedure Notification(AComponent: TComponent; Operation: TOperation); Override;
   public
-    Constructor Create(AOwner : TComponent); override;
-    Destructor Destroy; override;
-    Property DrawGrid : TDrawGrid read FDrawGrid write SetDrawGrid;
-    Property PendingOperations : Boolean read FPendingOperations write SetPendingOperations;
-    Property AccountNumber : Int64 read FAccountNumber write SetAccountNumber;
-    Property MustShowAlwaysAnAccount : Boolean read FMustShowAlwaysAnAccount write SetMustShowAlwaysAnAccount;
-    Property Node : TNode read GetNode write SetNode;
-    Procedure UpdateAccountOperations; virtual;
-    Procedure ShowModalDecoder(WalletKeys: TWalletKeys; AppParams : TAppParams);
-    Property BlockStart : Int64 read FBlockStart write SetBlockStart;
-    Property BlockEnd : Int64 read FBlockEnd write SetBlockEnd;
-    Procedure SetBlocks(bstart,bend : Int64);
-    Property OperationsResume : TOperationsResumeList read FOperationsResume;
+    constructor Create(AOwner : TComponent); override;
+    destructor Destroy; override;
+    property DrawGrid : TDrawGrid read FDrawGrid write SetDrawGrid;
+    property PendingOperations : Boolean read FPendingOperations write SetPendingOperations;
+    property SelectedOperation : TOperationResume read GetSelectedOperation;
+    property AccountNumber : Int64 read FAccountNumber write SetAccountNumber;
+    property MustShowAlwaysAnAccount : Boolean read FMustShowAlwaysAnAccount write SetMustShowAlwaysAnAccount;
+    property Node : TNode read GetNode write SetNode;
+    procedure UpdateAccountOperations; virtual;
+    property BlockStart : Int64 read FBlockStart write SetBlockStart;
+    property BlockEnd : Int64 read FBlockEnd write SetBlockEnd;
+    procedure SetBlocks(bstart,bend : Int64);
+    property OperationsResume : TOperationsResumeList read FOperationsResume;
   End;
 
   TBlockChainData = Record
@@ -847,23 +848,20 @@ begin
   UpdateAccountOperations;
 end;
 
-procedure TOperationsGrid.ShowModalDecoder(WalletKeys: TWalletKeys; AppParams : TAppParams);
+function TOperationsGrid.GetSelectedOperation : TOperationResume;
 Var i : Integer;
   opr : TOperationResume;
   FRM : TFRMPayloadDecoder;
 begin
   if Not Assigned(FDrawGrid) then exit;
-  if (FDrawGrid.Row<=0) Or (FDrawGrid.Row>FOperationsResume.Count) then exit;
-  opr := FOperationsResume.OperationResume[FDrawGrid.Row-1];
-  FRM := TFRMPayloadDecoder.Create(FDrawGrid.Owner);
-  try
-    FRM.Init(opr,WalletKeys,AppParams);
-    FRM.ShowModal;
-  finally
-    FRM.Free;
+  if (FDrawGrid.Row<=0) Or (FDrawGrid.Row>FOperationsResume.Count) then begin
+    Result := CT_TOperationResume_NUL;
+    exit;
   end;
+  Result := FOperationsResume.OperationResume[FDrawGrid.Row-1];
 end;
 
+
 procedure TOperationsGrid.UpdateAccountOperations;
 Var list : TList;
   i,j : Integer;