Skip to content

Commit

Permalink
Merge pull request #521 from us3r-network/u3-dev
Browse files Browse the repository at this point in the history
Release support for text for Frame
  • Loading branch information
qbig authored Feb 3, 2024
2 parents ffdf95c + 8014f8b commit 50603be
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 34 deletions.
12 changes: 6 additions & 6 deletions apps/u3/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ module.exports = {

// Replace include option for babel loader with exclude
// so babel will handle workspace projects as well.
config.module.rules[1].oneOf.forEach((r) => {
if (r.loader && r.loader.indexOf('babel') !== -1) {
r.exclude = /node_modules/;
delete r.include;
}
});
// config.module.rules[1].oneOf.forEach((r) => {
// if (r.loader && r.loader.indexOf('babel') !== -1) {
// r.exclude = /node_modules/;
// delete r.include;
// }
// });
config.resolve.fallback = {
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
Expand Down
21 changes: 18 additions & 3 deletions apps/u3/src/components/social/Embed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function EmbedCastFrame({
const castId: CastId = useFarcasterCastId({ cast });
const { encryptedSigner, isConnected, currFid } = useFarcasterCtx();

const [frameText, setFrameText] = useState('');
const [frameRedirect, setFrameRedirect] = useState('');
const [frameData, setFrameData] = useState<FarCastEmbedMeta>(data);

Expand All @@ -196,7 +197,7 @@ function EmbedCastFrame({
url: Buffer.from(data.url),
buttonIndex: index,
castId,
inputText: Buffer.from(''),
inputText: Buffer.from(frameText),
},
{
fid: currFid,
Expand All @@ -215,6 +216,7 @@ function EmbedCastFrame({
messageHash: toHex(trustedDataValue.hash),
network: FARCASTER_NETWORK,
buttonIndex: index,
inputText: frameText,
castId: {
fid: castId.fid,
hash: toHex(castId.hash),
Expand Down Expand Up @@ -248,16 +250,29 @@ function EmbedCastFrame({
setFrameRedirect(resp.data.data?.redirectUrl || '');
}
},
[frameData, currFid, encryptedSigner, castId]
[frameData, currFid, encryptedSigner, castId, frameText]
);
return (
<>
<div className="border rounded-xl overflow-hidden border-[#39424c]">
<div className="h-80 overflow-hidden flex items-center">
<img src={frameData.fcFrameImage} alt="" />
</div>
{frameData.fcFrameInputText && (
<div className="p-3">
<input
type="text"
className="w-full p-3 rounded-xl bg-[#39424c] border-[#39424c] text-[#fff] placeholder-[#718096] focus:outline-none"
placeholder={frameData.fcFrameInputText}
value={frameText}
onChange={(e) => {
setFrameText(e.target.value);
}}
/>
</div>
)}
{isConnected && (
<div className="flex items-center justify-around gap-3 mt-3">
<div className="flex items-center justify-around gap-3 mt-1">
{[
frameData.fcFrameButton1,
frameData.fcFrameButton2,
Expand Down
2 changes: 1 addition & 1 deletion apps/u3/src/components/social/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function PostCardUserInfo({
}

const PostCardUserInfoWrapper = styled.div`
flex: 1;
/* flex: 1; */
display: flex;
align-items: flex-start;
gap: 10px;
Expand Down
37 changes: 13 additions & 24 deletions apps/u3/src/components/social/farcaster/FCast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
PostCardActionsWrapper,
PostCardContentWrapper,
PostCardFooterWrapper,
PostCardHeaderWrapper,
PostCardShowMoreWrapper,
PostCardUserInfo,
PostCardWrapper,
Expand All @@ -40,6 +39,7 @@ import { pinupCastApi } from '@/services/social/api/farcaster';
import useLogin from '@/hooks/shared/useLogin';
import { SaveButton } from '@/components/shared/button/SaveButton';
import FCastTips from './FCastTips';
import FCastTipDetail from './FCastTipDetail';

export default function FCast({
cast,
Expand Down Expand Up @@ -70,6 +70,7 @@ export default function FCast({
farcasterUserData,
farcasterUserDataObj,
});
const [count, setCount] = useState(0);
const [showMore, setShowMore] = useState(false);
const { following, pinupHashes, updatePinupHashes } = useFarcasterCtx();
const { followAction, unfollowAction, isPending, isFollowing } =
Expand Down Expand Up @@ -159,7 +160,7 @@ export default function FCast({
navigate(`/social/post-detail/fcast/${id}`);
}}
>
<PostCardHeaderWrapper>
<div className="flex items-center gap-5">
<PostCardUserInfo
data={{
platform: SocialPlatform.Farcaster,
Expand All @@ -169,13 +170,21 @@ export default function FCast({
createdAt: cast.created_at || cast.createdAt,
}}
/>
<FCastTipDetail cast={cast} />
<div className="flex-grow" />
<div
className="flex items-center gap-2"
onClick={(e) => {
e.stopPropagation();
}}
>
<FCastTips userData={userData} cast={cast} />
<FCastTips
userData={userData}
cast={cast}
updateCb={() => {
setCount(count + 1);
}}
/>
{isAdmin && (
<Button
className={cn(
Expand All @@ -192,28 +201,8 @@ export default function FCast({
<ArrowUpIcon />
</Button>
)}
{/* {showMenuBtn && (
<div>
<PostCardMenuBtn
data={{
name: userData.display,
handle: userData.userName,
}}
isFollowed={followed}
followPending={isPending}
unfollowPending={isPending}
followAction={() => {
if (followed) {
unfollowAction(userData.fid);
} else {
followAction(userData.fid);
}
}}
/>
</div>
)} */}
</div>
</PostCardHeaderWrapper>
</div>

<PostCardContentWrapper ref={viewRef} showMore={showMore}>
<FCastText cast={cast} farcasterUserDataObj={farcasterUserDataObj} />
Expand Down
190 changes: 190 additions & 0 deletions apps/u3/src/components/social/farcaster/FCastTipDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { useCallback, useState } from 'react';
import dayjs from 'dayjs';
import { toast } from 'react-toastify';
import { Cross2Icon } from '@radix-ui/react-icons';

import { FarCast } from '@/services/social/types';
import ModalContainer from '@/components/common/modal/ModalContainer';
import { cn } from '@/lib/utils';
import { getCastTipsDetail } from '@/services/social/api/farcaster';
import Loading from '@/components/common/loading/Loading';
import {
Table,
TableBody,
TableCell,
TableFooter,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';

export default function FCastTipDetail({ cast }: { cast: FarCast }) {
const [openModal, setOpenModal] = useState(false);
const [loading, setLoading] = useState(false);
const [tipDetails, setTipDetails] = useState<
{
amount: number;
createdAt: number;
txHash: string;
type: string;
userDatas: { type: number; value: string }[];
}[]
>([]);

const loadTipsDetails = useCallback(async () => {
try {
setLoading(true);
const resp = await getCastTipsDetail(
Buffer.from(cast.hash.data).toString('hex')
);
if (resp.data.code !== 0) {
toast.error(resp.data.msg);
} else {
setTipDetails(resp.data.data);
}
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
}, [cast]);

if (!cast.tipsTotalAmount) {
return null;
}
return (
<>
<div
className="flex items-center cursor-pointer"
onClick={(e) => {
e.stopPropagation();
setOpenModal(true);
loadTipsDetails();
}}
>
{/* <span className="text-[#718096] text-sm"> received</span> */}
<span className="text-[#FFBB02]"> {cast.tipsTotalAmount} $DEGEN</span>
</div>
{openModal && (
<TipDetailsModal
open={openModal}
setOpen={setOpenModal}
loading={loading}
details={tipDetails}
tipsTotalAmount={tipDetails.reduce((acc, cur) => acc + cur.amount, 0)}
/>
)}
</>
);
}

function TipDetailsModal({
open,
setOpen,
details,
loading,
tipsTotalAmount,
}: {
open: boolean;
setOpen: (open: boolean) => void;
details: {
amount: number;
txHash: string;
createdAt: number;
type: string;
userDatas: { type: number; value: string }[];
}[];
loading: boolean;
tipsTotalAmount: number;
}) {
return (
<ModalContainer
open={open}
closeModal={() => {
setOpen(false);
}}
contentTop="40%"
className="w-full md:w-[600px]"
>
{(loading && (
<div className="flex justify-center items-center min-h-36">
<Loading />
</div>
)) || (
<div
className={cn(
'flex flex-col gap-5 p-5 bg-[#1B1E23] text-white border-[#39424C]',
'rounded-xl md:rounded-[20px] md:max-w-none md:w-[600px]'
)}
onClick={(e) => {
e.stopPropagation();
}}
>
<div className="flex flex-col gap-3 text-sm">
<div className="flex justify-between gap-2">
<div className="text-base">
<span className="text-[#718096]">Tips</span>
</div>
<div
className="hover:cursor-pointer"
onClick={() => {
setOpen(false);
}}
>
<Cross2Icon className="h-5 w-5 text-[#718096]" />
</div>
</div>
</div>
<Table>
<TableHeader className="border-none">
<TableRow className="hover:bg-none border-none">
<TableHead className="w-[300px]">From</TableHead>
<TableHead>Type</TableHead>
<TableHead>Price</TableHead>
<TableHead className="text-right">Date</TableHead>
</TableRow>
</TableHeader>
<TableBody className="border-none mb-5">
{details.map((detail, index) => {
const avatar = detail.userDatas.find((item) => item.type === 1);
const name = detail.userDatas.find((item) => item.type === 2);
const handle = detail.userDatas.find((item) => item.type === 6);
return (
<TableRow key={detail.createdAt} className="border-none">
<TableCell className="font-medium flex gap-3">
<img
src={avatar.value}
alt=""
className="w-12 h-12 object-cover rounded-full"
/>
<div>
<div className="text-lg">{name.value}</div>
<div className="text-sm text-[#718096]">
@{handle.value}
</div>
</div>
</TableCell>
<TableCell>{detail.type || 'Token'}</TableCell>
<TableCell>{detail.amount}</TableCell>
<TableCell className="text-right">
{dayjs(detail.createdAt).fromNow()}
</TableCell>
</TableRow>
);
})}
</TableBody>
<br />
<TableFooter className="bg-muted/0 border-[#718096]">
<TableRow className="">
<TableCell colSpan={2}>Tipped {details.length} times</TableCell>
<TableCell className="text-right" colSpan={2}>
Amount: {tipsTotalAmount} $DEGEN
</TableCell>
</TableRow>
</TableFooter>
</Table>
</div>
)}
</ModalContainer>
);
}
Loading

0 comments on commit 50603be

Please sign in to comment.