Skip to content

Commit

Permalink
Add KnownWallet helper
Browse files Browse the repository at this point in the history
  • Loading branch information
errfrom committed Aug 2, 2024
1 parent a3621d8 commit 01a5ee7
Show file tree
Hide file tree
Showing 35 changed files with 207 additions and 128 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ purs-args := "--stash --censor-lib --censor-codes=UserDefinedWarning,ImplicitImp
### Bundler setup

# The main Purescript module
ps-entrypoint := Ctl.Examples.ByUrl
ps-entrypoint := Ctl.Examples.Gov.SubmitVoteScript
# The entry point function in the main PureScript module
ps-entrypoint-function := main
# Whether to bundle for the browser ("1") or the node ("")
Expand Down
5 changes: 4 additions & 1 deletion examples/AdditionalUtxos.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import Contract.BalanceTxConstraints
)
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, runContract)
Expand All @@ -58,7 +60,8 @@ import Test.QuickCheck.Gen (randomSampleOne)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

example :: ContractParams -> Effect Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/AlwaysMints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import Cardano.Types.RedeemerDatum as RedeemerDatum
import Cardano.Types.Transaction as Transaction
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, liftContractM, runContract)
Expand All @@ -35,7 +37,8 @@ import Data.Map as Map

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

contract :: Contract Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/AlwaysSucceeds.purs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import Cardano.Types.TransactionUnspentOutput (toUtxoMap)
import Contract.Address (mkAddress)
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, runContract)
Expand All @@ -59,7 +61,8 @@ import Effect.Exception (error)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

contract :: Contract Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/AwaitTxConfirmedWithTimeout.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import Contract.Prelude
import Cardano.AsCbor (decodeCbor)
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, runContract, throwContractError)
Expand All @@ -25,7 +27,8 @@ import Partial.Unsafe (unsafePartial)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

example :: ContractParams -> Effect Unit
Expand Down
85 changes: 34 additions & 51 deletions examples/ByUrl.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import Prelude

import Contract.Config
( ContractParams
, KnownWallet(Nami, Gero, Flint, Eternl, Lode, Lace, NuFi)
, WalletSpec(ConnectToGenericCip30)
, blockfrostPublicPreprodServerConfig
, blockfrostPublicPreviewServerConfig
, mainnetConfig
, mkBlockfrostBackendParams
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract)
Expand Down Expand Up @@ -50,25 +52,6 @@ import Web.HTML (window)
import Web.HTML.Window (localStorage)
import Web.Storage.Storage (getItem)

data Wallet
= NamiWallet
| GeroWallet
| FlintWallet
| EternlWallet
| LodeWallet
| LaceWallet
| NuFiWallet

walletName :: Wallet -> String
walletName = case _ of
NamiWallet -> "nami"
GeroWallet -> "gerowallet"
FlintWallet -> "flint"
EternlWallet -> "eternl"
LodeWallet -> "LodeWallet"
LaceWallet -> "lace"
NuFiWallet -> "nufi"

main :: Effect Unit
main = do
-- Read Blockfrost API key from the browser storage.
Expand All @@ -84,59 +67,59 @@ main = do
Map.fromFoldable
[ "blockfrost-nami-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo NamiWallet }
{ walletSpec = connectTo Nami }
/\ Nothing
, "blockfrost-gero-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo GeroWallet }
{ walletSpec = connectTo Gero }
/\ Nothing
, "blockfrost-eternl-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo EternlWallet }
{ walletSpec = connectTo Eternl }
/\ Nothing
, "blockfrost-lode-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo LodeWallet }
{ walletSpec = connectTo Lode }
/\ Nothing
, "blockfrost-flint-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo FlintWallet }
{ walletSpec = connectTo Flint }
/\ Nothing
, "blockfrost-nufi-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo NuFiWallet }
{ walletSpec = connectTo NuFi }
/\ Nothing
, "blockfrost-lace-preview"
/\ (mkBlockfrostPreviewConfig mbApiKey)
{ walletSpec = connectTo LaceWallet }
{ walletSpec = connectTo Lace }
/\ Nothing
, "blockfrost-nami-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo NamiWallet }
{ walletSpec = connectTo Nami }
/\ Nothing
, "blockfrost-gero-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo GeroWallet }
{ walletSpec = connectTo Gero }
/\ Nothing
, "blockfrost-eternl-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo EternlWallet }
{ walletSpec = connectTo Eternl }
/\ Nothing
, "blockfrost-lode-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo LodeWallet }
{ walletSpec = connectTo Lode }
/\ Nothing
, "blockfrost-flint-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo FlintWallet }
{ walletSpec = connectTo Flint }
/\ Nothing
, "blockfrost-nufi-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo NuFiWallet }
{ walletSpec = connectTo NuFi }
/\ Nothing
, "blockfrost-lace-preprod"
/\ (mkBlockfrostPreprodConfig mbApiKey)
{ walletSpec = connectTo LaceWallet }
{ walletSpec = connectTo Lace }
/\ Nothing
]
addLinks walletsWithBlockfrost examples
Expand All @@ -155,26 +138,26 @@ getBlockfrostApiKey = do

wallets :: Map E2EConfigName (ContractParams /\ Maybe String)
wallets = map (map walletName) <$> Map.fromFoldable
[ "nami" /\ testnetConfig' NamiWallet /\ Nothing
, "gero" /\ testnetConfig' GeroWallet /\ Nothing
, "flint" /\ testnetConfig' FlintWallet /\ Nothing
, "eternl" /\ testnetConfig' EternlWallet /\ Nothing
, "lode" /\ testnetConfig' LodeWallet /\ Nothing
, "nufi" /\ testnetConfig' NuFiWallet /\ Nothing
, "lace" /\ testnetConfig' LaceWallet /\ Nothing
[ "nami" /\ testnetConfig' Nami /\ Nothing
, "gero" /\ testnetConfig' Gero /\ Nothing
, "flint" /\ testnetConfig' Flint /\ Nothing
, "eternl" /\ testnetConfig' Eternl /\ Nothing
, "lode" /\ testnetConfig' Lode /\ Nothing
, "nufi" /\ testnetConfig' NuFi /\ Nothing
, "lace" /\ testnetConfig' Lace /\ Nothing
, "nami-mainnet" /\ mainnetNamiConfig /\ Nothing
, "nami-mock" /\ testnetConfig' NamiWallet /\ Just NamiWallet
, "gero-mock" /\ testnetConfig' GeroWallet /\ Just GeroWallet
, "flint-mock" /\ testnetConfig' FlintWallet /\ Just FlintWallet
, "lode-mock" /\ testnetConfig' LodeWallet /\ Just LodeWallet
, "plutip-nami-mock" /\ testnetConfig' NamiWallet /\ Just NamiWallet
, "plutip-gero-mock" /\ testnetConfig' GeroWallet /\ Just GeroWallet
, "plutip-flint-mock" /\ testnetConfig' FlintWallet /\ Just FlintWallet
, "plutip-lode-mock" /\ testnetConfig' LodeWallet /\ Just LodeWallet
, "plutip-nufi-mock" /\ testnetConfig' NuFiWallet /\ Just NuFiWallet
, "nami-mock" /\ testnetConfig' Nami /\ Just Nami
, "gero-mock" /\ testnetConfig' Gero /\ Just Gero
, "flint-mock" /\ testnetConfig' Flint /\ Just Flint
, "lode-mock" /\ testnetConfig' Lode /\ Just Lode
, "plutip-nami-mock" /\ testnetConfig' Nami /\ Just Nami
, "plutip-gero-mock" /\ testnetConfig' Gero /\ Just Gero
, "plutip-flint-mock" /\ testnetConfig' Flint /\ Just Flint
, "plutip-lode-mock" /\ testnetConfig' Lode /\ Just Lode
, "plutip-nufi-mock" /\ testnetConfig' NuFi /\ Just NuFi
]
where
testnetConfig' :: Wallet -> ContractParams
testnetConfig' :: KnownWallet -> ContractParams
testnetConfig' wallet =
testnetConfig
{ walletSpec =
Expand All @@ -185,7 +168,7 @@ wallets = map (map walletName) <$> Map.fromFoldable
mainnetNamiConfig =
mainnetConfig
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName NamiWallet) { cip95: false }
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

mkBlockfrostPreviewConfig :: Maybe String -> ContractParams
Expand Down
5 changes: 4 additions & 1 deletion examples/Cip30.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import Cardano.Wallet.Cip30
import Cardano.Wallet.Cip30.TypeSafe as Cip30
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, liftContractAffM, runContract)
Expand All @@ -35,7 +37,8 @@ import Effect.Exception (error)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

example :: ContractParams -> Effect Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/DropTokens.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import Cardano.Types.MultiAsset as MultiAsset
import Cardano.Types.Value as Value
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, runContract)
Expand All @@ -25,7 +27,8 @@ import Test.Ctl.Fixtures (nullPaymentPubKeyHash)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

example :: ContractParams -> Effect Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/ExUnits.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import Cardano.Types.TransactionUnspentOutput (toUtxoMap)
import Contract.Address (mkAddress)
import Contract.Config
( ContractParams
, KnownWallet(Nami)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Credential (Credential(PubKeyHashCredential))
import Contract.Log (logInfo')
Expand All @@ -47,7 +49,8 @@ import JS.BigInt as BigInt

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "nami" { cip95: false }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Nami) { cip95: false }
}

contract :: Contract Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/Gov/DelegateVoteAbstain.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import Cardano.Types.PublicKey (hash) as PublicKey
import Cardano.Types.Transaction (hash) as Transaction
import Contract.Config
( ContractParams
, KnownWallet(Eternl)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logDebug', logInfo')
import Contract.Monad (Contract, launchAff_, runContract)
Expand All @@ -28,7 +30,8 @@ import Effect.Exception (error)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "eternl" { cip95: true }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Eternl) { cip95: true }
}

example :: ContractParams -> Effect Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/Gov/ManageDrep.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import Cardano.Types
import Cardano.Types.Transaction (hash) as Transaction
import Contract.Config
( ContractParams
, KnownWallet(Eternl)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, runContract)
Expand All @@ -35,7 +37,8 @@ import Effect.Exception (message)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "eternl" { cip95: true }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Eternl) { cip95: true }
}

example :: ContractParams -> Effect Unit
Expand Down
5 changes: 4 additions & 1 deletion examples/Gov/ManageDrepScript.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import Cardano.Types.RedeemerDatum (unit) as RedeemerDatum
import Cardano.Types.Transaction (hash) as Transaction
import Contract.Config
( ContractParams
, KnownWallet(Eternl)
, WalletSpec(ConnectToGenericCip30)
, testnetConfig
, walletName
)
import Contract.Log (logInfo')
import Contract.Monad (Contract, launchAff_, runContract)
Expand All @@ -41,7 +43,8 @@ import Effect.Exception (message)

main :: Effect Unit
main = example $ testnetConfig
{ walletSpec = Just $ ConnectToGenericCip30 "eternl" { cip95: true }
{ walletSpec =
Just $ ConnectToGenericCip30 (walletName Eternl) { cip95: true }
}

example :: ContractParams -> Effect Unit
Expand Down
Loading

0 comments on commit 01a5ee7

Please sign in to comment.