Pārlūkot izejas kodu

some more refactoring with respect to new models.

Ugochukwu Mmaduekwe 7 gadi atpakaļ
vecāks
revīzija
b2c4007ef7

+ 0 - 2
src/gui/wizards/UWIZModels.pas

@@ -62,14 +62,12 @@ type
     public
       SingleAmountToSend: int64;
       DestinationAccount: TAccount;
-      // SelectedAccounts: TArray<TAccount>;
     end;
 
     { TChangeKeyModel }
 
     TChangeKeyModel = class(TComponent)
     public
-      // SelectedAccounts: TArray<TAccount>;
       ChangeKeyMode: TChangeKeyMode;
     end;
 

+ 11 - 11
src/gui/wizards/operations/UWIZChangeKey.pas

@@ -165,7 +165,7 @@ begin
     Exit;
   end;
 
-  if Length(Model.ChangeKey.SelectedAccounts) = 0 then
+  if Length(Model.Account.SelectedAccounts) = 0 then
   begin
     errors := 'No sender account';
     Exit;
@@ -173,9 +173,9 @@ begin
   else
   begin
 
-    for iAcc := Low(Model.ChangeKey.SelectedAccounts) to High(Model.ChangeKey.SelectedAccounts) do
+    for iAcc := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
     begin
-      sender_account := Model.ChangeKey.SelectedAccounts[iAcc];
+      sender_account := Model.Account.SelectedAccounts[iAcc];
       iWallet := TWallet.Keys.IndexOfAccountKey(sender_account.accountInfo.accountKey);
       if (iWallet < 0) then
       begin
@@ -203,7 +203,7 @@ begin
     end;
   end;
 
-  Result := UpdateOpChangeKey(Model.ChangeKey.SelectedAccounts[0], signer_account,
+  Result := UpdateOpChangeKey(Model.Account.SelectedAccounts[0], signer_account,
     publicKey, errors);
   UpdatePayload(sender_account, e);
 end;
@@ -295,11 +295,11 @@ begin
     _signer_n_ops := 0;
     operationstxt := '';
     operation_to_string := '';
-    for iAcc := Low(Model.ChangeKey.SelectedAccounts) to High(Model.ChangeKey.SelectedAccounts) do
+    for iAcc := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
     begin
       loop_start:
         op := nil;
-      account := Model.ChangeKey.SelectedAccounts[iAcc];
+      account := Model.Account.SelectedAccounts[iAcc];
       if not UpdatePayload(account, errors) then
       begin
         raise Exception.Create('Error encoding payload of sender account ' +
@@ -326,11 +326,11 @@ begin
       if _V2 then
       begin
         // must ensure is Signer account last if included in sender accounts (not necessarily ordered enumeration)
-        if (iAcc < Length(Model.ChangeKey.SelectedAccounts) - 1) and
+        if (iAcc < Length(Model.Account.SelectedAccounts) - 1) and
           (account.account = signerAccount.account) then
         begin
-          TArrayTool<TAccount>.Swap(Model.ChangeKey.SelectedAccounts, iAcc,
-            Length(Model.ChangeKey.SelectedAccounts) - 1); // ensure signer account processed last
+          TArrayTool<TAccount>.Swap(Model.Account.SelectedAccounts, iAcc,
+            Length(Model.Account.SelectedAccounts) - 1); // ensure signer account processed last
           // TArrayTool_internal<Cardinal>.Swap(_senderAccounts, iAcc, Length(_senderAccounts) - 1);
           goto loop_start; // TODO: remove ugly hack with refactoring!
         end;
@@ -372,11 +372,11 @@ begin
     if (ops.OperationsCount = 0) then
       raise Exception.Create('No valid operation to execute');
 
-    if (Length(Model.ChangeKey.SelectedAccounts) > 1) then
+    if (Length(Model.Account.SelectedAccounts) > 1) then
     begin
       auxs := '';
       if Application.MessageBox(
-        PChar('Execute ' + IntToStr(Length(Model.ChangeKey.SelectedAccounts)) +
+        PChar('Execute ' + IntToStr(Length(Model.Account.SelectedAccounts)) +
         ' operations?' + #10 + 'Operation: ' + operationstxt + #10 +
         auxs + 'Total fee: ' + TAccountComp.FormatMoney(_totalfee) +
         #10 + #10 + 'Note: This operation will be transmitted to the network!'),

+ 8 - 8
src/gui/wizards/operations/UWIZChangeKey_ConfirmAccount.pas

@@ -50,9 +50,9 @@ type
 
   TAccountChangeKeyDataSource = class(TAccountsDataSourceBase)
   private
-    FModel: TWIZOperationsModel.TChangeKeyModel;
+    FModel: TWIZOperationsModel;
   public
-    property Model: TWIZOperationsModel.TChangeKeyModel read FModel write FModel;
+    property Model: TWIZOperationsModel read FModel write FModel;
     procedure FetchAll(const AContainer: TList<TAccount>); override;
   end;
 
@@ -95,14 +95,14 @@ begin
     Filters := SORTABLE_NUMERIC_FILTER;
   end;
   Data := TAccountChangeKeyDataSource.Create(FChangeKeyGrid);
-  Data.Model := Model.ChangeKey;
+  Data.Model := Model;
   FChangeKeyGrid.DataSource := Data;
   paGrid.AddControlDockCenter(FChangeKeyGrid);
 
   totalBalance := 0;
-  for i := Low(Model.ChangeKey.SelectedAccounts) to High(Model.ChangeKey.SelectedAccounts) do
+  for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    acc := Model.ChangeKey.SelectedAccounts[i];
+    acc := Model.Account.SelectedAccounts[i];
     totalBalance := totalBalance + acc.balance;
   end;
 
@@ -119,7 +119,7 @@ function TWIZChangeKey_ConfirmAccount.Validate(out message: ansistring): boolean
 begin
   Result := True;
   // get signer accounts from selected accounts
-  Model.Signer.SignerCandidates := TCoreTool.GetSignerCandidates(Length(Model.ChangeKey.SelectedAccounts), Model.ChangeKey.SelectedAccounts);
+  Model.Signer.SignerCandidates := TCoreTool.GetSignerCandidates(Length(Model.Account.SelectedAccounts), Model.Account.SelectedAccounts);
 
   if Length(Model.Signer.SignerCandidates) < 1 then
   begin
@@ -135,9 +135,9 @@ procedure TAccountChangeKeyDataSource.FetchAll(const AContainer: TList<TAccount>
 var
   i: integer;
 begin
-  for i := Low(Model.SelectedAccounts) to High(Model.SelectedAccounts) do
+  for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    AContainer.Add(Model.SelectedAccounts[i]);
+    AContainer.Add(Model.Account.SelectedAccounts[i]);
   end;
 end;
 

+ 2 - 2
src/gui/wizards/operations/UWIZChangeKey_Confirmation.pas

@@ -168,9 +168,9 @@ procedure TAccountChangeKeyDataSource.FetchAll(const AContainer: TList<TAccount>
 var
   i: integer;
 begin
-  for i := Low(Model.ChangeKey.SelectedAccounts) to High(Model.ChangeKey.SelectedAccounts) do
+  for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    AContainer.Add(Model.ChangeKey.SelectedAccounts[i]);
+    AContainer.Add(Model.Account.SelectedAccounts[i]);
   end;
 end;
 

+ 1 - 0
src/gui/wizards/operations/UWIZChangeKey_EnterKey.lfm

@@ -7,6 +7,7 @@ object WIZChangeKey_EnterKey: TWIZChangeKey_EnterKey
   Caption = 'ChangeKey_EnterKey'
   ClientHeight = 253
   ClientWidth = 429
+  LCLVersion = '1.8.2.0'
   Visible = False
   object gbNewPublicKey: TGroupBox
     Left = 16

+ 2 - 2
src/gui/wizards/operations/UWIZChangeKey_EnterKey.pas

@@ -81,9 +81,9 @@ begin
     Result := False;
     Exit;
   end;
-  for i := Low(Model.ChangeKey.SelectedAccounts) to High(Model.ChangeKey.SelectedAccounts) do
+  for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    if TAccountComp.EqualAccountKeys(Model.ChangeKey.SelectedAccounts[i].accountInfo.accountKey,
+    if TAccountComp.EqualAccountKeys(Model.Account.SelectedAccounts[i].accountInfo.accountKey,
       tempAccountKey) then
     begin
       Result := False;

+ 2 - 2
src/gui/wizards/operations/UWIZChangeKey_SelectKey.pas

@@ -148,9 +148,9 @@ begin
 
   tempAccountKey := TWallet.Keys.Key[PtrInt(cbNewPrivateKey.Items.Objects[cbNewPrivateKey.ItemIndex])].AccountKey;
 
-   for i := Low(Model.ChangeKey.SelectedAccounts) to High(Model.ChangeKey.SelectedAccounts) do
+   for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    if TAccountComp.EqualAccountKeys(Model.ChangeKey.SelectedAccounts[i].accountInfo.accountKey,
+    if TAccountComp.EqualAccountKeys(Model.Account.SelectedAccounts[i].accountInfo.accountKey,
       tempAccountKey) then
     begin
       Result := False;

+ 2 - 2
src/gui/wizards/operations/UWIZFeeOverride.pas

@@ -18,7 +18,7 @@ interface
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
   ExtCtrls, Buttons, Spin, UCommon, UCommon.Collections, UWallet,
-  UFRMAccountSelect, UNode, UWizard, UWIZSendPASC, UWIZPayloadOverride, UWIZSelectSignerOverride, UWIZModels;
+  UFRMAccountSelect, UNode, UWizard, UWIZPayloadOverride, UWIZSelectSignerOverride, UWIZModels;
 
 type
 
@@ -58,7 +58,7 @@ var
 begin
   TAccountComp.TxtToMoney(Trim(fseFee.ValueToStr(fseFee.Value)), opfee);
   lblTotalFeeValue.Caption := Format('%s PASC', [TAccountComp.FormatMoney(opfee *
-    Length(Model.SendPASC.SelectedAccounts))]);
+    Length(Model.Account.SelectedAccounts))]);
 end;
 
 procedure TWIZFeeOverride.fseFeeChange(Sender: TObject);

+ 11 - 11
src/gui/wizards/operations/UWIZSendPASC.pas

@@ -67,7 +67,7 @@ begin
     Exit;
   end;
 
-  if Length(Model.SendPASC.SelectedAccounts) = 0 then
+  if Length(Model.Account.SelectedAccounts) = 0 then
   begin
     errors := 'No sender account';
     Exit;
@@ -75,9 +75,9 @@ begin
   else
   begin
 
-    for iAcc := Low(Model.SendPASC.SelectedAccounts) to High(Model.SendPASC.SelectedAccounts) do
+    for iAcc := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
     begin
-      sender_account := Model.SendPASC.SelectedAccounts[iAcc];
+      sender_account := Model.Account.SelectedAccounts[iAcc];
       iWallet := TWallet.Keys.IndexOfAccountKey(sender_account.accountInfo.accountKey);
       if (iWallet < 0) then
       begin
@@ -105,7 +105,7 @@ begin
     end;
   end;
 
-  Result := UpdateOpTransaction(Model.SendPASC.SelectedAccounts[0], dest_account, amount, errors);
+  Result := UpdateOpTransaction(Model.Account.SelectedAccounts[0], dest_account, amount, errors);
   UpdatePayload(sender_account, e);
 end;
 
@@ -119,7 +119,7 @@ begin
 
   DestAccount := Model.SendPASC.DestinationAccount;
 
-  if Length(Model.SendPASC.SelectedAccounts) = 1 then
+  if Length(Model.Account.SelectedAccounts) = 1 then
   begin
     amount := Model.SendPASC.SingleAmountToSend;
   end
@@ -134,7 +134,7 @@ begin
     Exit;
   end;
 
-  if (Length(Model.SendPASC.SelectedAccounts) = 1) then
+  if (Length(Model.Account.SelectedAccounts) = 1) then
   begin
     if (SenderAccount.balance < (amount + Model.Fee.SingleOperationFee)) then
     begin
@@ -170,10 +170,10 @@ begin
     _signer_n_ops := 0;
     operationstxt := '';
     operation_to_string := '';
-    for iAcc := Low(Model.SendPASC.SelectedAccounts) to High(Model.SendPASC.SelectedAccounts) do
+    for iAcc := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
     begin
       op := nil;
-      account := Model.SendPASC.SelectedAccounts[iAcc];
+      account := Model.Account.SelectedAccounts[iAcc];
       if not UpdatePayload(account, errors) then
       begin
         raise Exception.Create('Error encoding payload of sender account ' +
@@ -195,7 +195,7 @@ begin
 
       if not UpdateOpTransaction(account, destAccount, _amount, errors) then
         raise Exception.Create(errors);
-      if Length(Model.SendPASC.SelectedAccounts) > 1 then
+      if Length(Model.Account.SelectedAccounts) > 1 then
       begin
         if account.balance > 0 then
         begin
@@ -240,12 +240,12 @@ begin
     if (ops.OperationsCount = 0) then
       raise Exception.Create('No valid operation to execute');
 
-    if (Length(Model.SendPASC.SelectedAccounts) > 1) then
+    if (Length(Model.Account.SelectedAccounts) > 1) then
     begin
       auxs := 'Total amount that dest will receive: ' + TAccountComp.FormatMoney(
         _totalamount) + #10;
       if Application.MessageBox(
-        PChar('Execute ' + IntToStr(Length(Model.SendPASC.SelectedAccounts)) +
+        PChar('Execute ' + IntToStr(Length(Model.Account.SelectedAccounts)) +
         ' operations?' + #10 + 'Operation: ' + operationstxt + #10 +
         auxs + 'Total fee: ' + TAccountComp.FormatMoney(_totalfee) +
         #10 + #10 + 'Note: This operation will be transmitted to the network!'),

+ 6 - 6
src/gui/wizards/operations/UWIZSendPASC_ConfirmSender.pas

@@ -48,9 +48,9 @@ type
 
   TAccountSenderDataSource = class(TAccountsDataSourceBase)
   private
-    FModel: TWIZOperationsModel.TSendPASCModel;
+    FModel: TWIZOperationsModel;
   public
-    property Model: TWIZOperationsModel.TSendPASCModel read FModel write FModel;
+    property Model: TWIZOperationsModel read FModel write FModel;
     procedure FetchAll(const AContainer: TList<TAccount>); override;
   end;
 
@@ -90,7 +90,7 @@ begin
     Filters := SORTABLE_NUMERIC_FILTER;
   end;
   Data := TAccountSenderDataSource.Create(FSendersGrid);
-  Data.Model := Model.SendPASC;
+  Data.Model := Model;
   FSendersGrid.DataSource := Data;
   paGrid.AddControlDockCenter(FSendersGrid);
 end;
@@ -104,7 +104,7 @@ function TWIZSendPASC_ConfirmSender.Validate(out message: ansistring): boolean;
 begin
   Result := True;
   // get signer accounts from selected accounts
-  Model.Signer.SignerCandidates := TCoreTool.GetSignerCandidates(Length(Model.SendPASC.SelectedAccounts), Model.SendPASC.SelectedAccounts);
+  Model.Signer.SignerCandidates := TCoreTool.GetSignerCandidates(Length(Model.Account.SelectedAccounts), Model.Account.SelectedAccounts);
 
   if Length(Model.Signer.SignerCandidates) < 1 then
   begin
@@ -120,9 +120,9 @@ procedure TAccountSenderDataSource.FetchAll(const AContainer: TList<TAccount>);
 var
   i: integer;
 begin
-  for i := Low(Model.SelectedAccounts) to High(Model.SelectedAccounts) do
+  for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    AContainer.Add(Model.SelectedAccounts[i]);
+    AContainer.Add(Model.Account.SelectedAccounts[i]);
   end;
 end;
 

+ 1 - 0
src/gui/wizards/operations/UWIZSendPASC_Confirmation.lfm

@@ -6,6 +6,7 @@ object WIZSendPASC_Confirmation: TWIZSendPASC_Confirmation
   Caption = 'WIZSendPASC_Confirmation'
   ClientHeight = 253
   ClientWidth = 429
+  LCLVersion = '1.8.2.0'
   Visible = False
   object GroupBox1: TGroupBox
     Left = 10

+ 2 - 2
src/gui/wizards/operations/UWIZSendPASC_Confirmation.pas

@@ -133,9 +133,9 @@ procedure TAccountSenderDataSource.FetchAll(const AContainer : TList<TAccount>);
 var
   i: Integer;
 begin
-  for i := Low(Model.SendPASC.SelectedAccounts) to High(Model.SendPASC.SelectedAccounts) do
+  for i := Low(Model.Account.SelectedAccounts) to High(Model.Account.SelectedAccounts) do
   begin
-    AContainer.Add( Model.SendPASC.SelectedAccounts[i] );
+    AContainer.Add( Model.Account.SelectedAccounts[i] );
   end;
 end;
 

+ 1 - 0
src/gui/wizards/operations/UWIZSendPASC_EnterRecipient.lfm

@@ -7,6 +7,7 @@ object WIZSendPASC_EnterRecipient: TWIZSendPASC_EnterRecipient
   Caption = 'WIZSendPASC_EnterRecipient'
   ClientHeight = 253
   ClientWidth = 429
+  LCLVersion = '1.8.2.0'
   Visible = False
   object gbRecipient: TGroupBox
     Left = 16

+ 1 - 1
src/gui/wizards/operations/UWIZSendPASC_EnterRecipient.pas

@@ -154,7 +154,7 @@ begin
   end;
 
   AccountNumbersWithChecksum :=
-    TListTool<TAccount, string>.Transform(Model.SendPASC.SelectedAccounts, GetAccNoWithCheckSum);
+    TListTool<TAccount, string>.Transform(Model.Account.SelectedAccounts, GetAccNoWithCheckSum);
 
   if TArrayTool<string>.Contains(AccountNumbersWithChecksum, edtDestAcc.Text) then
   begin