on 0297421 help sign in
skrepka/client/ViewAddContact.fs
70 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 smallButton Secondary "Scan QR Code" DoScanQR
44 let cpkTrimmed: string = cpk.Trim()
46 let isValid =
47 Phonemic.fromOb cpkTrimmed
48 |> Option.orElseWith (fun () -> Crypto.tryFromHex cpkTrimmed)
49 |> Option.filter (fun bytes -> bytes.Length = 32)
50 |> Option.isSome
52 let hasError = cpkTrimmed <> "" && not isValid
54 if hasError then
55 errorTextField cpk (fun key -> SetPage(AddContact(key)))
56 else
57 textField "" cpk (fun key -> SetPage(AddContact(key)))
60 if isValid then
61 smallButton Primary "Add" DoSaveContact
62 else
63 disabledSmallButton Primary "Add" DoSaveContact
64 })
65 .margin (20.)
66 )
68 let bar = HStack(8.) { backButton (SetPage Conversations) }
70 withBottomBar model.SafeAreaBottom bar content