Skip to content

Commit

Permalink
PLT-6704: Contract only with a wallet context
Browse files Browse the repository at this point in the history
  • Loading branch information
yveshauser committed Sep 18, 2023
1 parent 0859b77 commit 805ec3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
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

0 comments on commit 805ec3c

Please sign in to comment.