Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ jobs:
else
echo "stellar-scaffold already installed. Clear cache to force reinstall."
fi
- name: Start Stellar local network
uses: stellar/quickstart@main
with:
enable: "core,rpc"
- name: Add master account as default identity
run: |
mkdir -p .config/stellar/identity
echo 'secret_key = "SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L"' > .config/stellar/identity/me.toml
- run: npm ci
- run: npm run lint
- run: npx prettier . --check
Expand Down
1 change: 0 additions & 1 deletion src/components/GuessTheNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export const GuessTheNumber = () => {
// Create a transaction using the contract client
const tx = await game.guess(
{ a_number: BigInt(guess), guesser: address },
// @ts-expect-error js-stellar-sdk has bad typings; publicKey is, in fact, allowed
{ publicKey: address },
)

Expand Down
21 changes: 10 additions & 11 deletions src/hooks/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ export function useSubscription(
pollInterval = 5000,
) {
const id = `${contractId}:${topic}`
paging[id] = paging[id] || {}
if (!paging[id]) paging[id] = {}
const page = paging[id]
Comment on lines +39 to +40
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this change was necessary. Was a linter mad about it? Seems like equivalent logic, if I'm not mistaken.


React.useEffect(() => {
let timeoutId: NodeJS.Timeout | null = null
let stop = false

async function pollEvents(): Promise<void> {
try {
if (!paging[id].lastLedgerStart) {
if (!page.lastLedgerStart) {
const latestLedgerState = await server.getLatestLedger()
paging[id].lastLedgerStart = latestLedgerState.sequence
page.lastLedgerStart = latestLedgerState.sequence
}

// lastLedgerStart is now guaranteed to be a number
const lastLedger = paging[id].lastLedgerStart
const lastLedger = page.lastLedgerStart

const response = await server.getEvents(
paging[id].pagingToken
page.pagingToken
? {
cursor: paging[id].pagingToken,
cursor: page.pagingToken,
filters: [
{
contractIds: [contractId],
Expand All @@ -79,9 +79,9 @@ export function useSubscription(
},
)

paging[id].pagingToken = undefined
page.pagingToken = undefined
if (response.latestLedger) {
paging[id].lastLedgerStart = response.latestLedger
page.lastLedgerStart = response.latestLedger
}
if (response.events && response.events.length > 0) {
response.events.forEach((event) => {
Expand All @@ -94,9 +94,8 @@ export function useSubscription(
)
}
})
// Store the cursor from the response for pagination
if (response.cursor) {
paging[id].pagingToken = response.cursor
page.pagingToken = response.cursor
}
}
} catch (error) {
Expand Down
Loading