on ebc16eb help sign in
skrepka/client/ViewAddContact.fs
68 lines 2.2 kB history raw
1namespace Skrepka
3open Avalonia.Media
4open Fabulous.Avalonia
6open type Fabulous.Avalonia.View
8module ViewAddContact =
10 open AppTypes
11 open Buttons
12 open Styles
13 open Labels
14 open TextFields
16 let private qrBytes (text: string) =
17 use qr = new QRCoder.QRCodeGenerator()
18 use data = qr.CreateQrCode(text, QRCoder.QRCodeGenerator.ECCLevel.M)
19 use png = new QRCoder.PngByteQRCode(data)
20 png.GetGraphic(8, [| 0uy; 0uy; 0uy |], [| 255uy; 255uy; 255uy |])
22 let viewAddContact model (cpk: string) =
23 let content =
24 ScrollViewer(
25 (VStack(16.) {
27 h2 ("Share your address")
29 match model.Auth with
30 | Identified(id, _) ->
31 let ob = hexToOb id.PubKeyHex
33 Image(Styles.cachedBitmap (qrBytes ob), Stretch.Uniform).maxWidth(200.).centerHorizontal ()
35 body(ob).fontSize(12.).centerText ()
37 smallButton Primary "Copy Address" CopyPubKey
38 | NoIdentity -> ()
40 h2 "Enter someone else's address"
42 let cpkTrimmed: string = cpk.Trim()
44 let isValid =
45 Phonemic.fromOb cpkTrimmed
46 |> Option.orElseWith (fun () -> Crypto.tryFromHex cpkTrimmed)
47 |> Option.filter (fun bytes -> bytes.Length = 32)
48 |> Option.isSome
50 let hasError = cpkTrimmed <> "" && not isValid
52 if hasError then
53 errorTextField cpk (fun key -> SetPage(AddContact(key)))
54 else
55 textField cpk (fun key -> SetPage(AddContact(key)))
58 if isValid then
59 smallButton Primary "Add" DoSaveContact
60 else
61 disabledSmallButton Primary "Add" DoSaveContact
62 })
63 .margin (20.)
64 )
66 let bar = HStack(8.) { backButton (SetPage Conversations) }
68 withBottomBar bar content