Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-6704: Contract only with a wallet context #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions src/Component/App.purs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ autoConnectWallet walletBrand onSuccess = liftEffect (window >>= Wallet.cardano)

-- | Use this switch to autoconnect the wallet for testing.
debugWallet :: Maybe WalletBrand
debugWallet = Just Nami -- Just Lace -- Nami -- Eternl -- Nami -- Nothing
debugWallet = Nothing -- Nami -- Eternl -- Nami -- Nothing

data DisplayOption = Default | About

Expand Down Expand Up @@ -146,38 +146,38 @@ mkApp = do

possibleWalletInfoRef <- useStateRef walletInfoName possibleWalletInfo
possibleWalletContext /\ setWalletContext <- useState' Nothing
possibleWalletContextRef <- useStateRef' possibleWalletContext

possibleContractMap /\ setContractMap <- useState' Nothing

let
walletCtx = un WalletContext <$> possibleWalletContext

useAff ((\w -> w.usedAddresses /\ w.changeAddress) <$> walletCtx) do
let
(usedAddresses :: Array Bech32) = fromMaybe [] $ _.usedAddresses <$> walletCtx
(tokens :: Array AssetId) = map (uncurry AssetId) <<< fromMaybe [] $ Array.fromFoldable <<< Map.keys <<< un NonAdaAssets <<< nonAdaAssets <<< _.balance <$> walletCtx

reqInterval = RequestInterval (Milliseconds 50.0)
pollInterval = PollingInterval (Milliseconds 60_000.0)
filterContracts getContractResponse = case un ContractHeader getContractResponse.resource of
{ block: Nothing } -> true
{ block: Just (BlockHeader { blockNo: BlockNumber blockNo }) } -> blockNo > 909000 -- 904279
maxPages = Just (MaxPages 1)
params = { partyAddresses: usedAddresses, partyRoles: tokens, tags: [] }

ContractWithTransactionsStream contractStream <- Streaming.mkContractsWithTransactions pollInterval reqInterval params filterContracts maxPages runtime.serverURL
supervise do
void $ forkAff do
untilJust do
updates <- liftEffect $ contractStream.getLiveState
let
new = mkAppContractInfoMap possibleWalletContext updates
liftEffect $ setContractMap $ Just new
delay (Milliseconds 1_000.0)
pure Nothing
possibleWalletContextRef <- useStateRef' possibleWalletContext
possibleContractMap /\ setContractMap <- useState' Nothing

contractStream.start
useAff ((\w -> w.usedAddresses /\ w.changeAddress) <$> walletCtx) $
case walletCtx of
Just ctx -> do
let
reqInterval = RequestInterval (Milliseconds 50.0)
pollInterval = PollingInterval (Milliseconds 60_000.0)
filterContracts getContractResponse = case un ContractHeader getContractResponse.resource of
{ block: Nothing } -> true
{ block: Just (BlockHeader { blockNo: BlockNumber blockNo }) } -> blockNo > 909000 -- 904279
maxPages = Just (MaxPages 1)
tokens = map (uncurry AssetId) <<< Array.fromFoldable <<< Map.keys <<< un NonAdaAssets <<< nonAdaAssets $ ctx.balance
params = { partyAddresses: ctx.usedAddresses, partyRoles: tokens, tags: [] }

ContractWithTransactionsStream contractStream <- Streaming.mkContractsWithTransactions pollInterval reqInterval params filterContracts maxPages runtime.serverURL
supervise do
void $ forkAff do
untilJust do
updates <- liftEffect $ contractStream.getLiveState
let
new = mkAppContractInfoMap possibleWalletContext updates
liftEffect $ setContractMap $ Just new
delay (Milliseconds 1_000.0)
pure Nothing

contractStream.start
Nothing -> pure unit

useLoopAff walletInfoName (Milliseconds 20_000.0) do
pwi <- liftEffect $ readRef possibleWalletInfoRef
Expand Down
2 changes: 1 addition & 1 deletion src/Component/ContractList.purs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ mkContractList = do
buttons
]
, case possibleContracts'' of
Just contracts | not (null contracts) -> DOM.div { className: "row" } $ DOM.div { className: "col-12 mt-3" } do
Just contracts -> DOM.div { className: "row" } $ DOM.div { className: "col-12 mt-3" } do
[ table { striped: Table.striped.boolean true, hover: true }
[ DOM.thead {} do
let
Expand Down
Loading