Skip to content

Commit

Permalink
Merge pull request #64 from fullstack-development/FundraisingInfoTypes
Browse files Browse the repository at this point in the history
refactored FRInfo types
  • Loading branch information
olgaklimenko authored Sep 14, 2023
2 parents 16c39d8 + 7e169d2 commit a653845
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/535.index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can edit this file as you like.
, "encoding"
, "exceptions"
, "foldable-traversable"
, "integers"
, "math"
, "maybe"
, "monad-logger"
Expand Down
9 changes: 5 additions & 4 deletions src/Fundraising/Create.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Contract.Time (POSIXTime(..))
import Contract.TxConstraints as Constraints
import Contract.Value as Value
import Ctl.Internal.Types.ByteArray (byteArrayFromAscii)
import Data.BigInt (fromInt, toString)
import Data.BigInt (fromInt, toNumber, toString)
import Data.Int as Int
import Data.Lens (view)
import Data.String (take)
import Effect.Exception (throw)
Expand Down Expand Up @@ -177,9 +178,9 @@ contract protocolData (CreateFundraisingParams { title, amount, duration }) = do
pure $ FundraisingInfo
{ creator: Just creatorPkh
, title: title
, goal: targetAmount
, raisedAmt: fromInt 0
, deadline: deadline
, goal: toNumber targetAmount
, raisedAmt: Int.toNumber 0
, deadline: toNumber <<< unwrap $ deadline
, threadTokenCurrency: currencySymbolToString nftCs
, threadTokenName: fundraisingTokenNameString
, isCompleted: false
Expand Down
15 changes: 7 additions & 8 deletions src/Info/UserData.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import Contract.Prelude
import Contract.Address (Bech32String)
import Contract.Chain (currentTime)
import Contract.Monad (Contract, liftContractM)
import Contract.Time (POSIXTime)
import Contract.Value as Value
import Ctl.Internal.Types.ByteArray (ByteArray(..))
import Data.Array as Array
import Data.BigInt (BigInt)
import Data.BigInt (toNumber)
import Data.TextDecoder (decodeUtf8)
import Ext.Contract.Value (getCurrencyByTokenName, currencySymbolToString)
import Ext.Data.Either (eitherContract)
Expand All @@ -23,9 +22,9 @@ import Shared.Utxo (UtxoTuple, extractDatumFromUTxO, extractValueFromUTxO)
newtype FundraisingInfo = FundraisingInfo
{ creator :: Maybe Bech32String
, title :: String
, goal :: BigInt -- Goal in lovelaces
, raisedAmt :: BigInt -- Raised amount in lovelaces
, deadline :: POSIXTime
, goal :: Number -- Goal in lovelaces
, raisedAmt :: Number -- Raised amount in lovelaces
, deadline :: Number
, threadTokenCurrency :: String
, threadTokenName :: String
, isCompleted :: Boolean
Expand All @@ -48,9 +47,9 @@ mapToFundraisingInfo utxo = do
pure $ FundraisingInfo
{ creator: Just creator
, title: title
, goal: currentDatum.frAmount
, raisedAmt: currentFunds
, deadline: currentDatum.frDeadline
, goal: toNumber currentDatum.frAmount
, raisedAmt: toNumber currentFunds
, deadline: toNumber <<< unwrap $ currentDatum.frDeadline
, threadTokenCurrency: currencySymbolToString cs
, threadTokenName: fundraisingTokenNameString
, isCompleted: now > currentDatum.frDeadline || currentFunds >= currentDatum.frAmount
Expand Down

0 comments on commit a653845

Please sign in to comment.