Skip to content

Commit

Permalink
Fixed issue with Symbol typing
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Aug 21, 2023
1 parent 7ea64c6 commit 3441ddd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/codegen/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ export function generateActionNamesInterface(abi: ABI.Def): ts.InterfaceDeclarat

export function generateActionInterface(actionStruct, abi): ts.InterfaceDeclaration {
const members = actionStruct.fields.map((field) => {
const typeReferenceNode = ts.factory.createTypeReferenceNode(
findParamTypeString(field.type, 'Types.', abi)
)

return ts.factory.createPropertySignature(
undefined,
field.name.toLowerCase(),
field.type.includes('?')
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
: undefined,
ts.factory.createTypeReferenceNode(
findExternalType(field.type, abi, 'Types.'),
undefined
)
typeReferenceNode
)
})

Expand Down Expand Up @@ -68,3 +69,17 @@ export function generateActionsNamespace(abi: ABI.Def): ts.ModuleDeclaration {
ts.NodeFlags.Namespace
)
}

function findParamTypeString(typeString: string, namespace: string | null, abi: ABI.Def): string {
const fieldType = findExternalType(typeString, abi, namespace ? namespace : undefined)

if (['String', 'Boolean', 'Number'].includes(fieldType)) {
return fieldType.toLowerCase()
}

if (fieldType === 'Symbol') {
return 'Asset.SymbolType'
}

return fieldType
}
2 changes: 1 addition & 1 deletion test/data/contracts/mock-rewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export namespace RewardsGm {
amount?: AssetType
}
export interface Configure {
token_symbol: Symbol
token_symbol: Asset.SymbolType
oracle_account: NameType
oracle_pairs: Types.OraclePair[]
}
Expand Down

0 comments on commit 3441ddd

Please sign in to comment.