Skip to content

Commit

Permalink
PKG -- [fcl] fix block height issue in events subcriber (#1177)
Browse files Browse the repository at this point in the history
* fix block height issue in events

* update docs for events subcribe

* remove log

* add change set

* Update docs/reference/api.md

Co-authored-by: Greg Santos <greg.santos@dapperlabs.com>

Co-authored-by: Greg Santos <greg.santos@dapperlabs.com>
  • Loading branch information
hotrungnhan and gregsantos committed May 18, 2022
1 parent a0c6599 commit e38f9fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/empty-ants-switch.md
@@ -0,0 +1,6 @@
---
"@onflow/fcl": patch
---

- Fix events subcribe block height issue
- Add polling rate guide to docs
5 changes: 4 additions & 1 deletion docs/reference/api.md
Expand Up @@ -1654,8 +1654,11 @@ useEffect(() => fcl.tx(txId).subscribe(setTxStatus));
A utility function that lets you set the transaction to get subsequent status updates (via polling) and the finalized result once available.
鈿狅笍The poll rate is set at `10000ms` and will update at that interval for getting new events.
#### Arguments
Note:
鈿狅笍`fcl.eventPollRate` value **could** be set to change the polling rate of all events subcribers, check [FCL Configuration](#configuration) for guide.
#### Arguments
| Name | Type | Description |
| ----------- | ------ | ------------------- |
| `eventName` | string | A valid event name. |
Expand Down
12 changes: 7 additions & 5 deletions packages/fcl/src/events/index.js
Expand Up @@ -4,7 +4,7 @@ import {
block,
getEventsAtBlockHeightRange,
send,
decode
decode,
} from "@onflow/sdk"

const RATE = 10000
Expand All @@ -29,10 +29,12 @@ const HANDLERS = {
} else {
let next = await block()
ctx.put(HIGH_WATER_MARK, next)
const data = await send([
getEventsAtBlockHeightRange(ctx.self(), hwm.height, next.height - 1),
]).then(decode)
for (let d of data) ctx.broadcast(UPDATED, d.data)
if (hwm.height < next.height) {
const data = await send([
getEventsAtBlockHeightRange(ctx.self(), hwm.height + 1, next.height),
]).then(decode)
for (let d of data) ctx.broadcast(UPDATED, d.data)
}
ctx.put(TICK, await scheduleTick(ctx))
}
},
Expand Down

0 comments on commit e38f9fe

Please sign in to comment.