Skip to content

Commit

Permalink
General quality of life improvements (#161)
Browse files Browse the repository at this point in the history
* General quality of life improvements

* Fix review comments

* Change default wight config

* Lint

* Adds default config for commits

---------

Co-authored-by: Gabriel Ferraz <[email protected]>
  • Loading branch information
AlecErasmus and sudoFerraz authored May 17, 2024
1 parent 65040b8 commit 17a99d3
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 37 deletions.
4 changes: 2 additions & 2 deletions cred-manager/src/sourcecred/service/weightConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

@Injectable()
export class WeightConfigService {
constructor(private readonly prismaService: PrismaService) {}
constructor(private readonly prismaService: PrismaService) { }

async getTeamWeightConfigs(teamId: string): Promise<WeightConfigDto[]> {
const teamWeightConfigs =
Expand Down Expand Up @@ -42,7 +42,7 @@ export class WeightConfigService {
'N\u0000sourcecred\u0000github\u0000COMMENT\u0000':
nodeWeightsMap.get('NODE_COMMENT') || 0,
'N\u0000sourcecred\u0000github\u0000COMMIT\u0000':
nodeWeightsMap.get('NODE_COMMIT') || 0,
nodeWeightsMap.get('NODE_COMMIT') || 0.0625,
'N\u0000sourcecred\u0000github\u0000ISSUE\u0000':
nodeWeightsMap.get('NODE_ISSUE') || 0,
'N\u0000sourcecred\u0000github\u0000PULL\u0000':
Expand Down
11 changes: 7 additions & 4 deletions src/app/(dashboard)/projects/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ export default function CreateNewProjectPage() {

const handleCreateTeam = async () => {
nextStep();
const { data } = await axios.post("/api/teams", { name: createTeamName });
const { data } = await axios.post("/api/projects", {
name: createTeamName,
repoCount: selectedGithubRepos.length,
});
if (data.success) {
setProject(data.createdTeam);
await handleRegisterRepos(data.createdTeam.id);
handleGenerateReport(data.createdTeam.id);
setProject(data.createdProject);
await handleRegisterRepos(data.createdProject.id);
handleGenerateReport(data.createdProject.id);
} else {
previousStep();
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/configuration/weightConfig.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const defaultConfigResponse: WeightConfig = {
title: "Commit Weight",
description:
"This slider adjusts the relevance and weight you would like to assign for commits that were successfully merged.",
value: 0, // default value
value: 1, // default value
min: 0,
max: 10,
step: 1,
Expand Down
24 changes: 24 additions & 0 deletions src/app/api/projects/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { NextRequest, NextResponse } from "next/server";
import { options } from "../auth/[...nextauth]/options";
import { fetchUserTeam } from "../teams/fetchTeam";
import { fetchUserTeams } from "../teams/fetchUserTeams";
import { ProjectRegisterDto } from "./types/project.dto";
import { registerUserTeam } from "../teams/registerUserTeam";

export async function GET(req: NextRequest) {
const session = await getServerSession(options);
Expand All @@ -23,3 +25,25 @@ export async function GET(req: NextRequest) {
}
}
}

export async function POST(req: NextRequest) {
try {
const session = await getServerSession(options);
const registerProjectDto = (await req.json()) as ProjectRegisterDto;
if (session?.userId) {
const createdProject = await registerUserTeam(
session.userId,
registerProjectDto.name,
registerProjectDto.repoCount == 1,
);
return NextResponse.json({
success: true,
createdProject: createdProject,
});
}
return NextResponse.json({ success: true, createdProject: null });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, createdProject: null });
}
}
4 changes: 4 additions & 0 deletions src/app/api/projects/types/project.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type ProjectRegisterDto = {
name: string;
repoCount: number;
};
20 changes: 20 additions & 0 deletions src/components/payments/paymentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { truncateString } from "@/app/(dashboard)/utils/stringUtils";
import { SplitsBalance } from "./splits/splitsBalance";
import { Button } from "../ui/button";
import { toast } from "sonner";
import { Alert, AlertTitle } from "../ui/alert";
import { Icons } from "../icons";
import { useState } from "react";

interface PaymentsViewProps {
projectId: string;
Expand Down Expand Up @@ -35,6 +38,7 @@ export default function PaymentsView({
projectId,
paymentAddress,
}: PaymentsViewProps) {
const [loadedSuccessfully, setLoadedSuccessfully] = useState(true);
return (
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6">
<div className="flex items-start">
Expand Down Expand Up @@ -65,11 +69,26 @@ export default function PaymentsView({
</div>
</div>
</div>
{!loadedSuccessfully ? (
<div>
<Alert className="flex items-center bg-blue-500">
<Icons.warning className="mr-2 h-4 w-4" />
<AlertTitle>
You payment address has not been indexed yet, wait for a moment
until we are able to fetch it from onchain data and refresh this
page.
</AlertTitle>
</Alert>
</div>
) : (
<></>
)}
<div className="grid grid-cols-2 gap-4">
<div>
<SplitsBalance
projectId={projectId}
paymentAddress={paymentAddress}
setLoadedSuccessfully={setLoadedSuccessfully}
></SplitsBalance>
</div>
<div>
Expand All @@ -85,6 +104,7 @@ export default function PaymentsView({
<SplitsRecipients
paymentAddress={paymentAddress.wallet_address}
chainId={parseInt(paymentAddress.chain_id)}
setLoadedSuccessfully={setLoadedSuccessfully}
></SplitsRecipients>
</CardContent>
</Card>
Expand Down
77 changes: 49 additions & 28 deletions src/components/payments/splits/splitsBalance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ import {
useDistributeToken,
useSplitEarnings,
} from "@0xsplits/splits-sdk-react";
import { Split, Wallet2 } from "lucide-react";
import { Split, SwitchCamera, Wallet2 } from "lucide-react";
import { useEffect, useState } from "react";
import { useAccount } from "wagmi";
import { useAccount, useChainId } from "wagmi";
import { useSwitchChain } from "wagmi";

interface SplitsBalanceProps {
projectId: string;
paymentAddress: PaymentAddressDto;
setLoadedSuccessfully: (isSuccessfully: boolean) => void;
}

export function SplitsBalance({
projectId,
paymentAddress,
setLoadedSuccessfully,
}: SplitsBalanceProps) {
const account = useAccount();
const chainId = useChainId();
const [isLoading, setIsLoading] = useState(true);
const { switchChain } = useSwitchChain();
const { splitEarnings, status, error } = useSplitEarnings(
parseInt(paymentAddress.chain_id),
paymentAddress.wallet_address,
Expand All @@ -53,6 +58,9 @@ export function SplitsBalance({
}
setIsLoading(false);
}
if (error) {
setLoadedSuccessfully(false);
}
}, [splitEarnings, status, error, isLoading]);

useEffect(() => {
Expand All @@ -79,32 +87,45 @@ export function SplitsBalance({
</div>
</CardContent>
<CardFooter>
<Button
className="w-full text-md flex justify-between items-center"
disabled={
!(
account.isConnected &&
(distributeStatus == null ||
distributeStatus == "error" ||
distributeStatus == "complete")
)
}
onClick={() =>
distributeToken({
splitAddress: paymentAddress.wallet_address,
token: "0x0000000000000000000000000000000000000000",
})
}
>
{distributeStatus == "pendingApproval" ? (
<>Waiting for approval</>
) : distributeStatus == "txInProgress" ? (
<>In progress</>
) : (
<>Distribute Balances</>
)}
<Split className="mr-2 h-5 w-5 transform rotate-90" />
</Button>
{account.isConnected &&
chainId != parseInt(paymentAddress.chain_id) ? (
<Button
className="w-full text-md flex justify-between items-center"
onClick={() =>
switchChain({ chainId: parseInt(paymentAddress.chain_id) })
}
>
Switch Chains
<SwitchCamera className="mr-2 h-5 w-5" />
</Button>
) : (
<Button
className="w-full text-md flex justify-between items-center"
disabled={
!(
account.isConnected &&
(distributeStatus == null ||
distributeStatus == "error" ||
distributeStatus == "complete")
)
}
onClick={() =>
distributeToken({
splitAddress: paymentAddress.wallet_address,
token: "0x0000000000000000000000000000000000000000",
})
}
>
{distributeStatus == "pendingApproval" ? (
<>Waiting for approval</>
) : distributeStatus == "txInProgress" ? (
<>In progress</>
) : (
<>Distribute Balances</>
)}
<Split className="mr-2 h-5 w-5 transform rotate-90" />
</Button>
)}
</CardFooter>
</Card>
)}
Expand Down
12 changes: 10 additions & 2 deletions src/components/payments/splits/splitsRecipients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import axios from "axios";
interface SplitsRecipientsProps {
paymentAddress: string;
chainId: number;
setLoadedSuccessfully: (isSuccessfully: boolean) => void;
}

export interface SplitRecipient {
Expand All @@ -21,10 +22,14 @@ export interface SplitRecipient {
export default function SplitsRecipients({
paymentAddress,
chainId,
setLoadedSuccessfully,
}: SplitsRecipientsProps) {
const [recipient, setRecipient] = useState<SplitRecipient[]>([]);
const [isLoading, setIsLoading] = useState(true);
const { splitMetadata, status } = useSplitMetadata(chainId, paymentAddress);
const { splitMetadata, status, error } = useSplitMetadata(
chainId,
paymentAddress,
);

const handleSplitMetadata = async (splitRecipient: SplitRecipient[]) => {
const { data } = await axios.post(`/api/wallet/search`, splitRecipient);
Expand All @@ -42,7 +47,10 @@ export default function SplitsRecipients({
}));
handleSplitMetadata(mappedRecipient);
}
}, [status]);
if (error) {
setLoadedSuccessfully(false);
}
}, [status, error]);

return (
<SplitsDataTable
Expand Down
6 changes: 6 additions & 0 deletions src/components/projects/projectRepoNameForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { GithubRepoDto } from "@/app/api/github/repo/types/githubRepo.dto";
import ProjectGithubRepositoriesBadge from "../repo/projectGithubRepositoriesBadge";
import { useEffect } from "react";

interface ProjectTeamNameFormProps {
createTeamName: string;
Expand All @@ -27,6 +28,11 @@ export default function ProjectTeamNameForm({
selectedGithubRepos,
onSelectRepo,
}: ProjectTeamNameFormProps) {
useEffect(() => {
if (selectedGithubRepos.length == 1) {
setCreateTeamName(selectedGithubRepos[0].full_name);
}
}, []);
return (
<>
<div className="pt-36">
Expand Down

0 comments on commit 17a99d3

Please sign in to comment.