ts: Scope fields when formatting nested instruction accounts (#376)
This commit is contained in:
parent
2bcd44ded3
commit
50b000542c
|
@ -338,18 +338,34 @@ class InstructionFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
private static flattenIdlAccounts(accounts: IdlAccountItem[]): IdlAccount[] {
|
||||
private static flattenIdlAccounts(
|
||||
accounts: IdlAccountItem[],
|
||||
prefix?: string
|
||||
): IdlAccount[] {
|
||||
// @ts-ignore
|
||||
return accounts
|
||||
.map((account) => {
|
||||
const accName = sentenceCase(account.name);
|
||||
// @ts-ignore
|
||||
if (account.accounts) {
|
||||
const newPrefix = prefix ? `${prefix} > ${accName}` : accName;
|
||||
// @ts-ignore
|
||||
return InstructionFormatter.flattenIdlAccounts(account.accounts);
|
||||
return InstructionFormatter.flattenIdlAccounts(
|
||||
account.accounts,
|
||||
newPrefix
|
||||
);
|
||||
} else {
|
||||
return account;
|
||||
return {
|
||||
...account,
|
||||
name: prefix ? `${prefix} > ${accName}` : accName,
|
||||
};
|
||||
}
|
||||
})
|
||||
.flat();
|
||||
}
|
||||
}
|
||||
|
||||
function sentenceCase(field: string): string {
|
||||
const result = field.replace(/([A-Z])/g, " $1");
|
||||
return result.charAt(0).toUpperCase() + result.slice(1);
|
||||
}
|
||||
|
|
|
@ -131,10 +131,7 @@ const LangErrorMessage = new Map([
|
|||
LangErrorCode.ConstraintAssociatedInit,
|
||||
"An associated init constraint was violated",
|
||||
],
|
||||
[
|
||||
LangErrorCode.ConstraintClose,
|
||||
"A close constraint was violated"
|
||||
],
|
||||
[LangErrorCode.ConstraintClose, "A close constraint was violated"],
|
||||
|
||||
// Accounts.
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue