checkCoinPortion
    :: MonadError Text m
    => CoinPortion -> m ()
checkCoinPortion (CoinPortion x)
    | x <= coinPortionDenominator = pure ()
    | otherwise = throwError err
  where
    err =
        sformat
            ("CoinPortion: value is greater than coinPortionDenominator: "
            %int) x

-- | Make CoinPortion from Double. Caller must ensure that value is in
-- [0..1]. Internally 'CoinPortion' stores 'Word64' which is divided by
-- 'coinPortionDenominator' to get actual value. So some rounding may take
-- place.
checkCoinPortion
    :: MonadError Text m
    => CoinPortion -> m ()
checkCoinPortion (CoinPortion x)
    | x <= coinPortionDenominator = pure ()
    | otherwise = throwError err
  where
    err =
        sformat
            ("CoinPortion: value is greater than coinPortionDenominator: "
            %int) x

-- | Make CoinPortion from Double. Caller must ensure that value is in
-- [0..1]. Internally 'CoinPortion' stores 'Word64' which is divided by
-- 'coinPortionDenominator' to get actual value. So some rounding may take
-- place.
checkCoinPortion (CoinPortion x)
    | x <= coinPortionDenominator = pure ()
    | otherwise = throwError err
  where
    err =
        sformat
            ("CoinPortion: value is greater than coinPortionDenominator: "
            %int) x

-- | Make CoinPortion from Double. Caller must ensure that value is in
-- [0..1]. Internally 'CoinPortion' stores 'Word64' which is divided by
-- 'coinPortionDenominator' to get actual value. So some rounding may take
-- place.