Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add MoxieEarningStats to sidebar #518

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/common/components/ProfileInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Badge } from '@/components/ui/badge';
import { take } from 'lodash';
import { formatDistanceToNow } from 'date-fns';
import { cn } from '@/lib/utils';
import { formatLargeNumber } from '../helpers/text';

const priorityChannels = ['email', 'linkedin', 'telegram', 'twitter', 'github'];

Expand Down Expand Up @@ -46,6 +47,7 @@ const ProfileInfo = ({
</p>
);
};

const renderSocialCapitalScore = () =>
profile?.airstackSocialInfo?.socialCapitalRank && (
<TooltipProvider>
Expand Down Expand Up @@ -73,6 +75,32 @@ const ProfileInfo = ({
</a>
</TooltipContent>
</Tooltip>
{profile?.airstackSocialInfo?.moxieEarnings && (
<>
<br />
<Tooltip>
<TooltipTrigger asChild>
<span className="text-sm text-muted-foreground">
<span className="font-semibold text-foreground">
{formatLargeNumber(profile?.airstackSocialInfo?.moxieEarnings)}
</span>{' '}
Moxie earned
</span>
</TooltipTrigger>
<TooltipContent
className="w-44 p-3 bg-background border border-muted text-foreground/80"
side="bottom"
sideOffset={5}
>
Moxie is a community-owned and community-governed Farcaster protocol. Its mission is to grow the
Farcaster GDP. Learn more at{' '}
<a target="_blank" rel="noreferrer" className="underline cursor-pointer" href="https://moxie.xyz">
moxie.xyz
</a>
</TooltipContent>
</Tooltip>
</>
)}
</TooltipProvider>
);

Expand Down Expand Up @@ -133,7 +161,7 @@ const ProfileInfo = ({
<div className="mt-2 flex flex-wrap gap-1">
{take(profile.coordinapeAttestations, 15).map((attestation) => (
<span
key={`${fid}-${attestation}`}
key={`${fid}-${attestation.platform}-${attestation.skill}`}
className={cn(
'h-6 rounded-lg px-1 border border-foreground/20 text-xs text-muted-foreground flex items-center',
attestation.amount > 1 && 'pr-0 rounded-r-lg'
Expand Down
12 changes: 11 additions & 1 deletion src/common/helpers/airstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ init(process.env.NEXT_PUBLIC_AIRSTACK_API_KEY!);
export type AirstackSocialInfo = {
socialCapitalRank: number;
userCreatedAt: number;
moxieEarnings: number;
};

export async function getAirstackSocialInfoForFid(fid: string): Promise<AirstackSocialInfo | null> {
Expand All @@ -27,6 +28,13 @@ export async function getAirstackSocialInfoForFid(fid: string): Promise<Airstack
userCreatedAtBlockTimestamp
}
}
FarcasterMoxieEarningStats(
input: {timeframe: LIFETIME, blockchain: ALL, filter: {entityType: {_eq: USER}, entityId: {_eq: "${fid}"}}}
) {
FarcasterMoxieEarningStat {
allEarningsAmount
}
}
}`;
try {
const { data, error } = await fetchQuery(query);
Expand All @@ -35,13 +43,15 @@ export async function getAirstackSocialInfoForFid(fid: string): Promise<Airstack
return null;
}
const socialInfo = data?.Socials?.Social?.[0];
if (!socialInfo) {
const moxieEarnings = data?.FarcasterMoxieEarningStats?.FarcasterMoxieEarningStat?.[0]?.allEarningsAmount;
if (!socialInfo && !moxieEarnings) {
return null;
}

return {
socialCapitalRank: socialInfo.socialCapital.socialCapitalRank,
userCreatedAt: socialInfo.userCreatedAtBlockTimestamp,
moxieEarnings,
};
} catch (error) {
console.error('Error fetching Airstack data:', error);
Expand Down