Skip to content

Commit 03f4fe3

Browse files
committed
WIP
1 parent 26c1234 commit 03f4fe3

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

ghcjs/lightning-verifier/src/App/Widgets/Bolt11.hs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ bolt11 st =
2222
<> either (const mempty) invoiceWidget ln
2323
<> either
2424
(const mempty)
25-
(\x -> if x == mempty then mempty else preimageWidget x)
25+
(\bsR -> if bsR == mempty then mempty else preimageWidget rawR bsR)
2626
r
2727
where
2828
rawLn = st ^. #modelState . #stDoc . #stDocLnInvoice . #fieldOutput
2929
rawR = st ^. #modelState . #stDoc . #stDocLnPreimage . #fieldOutput
30-
ln = first inspect $ B11.decodeBolt11 rawLn
30+
ln = first (mappend "Bad invoice - " . inspect) $ B11.decodeBolt11 rawLn
3131
rh = ln >>= parsePreimageHash
3232
r = parsePreimage rawR
3333

@@ -42,8 +42,8 @@ verifierWidget src rh r =
4242
then mempty
4343
else
4444
if rh == sha256Hash r
45-
then success "Invoice and preimage match!"
46-
else failure "Invoice and preimage mismatch!"
45+
then success "The preimage matches the invoice"
46+
else failure "The preimage does not match the invoice"
4747

4848
invoiceWidget :: B11.Bolt11 -> [View Action]
4949
invoiceWidget ln =
@@ -65,31 +65,33 @@ invoiceWidget ln =
6565
. from @Prelude.String @MisoString
6666
. Prelude.show
6767

68-
preimageWidget :: ByteString -> [View Action]
69-
preimageWidget r =
68+
preimageWidget :: MisoString -> ByteString -> [View Action]
69+
preimageWidget rawR r =
7070
Header.headerViewer "Preimage Details"
7171
<> pairs
72-
[ simple "Preimage" r,
73-
simple "Preimage Hash" $ sha256Hash r
72+
[ simple "Preimage" rawR,
73+
simple "Preimage Hash" . inspect @ByteString $ sha256Hash r
7474
]
7575
where
76-
simple :: MisoString -> ByteString -> FieldPair DynamicField Identity
76+
simple :: MisoString -> MisoString -> FieldPair DynamicField Identity
7777
simple x =
7878
newFieldPairId x
7979
. DynamicFieldText
80-
. inspect
8180

8281
parsePreimage :: MisoString -> Either MisoString ByteString
8382
parsePreimage rawR =
8483
case B16.decode . T.encodeUtf8 $ from @MisoString @Prelude.Text rawR of
8584
(r, "") -> Right r
86-
res -> Left $ "Bad preimage " <> inspect res
85+
(_, e) ->
86+
Left
87+
$ "Bad preimage - non hex leftover "
88+
<> from @Prelude.String @MisoString (Prelude.show e)
8789

8890
parsePreimageHash :: B11.Bolt11 -> Either MisoString ByteString
8991
parsePreimageHash ln =
9092
case find B11.isPaymentHash $ B11.bolt11Tags ln of
9193
Just (B11.PaymentHash (B11.Hex rh)) -> Right rh
92-
_ -> Left "Bad invoice without preimage hash!"
94+
_ -> Left "Bad invoice - no preimage hash"
9395

9496
pairs :: [FieldPair DynamicField f] -> [View Action]
9597
pairs xs =

ghcjs/lightning-verifier/static/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ textarea {
3636
.app-success > div > span {
3737
color: white;
3838
background-color: #018786 !important;
39+
display: flex;
40+
justify-content: center;
3941
}
4042

4143
.app-failure > div > span {
4244
color: white;
4345
background-color: #b00020 !important;
46+
display: flex;
47+
justify-content: center;
4448
}
4549

4650
@media print {

0 commit comments

Comments
 (0)