Skip to content

Commit d0d9da6

Browse files
committed
wip
1 parent c711ba5 commit d0d9da6

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

pub/functora/functora.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ common pkg-rates
197197
, containers
198198
, modern-uri
199199
, money
200-
, tags
201200
, web
202201

203202
common pkg-tags

pub/functora/src/money/Functora/Money.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module Functora.Money
55
MoneyRep,
66
MoneyTags,
77
NewMoneyTags,
8-
Money (..),
8+
Money,
99
unMoney,
1010
parseMoney,
1111
SomeMoney (..),
12-
newSignedMoney,
12+
newMoney,
1313
newUnsignedMoneyBOS,
1414
newUnsignedMoneyGOL,
1515
newFeeRate,
@@ -36,7 +36,7 @@ import qualified Data.Text as T
3636
import Functora.MoneyFgpt as X ()
3737
import Functora.MoneySing as X
3838
import Functora.Prelude
39-
import Functora.Tags
39+
import Functora.Tags as X
4040
import qualified Language.Haskell.TH.Syntax as TH
4141

4242
type family MoneyRep sig where
@@ -120,13 +120,13 @@ instance (TestEquality (Sing :: k -> Type)) => Eq (SomeMoney k tags) where
120120

121121
deriving stock instance Show (SomeMoney k tags)
122122

123-
newSignedMoney ::
124-
forall prev next.
125-
( NewMoneyTags 'Signed next (prev |+| 'Signed)
123+
newMoney ::
124+
forall sig tags.
125+
( MoneyTags sig tags
126126
) =>
127-
Rational ->
128-
Money next
129-
newSignedMoney = Money
127+
Ratio (MoneyRep sig) ->
128+
Money tags
129+
newMoney = Money
130130

131131
newUnsignedMoneyBOS ::
132132
forall tags buy sell.

pub/functora/src/rates/Functora/Rates.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import qualified Data.Aeson.Combinators.Decode as A
4040
import qualified Data.Map as Map
4141
import Functora.Money
4242
import Functora.Prelude
43-
import Functora.Tags
4443
import Functora.Web
4544
import qualified Text.URI as URI
4645
import qualified Text.URI.Lens as URILens

pub/functora/src/sql/Functora/SqlOrphan.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import qualified Data.UUID as UUID
99
import Database.Esqueleto.Legacy hiding (from)
1010
import Functora.Money
1111
import Functora.Prelude hiding (Key)
12-
import Functora.Tags
1312
import qualified Text.URI as URI
1413

1514
deriving stock instance Data PersistValue
@@ -79,18 +78,20 @@ deriving via
7978
(MoneyTags sig tags) => PersistFieldSql (Money tags)
8079

8180
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
8686
fromPersistValue raw =
8787
case raw of
8888
PersistRational x ->
8989
case sing :: Sing sig of
9090
SSigned ->
91-
pure $ Money x
91+
pure $ newMoney @sig @tags x
9292
SUnsigned ->
93-
bimap (const failure) Money $ tryFrom @Rational @(Ratio Natural) x
93+
bimap (const failure) (newMoney @sig @tags) $
94+
tryFrom @Rational @(Ratio Natural) x
9495
_ ->
9596
Left failure
9697
where

pub/functora/test/Functora/RatesSpec.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@ spec = do
5858
it "getQuote" . withNewMarket $ do
5959
let quoteCurrency = CurrencyCode "usd"
6060
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
6268
lift $ res `shouldSatisfy` isRight

0 commit comments

Comments
 (0)