Skip to content

feat(wrappers): add messageTypes #3318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion src/bindings/writeTypescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,53 @@ export function writeTypescript(
w.append();
}

// Internal receivers
if (
abi.receivers &&
abi.receivers.filter((v) => v.receiver === "internal").length > 0
) {
// Types
const receivers: string[] = [];
for (const r of abi.receivers) {
if (r.receiver !== "internal") {
continue;
}
switch (r.message.kind) {
case "empty":
{
receivers.push(`null`);
}
break;
case "typed":
{
receivers.push(r.message.type);
}
break;
case "text":
{
if (
r.message.text !== null &&
r.message.text !== undefined
) {
receivers.push(JSON.stringify(r.message.text));
} else {
receivers.push(`string`);
}
}
break;
case "any":
{
receivers.push(`Slice`);
}
break;
}
}
w.append(
`export type ${abi.name}_messageTypes = ${receivers.join(" | ")};`,
);
w.append();
}

// Wrapper
w.append(`export class ${abi.name} implements Contract {`);
w.inIndent(() => {
Expand Down Expand Up @@ -450,7 +497,7 @@ export function writeTypescript(

// Receiver function
w.append(
`async send(provider: ContractProvider, via: Sender, args: { value: bigint, bounce?: boolean| null | undefined }, message: ${receivers.join(" | ")}) {`,
`async send(provider: ContractProvider, via: Sender, args: { value: bigint, bounce?: boolean| null | undefined }, message: ${abi.name}_messageTypes ) {`,
);
w.inIndent(() => {
w.append();
Expand Down
Loading