Skip to content

Commit

Permalink
Add HyperFrames
Browse files Browse the repository at this point in the history
  • Loading branch information
briandoyle81CB committed Feb 21, 2024
1 parent fae471e commit 7d8a4d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core/hyperframes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { HyperFrame } from "./types";

const frames: Record<string, HyperFrame> = {};

export function addHyperFrame(label: string, frame: HyperFrame) {
frames[label] = frame;
}

export function getHyperFrame(frame: string, text: string, button: number) {
const currentFrame = frames[frame];
const nextFrameIdOrFunction = currentFrame[button as keyof HyperFrame];

let nextFrameId: string;
if (typeof nextFrameIdOrFunction === 'function') {
nextFrameId = nextFrameIdOrFunction(text);
} else {
nextFrameId = nextFrameIdOrFunction as string;
}

if (!frames[nextFrameId]) {
throw new Error(`Frame not found: ${nextFrameId}`);
}

return frames[nextFrameId].frame;
}
13 changes: 13 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ export type FrameMetadataType = {
*/
export type FrameMetadataResponse = Record<string, string>;

/**
* A named frame with links to other named frames.
*
* Note: exported as public Type
*/
export type HyperFrame = {
frame: string;
1: string | ((text: string) => string) | (() => string);
2?: string | ((text: string) => string) | (() => string);
3?: string | ((text: string) => string) | (() => string);
4?: string | ((text: string) => string) | (() => string);
};

/**
* Ethereum Attestation Service (EAS) Attester Address
* The Ethereum address of the attester who created the attestation.
Expand Down

0 comments on commit 7d8a4d9

Please sign in to comment.