Skip to content

Commit

Permalink
- saving the FeeTarget (on sendTab) to the UiConfig file making it non
Browse files Browse the repository at this point in the history
volatile.
  • Loading branch information
molnard committed Dec 20, 2018
1 parent 1234158 commit 9ca284d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
8 changes: 6 additions & 2 deletions WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public SendTabViewModel(WalletViewModel walletViewModel)

ResetMax();
SetFeeTargetLimits();
FeeTarget = MinimumFeeTarget;
FeeTarget = Global.UiConfig.FeeTarget ?? MinimumFeeTarget;
SetFeesAndTexts();

Global.Synchronizer.PropertyChanged += Synchronizer_PropertyChanged;
Expand Down Expand Up @@ -525,7 +525,11 @@ public string Amount
public int FeeTarget
{
get => _feeTarget;
set => this.RaiseAndSetIfChanged(ref _feeTarget, value);
set
{
this.RaiseAndSetIfChanged(ref _feeTarget, value);
Global.UiConfig.FeeTarget = value;
}
}

public int MinimumFeeTarget
Expand Down
6 changes: 6 additions & 0 deletions WalletWasabi.Gui/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ public static string TorLogsFile
public static TorProcessManager TorManager { get; private set; }

public static Config Config { get; private set; }
public static UiConfig UiConfig { get; private set; }

public static void InitializeConfig(Config config)
{
Config = Guard.NotNull(nameof(config), config);
}

public static void InitializeUiConfig(UiConfig uiConfig)
{
UiConfig = Guard.NotNull(nameof(uiConfig), uiConfig);
}

private static long _triedDesperateDequeuing = 0;

private static async Task TryDesperateDequeueAllCoinsAsync()
Expand Down
26 changes: 12 additions & 14 deletions WalletWasabi.Gui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace WalletWasabi.Gui
{
public class MainWindow : MetroWindow
{
public UiConfig UiConfig { get; private set; }


public MainWindow()
{
Expand Down Expand Up @@ -46,14 +46,11 @@ private void InitializeComponent()

private async void MainWindow_ClosingAsync(object sender, CancelEventArgs e)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
UiConfig.WindowState = WindowState;
UiConfig.Width = Width;
UiConfig.Height = Height;
await UiConfig.ToFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is saved.");
}
Global.UiConfig.WindowState = WindowState;
Global.UiConfig.Width = Width;
Global.UiConfig.Height = Height;
await Global.UiConfig.ToFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is saved.");
}

#pragma warning disable IDE1006 // Naming Styles
Expand All @@ -62,13 +59,14 @@ private async void OnActivated(object sender, EventArgs e)
{
Activated -= OnActivated;

var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
var uiConfig = new UiConfig(uiConfigFilePath);
await uiConfig.LoadOrCreateDefaultFileAsync();
Global.InitializeUiConfig(uiConfig);
Logging.Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
var uiConfig = new UiConfig(uiConfigFilePath);
await uiConfig.LoadOrCreateDefaultFileAsync();
Logging.Logger.LogInfo<UiConfig>("UiConfig is successfully initialized.");
UiConfig = uiConfig;
MainWindowViewModel.Instance.Width = (double)uiConfig.Width;
MainWindowViewModel.Instance.Height = (double)uiConfig.Height;
MainWindowViewModel.Instance.WindowState = (WindowState)uiConfig.WindowState;
Expand Down
13 changes: 12 additions & 1 deletion WalletWasabi.Gui/UiConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class UiConfig : IConfig
[JsonProperty(PropertyName = "Width")]
public double? Width { get; internal set; }

[JsonProperty(PropertyName = "FeeTarget")]
public int? FeeTarget { get; internal set; }

public UiConfig()
{
}
Expand All @@ -37,11 +40,12 @@ public UiConfig(string filePath)
SetFilePath(filePath);
}

public UiConfig(WindowState windowState, double height, double width)
public UiConfig(WindowState windowState, double height, double width, int feeTarget)
{
WindowState = Guard.NotNull(nameof(windowState), windowState);
Height = Guard.NotNull(nameof(height), height);
Width = Guard.NotNull(nameof(width), width);
FeeTarget = Guard.NotNull(nameof(feeTarget), feeTarget);
}

/// <inheritdoc />
Expand All @@ -63,6 +67,7 @@ public async Task LoadOrCreateDefaultFileAsync()
WindowState = Avalonia.Controls.WindowState.Maximized;
Height = 530;
Width = 1100;
FeeTarget = 2;

if (!File.Exists(FilePath))
{
Expand All @@ -84,6 +89,7 @@ public async Task LoadFileAsync()
WindowState = config.WindowState ?? WindowState;
Height = config.Height ?? Height;
Width = config.Width ?? Width;
FeeTarget = config.FeeTarget ?? FeeTarget;
}

/// <inheritdoc />
Expand Down Expand Up @@ -114,6 +120,11 @@ public async Task<bool> CheckFileChangeAsync()
return true;
}

if (FeeTarget != config.FeeTarget)
{
return true;
}

return false;
}

Expand Down

0 comments on commit 9ca284d

Please sign in to comment.