Skip to content

Commit 097422e

Browse files
committed
WIP
1 parent 84da72a commit 097422e

File tree

10 files changed

+71
-542
lines changed

10 files changed

+71
-542
lines changed

ghcjs/lightning-verifier/lightning-verifier.cabal

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ common pkg
3131
App.Widgets.Fav
3232
App.Widgets.Main
3333
App.Widgets.Menu
34-
App.Widgets.SwapAmounts
35-
App.Widgets.SwapCurrencies
3634
App.Widgets.Templates
3735

3836
ghc-options:

ghcjs/lightning-verifier/src/App/Misc.hs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
module App.Misc
2-
( getConverterAmountOptic,
3-
getConverterCurrencyOptic,
4-
pushActionQueue,
2+
( pushActionQueue,
53
)
64
where
75

86
import App.Types
97
import Functora.Miso.Prelude
108

11-
getConverterAmountOptic ::
12-
( Functor f
13-
) =>
14-
TopOrBottom ->
15-
LensLike' f Model (Field Rational Unique)
16-
getConverterAmountOptic = \case
17-
Top -> #modelState . #stDoc . #stDocTopMoney . #moneyAmount
18-
Bottom -> #modelState . #stDoc . #stDocBottomMoney . #moneyAmount
19-
20-
getConverterCurrencyOptic ::
21-
( Functor f
22-
) =>
23-
TopOrBottom ->
24-
LensLike' f Model (Currency Unique)
25-
getConverterCurrencyOptic = \case
26-
Top -> #modelState . #stDoc . #stDocTopMoney . #moneyCurrency
27-
Bottom -> #modelState . #stDoc . #stDocBottomMoney . #moneyCurrency
28-
299
pushActionQueue ::
3010
( MonadIO m
3111
) =>

ghcjs/lightning-verifier/src/App/Types.hs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,8 @@ instance TraversableB St
9393
deriving via GenericType (St Identity) instance Binary (St Identity)
9494

9595
data StDoc f = StDoc
96-
{ stDocTopMoney :: Money f,
97-
stDocBottomMoney :: Money f,
98-
stDocTopOrBottom :: TopOrBottom,
99-
stDocFieldPairs :: [FieldPair DynamicField f],
100-
stDocOnlineOrOffline :: OnlineOrOffline,
96+
{ stDocFieldPairs :: [FieldPair DynamicField f],
97+
stDocLnInvoice :: Field MisoString f,
10198
stDocCreatedAt :: UTCTime
10299
}
103100
deriving stock (Generic)
@@ -119,15 +116,11 @@ deriving via GenericType (StDoc Identity) instance Binary (StDoc Identity)
119116
newStDoc :: (MonadIO m) => m (StDoc Unique)
120117
newStDoc = do
121118
ct <- getCurrentTime
122-
topMoney <- newMoney 1 btc
123-
bottomMoney <- newMoney 0 usd
119+
ln <- newTextField mempty
124120
pure
125121
StDoc
126-
{ stDocTopMoney = topMoney,
127-
stDocBottomMoney = bottomMoney,
128-
stDocTopOrBottom = Top,
129-
stDocFieldPairs = mempty,
130-
stDocOnlineOrOffline = Online,
122+
{ stDocFieldPairs = mempty,
123+
stDocLnInvoice = ln,
131124
stDocCreatedAt = ct
132125
}
133126

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

Lines changed: 13 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
module App.Widgets.Main (mainWidget) where
22

3-
import qualified App.Misc as Misc
43
import App.Types
54
import qualified App.Widgets.Decrypt as Decrypt
65
import qualified App.Widgets.Menu as Menu
7-
import qualified App.Widgets.SwapAmounts as SwapAmounts
8-
import qualified App.Widgets.SwapCurrencies as SwapCurrencies
96
import qualified Functora.Miso.Css as Css
10-
import qualified Functora.Miso.Jsm as Jsm
117
import Functora.Miso.Prelude
128
import qualified Functora.Miso.Widgets.BrowserLink as BrowserLink
13-
import qualified Functora.Miso.Widgets.Currency as Currency
149
import qualified Functora.Miso.Widgets.Field as Field
1510
import qualified Functora.Miso.Widgets.FieldPairs as FieldPairs
1611
import qualified Functora.Miso.Widgets.Header as Header
1712
import qualified Functora.Miso.Widgets.Qr as Qr
18-
import Functora.Money hiding (Text)
1913
import qualified Material.Button as Button
2014
import qualified Material.LayoutGrid as LayoutGrid
2115
import qualified Material.Theme as Theme
@@ -120,140 +114,25 @@ screenWidget st@Model {modelState = St {stScreen = QrCode sc}} =
120114
]
121115
)
122116
screenWidget st@Model {modelState = St {stScreen = Converter}} =
123-
let amountWidget' loc =
124-
Field.ratioField
117+
FieldPairs.fieldPairsViewer
118+
FieldPairs.Args
119+
{ FieldPairs.argsModel = st,
120+
FieldPairs.argsOptic = #modelState . #stDoc . #stDocFieldPairs,
121+
FieldPairs.argsAction = PushUpdate . Instant
122+
}
123+
<> [ Field.textField
125124
Field.Args
126125
{ Field.argsModel = st,
127-
Field.argsOptic = Misc.getConverterAmountOptic loc,
128-
Field.argsAction = PushUpdate . Instant
126+
Field.argsOptic = #modelState . #stDoc . #stDocLnInvoice,
127+
Field.argsAction = PushUpdate . Delayed 300
129128
}
130129
( Field.defOpts @Model @Action
131-
& #optsOnInputAction
132-
.~ Just
133-
( PushUpdate
134-
. Delayed 300
135-
. ( >=>
136-
pure
137-
. ( &
138-
#modelState
139-
. #stDoc
140-
. #stDocTopOrBottom
141-
.~ loc
142-
)
143-
)
144-
)
130+
& #optsFullWidth
131+
.~ True
145132
& #optsPlaceholder
146-
.~ ( st
147-
^. cloneLens (Misc.getConverterCurrencyOptic loc)
148-
. #currencyOutput
149-
. to (inspectCurrencyInfo @MisoString)
150-
)
133+
.~ "Lightning Invoice"
151134
)
152-
currencyWidget' tob =
153-
Currency.selectCurrency
154-
Currency.Args
155-
{ Currency.argsModel = st,
156-
Currency.argsOptic = Misc.getConverterCurrencyOptic tob,
157-
Currency.argsAction = PushUpdate . Instant,
158-
Currency.argsCurrencies = #modelCurrencies
159-
}
160-
Currency.Opts
161-
{ Currency.optsExtraOnClick = (& #modelLoading .~ True)
162-
}
163-
in ( FieldPairs.fieldPairsViewer
164-
FieldPairs.Args
165-
{ FieldPairs.argsModel = st,
166-
FieldPairs.argsOptic =
167-
#modelState
168-
. #stDoc
169-
. #stDocFieldPairs,
170-
FieldPairs.argsAction = PushUpdate . Instant
171-
}
172-
)
173-
<> [ amountWidget' Top,
174-
currencyWidget' Top,
175-
amountWidget' Bottom,
176-
currencyWidget' Bottom,
177-
SwapAmounts.swapAmounts,
178-
SwapCurrencies.swapCurrencies,
179-
ratesWidget st
180-
]
181-
182-
ratesWidget :: Model -> View Action
183-
ratesWidget st =
184-
LayoutGrid.cell
185-
[ LayoutGrid.span12,
186-
Typography.caption,
187-
style_
188-
$ [("text-align", "center")]
189-
<> ( case oof of
190-
Offline -> [("color", "#B00020")]
191-
Online -> mempty
192-
)
193-
]
194-
[ a_
195-
[ style_ [("cursor", "pointer")],
196-
onClick . PushUpdate . Instant $ Jsm.shareText msg
197-
]
198-
[ Miso.text msg
199-
]
200-
]
201-
where
202-
oof = st ^. #modelState . #stDoc . #stDocOnlineOrOffline
203-
top = st ^. #modelState . #stDoc . #stDocTopMoney
204-
topAmt = top ^. #moneyAmount . #fieldOutput
205-
topCur =
206-
top
207-
^. #moneyCurrency
208-
. #currencyOutput
209-
. #currencyInfoCode
210-
. #unCurrencyCode
211-
. to toMisoString
212-
bottom = st ^. #modelState . #stDoc . #stDocBottomMoney
213-
bottomAmt = bottom ^. #moneyAmount . #fieldOutput
214-
bottomCur =
215-
bottom
216-
^. #moneyCurrency
217-
. #currencyOutput
218-
. #currencyInfoCode
219-
. #unCurrencyCode
220-
. to toMisoString
221-
bottomPerTop =
222-
if topAmt == 0
223-
then 0
224-
else bottomAmt / topAmt
225-
topPerBottom =
226-
if bottomAmt == 0
227-
then 0
228-
else topAmt / bottomAmt
229-
msg =
230-
inspect oof
231-
<> " exchange rates"
232-
<> ( case oof of
233-
Offline -> mempty
234-
Online ->
235-
" on "
236-
<> ( st
237-
^. #modelState
238-
. #stDoc
239-
. #stDocCreatedAt
240-
. to utctDay
241-
. to inspect
242-
)
243-
)
244-
<> ": 1 "
245-
<> topCur
246-
<> " \8776 "
247-
<> inspectRatioDef bottomPerTop
248-
<> " "
249-
<> bottomCur
250-
<> ", 1 "
251-
<> bottomCur
252-
<> " \8776 "
253-
<> inspectRatioDef topPerBottom
254-
<> " "
255-
<> topCur
256-
<> "."
135+
]
257136

258137
tosWidget :: View Action
259138
tosWidget =

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

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import qualified Language.Javascript.JSaddle as JS
1717
import qualified Material.Button as Button
1818
import qualified Material.Dialog as Dialog
1919
import qualified Material.IconButton as IconButton
20-
import qualified Material.Select as Select
21-
import qualified Material.Select.Item as SelectItem
2220
import qualified Material.Theme as Theme
2321
import qualified Material.TopAppBar as TopAppBar
2422
import qualified Text.URI as URI
@@ -179,45 +177,6 @@ menu st =
179177
]
180178
)
181179
"Note",
182-
let item :| items = enumerateNE @OnlineOrOffline
183-
in Grid.mediumCell
184-
$ Select.outlined
185-
( Select.config
186-
& Select.setDisabled disabled
187-
& Select.setLabel
188-
( Just "Exchange rates"
189-
)
190-
& Select.setSelected
191-
( Just
192-
$ st
193-
^. #modelState
194-
. #stDoc
195-
. #stDocOnlineOrOffline
196-
)
197-
& Select.setOnChange
198-
( \x ->
199-
PushUpdate
200-
. Instant
201-
$ pure
202-
. ( &
203-
#modelState
204-
. #stDoc
205-
. #stDocOnlineOrOffline
206-
.~ x
207-
)
208-
)
209-
)
210-
( SelectItem.selectItem
211-
(SelectItem.config item)
212-
[text $ inspect item]
213-
)
214-
$ fmap
215-
( \x ->
216-
SelectItem.selectItem
217-
(SelectItem.config x)
218-
[text $ inspect x]
219-
)
220-
items,
221180
Grid.mediumCell
222181
$ Field.dynamicField
223182
Field.Args
@@ -329,18 +288,7 @@ defFavName st =
329288
if isJust (st ^. #modelState . #stCpt)
330289
|| (st ^. #modelState . #stIkm . #fieldOutput /= mempty)
331290
then mempty
332-
else getCode #stDocTopMoney <> "/" <> getCode #stDocBottomMoney
333-
where
334-
getCode optic =
335-
st
336-
^. #modelState
337-
. #stDoc
338-
. cloneLens optic
339-
. #moneyCurrency
340-
. #currencyOutput
341-
. #currencyInfoCode
342-
. #unCurrencyCode
343-
. to toMisoString
291+
else mempty
344292

345293
linksWidget :: Model -> [View Action]
346294
linksWidget st =

0 commit comments

Comments
 (0)