Skip to content

Commit d7a8ef3

Browse files
committed
wip
1 parent 16a3d12 commit d7a8ef3

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

pub/functora/functora.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ common pkg-bolt11
246246
import: pkg
247247
hs-source-dirs: src/bolt11
248248
build-depends:
249-
, aeson
250-
, array
251249
, attoparsec
252250
, base
253251
, base16-bytestring
@@ -346,6 +344,7 @@ library elm2miso-lib
346344

347345
library bolt11
348346
import: pkg-bolt11
347+
build-depends: functora
349348
exposed: True
350349
visibility: public
351350
exposed-modules: Functora.Bolt11

pub/functora/src/bolt11/Functora/Bolt11.hs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,19 @@ import Codec.Binary.Bech32 (Word5)
1818
import qualified Codec.Binary.Bech32.Internal as Bech32
1919
import Control.Applicative
2020
import Data.Attoparsec.Text
21-
import Data.Bifunctor (first)
2221
import Data.Bits (shiftL, (.|.))
23-
import Data.ByteString (ByteString)
2422
import qualified Data.ByteString as BS
2523
import qualified Data.ByteString.Base16 as B16
2624
import qualified Data.ByteString.Builder as BS
2725
import qualified Data.ByteString.Lazy.Char8 as BL
28-
import Data.Data (Data)
29-
import Data.Foldable (foldl')
30-
import Data.Maybe (fromMaybe)
31-
import Data.Ratio ((%))
32-
import Data.String (IsString (..))
33-
import Data.Text (Text)
3426
import qualified Data.Text as T
35-
import Data.Text.Encoding (decodeUtf8)
3627
import qualified Data.Text.Encoding as T
37-
import GHC.Generics (Generic)
38-
import Prelude
28+
import Functora.Prelude hiding (error)
29+
import Prelude (Show (..), error, splitAt, take)
3930

40-
newtype Hex = Hex {getHex :: ByteString}
31+
newtype Hex = Hex
32+
{ unHex :: ByteString
33+
}
4134
deriving newtype (Eq, Ord)
4235
deriving stock (Data, Generic)
4336

@@ -100,13 +93,22 @@ newtype Bolt11Amount = Bolt11Amount {_getBolt11Amount :: (Integer, Multiplier)}
10093

10194
instance Show Bolt11Amount where
10295
show (Bolt11Amount (amt, mul)) =
103-
show msat <> " msats"
96+
if (round sat) % 1 /= sat
97+
then show msat <> " Millisatoshi"
98+
else
99+
if sat < 1_000_000
100+
then show sat <> " Satoshi"
101+
else show btc <> " BTC"
104102
where
105-
msat :: Integer
106-
msat = round $ (amt % 1) * multiplierRatio mul * 1000_0000_0000
103+
btc :: Rational
104+
btc = (amt % 1) * multiplierRatio mul
105+
sat :: Rational
106+
sat = btc * 1_0000_0000
107+
msat :: Rational
108+
msat = sat * 1000
107109

108110
data Bolt11HRP = Bolt11HRP
109-
{ bolt11Currency :: Network,
111+
{ bolt11Network :: Network,
110112
bolt11Amount :: Maybe Bolt11Amount
111113
}
112114
deriving stock (Eq, Ord, Show, Data, Generic)

pub/functora/src/functora-ghcjs.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ common pkg
8181
build-depends:
8282
, aeson
8383
, aeson-combinators
84-
, array
8584
, async
8685
, attoparsec
8786
, base

pub/functora/src/test/Functora/Bolt11Spec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ goodSamples =
1010
Bolt11
1111
{ bolt11HRP =
1212
Bolt11HRP
13-
{ bolt11Currency = BitcoinMainnet,
13+
{ bolt11Network = BitcoinMainnet,
1414
bolt11Amount = Nothing
1515
},
1616
bolt11Timestamp = 1496314658,

0 commit comments

Comments
 (0)