Browse Source

implemented UWIZSendPASC_Confirmation.

Ugochukwu Mmaduekwe 7 years ago
parent
commit
abe4ca628e

+ 0 - 1
src/gui/UCTRLWallet.lfm

@@ -10,7 +10,6 @@ object CTRLWallet: TCTRLWallet
   ClientWidth = 1151
   OnCreate = FormCreate
   OnResize = FormResize
-  LCLVersion = '1.8.2.0'
   Visible = False
   object PairSplitter1: TPairSplitter
     Left = 0

+ 7 - 5
src/gui/wizards/UWIZSendPASC.pas

@@ -24,7 +24,9 @@ type
     public
       SelectedIndex: Integer;
       SelectedAccounts: TArray<TAccount>;
-      SignerAccount: TAccount;
+      SignerAccount, DestinationAccount: TAccount;
+      AmountToSend: String;
+      DefaultFee: Int64;
   end;
 
   { TWIZSendPASCWizard }
@@ -45,19 +47,19 @@ uses
   UWallet,
   UWIZSendPASC_Start,
   UWIZSendPASC_Transaction,
-  UWIZSendPASC_Confirmation,
-  UWIZSendPASC_Completion;
+  UWIZSendPASC_Confirmation;
+  //UWIZSendPASC_Completion;
 
 constructor TWIZSendPASCWizard.Create(AOwner: TComponent);
 begin
-  inherited Create(AOwner, [TWIZSendPASC_Start, TWIZSendPASC_Completion]);
+  inherited Create(AOwner, [TWIZSendPASC_Start, TWIZSendPASC_Confirmation]);
   TitleText := 'Send PASC';
   FinishText := 'Send PASC';
 end;
 
 function TWIZSendPASCWizard.DetermineHasNext : boolean;
 begin
-  Result := NOT (CurrentScreen is TWIZSendPASC_Completion);
+  Result := NOT (CurrentScreen is TWIZSendPASC_Confirmation);
 end;
 
 function TWIZSendPASCWizard.DetermineHasPrevious : boolean;

+ 0 - 18
src/gui/wizards/UWIZSendPASC_Completion.lfm

@@ -1,18 +0,0 @@
-object WIZSendPASC_Completion: TWIZSendPASC_Completion
-  Left = 0
-  Height = 253
-  Top = 0
-  Width = 429
-  Caption = 'WIZSendPASC_Completion'
-  ClientHeight = 253
-  ClientWidth = 429
-  Visible = False
-  object Button1: TButton
-    Left = 203
-    Height = 25
-    Top = 153
-    Width = 75
-    Caption = 'Button1'
-    TabOrder = 0
-  end
-end

+ 0 - 49
src/gui/wizards/UWIZSendPASC_Completion.pas

@@ -1,49 +0,0 @@
-unit UWIZSendPASC_Completion;
-
-{$mode delphi}
-{$modeswitch nestedprocvars}
-
-{ Copyright (c) 2018 by Ugochukwu Mmaduekwe
-
-  Distributed under the MIT software license, see the accompanying file LICENSE
-  or visit http://www.opensource.org/licenses/mit-license.php.
-}
-
-interface
-
-uses
-  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  UWizard, UWIZSendPASC;
-
-type
-
-  { TWIZSendPASC_Completion }
-
-  TWIZSendPASC_Completion = class(TWizardForm<TWIZSendPASCModel>)
-    Button1: TButton;
-
-
-  public
-    procedure OnPresent; override;
-    procedure OnNext; override;
-  end;
-
-
-implementation
-
-{$R *.lfm}
-
-{ TWIZSendPASC_Completion }
-
-procedure TWIZSendPASC_Completion.OnPresent;
-begin
-  inherited OnPresent;
-end;
-
-procedure TWIZSendPASC_Completion.OnNext;
-begin
-  inherited OnNext;
-end;
-
-end.
-

+ 52 - 6
src/gui/wizards/UWIZSendPASC_Confirmation.lfm

@@ -6,13 +6,59 @@ object WIZSendPASC_Confirmation: TWIZSendPASC_Confirmation
   Caption = 'WIZSendPASC_Confirmation'
   ClientHeight = 253
   ClientWidth = 429
+  LCLVersion = '1.8.1.0'
   Visible = False
-  object Edit1: TEdit
-    Left = 144
-    Height = 23
-    Top = 148
-    Width = 80
+  object GroupBox1: TGroupBox
+    Left = 10
+    Height = 232
+    Top = 8
+    Width = 408
+    Anchors = [akTop, akLeft, akRight, akBottom]
+    Caption = 'Confirm Transaction'
+    ClientHeight = 212
+    ClientWidth = 404
     TabOrder = 0
-    Text = 'Edit1'
+    object paGrid: TPanel
+      Left = 8
+      Height = 152
+      Top = 48
+      Width = 382
+      Anchors = [akTop, akLeft, akRight, akBottom]
+      BevelOuter = bvNone
+      Caption = 'GRID PANEL'
+      TabOrder = 0
+    end
+    object Label1: TLabel
+      Left = 8
+      Height = 15
+      Top = 2
+      Width = 84
+      Caption = 'Signer Account:'
+      ParentColor = False
+    end
+    object lblSgnAcc: TLabel
+      Left = 112
+      Height = 15
+      Top = 2
+      Width = 53
+      Caption = 'lblSgnAcc'
+      ParentColor = False
+    end
+    object Label2: TLabel
+      Left = 8
+      Height = 15
+      Top = 24
+      Width = 111
+      Caption = 'Destination Account:'
+      ParentColor = False
+    end
+    object lblDestAcc: TLabel
+      Left = 128
+      Height = 15
+      Top = 24
+      Width = 56
+      Caption = 'lblDestAcc'
+      ParentColor = False
+    end
   end
 end

+ 104 - 7
src/gui/wizards/UWIZSendPASC_Confirmation.pas

@@ -13,18 +13,23 @@ interface
 
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  UWizard, UWIZSendPASC;
+  ExtCtrls, UVisualGrid, UCommon.Data, UWizard, UWIZSendPASC;
 
 type
 
   { TWIZSendPASC_Confirmation }
 
   TWIZSendPASC_Confirmation = class(TWizardForm<TWIZSendPASCModel>)
-    Edit1: TEdit;
-
+    GroupBox1: TGroupBox;
+    Label1: TLabel;
+    Label2: TLabel;
+    lblDestAcc: TLabel;
+    lblSgnAcc: TLabel;
+    paGrid: TPanel;
+  private
+    FSendersGrid : TVisualGrid;
   public
     procedure OnPresent; override;
-    procedure OnNext; override;
   end;
 
 
@@ -32,17 +37,109 @@ implementation
 
 {$R *.lfm}
 
+uses UAccounts, UCommon, UCommon.UI, Generics.Collections;
+
+type
+
+  { TAccountSenderDataSource }
+
+  TAccountSenderDataSource = class(TCustomDataSource<TAccount>)
+    private
+      FModel : TWIZSendPASCModel;
+    protected
+      function GetColumns : TTableColumns;  override;
+    public
+      property Model : TWIZSendPASCModel read FModel write FModel;
+      function GetSearchCapabilities: TSearchCapabilities; override;
+      function GetEntityKey(constref AItem: TAccount) : Variant; override;
+      procedure FetchAll(const AContainer : TList<TAccount>); override;
+      function GetItemField(constref AItem: TAccount; const AColumnName : utf8string) : Variant; override;
+      procedure DehydrateItem(constref AItem: TAccount; var ATableRow: Variant); override;
+  end;
+
 { TWIZSendPASC_Confirmation }
 
 procedure TWIZSendPASC_Confirmation.OnPresent;
+var
+  data : TAccountSenderDataSource;
+begin
+  FSendersGrid := TVisualGrid.Create(Self);
+  FSendersGrid.CanSearch:= False;
+  FSendersGrid.SortMode := smMultiColumn;
+  FSendersGrid.FetchDataInThread := False;
+  FSendersGrid.AutoPageSize := True;
+  FSendersGrid.SelectionType := stNone;
+  FSendersGrid.Options := [vgoColAutoFill, vgoColSizing, vgoSortDirectionAllowNone, vgoAutoHidePaging];
+  FSendersGrid.DefaultColumnWidths :=
+    TArray<integer>.Create(
+    100, // Sender Account
+    100, // Balance
+    100, // AmountToSend
+    100 // Fee
+   );
+   data := TAccountSenderDataSource.Create(FSendersGrid);
+   data.Model := Model;
+   FSendersGrid.DataSource := data;
+   paGrid.AddControlDockCenter(FSendersGrid);
+   lblSgnAcc.Caption := TAccountComp.AccountNumberToAccountTxtNumber(Model.SignerAccount.account);
+   lblDestAcc.Caption := TAccountComp.AccountNumberToAccountTxtNumber(Model.DestinationAccount.account);
+end;
+
+{ TAccountSenderDataSource }
+
+function TAccountSenderDataSource.GetColumns : TTableColumns;
+begin
+  Result := TTableColumns.Create('SenderAccount', 'Balance', 'AmountToSend', 'Fee');
+end;
+
+function TAccountSenderDataSource.GetSearchCapabilities: TSearchCapabilities;
+begin
+  Result := TSearchCapabilities.Create(
+    TSearchCapability.From('SenderAccount', SORTABLE_NUMERIC_FILTER),
+    TSearchCapability.From('Balance', SORTABLE_TEXT_FILTER),
+    TSearchCapability.From('AmountToSend', SORTABLE_TEXT_FILTER),
+    TSearchCapability.From('Fee', SORTABLE_TEXT_FILTER)
+  );
+end;
+
+function TAccountSenderDataSource.GetEntityKey(constref AItem: TAccount) : Variant;
+begin
+  Result := AItem.account;
+end;
+
+function TAccountSenderDataSource.GetItemField(constref AItem: TAccount; const AColumnName : utf8string) : Variant;
+var
+  index : Integer;
+begin
+   if AColumnName = 'SenderAccount' then
+     Result := AItem.account
+   else if AColumnName = 'Balance' then
+     Result := TAccountComp.FormatMoneyDecimal(AItem.Balance)
+   else if AColumnName = 'AmountToSend' then
+     Result := Model.AmountToSend
+     else if AColumnName = 'Fee' then
+     Result := TAccountComp.FormatMoney(Model.DefaultFee)
+   else raise Exception.Create(Format('Field not found [%s]', [AColumnName]));
+end;
+
+procedure TAccountSenderDataSource.DehydrateItem(constref AItem: TAccount; var ATableRow: Variant);
 begin
-  inherited OnPresent;
+  ATableRow.SenderAccount := TAccountComp.AccountNumberToAccountTxtNumber(AItem.account);
+  ATableRow.Balance := TAccountComp.FormatMoney(AItem.balance);
+  ATableRow.AmountToSend := Model.AmountToSend;
+  ATableRow.Fee := TAccountComp.FormatMoney(Model.DefaultFee);
 end;
 
-procedure TWIZSendPASC_Confirmation.OnNext;
+procedure TAccountSenderDataSource.FetchAll(const AContainer : TList<TAccount>);
+var
+  i: Integer;
 begin
-  inherited OnNext;
+  for i := Low(Model.SelectedAccounts) to High(Model.SelectedAccounts) do
+  begin
+    AContainer.Add( Model.SelectedAccounts[i] );
+  end;
 end;
 
+
 end.
 

+ 8 - 8
src/gui/wizards/UWIZSendPASC_Start.lfm

@@ -2,27 +2,27 @@ object WIZSendPASC_Start: TWIZSendPASC_Start
   Left = 0
   Height = 261
   Top = 0
-  Width = 474
+  Width = 429
   Caption = 'WIZSendPASC_Start'
   ClientHeight = 261
-  ClientWidth = 474
-  LCLVersion = '1.8.2.0'
+  ClientWidth = 429
+  LCLVersion = '1.8.1.0'
   Visible = False
   object gpSender: TGroupBox
     Left = 4
     Height = 256
     Top = 0
-    Width = 462
+    Width = 420
     Anchors = [akTop, akLeft, akRight, akBottom]
     Caption = 'Sender Accounts'
     ClientHeight = 236
-    ClientWidth = 458
+    ClientWidth = 416
     TabOrder = 0
     object paGrid: TPanel
       Left = 8
-      Height = 214
-      Top = 16
-      Width = 440
+      Height = 192
+      Top = 24
+      Width = 400
       Anchors = [akTop, akLeft, akRight, akBottom]
       BevelOuter = bvNone
       Caption = 'GRID PANEL'

+ 2 - 2
src/gui/wizards/UWIZSendPASC_Start.pas

@@ -17,7 +17,7 @@ interface
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
   ExtCtrls, UVisualGrid, UCommon.Data,
-  UWizard, UWIZSendPASC, UWIZSendPASC_Transaction, UWIZSendPASC_Completion;
+  UWizard, UWIZSendPASC, UWIZSendPASC_Transaction, UWIZSendPASC_Confirmation;
 
 type
 
@@ -85,7 +85,7 @@ end;
 
 procedure TWIZSendPASC_Start.OnNext;
 begin
-  UpdatePath(ptReplaceAllNext, [TWIZSendPASC_Transaction, TWIZSendPASC_Completion]);
+  UpdatePath(ptReplaceAllNext, [TWIZSendPASC_Transaction, TWIZSendPASC_Confirmation]);
 end;
 
 { TAccountSenderDataSource }

+ 1 - 0
src/gui/wizards/UWIZSendPASC_Transaction.lfm

@@ -7,6 +7,7 @@ object WIZSendPASC_Transaction: TWIZSendPASC_Transaction
   Caption = 'WIZSendPASC_Transaction'
   ClientHeight = 253
   ClientWidth = 429
+  LCLVersion = '1.8.1.0'
   Visible = False
   object gbTransaction: TGroupBox
     Left = 22

+ 49 - 15
src/gui/wizards/UWIZSendPASC_Transaction.pas

@@ -14,7 +14,7 @@ interface
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
   ExtCtrls, Buttons, UCommon, UCommon.Collections, UWallet,
-  UFRMAccountSelect, UNode, UWizard, UWIZSendPASC, UWIZSendPASC_Confirmation, UWIZSendPASC_Completion;
+  UFRMAccountSelect, UNode, UWizard, UWIZSendPASC, UWIZSendPASC_Confirmation;
 
 type
 
@@ -36,7 +36,6 @@ type
     procedure btnSearchClick(Sender: TObject);
     procedure cbSignerAccountChange(Sender: TObject);
 
-
   public
     procedure OnPresent; override;
     procedure OnNext; override;
@@ -49,7 +48,7 @@ implementation
 {$R *.lfm}
 
 uses
-  UAccounts;
+  UAccounts, UUserInterface;
 
 { TWIZSendPASC_Transaction }
 
@@ -138,10 +137,44 @@ begin
 end;
 
 procedure TWIZSendPASC_Transaction.OnNext;
+
+  function GetAccNoWithoutChecksum(const AAccount: string): cardinal;
+  begin
+    if not TAccountComp.AccountTxtNumberToAccountNumber(AAccount, Result) then
+    begin
+      raise Exception.Create(
+        'Internal Error: Unable to parse account number from input');
+    end;
+  end;
+
+  function GetAccounts(AccountNumber: cardinal): TAccount;
+  var
+    acc: TAccount;
+    safeBox: TPCSafeBox;
+    keys: TOrderedAccountKeysList;
+    i: integer;
+  begin
+    keys := TWallet.keys.AccountsKeyList;
+    safeBox := TUserInterface.Node.Bank.safeBox;
+    safeBox.StartThreadSafe;
+    try
+      acc := safeBox.Account(AccountNumber);
+      if keys.IndexOfAccountKey(acc.accountInfo.accountKey) >= 0 then
+      begin
+        Result := acc;
+      end;
+    finally
+      safeBox.EndThreadSave;
+    end;
+
+  end;
+
 begin
   Model.SelectedIndex := cbSignerAccount.ItemIndex;
-  Model.SignerAccount := Model.SelectedAccounts[PtrInt(cbSignerAccount.Items.Objects[cbSignerAccount.ItemIndex])];
-  UpdatePath(ptReplaceAllNext, [TWIZSendPASC_Confirmation, TWIZSendPASC_Completion]);
+  Model.SignerAccount := Model.SelectedAccounts[PtrInt(
+    cbSignerAccount.Items.Objects[cbSignerAccount.ItemIndex])];
+  Model.DestinationAccount := GetAccounts(GetAccNoWithoutChecksum(edtDestAcc.Text));
+  Model.AmountToSend := edtAmt.Text;
 end;
 
 function TWIZSendPASC_Transaction.Validate(out message: ansistring): boolean;
@@ -157,6 +190,7 @@ var
   c: cardinal;
   DestAccount: TAccount;
   amount, opfee: int64;
+  i: integer;
 begin
   Accounts := Model.SelectedAccounts;
   Result := True;
@@ -203,22 +237,22 @@ begin
     Exit;
   end;
 
-  if not TAccountComp.TxtToMoney(Trim(edtOpFee.Text), opfee) then
+  if not TAccountComp.TxtToMoney(Trim(edtOpFee.Text), Model.DefaultFee) then
   begin
     message := 'Invalid fee value "' + edtOpFee.Text + '"';
     Result := False;
     Exit;
   end;
 
-  if Length(Model.SelectedAccounts) = 1 then
-  begin
-    if (Accounts[0].balance < (amount + opfee)) then
-    begin
-      message := 'Insufficient funds';
-      Result := False;
-      Exit;
-    end;
-  end;
+  //for i := Low(Accounts) to High(Accounts) do
+  //begin
+  //  if (Accounts[i].balance < (amount + opfee)) then
+  //  begin
+  //    message := 'Insufficient funds';
+  //    Result := False;
+  //    Exit;
+  //  end;
+  //end;
 
 end;
 

+ 2 - 9
src/pascalcoin_wallet.lpi

@@ -33,7 +33,7 @@
         <PackageName Value="LCL"/>
       </Item1>
     </RequiredPackages>
-    <Units Count="75">
+    <Units Count="74">
       <Unit0>
         <Filename Value="pascalcoin_wallet.dpr"/>
         <IsPartOfProject Value="True"/>
@@ -413,16 +413,9 @@
         <ResourceBaseClass Value="Form"/>
       </Unit72>
       <Unit73>
-        <Filename Value="gui\wizards\UWIZSendPASC_Completion.pas"/>
-        <IsPartOfProject Value="True"/>
-        <ComponentName Value="WIZSendPASC_Completion"/>
-        <HasResources Value="True"/>
-        <ResourceBaseClass Value="Form"/>
-      </Unit73>
-      <Unit74>
         <Filename Value="core\UCoreHelpers.pas"/>
         <IsPartOfProject Value="True"/>
-      </Unit74>
+      </Unit73>
     </Units>
   </ProjectOptions>
   <CompilerOptions>