on master help sign in
Show QR code with user's public key mnemonic on Add Contact page
0ff7467iko
client/Skrepka.fsproj+1
@@ -125,6 +125,7 @@
125 <PackageReference Include="Sodium.Core" Version="1.4.0" />
125 <PackageReference Include="Sodium.Core" Version="1.4.0" />
126 <PackageReference Include="Dapper.FSharp" Version="4.10.0" />
126 <PackageReference Include="Dapper.FSharp" Version="4.10.0" />
127 <PackageReference Include="Microsoft.Data.Sqlite" Version="11.0.0-preview.2.26159.112" />
127 <PackageReference Include="Microsoft.Data.Sqlite" Version="11.0.0-preview.2.26159.112" />
128+ <PackageReference Include="QRCoder" Version="1.6.0" />
128 </ItemGroup>
129 </ItemGroup>
129
130
130</Project>
131</Project>
client/ViewAddContact.fs+38−13
@@ -1,5 +1,6 @@
1namespace Skrepka
1namespace Skrepka
2
2
3+open Avalonia.Media
3open Fabulous.Avalonia
4open Fabulous.Avalonia
4
5
5open type Fabulous.Avalonia.View
6open type Fabulous.Avalonia.View
@@ -8,22 +9,46 @@ module ViewAddContact =
8
9
9 open AppTypes
10 open AppTypes
10
11
12+ let private qrBytes (text: string) =
13+ use qr = new QRCoder.QRCodeGenerator()
14+ use data = qr.CreateQrCode(text, QRCoder.QRCodeGenerator.ECCLevel.M)
15+ use png = new QRCoder.PngByteQRCode(data)
16+ png.GetGraphic(8, [| 0uy; 0uy; 0uy |], [| 255uy; 255uy; 255uy |])
17+
11 let viewAddContact model cpk cnn =
18 let viewAddContact model cpk cnn =
19+ ScrollViewer(
12− (VStack(16.) {
20+ (VStack(16.) {
13− HStack(8.) {
21+ HStack(8.) {
14− Button("< Back", SetPage Conversations)
22+ Button("< Back", SetPage Conversations)
23+
24+ TextBlock("Add Contact").fontSize (20.)
25+ }
26+
27+ match model.Auth with
28+ | Identified(id, _) ->
29+ let ob = hexToOb id.PubKeyHex
30+
31+ TextBlock("Your key (share with contact):").foreground (SolidColorBrush(Colors.DimGray))
32+
33+ Image(Styles.cachedBitmap (qrBytes ob), Stretch.Uniform)
34+ .maxWidth(200.)
35+ .centerHorizontal ()
15
36
37+ TextBlock(truncKey id.PubKeyHex)
16− TextBlock("Add Contact").fontSize (20.)
38+ .fontSize(12.)
17− }
39+ .foreground(SolidColorBrush(Colors.DimGray))
40+ .centerText ()
41+ | NoIdentity -> ()
18
42
19− viewErrorBanner model.Error
43+ viewErrorBanner model.Error
20
44
21− TextBlock("Public Key:")
45+ TextBlock("Public Key:")
22− TextBox(cpk, fun text -> SetPage(AddContact(text, cnn))).watermark ("sampel-palnet-...")
46+ TextBox(cpk, fun text -> SetPage(AddContact(text, cnn))).watermark ("sampel-palnet-...")
23
47
24− TextBlock("Nickname:")
48+ TextBlock("Nickname:")
25− TextBox(cnn, fun text -> SetPage(AddContact(cpk, text)))
49+ TextBox(cnn, fun text -> SetPage(AddContact(cpk, text)))
26
50
27− Button("Save Contact", DoSaveContact).centerHorizontal ()
51+ Button("Save Contact", DoSaveContact).centerHorizontal ()
28− })
52+ })
29− .margin (20.)
53+ .margin (20.)
54+ )