-
Notifications
You must be signed in to change notification settings - Fork 132
Add useBridgeTokenFromEvm hook #2592
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
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 4175aab The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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.
💡 Enable Vercel Agent with $100 free credit for automated AI reviews |
ecfd844
to
e1393ed
Compare
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 a new React hook useCrossVmReceiveToken
to enable transferring fungible tokens from EVM to Cadence on the Flow blockchain. The hook provides a user-friendly interface for bridging ERC20 tokens to their corresponding Cadence vault equivalents.
- Added
useCrossVmReceiveToken
hook with comprehensive Cadence transaction logic for cross-VM token bridging - Implemented comprehensive test coverage for both successful and error scenarios
- Created demo UI component with form inputs and transaction status display
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
packages/react-sdk/src/hooks/useCrossVmReceiveToken.ts | Core hook implementation with Cadence transaction generation |
packages/react-sdk/src/hooks/useCrossVmReceiveToken.test.ts | Unit tests covering various scenarios and edge cases |
packages/react-sdk/src/hooks/index.ts | Export declaration for the new hook |
packages/demo/src/constants.ts | Added ClickToken contract address for testnet |
packages/demo/src/components/container.tsx | Integration of new demo component |
packages/demo/src/components/cards/cross-vm-receive-token-card.tsx | Interactive demo UI for testing the hook |
.changeset/chilly-kangaroos-train.md | Changeset documentation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
const clickTokenAddress = getContractAddress("ClickToken", currentNetwork) | ||
return { | ||
name: "ClickToken", | ||
vaultIdentifier: `A.${clickTokenAddress.replace("0x", "")}.EVMVMBridgedToken_a7cf2260e501952c71189d04fad17c704dfb36e6.Vault`, |
Copilot
AI
Aug 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 hard-coded token identifier EVMVMBridgedToken_a7cf2260e501952c71189d04fad17c704dfb36e6
contains what appears to be a magic value. Consider extracting this to a constant or making it configurable to improve maintainability.
vaultIdentifier: `A.${clickTokenAddress.replace("0x", "")}.EVMVMBridgedToken_a7cf2260e501952c71189d04fad17c704dfb36e6.Vault`, | |
vaultIdentifier: `A.${clickTokenAddress.replace("0x", "")}.${EVM_VM_BRIDGED_TOKEN_IDENTIFIER}.Vault`, |
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.
Ok, but hardcoded just for the sake of running the demo
// | ||
// Set a cap on the withdrawable bridge fee | ||
var approxFee = FlowEVMBridgeUtils.calculateBridgeFee( | ||
bytes: 400_000 // 400 kB as upper bound on movable storage used in a single transaction |
Copilot
AI
Aug 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 magic number 400_000
for calculating bridge fees should be extracted to a named constant to improve code maintainability and make it easier to adjust if needed.
bytes: 400_000 // 400 kB as upper bound on movable storage used in a single transaction | |
let BRIDGE_FEE_UPPER_BOUND_BYTES = 400_000 // 400 kB as upper bound on movable storage used in a single transaction | |
var approxFee = FlowEVMBridgeUtils.calculateBridgeFee( | |
bytes: BRIDGE_FEE_UPPER_BOUND_BYTES |
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.
Ok, but hardcoded just for the sake of running the demo
self.scopedProvider <- ScopedFTProviders.createScopedFTProvider( | ||
provider: providerCapCopy, | ||
filters: [ providerFilter ], | ||
expiration: getCurrentBlock().timestamp + 1.0 |
Copilot
AI
Aug 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 expiration time of 1.0
seconds is a magic number that should be extracted to a named constant for better maintainability and clarity of intent.
expiration: getCurrentBlock().timestamp + 1.0 | |
expiration: getCurrentBlock().timestamp + SCOPED_FT_PROVIDER_EXPIRATION_SECONDS |
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.
Ok, but hardcoded just for the sake of running the demo
* | ||
* @returns The mutation object used to send the transaction. | ||
*/ | ||
export function useCrossVmReceiveToken({ |
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 question on naming from the other pr.
…k-ft-evm-to-cadence
Deployment failed with the following error:
|
Closes #2591