@@ -25,10 +25,18 @@ bolt11 st =
25
25
(\ bsR -> if bsR == mempty then mempty else preimageWidget rawR bsR)
26
26
r
27
27
where
28
+ rawLn :: MisoString
28
29
rawLn = st ^. # modelState . # stDoc . # stDocLnInvoice . # fieldOutput
30
+ rawR :: MisoString
29
31
rawR = st ^. # modelState . # stDoc . # stDocLnPreimage . # fieldOutput
30
- ln = first (mappend " Bad invoice - " . inspect) $ B11. decodeBolt11 rawLn
32
+ ln :: Either MisoString B11. Bolt11
33
+ ln =
34
+ first (mappend " Bad invoice - " . from @ Prelude. String @ MisoString )
35
+ . B11. decodeBolt11
36
+ $ from @ MisoString @ Prelude. Text rawLn
37
+ rh :: Either MisoString ByteString
31
38
rh = ln >>= parsePreimageHash
39
+ r :: Either MisoString ByteString
32
40
r = parsePreimage rawR
33
41
34
42
parserWidget :: MisoString -> Either MisoString a -> [View Action ]
@@ -49,34 +57,54 @@ invoiceWidget :: B11.Bolt11 -> [View Action]
49
57
invoiceWidget ln =
50
58
Header. headerViewer " Invoice Details"
51
59
<> pairs
52
- ( [ simple " Network" . B11. bolt11Currency $ B11. bolt11HRP ln,
53
- simple " Amount" . B11. bolt11Amount $ B11. bolt11HRP ln,
54
- simple " Timestamp" $ B11. bolt11Timestamp ln
60
+ ( [ pair " Network"
61
+ $ case B11. bolt11Currency $ B11. bolt11HRP ln of
62
+ B11. Bitcoin -> " Bitcoin Mainnet"
63
+ B11. BitcoinTestnet -> " Bitcoin Testnet"
64
+ B11. BitcoinRegtest -> " Bitcoin Regtest" ,
65
+ pair " Amount"
66
+ . maybe " 0" defShow
67
+ . B11. bolt11Amount
68
+ $ B11. bolt11HRP ln,
69
+ pair " Timestamp"
70
+ . inspect
71
+ $ B11. bolt11Timestamp ln
55
72
]
56
- <> fmap (simple " Tag" ) (B11. bolt11Tags ln)
57
- <> [ simple " Signature" $ B11. bolt11Signature ln
73
+ <> ( B11. bolt11Tags ln
74
+ >>= invoiceTagWidget
75
+ )
76
+ <> [ pair " Signature"
77
+ . defShow
78
+ $ B11. bolt11Signature ln
58
79
]
59
80
)
81
+
82
+ invoiceTagWidget :: B11. Tag -> [FieldPair DynamicField Identity ]
83
+ invoiceTagWidget = \ case
84
+ B11. PaymentHash x -> simple " Preimage Hash" x
85
+ B11. PaymentSecret x -> simple " Payment Secret" x
86
+ B11. Description x -> pure . pair " Description" $ inspect x
87
+ B11. PayeePubkey x -> simple " Payee Pubkey" x
88
+ B11. DescriptionHash x -> simple " Description Hash" x
89
+ B11. Expiry x -> simple " Expiry" x
90
+ B11. MinFinalCltvExpiry x -> simple " Min Final CLTV Expiry" x
91
+ B11. OnchainFallback x -> simple " Onchain Fallback" x
92
+ B11. ExtraRouteInfo -> mempty
93
+ B11. FeatureBits x -> simple " Feature Bits" x
60
94
where
61
- simple :: (Show a ) => MisoString -> a -> FieldPair DynamicField Identity
95
+ simple :: (Show a ) => MisoString -> a -> [ FieldPair DynamicField Identity ]
62
96
simple x =
63
- newFieldPairId x
64
- . DynamicFieldText
65
- . from @ Prelude. String @ MisoString
66
- . Prelude. show
97
+ pure
98
+ . pair x
99
+ . defShow
67
100
68
101
preimageWidget :: MisoString -> ByteString -> [View Action ]
69
102
preimageWidget rawR r =
70
103
Header. headerViewer " Preimage Details"
71
104
<> pairs
72
- [ simple " Preimage" rawR,
73
- simple " Preimage Hash" . inspect @ ByteString $ sha256Hash r
105
+ [ pair " Preimage" rawR,
106
+ pair " Preimage Hash" . inspect @ ByteString $ sha256Hash r
74
107
]
75
- where
76
- simple :: MisoString -> MisoString -> FieldPair DynamicField Identity
77
- simple x =
78
- newFieldPairId x
79
- . DynamicFieldText
80
108
81
109
parsePreimage :: MisoString -> Either MisoString ByteString
82
110
parsePreimage rawR =
@@ -93,6 +121,11 @@ parsePreimageHash ln =
93
121
Just (B11. PaymentHash (B11. Hex rh)) -> Right rh
94
122
_ -> Left " Bad invoice - no preimage hash"
95
123
124
+ pair :: MisoString -> MisoString -> FieldPair DynamicField Identity
125
+ pair x =
126
+ newFieldPairId x
127
+ . DynamicFieldText
128
+
96
129
pairs :: [FieldPair DynamicField f ] -> [View Action ]
97
130
pairs xs =
98
131
FieldPairs. fieldPairsViewer
@@ -105,6 +138,11 @@ pairs xs =
105
138
pure next
106
139
}
107
140
141
+ defShow :: (Show a ) => a -> MisoString
142
+ defShow =
143
+ from @ Prelude. String @ MisoString
144
+ . Prelude. show
145
+
108
146
success :: MisoString -> [View Action ]
109
147
success msg =
110
148
css " app-success"
0 commit comments