Skip to content

Commit

Permalink
chore: add farcaster v2 to protocol selector
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkvasnicak committed Nov 28, 2024
1 parent a1f6acf commit 996b84d
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 295 deletions.
2 changes: 0 additions & 2 deletions packages/debugger/app/components/action-debugger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { CastActionDefinitionResponse } from "../frames/route";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { ComposerActionDebugger } from "./composer-action-debugger";
import { CastActionDebugger } from "./cast-action-debugger";
import { useProtocolSelector } from "../providers/ProtocolSelectorProvider";

type ActionDebuggerProps = {
actionMetadataItem: CastActionDefinitionResponse;
Expand Down Expand Up @@ -40,7 +39,6 @@ export const ActionDebugger = React.forwardRef<
},
ref
) => {
const protocolSelector = useProtocolSelector();
const [activeTab, setActiveTab] = useState<TabValues>(
"type" in actionMetadataItem.action &&
actionMetadataItem.action.type === "composer"
Expand Down
6 changes: 4 additions & 2 deletions packages/debugger/app/components/cast-action-debugger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import type { CastActionDefinitionResponse } from "../frames/route";
import IconByName from "./octicons";
import { useToast } from "@/components/ui/use-toast";
import { ActionInfo } from "./action-info";
import { defaultTheme, fallbackFrameContext } from "@frames.js/render";
import { defaultTheme } from "@frames.js/render";
import { useCastAction } from "@frames.js/render/use-cast-action";
import { FrameDebugger } from "./frame-debugger";
import { useFarcasterIdentity } from "../hooks/useFarcasterIdentity";
import { type Dispatch, type SetStateAction, useState } from "react";
import type { MockHubActionContext } from "../utils/mock-hub-utils";
import { useFrameContext } from "../providers/FrameContextProvider";

type CastActionDebuggerProps = {
actionMetadataItem: CastActionDefinitionResponse;
Expand All @@ -28,6 +29,7 @@ export function CastActionDebugger({
const { toast } = useToast();
const farcasterIdentity = useFarcasterIdentity();
const [postUrl, setPostUrl] = useState<string | null>(null);
const frameContext = useFrameContext();
const castAction = useCastAction({
...(postUrl
? {
Expand All @@ -38,7 +40,7 @@ export function CastActionDebugger({
enabled: false,
postUrl: "",
}),
castId: fallbackFrameContext.castId,
castId: frameContext.farcaster.castId,
proxyUrl: "/frames",
signer: farcasterIdentity,
onInvalidResponse(response) {
Expand Down
58 changes: 10 additions & 48 deletions packages/debugger/app/components/frame-debugger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import {
} from "react";
import React from "react";
import { useFrame_unstable as useFrame } from "@frames.js/render/unstable-use-frame";
import {
attribution,
CollapsedFrameUI,
defaultTheme,
fallbackFrameContext,
} from "@frames.js/render";
import { attribution, CollapsedFrameUI, defaultTheme } from "@frames.js/render";
import { FrameImageNext } from "@frames.js/render/next";
import {
BanIcon,
Expand Down Expand Up @@ -45,21 +40,11 @@ import { FrameDebuggerRequestCardContent } from "./frame-debugger-request-card-c
import { useSharedFrameEventHandlers } from "../hooks/useSharedFrameEventHandlers";
import { ProtocolConfiguration } from "./protocol-config-button";
import { useFarcasterIdentity } from "../hooks/useFarcasterIdentity";
import {
useXmtpFrameContext,
useXmtpIdentity,
} from "@frames.js/render/identity/xmtp";
import {
useLensFrameContext,
useLensIdentity,
} from "@frames.js/render/identity/lens";
import { useXmtpIdentity } from "@frames.js/render/identity/xmtp";
import { useLensIdentity } from "@frames.js/render/identity/lens";
import { useAnonymousIdentity } from "@frames.js/render/identity/anonymous";
import { useFarcasterFrameContext } from "@frames.js/render/identity/farcaster";
import { useAccount } from "wagmi";
import { zeroAddress } from "viem";
import type { ParseFramesWithReportsResult } from "frames.js/frame-parsers";

const anonymousFrameContext = {};
import { useFrameContext } from "../providers/FrameContextProvider";

type FrameDebuggerProps = {
url: string;
Expand Down Expand Up @@ -91,30 +76,11 @@ export const FrameDebugger = React.forwardRef<
},
ref
) => {
const account = useAccount();
const farcasterSignerState = useFarcasterIdentity();
const xmtpSignerState = useXmtpIdentity();
const lensSignerState = useLensIdentity();
const anonymousSignerState = useAnonymousIdentity();

const farcasterFrameContext = useFarcasterFrameContext({
fallbackContext: fallbackFrameContext,
});

const xmtpFrameContext = useXmtpFrameContext({
fallbackContext: {
conversationTopic: "test",
participantAccountAddresses: account.address
? [account.address, zeroAddress]
: [zeroAddress],
},
});

const lensFrameContext = useLensFrameContext({
fallbackContext: {
pubId: "0x01-0x01",
},
});
const frameContext = useFrameContext();

const sharedFrameEventHandlers = useSharedFrameEventHandlers({
debuggerRef: null,
Expand Down Expand Up @@ -142,19 +108,15 @@ export const FrameDebugger = React.forwardRef<
// it creates copies of the signer which is bad because if the signer is internally
// updated, we see only old value although the signer is updated. This is true only for public properties
// probably getters will be better in this regard?
return farcasterSignerState.withContext(
farcasterFrameContext.frameContext
);
return farcasterSignerState.withContext(frameContext.farcaster);
case "farcaster_v2":
return farcasterSignerState.withContext(
farcasterFrameContext.frameContext
);
return farcasterSignerState.withContext(frameContext.farcaster);
case "xmtp":
return xmtpSignerState.withContext(xmtpFrameContext.frameContext);
return xmtpSignerState.withContext(frameContext.xmtp);
case "lens":
return lensSignerState.withContext(lensFrameContext.frameContext);
return lensSignerState.withContext(frameContext.lens);
case "anonymous":
return anonymousSignerState.withContext(anonymousFrameContext);
return anonymousSignerState.withContext(frameContext.anonymous);
default:
throw new Error(`Unknown protocol`);
}
Expand Down
Loading

0 comments on commit 996b84d

Please sign in to comment.