I had some time to debug this further and it was a file system permissions issue on my end causing the problem with not being able to resolve the “Module not found” error. I was using a network drive, so stopped using that and it fixed it. In order to get it to compile and then replicate the issue I had to do the following:
Change daml/User.daml
file so it has an additional component to the key:
template Counter with
owner: Party
count: Int
code : Int
where
signatory owner
key (owner, code) : (Party, Int)
maintainer key._1
preconsuming choice Increment: ContractId Counter with
controller owner
do
create this with count = count + 1
From t
folder, run daml start
.
Change the components/Counter.tsx
to add a button to change the key:
import React, { useState } from 'react'
import { Button, List, ListItem } from 'semantic-ui-react';
import { User } from '@daml.js/t-0.1.0/lib';
import { useStreamFetchByKeys, useParty } from '@daml/react';
const Counter: React.FC = () => {
const me = useParty();
const [code, setCode] = useState("0");
const result = useStreamFetchByKeys(
User.Counter,
() => [{_1: me, _2: code}], [code]
);
return (
<div>
<Button onClick={_ => setCode((parseInt(code) + 1).toString())}>Increment code</Button>
<List relaxed>
{result.contracts.map(message => {
return (
<ListItem
className='test-select-message-item'
key={1}>
<strong>{message ? message.payload.count : "not found"}</strong>
</ListItem>
);
})}
</List>
</div>
);
};
export default Counter;
In all the typescript code change the imports from '@daml.js/t'
to '@daml.js/t-0.1.0/lib'
Then from ui
folder:
npm install daml.js/t-0.1.0
npm install
npm start
(I know I shouldn’t have to change all the imports or do npm install daml.js/t-0.1.0
but I can’t seem to get it compiling otherwise).
Login as alice
and open up the JS console. Then rapidly double click the “Increment code” button, I see “useStreamFetchByKeys: WebSocket connection failed.” error in the console. The app still seems to keeping working after this if you click the button normally again. In my original code my app didn’t seem to recover, unfortunately can’t share the original code, so not sure if this is the same problem.