-
Notifications
You must be signed in to change notification settings - Fork 133
Add useFlowSchedule hook #2653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add useFlowSchedule hook #2653
Conversation
🦋 Changeset detectedLatest commit: 35d80ff The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for GitHub.
|
.changeset/upset-cities-start.md
Outdated
"@onflow/react-sdk": minor | ||
--- | ||
|
||
Added useFlowSchedule hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this more descriptive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved 👍
High = 2, | ||
} | ||
|
||
export enum TransactionStatus { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this already exported from FCL? If so, should we use that type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this type is specific for Scheduled Transactions
import {CONTRACT_ADDRESSES, CADENCE_UFIX64_PRECISION} from "../constants" | ||
import {parseUnits} from "viem/utils" | ||
|
||
export enum TransactionPriority { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we export this from FCL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this type is specific for Scheduled Transactions
Cancelled = 4, | ||
} | ||
|
||
export interface TransactionInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same q
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is specific to the scripts used to retrieve data from the manager, so it's specific for the implementation
// Gets a transaction by ID | ||
// Equivalent to: flow schedule get <transaction-id> [--include-handler-data] | ||
get: ( | ||
transactionId: bigint, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have mixed txId
and transactionId
across the React SDK. We should probably be consistent. I'm for transactionId
for clarity, so this is fine, but curious what everyone else thinks. cc @jribbink
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, we are using txId in react-sdk. i just updated it to have txId instead of transactionId for consistency 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same discussion goes for the numeric values. FCL traditionally uses string
to represent numbers. We don't use/support bigint elsewhere so I'm hesitant to introduce this inconsistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, just updated to string for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive support for Flow blockchain scheduled transactions through new React hooks. The implementation provides setup, listing, fetching, and canceling capabilities for scheduled transactions, following patterns similar to the Flow CLI's scheduled transaction functionality.
Key changes:
- Added four new hooks for scheduled transaction management
- Implemented type-safe transaction status and priority enums
- Integrated contract addresses for scheduler utilities across networks
- Created demo UI for testing the new functionality
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/react-sdk/src/hooks/useFlowScheduledTransactionSetup.ts |
Hook for one-time scheduler manager setup in user accounts |
packages/react-sdk/src/hooks/useFlowScheduledTransactionList.ts |
Hook for listing all scheduled transactions for an account |
packages/react-sdk/src/hooks/useFlowScheduledTransactionCancel.ts |
Hook for canceling scheduled transactions with fee refunds |
packages/react-sdk/src/hooks/useFlowScheduledTransaction.ts |
Hook for fetching individual scheduled transaction details |
packages/react-sdk/src/hooks/index.ts |
Exports the new hooks and types |
packages/react-sdk/src/constants.ts |
Added scheduler contract addresses for all networks |
packages/demo/src/components/hook-cards/use-flow-scheduled-transaction-card.tsx |
Interactive demo component showcasing all scheduler hooks |
packages/demo/src/components/content-sidebar.tsx |
Added sidebar navigation for the demo |
packages/demo/src/components/content-section.tsx |
Integrated demo card into main content |
.changeset/upset-cities-start.md |
Changeset documenting the new feature |
Test files | Comprehensive unit tests for all new hooks |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
packages/react-sdk/src/constants.ts
Outdated
FlowTransactionScheduler: "0x0000000000000000", | ||
FlowTransactionSchedulerUtils: "0x0000000000000000", |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The placeholder addresses for mainnet (0x0000000000000000) could cause runtime errors if used before being updated. Consider adding runtime validation to throw a descriptive error when these placeholder addresses are detected, helping developers identify the issue quickly.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Chase Fleming <[email protected]>
Co-authored-by: Chase Fleming <[email protected]>
@chasefleming Improved playground card with full description of scheduled transactions and description of each feature in each tab (list, setup, cancel, get) 🚀 |
packages/react-sdk/src/constants.ts
Outdated
FlowTransactionScheduler: "0x0000000000000000", | ||
FlowTransactionSchedulerUtils: "0x0000000000000000", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can update these now, it's just going to be the service address https://contractbrowser.com/A.e467b9dd11fa00df.FlowServiceAccount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any concerns about pagination/limits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it make sense even if the number probably won't be that high because it will only show the ones in "Pending" state. To avoid overengineering this (which would be the part of the indexer API), i think we can:
- Add a limit parameter with a default
- Update the Cadence script to apply the limit after fetching
Alternatively, we could leverage getTransactionIDsByTimestampRange from the FlowTransactionSchedulerUtils contract for time-based pagination, which feel more natural for scheduled transactions. This would let users fetch transactions by time windows while still applying a limit to prevent unbounded queries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sounds good, let's just ship as is then and worry about pagination as future scope 👍
} from "./useFlowScheduledTransactionList" | ||
|
||
export interface UseFlowScheduledTransactionArgs { | ||
scheduledTxId?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts about renaming this arg to simply txId
everywhere?
From a DevEx angle, we're going to try to mostly hide the distinction between TX ID/scheduled TX ID through SDKs/APIs.
Devs will already be able to use scheduled tx IDs as txId
in useFlowTransaction
/useFlowTransactionResult
, so this would be consistent.
The idea is that if we frame and support scheduled tx id as interchangeable with regular tx IDs everywhere, the developers do not need to learn this distinction between identifier types.
Added hook with core scheduled transactions functionalities as in flow cli.