File tree Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Expand file tree Collapse file tree 4 files changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module Functora.Money
20
20
fundsMoneyAmount ,
21
21
fundsCurrencyCode ,
22
22
unJsonRational ,
23
- unJsonSignedMoney ,
23
+ unJsonMoney ,
24
24
unJsonUnsignedMoneyBOS ,
25
25
unJsonUnsignedMoneyGOL ,
26
26
CurrencyCode (.. ),
@@ -121,7 +121,7 @@ instance (TestEquality (Sing :: k -> Type)) => Eq (SomeMoney k tags) where
121
121
deriving stock instance Show (SomeMoney k tags )
122
122
123
123
newMoney ::
124
- forall sig tags .
124
+ forall tags sig .
125
125
( MoneyTags sig tags
126
126
) =>
127
127
Ratio (MoneyRep sig ) ->
@@ -232,10 +232,17 @@ deriving stock instance (MoneyTags sig tags) => Read (Funds tags)
232
232
deriving stock instance (MoneyTags sig tags ) => Data (Funds tags )
233
233
234
234
unJsonRational :: A. Decoder Rational
235
- unJsonRational = toRational <$> A. scientific
236
-
237
- unJsonSignedMoney :: (MoneyTags 'Signed tags ) => A. Decoder (Money tags )
238
- unJsonSignedMoney = Money <$> unJsonRational
235
+ unJsonRational =
236
+ toRational <$> A. scientific
237
+
238
+ unJsonMoney :: forall tags sig . (MoneyTags sig tags ) => A. Decoder (Money tags )
239
+ unJsonMoney = do
240
+ rat <- unJsonRational
241
+ case sing :: Sing sig of
242
+ SSigned -> pure $ newMoney rat
243
+ SUnsigned ->
244
+ either (fail . inspect) (pure . newMoney)
245
+ $ tryFrom @ Rational @ (Ratio Natural ) rat
239
246
240
247
unJsonUnsignedMoneyBOS ::
241
248
forall tags .
Original file line number Diff line number Diff line change @@ -246,7 +246,7 @@ tryFetchQuotesPerBase cur uri = tryMarket $ do
246
246
createdAt <- A. at [" date" ] A. day
247
247
quotesMap <-
248
248
A. at [fromString . from @ Text @ String $ unCurrencyCode cur]
249
- $ A. mapStrict unJsonSignedMoney
249
+ $ A. mapStrict unJsonMoney
250
250
pure
251
251
QuotesPerBaseAt
252
252
{ quotesPerBaseQuotesMap = Map. mapKeys CurrencyCode quotesMap,
Original file line number Diff line number Diff line change @@ -88,9 +88,9 @@ instance (MoneyTags sig tags) => PersistField (Money tags) where
88
88
PersistRational x ->
89
89
case sing :: Sing sig of
90
90
SSigned ->
91
- pure $ newMoney @ sig @ tags x
91
+ pure $ newMoney x
92
92
SUnsigned ->
93
- bimap (const failure) ( newMoney @ sig @ tags ) $
93
+ bimap (const failure) newMoney $
94
94
tryFrom @ Rational @ (Ratio Natural ) x
95
95
_ ->
96
96
Left failure
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ spec = do
61
61
tryMarket
62
62
$ getQuote
63
63
( Funds
64
- (newMoney @ 'Signed 1 )
64
+ (newMoney 1 )
65
65
(CurrencyCode " btc" )
66
66
)
67
67
quoteCurrency
You can’t perform that action at this time.
0 commit comments