diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5df625..5d0f5da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/src/components/GuessTheNumber.tsx b/src/components/GuessTheNumber.tsx index 7b24a68..905ff88 100644 --- a/src/components/GuessTheNumber.tsx +++ b/src/components/GuessTheNumber.tsx @@ -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 }, ) diff --git a/src/hooks/useSubscription.ts b/src/hooks/useSubscription.ts index 98d5293..110fc0e 100644 --- a/src/hooks/useSubscription.ts +++ b/src/hooks/useSubscription.ts @@ -36,7 +36,8 @@ export function useSubscription( pollInterval = 5000, ) { const id = `${contractId}:${topic}` - paging[id] = paging[id] || {} + if (!paging[id]) paging[id] = {} + const page = paging[id] React.useEffect(() => { let timeoutId: NodeJS.Timeout | null = null @@ -44,18 +45,17 @@ export function useSubscription( async function pollEvents(): Promise { 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], @@ -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) => { @@ -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) {