@@ -85,6 +85,7 @@ data ModelMoney = ModelMoney
85
85
{ modelMoneyAmountUuid :: UUID ,
86
86
modelMoneyAmountInput :: Text ,
87
87
modelMoneyAmountOutput :: Money (Tags 'Signed |+| 'MoneyAmount),
88
+ modelMoneyCurrencyUuid :: UUID ,
88
89
modelMoneyCurrencyInfo :: CurrencyInfo ,
89
90
modelMoneyCurrencyOpen :: Bool ,
90
91
modelMoneyCurrencySearch :: Text
@@ -104,8 +105,10 @@ newModel = do
104
105
prod <- liftIO newBroadcastTChanIO
105
106
cons <- liftIO . atomically $ dupTChan prod
106
107
market <- newMarket
107
- topUuid <- newUuid
108
- bottomUuid <- newUuid
108
+ topAmtUuid <- newUuid
109
+ topCurUuid <- newUuid
110
+ bottomAmtUuid <- newUuid
111
+ bottomCurUuid <- newUuid
109
112
let btc =
110
113
CurrencyInfo
111
114
{ currencyInfoCode = CurrencyCode " btc" ,
@@ -121,18 +124,20 @@ newModel = do
121
124
ModelData
122
125
{ modelDataTopMoney =
123
126
ModelMoney
124
- { modelMoneyAmountUuid = topUuid ,
127
+ { modelMoneyAmountUuid = topAmtUuid ,
125
128
modelMoneyAmountInput = inspectMoneyAmount zero,
126
129
modelMoneyAmountOutput = zero,
130
+ modelMoneyCurrencyUuid = topCurUuid,
127
131
modelMoneyCurrencyInfo = btc,
128
132
modelMoneyCurrencyOpen = False ,
129
133
modelMoneyCurrencySearch = mempty
130
134
},
131
135
modelDataBottomMoney =
132
136
ModelMoney
133
- { modelMoneyAmountUuid = bottomUuid ,
137
+ { modelMoneyAmountUuid = bottomAmtUuid ,
134
138
modelMoneyAmountInput = inspectMoneyAmount zero,
135
139
modelMoneyAmountOutput = zero,
140
+ modelMoneyCurrencyUuid = bottomCurUuid,
136
141
modelMoneyCurrencyInfo = usd,
137
142
modelMoneyCurrencyOpen = False ,
138
143
modelMoneyCurrencySearch = mempty
@@ -172,18 +177,20 @@ newModel = do
172
177
ModelData
173
178
{ modelDataTopMoney =
174
179
ModelMoney
175
- { modelMoneyAmountUuid = topUuid ,
180
+ { modelMoneyAmountUuid = topAmtUuid ,
176
181
modelMoneyAmountInput = inspectMoneyAmount baseAmt,
177
182
modelMoneyAmountOutput = unTag @ 'Base baseAmt,
183
+ modelMoneyCurrencyUuid = topCurUuid,
178
184
modelMoneyCurrencyInfo = baseCur,
179
185
modelMoneyCurrencyOpen = False ,
180
186
modelMoneyCurrencySearch = mempty
181
187
},
182
188
modelDataBottomMoney =
183
189
ModelMoney
184
- { modelMoneyAmountUuid = bottomUuid ,
190
+ { modelMoneyAmountUuid = bottomAmtUuid ,
185
191
modelMoneyAmountInput = inspectMoneyAmount quoteAmt,
186
192
modelMoneyAmountOutput = unTag @ 'Quote quoteAmt,
193
+ modelMoneyCurrencyUuid = bottomCurUuid,
187
194
modelMoneyCurrencyInfo = quoteCur,
188
195
modelMoneyCurrencyOpen = False ,
189
196
modelMoneyCurrencySearch = mempty
@@ -547,7 +554,7 @@ amountWidget st loc =
547
554
^. # modelData
548
555
. getMoneyOptic loc
549
556
. # modelMoneyAmountUuid,
550
- onKeyDown onKeyDownAction,
557
+ onKeyDown $ onKeyDownAction uuid ,
551
558
onBlur onBlurAction
552
559
]
553
560
]
@@ -568,18 +575,6 @@ amountWidget st loc =
568
575
. getMoneyOptic loc
569
576
. # modelMoneyAmountInput
570
577
.~ inspectMoneyAmount output
571
- onKeyDownAction (KeyCode code) =
572
- let enterOrEscape = [13 , 27 ] :: [Int ]
573
- in PushUpdate
574
- ( when (code `elem` enterOrEscape)
575
- . void
576
- . JS. eval @ Text
577
- $ " document.getElementById('"
578
- <> htmlUuid uuid
579
- <> " ').getElementsByTagName('input')[0].blur();"
580
- )
581
- ( ChanItem 300 id
582
- )
583
578
onInputAction txt =
584
579
pureUpdate 300 $ \ st' ->
585
580
st'
@@ -621,6 +616,20 @@ amountWidget st loc =
621
616
.~ loc
622
617
)
623
618
619
+ onKeyDownAction :: UUID -> KeyCode -> Action
620
+ onKeyDownAction uuid (KeyCode code) =
621
+ let enterOrEscape = [13 , 27 ] :: [Int ]
622
+ in PushUpdate
623
+ ( when (code `elem` enterOrEscape)
624
+ . void
625
+ . JS. eval @ Text
626
+ $ " document.getElementById('"
627
+ <> htmlUuid uuid
628
+ <> " ').getElementsByTagName('input')[0].blur();"
629
+ )
630
+ ( ChanItem 300 id
631
+ )
632
+
624
633
currencyWidget ::
625
634
Model ->
626
635
TopOrBottom ->
@@ -686,7 +695,9 @@ currencyWidget st loc =
686
695
. # modelMoneyCurrencyInfo
687
696
)
688
697
. TextField. setAttributes
689
- [ class_ " fill"
698
+ [ class_ " fill" ,
699
+ id_ . ms $ htmlUuid @ Text uuid,
700
+ onKeyDown $ onKeyDownAction uuid
690
701
]
691
702
$ TextField. config,
692
703
Button. raised
@@ -701,6 +712,7 @@ currencyWidget st loc =
701
712
)
702
713
]
703
714
where
715
+ uuid = st ^. # modelData . getMoneyOptic loc . # modelMoneyCurrencyUuid
704
716
search input =
705
717
pureUpdate 0 $ \ st' ->
706
718
st'
0 commit comments