ソースを参照

GUI: cleanup fee wizard, add remember this fee checkbox

Herman Schoenfeld 7 年 前
コミット
7e54cb34de

+ 29 - 26
src/gui/wizards/operations/UWIZOperationFee_Custom.lfm

@@ -7,23 +7,22 @@ object WIZOperationFee_Custom: TWIZOperationFee_Custom
   Caption = 'WIZOperationFee_Custom'
   ClientHeight = 253
   ClientWidth = 429
-  LCLVersion = '1.8.2.0'
   Visible = False
   object gbTransactionFee: TGroupBox
-    Left = 14
-    Height = 232
-    Top = 8
-    Width = 400
+    Left = 0
+    Height = 248
+    Top = 0
+    Width = 422
     Anchors = [akTop, akLeft, akRight, akBottom]
     Caption = 'Operation Fee'
-    ClientHeight = 212
-    ClientWidth = 396
+    ClientHeight = 228
+    ClientWidth = 418
     TabOrder = 0
     object fseFee: TFloatSpinEdit
       Left = 11
       Height = 23
       Top = 35
-      Width = 173
+      Width = 125
       DecimalPlaces = 4
       Increment = 0.0001
       MaxValue = 1
@@ -36,20 +35,12 @@ object WIZOperationFee_Custom: TWIZOperationFee_Custom
       Left = 11
       Height = 15
       Top = 8
-      Width = 207
-      Caption = 'Please enter the fee for this transaction.'
-      ParentColor = False
-    end
-    object lblNote2: TLabel
-      Left = 11
-      Height = 30
-      Top = 88
-      Width = 378
-      Caption = 'NOTE: if you are sending from multiple accounts, the fee is required for '#13#10'each sender account '
+      Width = 179
+      Caption = 'Please enter the fee per operation.'
       ParentColor = False
     end
     object lblPASC: TLabel
-      Left = 192
+      Left = 144
       Height = 15
       Top = 40
       Width = 28
@@ -59,24 +50,36 @@ object WIZOperationFee_Custom: TWIZOperationFee_Custom
       ParentFont = False
     end
     object lblestimatedfee: TLabel
-      Left = 11
+      Left = 246
       Height = 15
-      Top = 66
-      Width = 190
-      Caption = 'Estimated Fee For All Transcations:'
+      Top = 40
+      Width = 53
+      Alignment = taRightJustify
+      Anchors = [akTop, akRight]
+      Caption = 'Total Fee:'
       Font.Style = [fsBold]
       ParentColor = False
       ParentFont = False
     end
     object lblTotalFeeValue: TLabel
-      Left = 208
+      Left = 310
       Height = 15
-      Top = 66
-      Width = 28
+      Top = 40
+      Width = 112
+      Anchors = [akTop, akRight]
+      AutoSize = False
       Caption = 'xxxx'
       Font.Style = [fsBold]
       ParentColor = False
       ParentFont = False
     end
+    object cbOverrideDefaultFee: TCheckBox
+      Left = 11
+      Height = 19
+      Top = 72
+      Width = 262
+      Caption = 'Make this my default fee for future operations'
+      TabOrder = 1
+    end
   end
 end

+ 43 - 42
src/gui/wizards/operations/UWIZOperationFee_Custom.pas

@@ -17,27 +17,29 @@ interface
 
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  ExtCtrls, Buttons, Spin, UCommon, UCommon.Collections, UWallet, UCoreObjects,
-  UFRMAccountSelect, UNode,
-  UWizard, UWIZOperation, UWIZOperationPayload_Encryption, UWIZOperationSigner_Select;
+  ExtCtrls, Buttons, Spin, UCommon, UWallet, UCoreObjects,
+  UNode, UWizard, UWIZOperation, UWIZOperationPayload_Encryption, UWIZOperationSigner_Select;
 
 type
 
   { TWIZOperationFee_Custom }
 
   TWIZOperationFee_Custom = class(TWizardForm<TWIZOperationsModel>)
+    cbOverrideDefaultFee: TCheckBox;
     fseFee: TFloatSpinEdit;
     gbTransactionFee: TGroupBox;
     lblestimatedfee: TLabel;
     lblPASC: TLabel;
     lblNote1: TLabel;
-    lblNote2: TLabel;
     lblTotalFeeValue: TLabel;
-    procedure UpdateUI();
     procedure fseFeeChange(Sender: TObject);
-
-
+  private
+    procedure UpdateUI();
+    procedure SetFee(const AValue : int64);
+    function GetFee : Int64;
   public
+    property Fee : Int64 read GetFee write SetFee;
+    procedure Initialize; override;
     procedure OnPresent; override;
     procedure OnNext; override;
     function Validate(out message: ansistring): boolean; override;
@@ -53,17 +55,9 @@ uses
 
 { TWIZOperationFee_Custom }
 
-procedure TWIZOperationFee_Custom.UpdateUI();
-var
-  LOperationFee: int64;
-begin
-  TAccountComp.TxtToMoney(Trim(fseFee.ValueToStr(fseFee.Value)), LOperationFee);
-  lblTotalFeeValue.Caption := Format('%s PASC', [TAccountComp.FormatMoney(LOperationFee * Length(Model.Account.SelectedAccounts))]);
-end;
-
-procedure TWIZOperationFee_Custom.fseFeeChange(Sender: TObject);
+procedure TWIZOperationFee_Custom.Initialize;
 begin
-  UpdateUI();
+  Fee := TSettings.DefaultFee;
 end;
 
 procedure TWIZOperationFee_Custom.OnPresent;
@@ -74,6 +68,15 @@ end;
 
 procedure TWIZOperationFee_Custom.OnNext;
 begin
+  if cbOverrideDefaultFee.Checked then begin
+    TSettings.DefaultFee := Fee;
+    TSettings.Save;
+  end;
+
+  Model.Fee.SingleOperationFee := Fee;
+  Model.Signer.SignerCandidates := TCoreTool.GetSignerCandidates(Length(Model.Account.SelectedAccounts), Fee, Model.Account.SelectedAccounts);
+
+  // TODO: move this out -- inappropriate to have payload/signer considerations here
   if Model.Payload.HasPayload then
     UpdatePath(ptInject, [TWIZOperationPayload_Encryption])
   else if Length(Model.Account.SelectedAccounts) > 1 then
@@ -86,40 +89,38 @@ begin
 end;
 
 function TWIZOperationFee_Custom.Validate(out message: ansistring): boolean;
-var
-  LOperationFee: int64;
-  LAccount: TAccount;
 begin
-  Result := True;
-
-  if not TAccountComp.TxtToMoney(Trim(fseFee.ValueToStr(fseFee.Value)), LOperationFee) then
-  begin
-    message := Format('Invalid Fee Value "%s"', [fseFee.ValueToStr(fseFee.Value)]);
+  if (Length(Model.Account.SelectedAccounts) > 1) AND (Fee = 0) then begin
+    message := 'Insufficient fee for multiple operations. Zero fees only allowed for single operation.';
     Result := False;
-    Exit;
   end;
 
-  Model.Fee.SingleOperationFee := LOperationFee;
-
-  if Length(Model.Account.SelectedAccounts) > 1 then
-    if not (Model.Fee.SingleOperationFee > 0) then
-    begin
-      message := 'Zero Fee Is Only Allowed For Single Operations.';
-      Result := False;
-      Exit;
-    end;
-
-
-  // get signer accounts from selected accounts
-  Model.Signer.SignerCandidates := TCoreTool.GetSignerCandidates(Length(Model.Account.SelectedAccounts), Model.Fee.SingleOperationFee, Model.Account.SelectedAccounts);
-
-  if Length(Model.Signer.SignerCandidates) < 1 then
-  begin
+  if Length(TCoreTool.GetSignerCandidates(Length(Model.Account.SelectedAccounts), Model.Fee.SingleOperationFee, Model.Account.SelectedAccounts)) = 0 then begin
     message := 'No Valid Signer Account Was Found With The Current Requirements.';
     Result := False;
     Exit;
   end;
+end;
 
+procedure TWIZOperationFee_Custom.SetFee(const AValue : int64);
+begin
+  fseFee.Value := TAccountComp.FormatMoneyDecimal(AValue);
+end;
+
+function TWIZOperationFee_Custom.GetFee : Int64;
+begin
+  if NOT TAccountComp.TxtToMoney(Trim(fseFee.ValueToStr(fseFee.Value)), Result) then
+    raise Exception.Create('Illegal value in fee selector');
+end;
+
+procedure TWIZOperationFee_Custom.UpdateUI();
+begin
+  lblTotalFeeValue.Caption := Format('%s PASC', [TAccountComp.FormatMoney(Fee * Length(Model.Account.SelectedAccounts))]);
+end;
+
+procedure TWIZOperationFee_Custom.fseFeeChange(Sender: TObject);
+begin
+  UpdateUI();
 end;
 
 end.