@@ -11,8 +11,6 @@ import qualified Functora.Miso.Widgets.FieldPairs as FieldPairs
11
11
import qualified Functora.Miso.Widgets.Flex as Flex
12
12
import qualified Functora.Miso.Widgets.Icon as Icon
13
13
import qualified Functora.Miso.Widgets.Spinner as Spinner
14
- import qualified Functora.Money as Money
15
- import Lens.Micro ((^..) )
16
14
import Miso hiding (at , view )
17
15
18
16
mainWidget :: Model -> View Action
@@ -150,7 +148,7 @@ screenWidget st@Model {modelState = St {stScreen = Main}} =
150
148
151
149
totalViewer :: Model -> [View Action ]
152
150
totalViewer st =
153
- if base == 0
151
+ if null total
154
152
then mempty
155
153
else
156
154
singleton
@@ -160,81 +158,12 @@ totalViewer st =
160
158
FieldPairs. defOpts
161
159
FieldPairs. Args
162
160
{ FieldPairs. argsModel = st,
163
- FieldPairs. argsOptic =
164
- constTraversal
165
- [ newFieldPairId (" Subtotal " <> baseCur)
166
- . DynamicFieldText
167
- $ inspectRatioDef base,
168
- newFieldPairId (" Subtotal " <> quoteCur)
169
- . DynamicFieldText
170
- $ inspectRatioDef quote,
171
- FieldPair (newTextFieldId " Fee %" )
172
- $ uniqueToIdentity fee
173
- & # fieldOpts
174
- . # fieldOptsQrState
175
- .~ Nothing ,
176
- newFieldPairId (" Total " <> quoteCur)
177
- . DynamicFieldText
178
- . inspectRatioDef
179
- . foldField quote
180
- $ fee
181
- ],
161
+ FieldPairs. argsOptic = constTraversal total,
182
162
FieldPairs. argsAction = PushUpdate . Instant ,
183
163
FieldPairs. argsEmitter = pushActionQueue st . Instant
184
164
}
185
165
where
186
- fee = st ^. # modelState . # stMerchantFeePercent
187
- rate = st ^. # modelState . # stExchangeRate . # fieldOutput
188
- base =
189
- foldl
190
- ( \ acc fps ->
191
- if any
192
- ((== FieldTypeNumber ) . (^. # fieldPairValue . # fieldType))
193
- fps
194
- then acc + foldl foldFieldPair 1 fps
195
- else acc
196
- )
197
- 0
198
- ( st
199
- ^.. # modelState
200
- . # stAssets
201
- . each
202
- . # assetFieldPairs
203
- )
204
- quote =
205
- rate * base
206
- baseCur =
207
- st
208
- ^. # modelState
209
- . # stAssetCurrency
210
- . # currencyOutput
211
- . # currencyInfoCode
212
- . to Money. inspectCurrencyCode
213
- . to toUpper
214
- quoteCur =
215
- st
216
- ^. # modelState
217
- . # stMerchantCurrency
218
- . # currencyOutput
219
- . # currencyInfoCode
220
- . to Money. inspectCurrencyCode
221
- . to toUpper
222
-
223
- foldField :: Rational -> Field DynamicField f -> Rational
224
- foldField acc Field {fieldType = typ, fieldOutput = out} =
225
- case out of
226
- DynamicFieldNumber x
227
- | typ == FieldTypeNumber ->
228
- acc * x
229
- DynamicFieldNumber x
230
- | typ == FieldTypePercent ->
231
- acc * (1 + (x / 100 ))
232
- _ ->
233
- acc
234
-
235
- foldFieldPair :: Rational -> FieldPair DynamicField f -> Rational
236
- foldFieldPair acc =
237
- foldField acc . fieldPairValue
166
+ total = newTotal st
238
167
239
168
tosWidget :: View Action
240
169
tosWidget =
0 commit comments