Skip to content

Commit

Permalink
Demo Mode dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
S74nk0 committed Feb 14, 2020
1 parent 03391af commit 7fbca80
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/NiceHashMiner/NiceHashMiner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<Compile Include="Views\Common\EnterWalletDialog.xaml.cs">
<DependentUpon>EnterWalletDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Common\EnterWalletDialogDemo.xaml.cs">
<DependentUpon>EnterWalletDialogDemo.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Common\EnterWorkernameDialog.xaml.cs">
<DependentUpon>EnterWorkernameDialog.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -384,6 +387,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Common\EnterWalletDialogDemo.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Common\EnterWorkernameDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
127 changes: 127 additions & 0 deletions src/NiceHashMiner/Views/Common/EnterWalletDialogDemo.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<UserControl x:Class="NiceHashMiner.Views.Common.EnterWalletDialogDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:NiceHashMiner.Views.Common"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="800">
<UserControl.Resources>
<Style x:Key="local.ExitTextBlock" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource FontAwesome}" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontStretch" Value="Normal" />
<Setter Property="FontStyle" Value="Normal" />
<Setter Property="LineHeight" Value="1.5" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Foreground" Value="{StaticResource Gray2ColorBrush}" />
<Setter Property="Text" Value="&#xF00D;" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource PrimaryColorBrush}" />
</Trigger>
</Style.Triggers>
</Style>

<Style x:Key="local.ExitTextButton" TargetType="Button" BasedOn="{StaticResource ButtonTextBlock}">
<Style.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource local.ExitTextBlock}" />
</Style.Resources>
</Style>

<Style x:Key="local.WalletHeader" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource Ubuntu-Regular}" />
<Setter Property="FontSize" Value="18" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontStretch" Value="Normal" />
<Setter Property="FontStyle" Value="Normal" />
<Setter Property="LineHeight" Value="1.24" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Foreground" Value="{StaticResource Gray1ColorBrush}" />
</Style>


<Style x:Key="local.WalletSubHeader" TargetType="TextBlock">
<Setter Property="FontFamily" Value="{StaticResource Ubuntu-Regular}" />
<Setter Property="FontSize" Value="12" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontStretch" Value="Normal" />
<Setter Property="FontStyle" Value="Normal" />
<Setter Property="LineHeight" Value="1.5" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource TextColorBrush}" />
</Style>

</UserControl.Resources>
<Grid MaxHeight="260" MaxWidth="392" Height="Auto" Width="Auto" MinHeight="232" MinWidth="392" Background="{DynamicResource BackgroundColor}">
<Grid.Effect>
<DropShadowEffect BlurRadius="50" ShadowDepth="10" Direction="-75" RenderingBias="Performance" Opacity="0.4"/>
</Grid.Effect>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button Grid.Row="0"
Style="{StaticResource local.ExitTextButton}"
Content="&#xF00D;"
Margin="0,20,20,0"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Click="CloseDialog"/>
<TextBlock Grid.Row="1"
Style="{StaticResource local.WalletHeader}"
VerticalAlignment="Stretch"
HorizontalAlignment="Left"
Margin="24,0,0,0"
Text="Demo Mode"/>
<TextBlock Grid.Row="2"
Style="{StaticResource local.WalletSubHeader}"
TextWrapping="WrapWithOverflow"
TextAlignment="Left"
VerticalAlignment="Stretch"
HorizontalAlignment="Left"
Margin="25,8,6,0">
<Run Text="You are currently mining in Demo Mode. "/>
<Run Text="Add your Wallet Address " FontWeight="Bold"/>
<Run Text="to start earning Bitcoins." />
</TextBlock>
<TextBlock Grid.Row="3"
Style="{StaticResource local.WalletSubHeader}"
VerticalAlignment="Stretch"
HorizontalAlignment="Left"
Margin="25,8,0,0"
Text="Wallet Address"/>
<TextBox Grid.Row="4"
Style="{StaticResource inputBox}"
x:Name="textBoxBTCAddress"
Text="{Binding CredentialsSettings.BitcoinAddress, Mode=OneWay}"
TextChanged="TextBoxBitcoinAddress_TextChanged"
KeyUp="TextBoxBitcoinAddress_KeyUp"
LostFocus="TextBoxBitcoinAddress_LostFocus"
Margin="0,8,0,0" />
<TextBlock Grid.Row="5"
Margin="25,8,0,0">
<Hyperlink x:Name="addressHyperlink" RequestNavigate="AddressHyperlink_RequestNavigate" NavigateUri="https://www.nicehash.com/support/general-help/account/creating-a-new-account" TextDecorations="{x:Null}" Foreground="{StaticResource Brushes.Light.Basic.NoticeColor}">
How to create a Wallet Address?
</Hyperlink>
</TextBlock>
<Button Grid.Row="6"
x:Name="SaveButton"
Style="{DynamicResource OKButton}"
FontSize="10"
Width="136"
Height="24"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Content="SAVE"
IsEnabled="False"
Click="SaveButtonClicked"
Margin="25,24,24,24"/>
</Grid>
</UserControl>
89 changes: 89 additions & 0 deletions src/NiceHashMiner/Views/Common/EnterWalletDialogDemo.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using NHMCore;
using NHMCore.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace NiceHashMiner.Views.Common
{
/// <summary>
/// Interaction logic for EnterWalletDialogDemo.xaml
/// </summary>
public partial class EnterWalletDialogDemo : UserControl
{
public EnterWalletDialogDemo()
{
InitializeComponent();
}
private void BtcTextValidation()
{
var trimmedBtcText = textBoxBTCAddress.Text.Trim();
var btcOK = CredentialValidators.ValidateBitcoinAddress(trimmedBtcText);
SaveButton.IsEnabled = btcOK;
if (btcOK)
{
textBoxBTCAddress.Style = Application.Current.FindResource("InputBoxGood") as Style;
textBoxBTCAddress.BorderBrush = (Brush)Application.Current.FindResource("NastyGreenBrush");
}
else
{
textBoxBTCAddress.Style = Application.Current.FindResource("InputBoxBad") as Style;
textBoxBTCAddress.BorderBrush = (Brush)Application.Current.FindResource("RedDangerColorBrush");
}
}

private void TextBoxBitcoinAddress_TextChanged(object sender, TextChangedEventArgs e)
{
BtcTextValidation();
}

private void TextBoxBitcoinAddress_KeyUp(object sender, KeyEventArgs e)
{
BtcTextValidation();
}

private void TextBoxBitcoinAddress_LostFocus(object sender, RoutedEventArgs e)
{
BtcTextValidation();
}

private void AddressHyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
{
Process.Start(e.Uri.AbsoluteUri);
}

private void CloseDialog(object sender, RoutedEventArgs e)
{
CustomDialogManager.HideCurrentModal();
}

private async void SaveButtonClicked(object sender, RoutedEventArgs e)
{
var trimmedBtcText = textBoxBTCAddress.Text.Trim();
var result = await ApplicationStateManager.SetBTCIfValidOrDifferent(trimmedBtcText);
if (ApplicationStateManager.SetResult.INVALID == result)
{
textBoxBTCAddress.Style = Application.Current.FindResource("InputBoxBad") as Style;
textBoxBTCAddress.BorderBrush = (Brush)Application.Current.FindResource("RedDangerColorBrush");
}
else
{
CustomDialogManager.HideCurrentModal();
textBoxBTCAddress.Style = Application.Current.FindResource("InputBoxGood") as Style;
textBoxBTCAddress.BorderBrush = (Brush)Application.Current.FindResource("NastyGreenBrush");
}
}
}
}
15 changes: 1 addition & 14 deletions src/NiceHashMiner/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,12 @@ private void MiningStateInstance_PropertyChanged(object sender, System.Component
{
if (nameof(MiningState.Instance.IsDemoMining) == e.PropertyName && MiningState.Instance.IsDemoMining)
{
Logger.Debug("DEMO", MiningState.Instance.IsDemoMining.ToString());
Dispatcher.Invoke(() =>
{
var demoMiningDialog = new CustomDialog()
{
Title = Translations.Tr("Demo mining"),
Description = Translations.Tr("You are currently mining in DEMO mode!"),
OkText = Translations.Tr("Ok"),
CancelVisible = Visibility.Collapsed,
AnimationVisible = Visibility.Collapsed,
CloseOnOk = true
};
var demoMiningDialog = new EnterWalletDialogDemo();
CustomDialogManager.ShowModalDialog(demoMiningDialog);
});
}
else if(nameof(MiningState.Instance.IsDemoMining) == e.PropertyName && !MiningState.Instance.IsDemoMining)
{
Logger.Debug("DEMO NOT", MiningState.Instance.IsDemoMining.ToString());
}
}

private void Instance_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
Expand Down

0 comments on commit 7fbca80

Please sign in to comment.