Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #16 from chaincase-cash/feature/reactive-ui-databi…
Browse files Browse the repository at this point in the history
…ndings

Feature/reactive ui databindings
  • Loading branch information
DanGould authored Oct 27, 2019
2 parents 455f168 + 287b0eb commit 73d50c3
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 69 deletions.
1 change: 0 additions & 1 deletion Chaincase.GTK/gtk-gui/gui.stetic
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<stetic-interface>
<import>
<widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<widget-library name="../../packages/Xamarin.Forms.Platform.GTK.4.3.0.851321-pre3/lib/net45/webkit-sharp.dll" />
<widget-library name="../bin/Debug/Chaincase.GTK.exe" internal="true" />
</import>
Expand Down
28 changes: 14 additions & 14 deletions Chaincase.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WalletWasabi.Backend", "WalletWasabi\WalletWasabi.Backend\WalletWasabi.Backend.csproj", "{EEF104BB-9D85-4C11-A341-AAF5E436C965}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WalletWasabi.Standard", "WalletWasabi\WalletWasabi.Standard\WalletWasabi.Standard.csproj", "{9D77E7C0-CD14-448B-920B-01674EDE53D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WalletWasabi.Tests", "WalletWasabi\WalletWasabi.Tests\WalletWasabi.Tests.csproj", "{596333FF-2511-40F8-BFB7-1638898C9A8A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chaincase.macOS", "Chaincase.macOS\Chaincase.macOS.csproj", "{8AD32D8C-8E47-47FD-BF46-08198C94174F}"
Expand All @@ -19,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chaincase.Android", "Chainc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chaincase.GTK", "Chaincase.GTK\Chaincase.GTK.csproj", "{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}"
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "WalletWasabi.Standard", "WalletWasabi\WalletWasabi.Standard\WalletWasabi.Standard.csproj", "{F2C2026E-C761-47A7-8218-AF33B3D1475D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -41,18 +41,6 @@ Global
{EEF104BB-9D85-4C11-A341-AAF5E436C965}.Debug|iPhone.Build.0 = Debug|Any CPU
{EEF104BB-9D85-4C11-A341-AAF5E436C965}.Release|iPhone.ActiveCfg = Release|Any CPU
{EEF104BB-9D85-4C11-A341-AAF5E436C965}.Release|iPhone.Build.0 = Release|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|Any CPU.Build.0 = Release|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhone.Build.0 = Debug|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhone.ActiveCfg = Release|Any CPU
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhone.Build.0 = Release|Any CPU
{596333FF-2511-40F8-BFB7-1638898C9A8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{596333FF-2511-40F8-BFB7-1638898C9A8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{596333FF-2511-40F8-BFB7-1638898C9A8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -137,5 +125,17 @@ Global
{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}.Debug|iPhone.Build.0 = Debug|Any CPU
{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}.Release|iPhone.ActiveCfg = Release|Any CPU
{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}.Release|iPhone.Build.0 = Release|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|Any CPU.Build.0 = Release|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhone.Build.0 = Debug|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhone.ActiveCfg = Release|Any CPU
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhone.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion Chaincase/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MainViewModel : ViewModelBase
private String _balance;
public String Balance
{
get => _balance.ToString();
get => _balance;
set => this.RaiseAndSetIfChanged(ref _balance, value);
}

Expand Down
19 changes: 7 additions & 12 deletions Chaincase/ViewModels/ReceiveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ReceiveViewModel : ViewModelBase
{
private ObservableCollection<AddressViewModel> _addresses;
private AddressViewModel _selectedAddress;
private string _label;
private string _memo;
public ObservableCollection<AddressViewModel> Addresses
{
get => _addresses;
Expand All @@ -23,10 +23,10 @@ public AddressViewModel SelectedAddress
get => _selectedAddress;
set => this.RaiseAndSetIfChanged(ref _selectedAddress, value);
}
public string Label
public string Memo
{
get => _label;
set => this.RaiseAndSetIfChanged(ref _label, value);
get => _memo;
set => this.RaiseAndSetIfChanged(ref _memo, value);
}

public ICommand GenerateCommand { get; }
Expand All @@ -39,27 +39,22 @@ public ReceiveViewModel(IScreen hostScreen) : base(hostScreen)

GenerateCommand = new Command(() =>
{
Label = Label.Trim(',', ' ').Trim();
Memo = Memo.Trim(',', ' ').Trim();
// Require label in next iteration

Device.BeginInvokeOnMainThread(() =>
{
var label = Label;
HdPubKey newKey = Global.WalletService.GetReceiveKey(label, Addresses.Select(x => x.Model).Take(7)); // Never touch the first 7 keys.
HdPubKey newKey = Global.WalletService.GetReceiveKey(Memo, Addresses.Select(x => x.Model).Take(7)); // Never touch the first 7 keys.
Memo = null;

AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
if (found != default)
{
Addresses.Remove(found);
}

var newAddress = new AddressViewModel(_hostScreen, newKey);

Addresses.Insert(0, newAddress);

SelectedAddress = newAddress;

Label = "";
});
});
}
Expand Down
29 changes: 18 additions & 11 deletions Chaincase/ViewModels/VerifyMnemonicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ namespace Chaincase.ViewModels
{
public class VerifyMnemonicViewModel : ViewModelBase
{
public string MnemonicString { get; }
public string[] MnemonicWords { get; }
public string[] Recall { get; }
private bool _isVerified;
private string _mnemonicString { get; }
private string[] _mnemonicWords { get; }

private string[] _recall;
public string[] Recall
{
get => _recall;
set => this.RaiseAndSetIfChanged(ref _recall, value);
}

private bool _isVerified;
public bool IsVerified
{
get => _isVerified;
Expand All @@ -31,8 +38,8 @@ public string Passphrase

public VerifyMnemonicViewModel(IScreen hostScreen, string mnemonicString) : base(hostScreen)
{
MnemonicString = mnemonicString;
MnemonicWords = mnemonicString.Split(" ");
_mnemonicString = mnemonicString;
_mnemonicWords = mnemonicString.Split(" ");
Recall = new string[4];
IsVerified = false;

Expand All @@ -50,11 +57,11 @@ private async Task TryCompleteInitializationAsync()
{
System.Diagnostics.Debug.WriteLine(string.Join(" ", Recall));

IsVerified = string.Equals(Recall[0], MnemonicWords[0], StringComparison.CurrentCultureIgnoreCase) &&
string.Equals(Recall[1], MnemonicWords[3], StringComparison.CurrentCultureIgnoreCase) &&
string.Equals(Recall[2], MnemonicWords[6], StringComparison.CurrentCultureIgnoreCase) &&
string.Equals(Recall[3], MnemonicWords[9], StringComparison.CurrentCultureIgnoreCase) &&
WalletController.VerifyWalletCredentials(MnemonicString, _passphrase, Global.Network);
IsVerified = string.Equals(Recall[0], _mnemonicWords[0], StringComparison.CurrentCultureIgnoreCase) &&
string.Equals(Recall[1], _mnemonicWords[3], StringComparison.CurrentCultureIgnoreCase) &&
string.Equals(Recall[2], _mnemonicWords[6], StringComparison.CurrentCultureIgnoreCase) &&
string.Equals(Recall[3], _mnemonicWords[9], StringComparison.CurrentCultureIgnoreCase) &&
WalletController.VerifyWalletCredentials(_mnemonicString, _passphrase, Global.Network);
if (!IsVerified) return;
WalletController.LoadWalletAsync(Global.Network);
NavMainCommand.Execute();
Expand Down
2 changes: 1 addition & 1 deletion Chaincase/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns="http://xamarin.com/schemas/2014/forms">
<StackLayout>
<Label x:Name="Balance" Text="{Binding Balance, StringFormat='₿{0:C}'}"
<Label x:Name="Balance"
HorizontalOptions="Center"
FontAttributes="Bold"
/>
Expand Down
3 changes: 1 addition & 2 deletions Chaincase/Views/MnemonicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<Label Text="Deterministic Seed (Mnemonic)"
HorizontalOptions="Center"
FontAttributes="Bold" />
<Label Text="{Binding MnemonicString}"
/>
<Label x:Name="Mnemonic" />
<Label Text="Write this down. Your keys are generated from this and your passphrase together." />
<Button Text="Accept"
x:Name="Accept" />
Expand Down
6 changes: 5 additions & 1 deletion Chaincase/Views/MnemonicPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public MnemonicPage()
vm => vm.AcceptCommand,
v => v.Accept)
.DisposeWith(disposables);
});
this.OneWayBind(ViewModel,
vm => vm.MnemonicString,
v => v.Mnemonic.Text)
.DisposeWith(disposables);
});
}
}
}
2 changes: 1 addition & 1 deletion Chaincase/Views/PassphrasePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Label Text="Passphrase"
HorizontalOptions="Center"
FontAttributes="Bold" />
<Entry Text="{Binding Passphrase}"
<Entry x:Name="Passphrase"
Placeholder="thIsisAPaSsPhrAseToGenerateKeys"
IsPassword="true"
/>
Expand Down
8 changes: 6 additions & 2 deletions Chaincase/Views/PassphrasePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ public PassphrasePage()
this.BindCommand(ViewModel,
vm => vm.SubmitCommand,
v => v.Submit)
.DisposeWith(disposables);
});
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm.Passphrase,
v => v.Passphrase.Text)
.DisposeWith(disposables);
});
}
}
}
7 changes: 3 additions & 4 deletions Chaincase/Views/ReceivePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
<!-- ADDRESSES -->
<StackLayout>

<Entry Text="{Binding Label}"
Placeholder="something unique"
/>
<Entry Placeholder="the source of income"
x:Name="Memo" />
<Button Text="New Address"
Command="{Binding GenerateCommand}" />
x:Name="Generate" />
</StackLayout>
<ListView
ItemsSource="{Binding Addresses}">
Expand Down
17 changes: 15 additions & 2 deletions Chaincase/Views/ReceivePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
using ReactiveUI.XamForms;
using Chaincase.ViewModels;
using ReactiveUI;
using System.Reactive.Disposables;

namespace Chaincase.Views
{
public partial class ReceivePage : ReactiveContentPage<ReceiveViewModel>
{
public ReceivePage()
{
InitializeComponent();
}
InitializeComponent();
this.WhenActivated(disposables =>
{
this.BindCommand(ViewModel,
vm => vm.GenerateCommand,
v => v.Generate)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm.Memo,
v => v.Memo.Text)
.DisposeWith(disposables);
});
}
}
}
26 changes: 12 additions & 14 deletions Chaincase/Views/VerifyMnemonicPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,30 @@
<ColumnDefinition Width="*" />

</Grid.ColumnDefinitions>
<Entry Text="{Binding Recall[0]}"
/>
<Entry Text=""
x:Name="Recall0" />
<Entry Grid.Column="1"
Text="{Binding Recall[1]}"
/>
Text=""
x:Name="Recall1" />
<Entry Grid.Column="2"
Text="{Binding Recall[2]}"
/>
Text=""
x:Name="Recall2" />
<Entry Grid.Column="3"
Text="{Binding Recall[3]}"
/>

Text=""
x:Name="Recall3" />
</Grid>
<Entry Grid.Column="3"
Text="{Binding Passphrase}"
x:Name="Passphrase"
Placeholder="thIsisAPaSsPhrAseToGenerateKeys"
IsPassword="true"
/>
IsPassword="true" />
<Button Text="Continue"
x:Name="Continue" />
<Label Text="Hello World!">
<Label.Triggers>
<DataTrigger TargetType="Label" Binding="{Binding IsVerified}" Value="false">
<DataTrigger TargetType="Label" x:Name="IsVerifiedTriggerFalse" Value="false">
<Setter Property="Text" Value="Not Verified" />
</DataTrigger>
<DataTrigger TargetType="Label" Binding="{Binding IsVerified}" Value="true">
<DataTrigger TargetType="Label" x:Name="IsVerifiedTriggerTrue" Value="true">
<Setter Property="Text" Value="Verified" />
</DataTrigger>
</Label.Triggers>
Expand Down
34 changes: 31 additions & 3 deletions Chaincase/Views/VerifyMnemonicPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,37 @@ public VerifyMnemonicPage()
{
this.BindCommand(ViewModel,
vm => vm.TryCompleteInitializationCommand,
x => x.Continue)
.DisposeWith(disposables);
});
v => v.Continue)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm .Recall[0],
v => v.Recall0.Text)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm .Recall[1],
v => v.Recall1.Text)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm.Recall[2],
v => v.Recall2.Text)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm.Recall[3],
v => v.Recall3.Text)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm.Passphrase,
v => v.Passphrase.Text)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => vm.IsVerified,
v => v.IsVerifiedTriggerTrue)
.DisposeWith(disposables);
this.Bind(ViewModel,
vm => !vm.IsVerified,
v => v.IsVerifiedTriggerFalse)
.DisposeWith(disposables);
});
}
}
}

0 comments on commit 73d50c3

Please sign in to comment.