-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove non-signer function overloads in JS experimental (#182)
- Loading branch information
1 parent
dc8dea7
commit 7af4ce6
Showing
87 changed files
with
2,869 additions
and
17,332 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@metaplex-foundation/kinobi": minor | ||
--- | ||
|
||
Remove non-signer function overloads in JS experimental renderer |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@metaplex-foundation/kinobi": patch | ||
--- | ||
|
||
Use generated address constant in instruction pages of JS experimental renderer |
This file contains 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
This file contains 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
62 changes: 62 additions & 0 deletions
62
src/renderers/js-experimental/fragments/instructionFunction.njk
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{ inputTypeFragment }} | ||
|
||
export {{ 'async' if useAsync }} function {{ functionName }}<{{ typeParamsFragment }}>(input: {{ inputTypeCallFragment }}): {{ getReturnType(instructionTypeFragment) }} { | ||
// Program address. | ||
const programAddress = {{ programAddressConstant }}; | ||
|
||
{% if hasAccounts %} | ||
// Original accounts. | ||
const originalAccounts = { | ||
{% for account in instruction.accounts %} | ||
{{ account.name | camelCase }}: { value: input.{{ account.name | camelCase }} ?? null, isWritable: {{ "true" if account.isWritable else "false" }} }, | ||
{% endfor %} | ||
}; | ||
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>; | ||
{% endif %} | ||
|
||
{% if hasAnyArgs %} | ||
// Original args. | ||
const args = { ...input, {{ renamedArgs }} }; | ||
{% endif %} | ||
|
||
{% if hasResolver %} | ||
// Resolver scope. | ||
const resolverScope = { programAddress{{ ', accounts' if hasAccounts }}{{ ', args' if hasAnyArgs }} }; | ||
{% endif %} | ||
|
||
{{ resolvedFragment }} | ||
|
||
{% if hasAccounts %} | ||
const getAccountMeta = getAccountMetaFactory(programAddress, '{{ 'omitted' if instruction.optionalAccountStrategy === 'omitted' else 'programId' }}'); | ||
{% endif %} | ||
const instruction = { | ||
{%- if hasAccounts -%} | ||
accounts: [ | ||
{% for account in instruction.accounts %} | ||
getAccountMeta(accounts.{{ account.name | camelCase }}), | ||
{% endfor %} | ||
{% if hasRemainingAccounts %} | ||
...remainingAccounts, | ||
{% endif %} | ||
] | ||
{%- if hasLegacyOptionalAccounts -%} | ||
.filter(<T>(x: T | undefined): x is T => x !== undefined) | ||
{% endif %} | ||
, | ||
{%- elif hasRemainingAccounts -%} | ||
accounts: remainingAccounts, | ||
{% endif %} | ||
programAddress, | ||
{% if hasDataArgs %} | ||
data: {{ encoderFunction }}.encode(args as {{ argsTypeFragment }}), | ||
{% elif hasData %} | ||
data: {{ encoderFunction }}.encode({}), | ||
{% endif %} | ||
} as {{ instructionTypeFragment }}; | ||
|
||
{% if hasByteDeltas %} | ||
return Object.freeze({ ...instruction, byteDelta }); | ||
{% else %} | ||
return instruction; | ||
{% endif %} | ||
} |
This file contains 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
Oops, something went wrong.