@@ -82,7 +82,8 @@ data TopOrBottom
82
82
deriving stock (Eq , Ord , Show , Read , Enum , Bounded , Data , Generic )
83
83
84
84
data ModelMoney = ModelMoney
85
- { modelMoneyAmountInput :: Text ,
85
+ { modelMoneyAmountUuid :: UUID ,
86
+ modelMoneyAmountInput :: Text ,
86
87
modelMoneyAmountOutput :: Money (Tags 'Signed |+| 'MoneyAmount),
87
88
modelMoneyCurrencyInfo :: CurrencyInfo ,
88
89
modelMoneyCurrencyOpen :: Bool ,
@@ -97,12 +98,14 @@ data ModelData = ModelData
97
98
}
98
99
deriving stock (Eq , Ord , Show , Read , Data , Generic )
99
100
100
- mkModel :: (MonadThrow m , MonadUnliftIO m ) => m Model
101
- mkModel = do
101
+ newModel :: (MonadThrow m , MonadUnliftIO m ) => m Model
102
+ newModel = do
102
103
ct <- getCurrentTime
103
104
prod <- liftIO newBroadcastTChanIO
104
105
cons <- liftIO . atomically $ dupTChan prod
105
106
market <- newMarket
107
+ topUuid <- newUuid
108
+ bottomUuid <- newUuid
106
109
let btc =
107
110
CurrencyInfo
108
111
{ currencyInfoCode = CurrencyCode " btc" ,
@@ -118,15 +121,17 @@ mkModel = do
118
121
ModelData
119
122
{ modelDataTopMoney =
120
123
ModelMoney
121
- { modelMoneyAmountInput = inspectMoneyAmount zero,
124
+ { modelMoneyAmountUuid = topUuid,
125
+ modelMoneyAmountInput = inspectMoneyAmount zero,
122
126
modelMoneyAmountOutput = zero,
123
127
modelMoneyCurrencyInfo = btc,
124
128
modelMoneyCurrencyOpen = False ,
125
129
modelMoneyCurrencySearch = mempty
126
130
},
127
131
modelDataBottomMoney =
128
132
ModelMoney
129
- { modelMoneyAmountInput = inspectMoneyAmount zero,
133
+ { modelMoneyAmountUuid = bottomUuid,
134
+ modelMoneyAmountInput = inspectMoneyAmount zero,
130
135
modelMoneyAmountOutput = zero,
131
136
modelMoneyCurrencyInfo = usd,
132
137
modelMoneyCurrencyOpen = False ,
@@ -167,15 +172,17 @@ mkModel = do
167
172
ModelData
168
173
{ modelDataTopMoney =
169
174
ModelMoney
170
- { modelMoneyAmountInput = inspectMoneyAmount baseAmt,
175
+ { modelMoneyAmountUuid = topUuid,
176
+ modelMoneyAmountInput = inspectMoneyAmount baseAmt,
171
177
modelMoneyAmountOutput = unTag @ 'Base baseAmt,
172
178
modelMoneyCurrencyInfo = baseCur,
173
179
modelMoneyCurrencyOpen = False ,
174
180
modelMoneyCurrencySearch = mempty
175
181
},
176
182
modelDataBottomMoney =
177
183
ModelMoney
178
- { modelMoneyAmountInput = inspectMoneyAmount quoteAmt,
184
+ { modelMoneyAmountUuid = bottomUuid,
185
+ modelMoneyAmountInput = inspectMoneyAmount quoteAmt,
179
186
modelMoneyAmountOutput = unTag @ 'Quote quoteAmt,
180
187
modelMoneyCurrencyInfo = quoteCur,
181
188
modelMoneyCurrencyOpen = False ,
@@ -231,7 +238,7 @@ extendedEvents =
231
238
232
239
main :: IO ()
233
240
main = do
234
- st <- mkModel
241
+ st <- newModel
235
242
runApp
236
243
$ startApp
237
244
App
@@ -336,7 +343,7 @@ syncInputs st =
336
343
forM_ enumerate $ \ loc -> do
337
344
JS. eval @ Text
338
345
$ " var el = document.getElementById('"
339
- <> inspect loc
346
+ <> htmlUuid (st ^. # modelData . getMoneyOptic loc . # modelMoneyAmountUuid)
340
347
<> " '); if (el && !(el.getElementsByTagName('input')[0] === document.activeElement)) el.value = '"
341
348
<> (st ^. # modelData . getMoneyOptic loc . # modelMoneyAmountInput)
342
349
<> " ';"
@@ -533,12 +540,19 @@ amountWidget st loc =
533
540
)
534
541
& TextField. setAttributes
535
542
[ class_ " fill" ,
536
- id_ $ inspect loc,
543
+ id_
544
+ . ms
545
+ . htmlUuid @ Text
546
+ $ st
547
+ ^. # modelData
548
+ . getMoneyOptic loc
549
+ . # modelMoneyAmountUuid,
537
550
onKeyDown onKeyDownAction,
538
551
onBlur onBlurAction
539
552
]
540
553
]
541
554
where
555
+ uuid = st ^. # modelData . getMoneyOptic loc . # modelMoneyAmountUuid
542
556
input = st ^. # modelData . getMoneyOptic loc . # modelMoneyAmountInput
543
557
output = st ^. # modelData . getMoneyOptic loc . # modelMoneyAmountOutput
544
558
valid =
@@ -561,7 +575,7 @@ amountWidget st loc =
561
575
. void
562
576
. JS. eval @ Text
563
577
$ " document.getElementById('"
564
- <> inspect loc
578
+ <> htmlUuid uuid
565
579
<> " ').getElementsByTagName('input')[0].blur();"
566
580
)
567
581
( ChanItem 300 id
@@ -589,11 +603,11 @@ amountWidget st loc =
589
603
onClearAction =
590
604
PushUpdate
591
605
( do
592
- focus $ inspect loc
606
+ focus . ms $ htmlUuid @ Text uuid
593
607
void
594
608
. JS. eval @ Text
595
609
$ " var el = document.getElementById('"
596
- <> inspect loc
610
+ <> htmlUuid uuid
597
611
<> " '); if (el) el.value = '';"
598
612
)
599
613
( ChanItem 300 $ \ st' ->
0 commit comments