Repository navigation
feat(studio/scenarios): type the account of an override whose template names none - #42
Conversation
SummaryFor templates whose address is an empty Overall the change is small and works, but there are three things to look at:
For a typed account, an empty or unparsed result (the account doesn't exist, or is owned by another program) leaves the form blank with no message. Add still saves an override for that account. Consider showing "Account not found" or "Not a account" when
Small point: this early return happens after
Unrelated to the scenario editor change, so better in a separate PR. Also, the PR title and body go into the prompt unescaped, and |
There was a problem hiding this comment.
Summary
For templates whose address is a pubkey with no value, the editor now shows an Account input. When the user types a valid address, the editor loads that account, and Add/Update send { pubkey } with it. The Add/Update button stays disabled until the address is valid. Reopening a saved override fills the input from existingAction.account.pubkey. The change is small and works, and the three new tests cover the main paths.
PublicKey in web3.js ^1.98 requires the address to decode to exactly 32 bytes, so isSolanaAddress rejects short base58 strings like "abc".
Issues
- Changing the account throws away edits. Every new valid address goes through
handleActionSelect, which clearsaccountData,modifiedFields,arrayEntryIndexandfetchBeforeUse. Deleting one character and typing it back counts as a new address, because the invalid value in between differs from the restored one. So the account reloads and every field the user changed is lost. Consider reloading only when the address differs from the last one actually loaded, and/or keepingmodifiedFieldsacross the reload. - The editor can show data for an account it isn't targeting. If the user types a valid address and then edits it to something invalid or empty, no new request is made. The request for the earlier address can still finish and fill the fields. Save is disabled in that state, so it doesn't corrupt anything, but the fields don't match the input. Bumping
accountRequestRef.currentand clearingaccountDatawhen the address stops being valid would fix this. - Nothing checks that the account belongs to the template's program. If the account doesn't exist, the user can still save an override with empty
overrides. If it belongs to another program, its parsed data is shown as editable fields. A short note in the UI whengetAccountInforeturnsnullor a different owner would help. - Validation lives only in the button.
addActionToSlotand the update path (lines 837 and 882) depend on the button being disabled. If anything else calls them, they will save{ pubkey: '' }. A cheap guard in those functions would close that off. - Unrelated file in this PR.
.github/workflows/claude-review.ymlhas nothing to do with the scenario editor and isn't mentioned in the PR body. It should go in its own PR. It also puts the PR title and body straight into the prompt; that's acceptable with read-only tools, but it's worth noting.
| const pubkey = event.target.value.trim(); | ||
| setTypedAccount(event.target.value); | ||
| if (selectedAction && pubkey !== typedAccountPubkey && isSolanaAddress(pubkey)) { | ||
| handleActionSelect(selectedAction, pubkey); |
There was a problem hiding this comment.
Every new valid address calls handleActionSelect, which clears accountData, modifiedFields, arrayEntryIndex and fetchBeforeUse. Deleting one character and typing it back counts as a new address, because the invalid value in between differs from the restored one. So the same account reloads and every field the user changed is lost. Consider comparing against the last loaded address (e.g. a ref) rather than the previous input value.
When the input turns invalid or empty, no request is made, so a request already in flight for the old address can still fill the fields. Bumping accountRequestRef.current and clearing accountData there would keep the fields consistent with the input.
| } | ||
| // A PDA template, or one that leaves the account to the override, reads the saved account. | ||
| if (accountPubkey && !addressString) addressString = accountPubkey; | ||
| if (!addressString && leavesAccountToOverride(action.template.address)) { |
There was a problem hiding this comment.
This early return skips the fetch but leaves accountRequestRef already incremented, so that part is fine. One gap remains for a typed account: if getAccountInfo returns value: null (no such account) or an account owned by another program, the user can still save. They get an empty override or one built from unrelated parsed fields. A short notice in the UI for that case would help.
| modifiedFields: Array.from(modifiedFields), | ||
| fetchBeforeUse: fetchBeforeUse, | ||
| account: action.template?.address, | ||
| account: leavesAccountToOverride(action.template?.address) |
There was a problem hiding this comment.
Validation is enforced only through the button's disabled prop. A guard here, and in the update path at line 882, such as if (needsTypedAccount && !hasTypedAccount) return;, would stop any other caller from saving { pubkey: '' }.
…issing or foreign one
SummaryThe PR adds an "Account" field to the scenario editor for templates whose address is an empty Points to look at
This blocks Update when the saved account's owner differs from
When
The button is enabled while the typed account is still loading: |
…archable picker, pasting its address
There was a problem hiding this comment.
Summary
This PR adds an "Account" combobox to the scenario editor for templates whose address is a pubkey with no value. A valid address triggers a load of that account. Add and Update send { pubkey: typedAccount } and are blocked until the address is valid and loaded. It also adds an onQueryChange prop to the shared Combobox and updates MockCombobox to match.
Overall the change is well reasoned. The stale-response guard is reused correctly, and Add/Update is hidden while loadingAccountData, so a save can't race the load. A few points:
- Behaviour the description leaves out: the code also adds owner/existence validation (
'missing'/'foreign'), which blocks saves. That includes reopening an existing saved override whose account has since closed or whose owner differs fromidl.address. This is a real behaviour change and should be described, ideally with a test for each case. - Unrelated file:
.github/workflows/claude-review.ymlhas nothing to do with the feature. Please move it to its own PR so it gets its own review. It adds a write-scoped job and puts the untrusted PR title and body into the prompt. - Error handling: an RPC error or a thrown fetch is not handled separately (see the inline comment).
| if (accountPubkey && leavesAccountToOverride(action.template.address)) { | ||
| const programId = action.template.idl.address; | ||
| if (!account) issue = 'missing'; | ||
| else if (programId && account.owner !== programId) issue = 'foreign'; |
There was a problem hiding this comment.
account.owner !== idl.address assumes the IDL's program owns every account the template edits. That fails when the IDL address differs from the deployed owner, for example Pyth price-update accounts owned by the receiver program, or a template whose IDL carries a stale or devnet address. It would block legitimate saves, including Update on overrides that were saved before this PR. Could you check this owner assumption against all 66 affected templates? Alternatively, make 'foreign' a warning rather than a hard block.
| let issue: TypedAccountIssue = null; | ||
| if (accountPubkey && leavesAccountToOverride(action.template.address)) { | ||
| const programId = action.template.idl.address; | ||
| if (!account) issue = 'missing'; |
There was a problem hiding this comment.
An RPC error response ({ error: ... } with no result) is reported as 'missing' ("No account at this address."), which is misleading. The opposite also happens: if fetch or .json() throws, the catch leaves typedAccountIssue at null, so an account that was never verified can be saved. Consider checking accountInfoData.error, and adding an error state to the catch.
|
|
||
| const renderAccountOption = (option: TokenSelectorOption) => ( | ||
| <ComboboxOption key={option.id} value={option}> | ||
| <ComboboxLabel>{option.metadata?.symbol}</ComboboxLabel> |
There was a problem hiding this comment.
Options come from customValueOption, so the selected account is labelled Custom · <address>. "Custom" makes sense for the token selectors, but this field only ever holds a pasted address. Consider rendering option.value directly here.
| return; | ||
| } | ||
| // A finished read stays, so choosing its address again keeps the edits; a read in flight must not fill the fields | ||
| if (loadingAccountData) { |
There was a problem hiding this comment.
After a finished read, clearing the field keeps the previous account's decoded fields on screen with an empty Account input. That is intentional so the edits survive re-selecting the same address, but it may confuse users. A short hint, or dimming the fields while the account is empty, would help.
… one the RPC could not read
There was a problem hiding this comment.
Summary
The PR adds an "Account" combobox for templates whose address is a pubkey with no value. It checks the typed address, reads the account (and flags it as missing, owned by another program, or unreadable), and saves account: { pubkey } on Add and Update. Combobox gets an onQueryChange prop, and the test mock is updated to match.
The approach is sound. The stale-response handling extends the existing accountRequestRef guard, and hiding the button while a read is in flight means a save can't skip the checks. A few points are worth a look:
- Owner check could block existing presets (main risk). An override is rejected as
foreignwhen the account's owner isn'tidl.address, and on reopen this now disables Update for saved overrides. For templates where the edited account is owned by a different program than the IDL's address (oracle and receiver setups, IDLs with a staleaddress), saved preset overrides that used to update fine will be stuck. Consider showing this as a warning instead of blocking. - Silent loss of edits. Picking a different account calls
handleActionSelect, which clearsaccountDataandmodifiedFields. When editing a saved override, the restored overrides disappear with no prompt. - Change for raw-layout templates on reopen. No-IDL templates with a fixed address now trigger a
getAccountInfoon reopen, becauseaccountPubkeyis passed. This is harmless but unintended, and it's not in the PR description. - Unrelated file.
.github/workflows/claude-review.ymlis part of this diff but has nothing to do with the feature. It would be cleaner as its own PR. - Minor UX issues.
- The selected account shows in the list as
Custom · <address>, becausecustomValueOptionis reused. A plain address would read better here. - After a
missingorforeignresult, picking the same address again doesn't re-read it. Only anunverifiedresult allows a retry, so an account created afterwards can't be picked up without switching to another address first.
- The selected account shows in the list as
Tests cover the main paths. None of the three new tests covers the foreign, missing or unverified branches.
| const programId = action.template.idl?.address; | ||
| if (accountInfoData.error) issue = 'unverified'; | ||
| else if (!account) issue = 'missing'; | ||
| else if (programId && account.owner !== programId) issue = 'foreign'; |
There was a problem hiding this comment.
This blocks saving whenever account.owner !== idl.address. Some bundled templates may edit accounts owned by a different program than the IDL's address, such as oracle and receiver accounts, or IDLs whose address isn't the deployed program. Because reopen also runs this check, Update is disabled for saved preset overrides that worked before this PR. Was this checked against all 66 affected templates? A non-blocking warning may be safer.
| setTypedAccount(pubkey); | ||
| if (!selectedAction) return; | ||
| if (pubkey) { | ||
| if (pubkey !== loadedTypedAccountRef.current) handleActionSelect(selectedAction, pubkey); |
There was a problem hiding this comment.
When editing a saved override, choosing a different account goes through handleActionSelect, which resets accountData and modifiedFields. The overrides restored on reopen are dropped with no warning. Either keep modifiedFields and re-apply them over the new account's data, or confirm with the user before discarding.
| // Without an IDL, as on raw-layout templates, only a given account is read: nothing is decoded, | ||
| // but the read checks that the account exists. | ||
| const hasIdl = !!action.template?.idl; | ||
| if (!action.template?.address || (!hasIdl && !accountPubkey)) { |
There was a problem hiding this comment.
Reopen passes action.account?.pubkey for every template. No-IDL templates with a fixed address used to return early here, and now they make a base64 getAccountInfo call and set typedAccount even though no field is shown. If the read is only meant for typed accounts, gate it on leavesAccountToOverride(action.template.address).
The scenario editor could not create an override for a template whose address is a
pubkeywith no value: it sent the template's empty address and had no field for the account. Most bundled templates are like that (Kamino, Drift, Phoenix, Pyth, Doves, Velocity and others), so for them only presets and the AI could target an account.account: { pubkey }with the picked address. Templates with a fixed address or a PDA keep their own address.onQueryChangeprop for the invalid-address line, andMockComboboxfollows it.The card sits above "Fetch before use", because a new account reloads the action and resets that switch.
Tests in
scenario-editor.test.tsxcover adding with a picked account, retyping, missing, foreign and unreadable accounts, a template without an IDL, a read cleared in flight and reopening a saved override; the new ones fail without the change.