Skip to content

Commit 9536f33

Browse files
authored
[renderers-js] Fix missing getNextOptionalAccount (#715)
This PR uses the `programId` optional account strategy as a fallback strategy to ensure the `getNextOptionalAccount` helper is always generated when optional account exist on the instruction.
1 parent d6a664b commit 9536f33

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

.changeset/stupid-bobcats-hug.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-js': patch
3+
---
4+
5+
Fix an issue where `getNextOptionalAccount` would not get generated even if optional accounts exist on the instruction.

packages/renderers-js/public/templates/fragments/instructionParseFunction.njk

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ export function {{ instructionParseFunction }}<
4747
accountIndex += 1;
4848
return accountMeta;
4949
}
50-
{% if hasOptionalAccounts and instruction.optionalAccountStrategy === 'programId' %}
51-
const getNextOptionalAccount = () => {
52-
const accountMeta = getNextAccount();
53-
return accountMeta.address === {{ programAddressConstant }} ? undefined : accountMeta;
54-
};
55-
{% elif hasOptionalAccounts and instruction.optionalAccountStrategy === 'omitted' %}
50+
{% if hasOptionalAccounts and instruction.optionalAccountStrategy === 'omitted' %}
5651
let optionalAccountsRemaining = instruction.accounts.length - {{ minimumNumberOfAccounts }};
5752
const getNextOptionalAccount = () => {
5853
if (optionalAccountsRemaining === 0) return undefined;
5954
optionalAccountsRemaining -= 1;
6055
return getNextAccount();
6156
};
57+
{% elif hasOptionalAccounts %}
58+
const getNextOptionalAccount = () => {
59+
const accountMeta = getNextAccount();
60+
return accountMeta.address === {{ programAddressConstant }} ? undefined : accountMeta;
61+
};
6262
{% endif %}
6363
{% endif %}
6464
return {

0 commit comments

Comments
 (0)