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

Commit 73d50c3

Browse files
authored
Merge pull request #16 from chaincase-cash/feature/reactive-ui-databindings
Feature/reactive ui databindings
2 parents 455f168 + 287b0eb commit 73d50c3

14 files changed

+115
-69
lines changed

Chaincase.GTK/gtk-gui/gui.stetic

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<stetic-interface>
33
<import>
4-
<widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
54
<widget-library name="../../packages/Xamarin.Forms.Platform.GTK.4.3.0.851321-pre3/lib/net45/webkit-sharp.dll" />
65
<widget-library name="../bin/Debug/Chaincase.GTK.exe" internal="true" />
76
</import>

Chaincase.sln

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
44
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WalletWasabi.Backend", "WalletWasabi\WalletWasabi.Backend\WalletWasabi.Backend.csproj", "{EEF104BB-9D85-4C11-A341-AAF5E436C965}"
55
EndProject
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WalletWasabi.Standard", "WalletWasabi\WalletWasabi.Standard\WalletWasabi.Standard.csproj", "{9D77E7C0-CD14-448B-920B-01674EDE53D1}"
7-
EndProject
86
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WalletWasabi.Tests", "WalletWasabi\WalletWasabi.Tests\WalletWasabi.Tests.csproj", "{596333FF-2511-40F8-BFB7-1638898C9A8A}"
97
EndProject
108
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chaincase.macOS", "Chaincase.macOS\Chaincase.macOS.csproj", "{8AD32D8C-8E47-47FD-BF46-08198C94174F}"
@@ -19,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chaincase.Android", "Chainc
1917
EndProject
2018
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chaincase.GTK", "Chaincase.GTK\Chaincase.GTK.csproj", "{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}"
2119
EndProject
20+
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "WalletWasabi.Standard", "WalletWasabi\WalletWasabi.Standard\WalletWasabi.Standard.csproj", "{F2C2026E-C761-47A7-8218-AF33B3D1475D}"
21+
EndProject
2222
Global
2323
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2424
Debug|Any CPU = Debug|Any CPU
@@ -41,18 +41,6 @@ Global
4141
{EEF104BB-9D85-4C11-A341-AAF5E436C965}.Debug|iPhone.Build.0 = Debug|Any CPU
4242
{EEF104BB-9D85-4C11-A341-AAF5E436C965}.Release|iPhone.ActiveCfg = Release|Any CPU
4343
{EEF104BB-9D85-4C11-A341-AAF5E436C965}.Release|iPhone.Build.0 = Release|Any CPU
44-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|Any CPU.Build.0 = Release|Any CPU
48-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
49-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
50-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
51-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
52-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhone.ActiveCfg = Debug|Any CPU
53-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Debug|iPhone.Build.0 = Debug|Any CPU
54-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhone.ActiveCfg = Release|Any CPU
55-
{9D77E7C0-CD14-448B-920B-01674EDE53D1}.Release|iPhone.Build.0 = Release|Any CPU
5644
{596333FF-2511-40F8-BFB7-1638898C9A8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5745
{596333FF-2511-40F8-BFB7-1638898C9A8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
5846
{596333FF-2511-40F8-BFB7-1638898C9A8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -137,5 +125,17 @@ Global
137125
{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}.Debug|iPhone.Build.0 = Debug|Any CPU
138126
{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}.Release|iPhone.ActiveCfg = Release|Any CPU
139127
{578B43C6-AC2C-40B1-8B1A-6359FA87E4C2}.Release|iPhone.Build.0 = Release|Any CPU
128+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
129+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|Any CPU.Build.0 = Debug|Any CPU
130+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|Any CPU.ActiveCfg = Release|Any CPU
131+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
133+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
134+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
135+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
136+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhone.ActiveCfg = Debug|Any CPU
137+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Debug|iPhone.Build.0 = Debug|Any CPU
138+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhone.ActiveCfg = Release|Any CPU
139+
{F2C2026E-C761-47A7-8218-AF33B3D1475D}.Release|iPhone.Build.0 = Release|Any CPU
140140
EndGlobalSection
141141
EndGlobal

Chaincase/ViewModels/MainViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class MainViewModel : ViewModelBase
2020
private String _balance;
2121
public String Balance
2222
{
23-
get => _balance.ToString();
23+
get => _balance;
2424
set => this.RaiseAndSetIfChanged(ref _balance, value);
2525
}
2626

Chaincase/ViewModels/ReceiveViewModel.cs

+7-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ReceiveViewModel : ViewModelBase
1212
{
1313
private ObservableCollection<AddressViewModel> _addresses;
1414
private AddressViewModel _selectedAddress;
15-
private string _label;
15+
private string _memo;
1616
public ObservableCollection<AddressViewModel> Addresses
1717
{
1818
get => _addresses;
@@ -23,10 +23,10 @@ public AddressViewModel SelectedAddress
2323
get => _selectedAddress;
2424
set => this.RaiseAndSetIfChanged(ref _selectedAddress, value);
2525
}
26-
public string Label
26+
public string Memo
2727
{
28-
get => _label;
29-
set => this.RaiseAndSetIfChanged(ref _label, value);
28+
get => _memo;
29+
set => this.RaiseAndSetIfChanged(ref _memo, value);
3030
}
3131

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

4040
GenerateCommand = new Command(() =>
4141
{
42-
Label = Label.Trim(',', ' ').Trim();
42+
Memo = Memo.Trim(',', ' ').Trim();
4343
// Require label in next iteration
4444

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

5050
AddressViewModel found = Addresses.FirstOrDefault(x => x.Model == newKey);
5151
if (found != default)
5252
{
5353
Addresses.Remove(found);
5454
}
55-
5655
var newAddress = new AddressViewModel(_hostScreen, newKey);
57-
5856
Addresses.Insert(0, newAddress);
59-
6057
SelectedAddress = newAddress;
61-
62-
Label = "";
6358
});
6459
});
6560
}

Chaincase/ViewModels/VerifyMnemonicViewModel.cs

+18-11
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ namespace Chaincase.ViewModels
1212
{
1313
public class VerifyMnemonicViewModel : ViewModelBase
1414
{
15-
public string MnemonicString { get; }
16-
public string[] MnemonicWords { get; }
17-
public string[] Recall { get; }
18-
private bool _isVerified;
15+
private string _mnemonicString { get; }
16+
private string[] _mnemonicWords { get; }
17+
18+
private string[] _recall;
19+
public string[] Recall
20+
{
21+
get => _recall;
22+
set => this.RaiseAndSetIfChanged(ref _recall, value);
23+
}
24+
25+
private bool _isVerified;
1926
public bool IsVerified
2027
{
2128
get => _isVerified;
@@ -31,8 +38,8 @@ public string Passphrase
3138

3239
public VerifyMnemonicViewModel(IScreen hostScreen, string mnemonicString) : base(hostScreen)
3340
{
34-
MnemonicString = mnemonicString;
35-
MnemonicWords = mnemonicString.Split(" ");
41+
_mnemonicString = mnemonicString;
42+
_mnemonicWords = mnemonicString.Split(" ");
3643
Recall = new string[4];
3744
IsVerified = false;
3845

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

53-
IsVerified = string.Equals(Recall[0], MnemonicWords[0], StringComparison.CurrentCultureIgnoreCase) &&
54-
string.Equals(Recall[1], MnemonicWords[3], StringComparison.CurrentCultureIgnoreCase) &&
55-
string.Equals(Recall[2], MnemonicWords[6], StringComparison.CurrentCultureIgnoreCase) &&
56-
string.Equals(Recall[3], MnemonicWords[9], StringComparison.CurrentCultureIgnoreCase) &&
57-
WalletController.VerifyWalletCredentials(MnemonicString, _passphrase, Global.Network);
60+
IsVerified = string.Equals(Recall[0], _mnemonicWords[0], StringComparison.CurrentCultureIgnoreCase) &&
61+
string.Equals(Recall[1], _mnemonicWords[3], StringComparison.CurrentCultureIgnoreCase) &&
62+
string.Equals(Recall[2], _mnemonicWords[6], StringComparison.CurrentCultureIgnoreCase) &&
63+
string.Equals(Recall[3], _mnemonicWords[9], StringComparison.CurrentCultureIgnoreCase) &&
64+
WalletController.VerifyWalletCredentials(_mnemonicString, _passphrase, Global.Network);
5865
if (!IsVerified) return;
5966
WalletController.LoadWalletAsync(Global.Network);
6067
NavMainCommand.Execute();

Chaincase/Views/MainPage.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
88
xmlns="http://xamarin.com/schemas/2014/forms">
99
<StackLayout>
10-
<Label x:Name="Balance" Text="{Binding Balance, StringFormat='₿{0:C}'}"
10+
<Label x:Name="Balance"
1111
HorizontalOptions="Center"
1212
FontAttributes="Bold"
1313
/>

Chaincase/Views/MnemonicPage.xaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
<Label Text="Deterministic Seed (Mnemonic)"
1111
HorizontalOptions="Center"
1212
FontAttributes="Bold" />
13-
<Label Text="{Binding MnemonicString}"
14-
/>
13+
<Label x:Name="Mnemonic" />
1514
<Label Text="Write this down. Your keys are generated from this and your passphrase together." />
1615
<Button Text="Accept"
1716
x:Name="Accept" />

Chaincase/Views/MnemonicPage.xaml.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public MnemonicPage()
1717
vm => vm.AcceptCommand,
1818
v => v.Accept)
1919
.DisposeWith(disposables);
20-
});
20+
this.OneWayBind(ViewModel,
21+
vm => vm.MnemonicString,
22+
v => v.Mnemonic.Text)
23+
.DisposeWith(disposables);
24+
});
2125
}
2226
}
2327
}

Chaincase/Views/PassphrasePage.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Label Text="Passphrase"
1111
HorizontalOptions="Center"
1212
FontAttributes="Bold" />
13-
<Entry Text="{Binding Passphrase}"
13+
<Entry x:Name="Passphrase"
1414
Placeholder="thIsisAPaSsPhrAseToGenerateKeys"
1515
IsPassword="true"
1616
/>

Chaincase/Views/PassphrasePage.xaml.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ public PassphrasePage()
1616
this.BindCommand(ViewModel,
1717
vm => vm.SubmitCommand,
1818
v => v.Submit)
19-
.DisposeWith(disposables);
20-
});
19+
.DisposeWith(disposables);
20+
this.Bind(ViewModel,
21+
vm => vm.Passphrase,
22+
v => v.Passphrase.Text)
23+
.DisposeWith(disposables);
24+
});
2125
}
2226
}
2327
}

Chaincase/Views/ReceivePage.xaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
<!-- ADDRESSES -->
1313
<StackLayout>
1414

15-
<Entry Text="{Binding Label}"
16-
Placeholder="something unique"
17-
/>
15+
<Entry Placeholder="the source of income"
16+
x:Name="Memo" />
1817
<Button Text="New Address"
19-
Command="{Binding GenerateCommand}" />
18+
x:Name="Generate" />
2019
</StackLayout>
2120
<ListView
2221
ItemsSource="{Binding Addresses}">

Chaincase/Views/ReceivePage.xaml.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
using ReactiveUI.XamForms;
22
using Chaincase.ViewModels;
3+
using ReactiveUI;
4+
using System.Reactive.Disposables;
35

46
namespace Chaincase.Views
57
{
68
public partial class ReceivePage : ReactiveContentPage<ReceiveViewModel>
79
{
810
public ReceivePage()
911
{
10-
InitializeComponent();
11-
}
12+
InitializeComponent();
13+
this.WhenActivated(disposables =>
14+
{
15+
this.BindCommand(ViewModel,
16+
vm => vm.GenerateCommand,
17+
v => v.Generate)
18+
.DisposeWith(disposables);
19+
this.Bind(ViewModel,
20+
vm => vm.Memo,
21+
v => v.Memo.Text)
22+
.DisposeWith(disposables);
23+
});
24+
}
1225
}
1326
}

Chaincase/Views/VerifyMnemonicPage.xaml

+12-14
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,30 @@
1919
<ColumnDefinition Width="*" />
2020

2121
</Grid.ColumnDefinitions>
22-
<Entry Text="{Binding Recall[0]}"
23-
/>
22+
<Entry Text=""
23+
x:Name="Recall0" />
2424
<Entry Grid.Column="1"
25-
Text="{Binding Recall[1]}"
26-
/>
25+
Text=""
26+
x:Name="Recall1" />
2727
<Entry Grid.Column="2"
28-
Text="{Binding Recall[2]}"
29-
/>
28+
Text=""
29+
x:Name="Recall2" />
3030
<Entry Grid.Column="3"
31-
Text="{Binding Recall[3]}"
32-
/>
33-
31+
Text=""
32+
x:Name="Recall3" />
3433
</Grid>
3534
<Entry Grid.Column="3"
36-
Text="{Binding Passphrase}"
35+
x:Name="Passphrase"
3736
Placeholder="thIsisAPaSsPhrAseToGenerateKeys"
38-
IsPassword="true"
39-
/>
37+
IsPassword="true" />
4038
<Button Text="Continue"
4139
x:Name="Continue" />
4240
<Label Text="Hello World!">
4341
<Label.Triggers>
44-
<DataTrigger TargetType="Label" Binding="{Binding IsVerified}" Value="false">
42+
<DataTrigger TargetType="Label" x:Name="IsVerifiedTriggerFalse" Value="false">
4543
<Setter Property="Text" Value="Not Verified" />
4644
</DataTrigger>
47-
<DataTrigger TargetType="Label" Binding="{Binding IsVerified}" Value="true">
45+
<DataTrigger TargetType="Label" x:Name="IsVerifiedTriggerTrue" Value="true">
4846
<Setter Property="Text" Value="Verified" />
4947
</DataTrigger>
5048
</Label.Triggers>

Chaincase/Views/VerifyMnemonicPage.xaml.cs

+31-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,37 @@ public VerifyMnemonicPage()
1414
{
1515
this.BindCommand(ViewModel,
1616
vm => vm.TryCompleteInitializationCommand,
17-
x => x.Continue)
18-
.DisposeWith(disposables);
19-
});
17+
v => v.Continue)
18+
.DisposeWith(disposables);
19+
this.Bind(ViewModel,
20+
vm => vm .Recall[0],
21+
v => v.Recall0.Text)
22+
.DisposeWith(disposables);
23+
this.Bind(ViewModel,
24+
vm => vm .Recall[1],
25+
v => v.Recall1.Text)
26+
.DisposeWith(disposables);
27+
this.Bind(ViewModel,
28+
vm => vm.Recall[2],
29+
v => v.Recall2.Text)
30+
.DisposeWith(disposables);
31+
this.Bind(ViewModel,
32+
vm => vm.Recall[3],
33+
v => v.Recall3.Text)
34+
.DisposeWith(disposables);
35+
this.Bind(ViewModel,
36+
vm => vm.Passphrase,
37+
v => v.Passphrase.Text)
38+
.DisposeWith(disposables);
39+
this.Bind(ViewModel,
40+
vm => vm.IsVerified,
41+
v => v.IsVerifiedTriggerTrue)
42+
.DisposeWith(disposables);
43+
this.Bind(ViewModel,
44+
vm => !vm.IsVerified,
45+
v => v.IsVerifiedTriggerFalse)
46+
.DisposeWith(disposables);
47+
});
2048
}
2149
}
2250
}

0 commit comments

Comments
 (0)