Skip to content

Commit 41b4b06

Browse files
committed
rates widget
1 parent 9afd6cb commit 41b4b06

File tree

2 files changed

+78
-34
lines changed

2 files changed

+78
-34
lines changed

ghcjs/currency-converter/src/App/Widgets/Main.hs

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,7 @@ screenWidget st@Model {modelState = St {stScreen = QrCode sc}} =
110110
]
111111
)
112112
screenWidget st@Model {modelState = St {stScreen = Converter}} =
113-
let oof =
114-
st
115-
^. #modelState
116-
. #stDoc
117-
. #stDocOnlineOrOffline
118-
amountWidget' loc =
113+
let amountWidget' loc =
119114
Field.ratioField
120115
st
121116
( Misc.getConverterAmountOptic loc
@@ -153,34 +148,83 @@ screenWidget st@Model {modelState = St {stScreen = Converter}} =
153148
currencyWidget' Bottom,
154149
SwapAmounts.swapAmounts,
155150
Currency.swapCurrencies,
156-
LayoutGrid.cell
157-
[ LayoutGrid.span12,
158-
Typography.caption,
159-
style_
160-
$ [("text-align", "center")]
161-
<> ( if oof == Offline
162-
then [("color", "#B00020")]
163-
else mempty
164-
)
165-
]
166-
[ Miso.text
167-
$ inspect oof
168-
<> " exchange rate"
169-
<> ( case oof of
170-
Offline -> mempty
171-
Online ->
172-
" on "
173-
<> ( st
174-
^. #modelState
175-
. #stDoc
176-
. #stDocCreatedAt
177-
. to utctDay
178-
. to inspect
179-
)
180-
)
181-
]
151+
ratesWidget st
182152
]
183153

154+
ratesWidget :: Model -> View Action
155+
ratesWidget st =
156+
LayoutGrid.cell
157+
[ LayoutGrid.span12,
158+
Typography.caption,
159+
style_
160+
$ [("text-align", "center")]
161+
<> ( case oof of
162+
Offline -> [("color", "#B00020")]
163+
Online -> mempty
164+
)
165+
]
166+
[ a_
167+
[ style_ [("cursor", "pointer")],
168+
onClick $ Misc.copyIntoClipboardAction st msg
169+
]
170+
[ Miso.text msg
171+
]
172+
]
173+
where
174+
oof = st ^. #modelState . #stDoc . #stDocOnlineOrOffline
175+
top = st ^. #modelState . #stDoc . #stDocTopMoney
176+
topAmt = top ^. #moneyAmount . #fieldOutput
177+
topCur =
178+
top
179+
^. #moneyCurrency
180+
. #currencyOutput
181+
. #currencyInfoCode
182+
. #unCurrencyCode
183+
bottom = st ^. #modelState . #stDoc . #stDocBottomMoney
184+
bottomAmt = bottom ^. #moneyAmount . #fieldOutput
185+
bottomCur =
186+
bottom
187+
^. #moneyCurrency
188+
. #currencyOutput
189+
. #currencyInfoCode
190+
. #unCurrencyCode
191+
bottomPerTop =
192+
if topAmt == 0
193+
then 0
194+
else bottomAmt / topAmt
195+
topPerBottom =
196+
if bottomAmt == 0
197+
then 0
198+
else topAmt / bottomAmt
199+
msg =
200+
inspect oof
201+
<> " exchange rates"
202+
<> ( case oof of
203+
Offline -> mempty
204+
Online ->
205+
" on "
206+
<> ( st
207+
^. #modelState
208+
. #stDoc
209+
. #stDocCreatedAt
210+
. to utctDay
211+
. to inspect
212+
)
213+
)
214+
<> ": 1 "
215+
<> topCur
216+
<> " \8776 "
217+
<> inspectRatioDef bottomPerTop
218+
<> " "
219+
<> bottomCur
220+
<> ", 1 "
221+
<> bottomCur
222+
<> " \8776 "
223+
<> inspectRatioDef topPerBottom
224+
<> " "
225+
<> topCur
226+
<> "."
227+
184228
tosWidget :: View Action
185229
tosWidget =
186230
LayoutGrid.cell

ghcjs/currency-converter/src/App/Widgets/Menu.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ menu st =
145145
]
146146
)
147147
$ if isQrCode sc
148-
then "Rate"
148+
then "Rates"
149149
else "QR",
150150
Cell.smallCell
151151
$ Button.raised
@@ -172,7 +172,7 @@ menu st =
172172
( Select.config
173173
& Select.setDisabled disabled
174174
& Select.setLabel
175-
( Just "Exchange rate"
175+
( Just "Exchange rates"
176176
)
177177
& Select.setAttributes
178178
[ class_ "fill-inner"

0 commit comments

Comments
 (0)