Skip to content

Commit

Permalink
fix: fix near-contract-standards event emission
Browse files Browse the repository at this point in the history
  • Loading branch information
nujabes403 authored and fospring committed Mar 17, 2024
1 parent 61fe54e commit da3ac99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
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[];

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();});
}

0 comments on commit da3ac99

Please sign in to comment.