File tree Expand file tree Collapse file tree 5 files changed +24
-19
lines changed Expand file tree Collapse file tree 5 files changed +24
-19
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,6 @@ common pkg-rates
197
197
, containers
198
198
, modern-uri
199
199
, money
200
- , tags
201
200
, web
202
201
203
202
common pkg-tags
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ module Functora.Money
5
5
MoneyRep ,
6
6
MoneyTags ,
7
7
NewMoneyTags ,
8
- Money ( .. ) ,
8
+ Money ,
9
9
unMoney ,
10
10
parseMoney ,
11
11
SomeMoney (.. ),
12
- newSignedMoney ,
12
+ newMoney ,
13
13
newUnsignedMoneyBOS ,
14
14
newUnsignedMoneyGOL ,
15
15
newFeeRate ,
@@ -36,7 +36,7 @@ import qualified Data.Text as T
36
36
import Functora.MoneyFgpt as X ()
37
37
import Functora.MoneySing as X
38
38
import Functora.Prelude
39
- import Functora.Tags
39
+ import Functora.Tags as X
40
40
import qualified Language.Haskell.TH.Syntax as TH
41
41
42
42
type family MoneyRep sig where
@@ -120,13 +120,13 @@ instance (TestEquality (Sing :: k -> Type)) => Eq (SomeMoney k tags) where
120
120
121
121
deriving stock instance Show (SomeMoney k tags )
122
122
123
- newSignedMoney ::
124
- forall prev next .
125
- ( NewMoneyTags 'Signed next ( prev |+| 'Signed)
123
+ newMoney ::
124
+ forall sig tags .
125
+ ( MoneyTags sig tags
126
126
) =>
127
- Rational ->
128
- Money next
129
- newSignedMoney = Money
127
+ Ratio ( MoneyRep sig ) ->
128
+ Money tags
129
+ newMoney = Money
130
130
131
131
newUnsignedMoneyBOS ::
132
132
forall tags buy sell .
Original file line number Diff line number Diff line change @@ -40,7 +40,6 @@ import qualified Data.Aeson.Combinators.Decode as A
40
40
import qualified Data.Map as Map
41
41
import Functora.Money
42
42
import Functora.Prelude
43
- import Functora.Tags
44
43
import Functora.Web
45
44
import qualified Text.URI as URI
46
45
import qualified Text.URI.Lens as URILens
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import qualified Data.UUID as UUID
9
9
import Database.Esqueleto.Legacy hiding (from )
10
10
import Functora.Money
11
11
import Functora.Prelude hiding (Key )
12
- import Functora.Tags
13
12
import qualified Text.URI as URI
14
13
15
14
deriving stock instance Data PersistValue
@@ -79,18 +78,20 @@ deriving via
79
78
(MoneyTags sig tags ) => PersistFieldSql (Money tags )
80
79
81
80
instance (MoneyTags sig tags ) => PersistField (Money tags ) where
82
- toPersistValue (Money rep) =
83
- case sing :: Sing sig of
84
- SSigned -> PersistRational rep
85
- SUnsigned -> PersistRational $ from @ (Ratio Natural ) @ Rational rep
81
+ toPersistValue money =
82
+ let rep = unMoney money
83
+ in case sing :: Sing sig of
84
+ SSigned -> PersistRational rep
85
+ SUnsigned -> PersistRational $ from @ (Ratio Natural ) @ Rational rep
86
86
fromPersistValue raw =
87
87
case raw of
88
88
PersistRational x ->
89
89
case sing :: Sing sig of
90
90
SSigned ->
91
- pure $ Money x
91
+ pure $ newMoney @ sig @ tags x
92
92
SUnsigned ->
93
- bimap (const failure) Money $ tryFrom @ Rational @ (Ratio Natural ) x
93
+ bimap (const failure) (newMoney @ sig @ tags ) $
94
+ tryFrom @ Rational @ (Ratio Natural ) x
94
95
_ ->
95
96
Left failure
96
97
where
Original file line number Diff line number Diff line change @@ -58,5 +58,11 @@ spec = do
58
58
it " getQuote" . withNewMarket $ do
59
59
let quoteCurrency = CurrencyCode " usd"
60
60
res <-
61
- tryMarket $ getQuote (Funds (Money 1 ) $ CurrencyCode " btc" ) quoteCurrency
61
+ tryMarket
62
+ $ getQuote
63
+ ( Funds
64
+ (newMoney @ 'Signed 1 )
65
+ (CurrencyCode " btc" )
66
+ )
67
+ quoteCurrency
62
68
lift $ res `shouldSatisfy` isRight
You can’t perform that action at this time.
0 commit comments