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

fix: fix near-contract-standards event emission #374

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
21 changes: 13 additions & 8 deletions packages/near-contract-standards/src/fungible_token/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
import { NearEvent } from "../event";
import { Option } from "../non_fungible_token/utils";
import { AccountId, Balance } from "near-sdk-js";
import { toSnakeCase } from "../util";

export type Nep141EventKind = FtMint[] | FtTransfer[] | FtBurn[];

export class Nep141Event extends NearEvent {
version: string;
event_kind: Nep141EventKind;

constructor(version: string, event_kind: Nep141EventKind) {
super();
this.version = version;
this.event_kind = event_kind;
}
standard: string;
version: string;
event: string;
data: Nep141EventKind;

constructor(version: string, event_kind: Nep141EventKind) {
super();
this.standard = "nep141"
this.version = version
this.event = toSnakeCase(event_kind[0].constructor.name)
this.data = event_kind
}
}

/** Data to log for an FT mint event. To log this event, call [`.emit()`](FtMint::emit). */
export class FtMint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@
import { AccountId } from "near-sdk-js";
import { NearEvent } from "../event";
import { TokenId } from "./token";
import { toSnakeCase } from "../util";

export type Nep171EventKind = NftMint[] | NftTransfer[] | NftBurn[];
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also add the event typf of ContractMetadataUpdate: https://nomicon.io/Standards/Tokens/NonFungibleToken/Event#interface


export class Nep171Event extends NearEvent {
standard: string;
version: string;
event_kind: Nep171EventKind;
event: string;
data: Nep171EventKind;

constructor(version: string, event_kind: Nep171EventKind) {
super();
this.version = version;
this.event_kind = event_kind;
this.standard = "nep171"
this.version = version
this.event = toSnakeCase(event_kind[0].constructor.name)
this.data = event_kind
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/near-contract-standards/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const toSnakeCase = (str: string) => {
return str.replace(/[A-Z]/g, (letter, index) => { return index == 0 ? letter.toLowerCase() : '_'+ letter.toLowerCase();});
}
Loading