fix variable-length array destructuring bug in spend-permissions complete integration example#1525
Open
weirdDevelop wants to merge 1 commit into
Open
fix variable-length array destructuring bug in spend-permissions complete integration example#1525weirdDevelop wants to merge 1 commit into
weirdDevelop wants to merge 1 commit into
Conversation
…gration example prepareSpendCallData returns 1 call when permission is already registered and 2 calls on first use. The guide destructures it as a fixed 2-element array, causing spendCall=undefined on repeat executions and silently passing undefined into wallet_sendCalls. Replaces fixed destructure with the full array, matching the reference page's own example. Also adds unit clarification for remainingSpend.
Collaborator
🟡 Heimdall Review Status
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Complete Integration Example in
docs/base-account/improve-ux/spend-permissions.mdxcontains a workflow bug that causes silent runtime failures on repeat executions of a
spend permission.
Problem
Bug 1 — Fixed destructuring of a variable-length array
The guide currently does:
According to the
prepareSpendCallDatareference page, the function returns either 1 or 2calls depending on whether the permission is already registered onchain:
[approveWithSignatureCall, spendCall]— 2 elements[spendCall]— 1 elementWhen only 1 element is returned,
spendCallbecomesundefined. The guide then passes[approveCall, undefined]directly intowallet_sendCalls, which fails at runtime with noclear error. The first execution succeeds, every subsequent one silently breaks — making
this extremely hard to diagnose.
Bug 2 — Missing unit context on
remainingSpendcheckThe guide checks:
remainingSpendis returned in the token's smallest unit (wei for ETH, 6-decimal unitsfor USDC). There is no unit guidance anywhere on the page, so a developer comparing
remainingSpendto a human-readableamountvalue will get incorrect logic for anyERC-20 token that isn't 18 decimals.
Fix
Bug 1 — Replace fixed destructuring with the full array, matching what the
prepareSpendCallDatareference page itself demonstrates:Bug 2 — Add a one-line inline comment after the
remainingSpendcomparison clarifyingunits:
Verification
prepareSpendCallDatareturn type confirmed against:/base-account/reference/spend-permission-utilities/prepareSpendCallDatagetPermissionStatusreturn shape confirmed against:/base-account/reference/spend-permission-utilities/getPermissionStatusspendCallsas a whole array — neverdestructured. The guide contradicts its own reference.
Impact
This is a timing-dependent failure. The first execution always succeeds (2-element array,
destructuring works). Every subsequent execution silently fails (1-element array,
spendCall = undefinedpassed towallet_sendCalls). Developers who test once and shipwill hit this in production.
Files Changed
docs/base-account/improve-ux/spend-permissions.mdx