diff --git a/package.json b/package.json index fab4a0c..2a6bcf0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@neynar/react", - "version": "0.8.0", + "version": "0.8.1", "description": "Farcaster frontend component library powered by Neynar", "main": "dist/bundle.cjs.js", "module": "dist/bundle.es.js", diff --git a/src/components/molecules/FrameCard.tsx b/src/components/molecules/FrameCard.tsx index 9db85ae..f9e0cb7 100644 --- a/src/components/molecules/FrameCard.tsx +++ b/src/components/molecules/FrameCard.tsx @@ -79,18 +79,9 @@ const InputField = styled.input({ }); function CastFrameBtn({ number, text, actionType, target, frameUrl, handleOnClick }: any) { - const handleClick = () => { - if (actionType === "link" && target) { - window.open(target, "_blank"); - } else if(actionType === "mint") { - window.open(frameUrl, "_blank"); - } else { - handleOnClick(number); - } - }; return ( - + handleOnClick(number)}> {text} {(actionType === "link" || actionType === "post_redirect" || actionType === "mint") && } diff --git a/src/components/organisms/NeynarFrameCard/index.tsx b/src/components/organisms/NeynarFrameCard/index.tsx index dacb757..9008e5f 100644 --- a/src/components/organisms/NeynarFrameCard/index.tsx +++ b/src/components/organisms/NeynarFrameCard/index.tsx @@ -93,41 +93,46 @@ export const NeynarFrameCard: React.FC = ({ url, onFrameBt showToast(ToastType.Error, 'Signer UUID is not available'); throw new Error('Signer UUID is not available'); } - + const button = localFrame.buttons.find(btn => btn.index === btnIndex); const postUrl = button?.post_url; - - try { - const response = await fetchWithTimeout(`${NEYNAR_API_URL}/v2/farcaster/frame/action?client_id=${client_id}`, { - method: "POST", - headers: { - "accept": "application/json", - "content-type": "application/json" - }, - body: JSON.stringify({ - "signer_uuid": signerValue, - "action": { - "button": button, - "frames_url": localFrame.frames_url, - "post_url": postUrl ? postUrl : localFrame.frames_url, - "input": { - "text": inputValue + + if ((button?.action_type === "link" || button?.action_type === "post_redirect" || button?.action_type === "mint")) { + window.open(button.action_type !== 'mint' && button?.target ? button?.target : localFrame.frames_url, '_blank'); + return localFrame; + } else { + try { + const response = await fetchWithTimeout(`${NEYNAR_API_URL}/v2/farcaster/frame/action?client_id=${client_id}`, { + method: "POST", + headers: { + "accept": "application/json", + "content-type": "application/json" + }, + body: JSON.stringify({ + "signer_uuid": signerValue, + "action": { + "button": button, + "frames_url": localFrame.frames_url, + "post_url": postUrl ? postUrl : localFrame.frames_url, + "input": { + "text": inputValue + } } - } - }) - }) as Response; - if (response.ok) { - const json = await response.json() as NeynarFrame; - return json; - } else { - showToast(ToastType.Error, `HTTP error! status: ${response.status}`); - throw new Error(`HTTP error! status: ${response.status}`); + }) + }) as Response; + if (response.ok) { + const json = await response.json() as NeynarFrame; + return json; + } else { + showToast(ToastType.Error, `HTTP error! status: ${response.status}`); + throw new Error(`HTTP error! status: ${response.status}`); + } + } catch (error) { + showToast(ToastType.Error, `An error occurred while processing the button press: ${error}`); + throw error; } - } catch (error) { - showToast(ToastType.Error, `An error occurred while processing the button press: ${error}`); - throw error; } - }; + } const handleFrameBtnPress = async ( btnIndex: number,