Skip to content
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

Feat: update typescript/app template to latest bindings #1855

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/schema/bind/src/bindings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getGenerateBindingFn(
);
case "app-ts":
return WrapBindgen.getGenerateBindingFn(
"https://github.com/polywrap/wrap-abi-bindgen/tree/wrap-0.1/implementations/app-typescript"
"https://github.com/polywrap/wrap-abi-bindgen/tree/nk/ts-app-codegen/implementations/app-typescript"
);
default:
throw Error(`Error: Language binding unsupported - ${bindLanguage}`);
Expand Down
15 changes: 15 additions & 0 deletions packages/templates/app/typescript/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseEthereum } from "./wrap";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would go in npm sdk


import { CoreClient, PolywrapClient } from "@polywrap/client-js";

export class Ethereum extends BaseEthereum {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an app developer, it feels weird that I have to do this every time. I would imagine that the code below would be the "sane defaults", and if I wanted to change it I could do something like:

import { Ethereum as DefaultEthereum } from "./wrap"

class Ethereum extends DefaultEthereum {
  protected _getDefaultClient(): CoreClient {
    // TODO: create your own custom client
  }
}

protected _getDefaultClient(): CoreClient {
return new PolywrapClient();
}
protected _getDefaultUri(): string | undefined {
return undefined;
}
protected _getDefaultEnv(): Record<string, unknown> | undefined {
return undefined;
}
}
37 changes: 16 additions & 21 deletions packages/templates/app/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
import {
Logging_Module,
Ethereum_Module,
} from "./wrap";

import { PolywrapClient } from "@polywrap/client-js";

const client = new PolywrapClient();
import { Ethereum } from "./ethereum";
import { Logger } from "./logger";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be npm wrap sdk

async function main() {
console.log("Invoking: Logging.info(...)");

await Logging_Module.info({
const logger = new Logger();

await logger.info({
message: "Hello there",
}, client);
});

await Logging_Module.info({
await logger.info({
message: "Hello again",
}, client);
});

await Logging_Module.info({
await logger.info({
message: "One last time...",
}, client);
});

console.log("Invoking: Ethereum.encodeParams(...)");

const result = await Ethereum_Module.encodeParams(
{
types: ["address", "uint256"],
values: ["0xB1B7586656116D546033e3bAFF69BFcD6592225E", "500"],
},
client
);
const eth = new Ethereum();

const result = await eth.encodeParams({
types: ["address", "uint256"],
values: ["0xB1B7586656116D546033e3bAFF69BFcD6592225E", "500"],
});

if (result.ok) {
console.log(`Ethereum.encodeParams:\n${result.value}`);
Expand Down
15 changes: 15 additions & 0 deletions packages/templates/app/typescript/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { BaseLogging } from "./wrap";

import { CoreClient, PolywrapClient } from "@polywrap/client-js";

export class Logger extends BaseLogging {
protected _getDefaultClient(): CoreClient {
return new PolywrapClient();
}
protected _getDefaultUri(): string | undefined {
return undefined;
}
protected _getDefaultEnv(): Record<string, unknown> | undefined {
return undefined;
}
}
Loading