Skip to content

Commit cefd5a8

Browse files
Adds splits sdk and provider (#149)
* Add splits sdk * Adds working reading usage of splits sdk * Adds working sdk usage with dependencies * Removes unncessary providers * Cleans up debugging code --------- Co-authored-by: Alec <alecerasmus2@gmail.com>
1 parent 78a11be commit cefd5a8

File tree

7 files changed

+713
-520
lines changed

7 files changed

+713
-520
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"lint:fix": "eslint \"{src/components,src/app}/*/\" --ext=.ts,.tsx --fix"
1212
},
1313
"dependencies": {
14+
"@0xsplits/splits-sdk-react": "^1.3.3",
1415
"@ethereum-attestation-service/eas-sdk": "1.5.0",
1516
"@mdx-js/loader": "^3.0.0",
1617
"@mdx-js/react": "^3.0.0",

src/app/(dashboard)/projects/[projectId]/payments/page.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ interface PageProps {
1111

1212
export default function ProjectPaymentsPage({ params }: PageProps) {
1313
const projectId = params.projectId;
14-
const breadcrumbItems = [
15-
{ title: "Projects", link: "/projects" },
16-
{ title: "Project details", link: `/projects/${projectId}` },
17-
{ title: "Project Payments", link: `/projects/${projectId}/payments` },
18-
];
1914
const [projectPaymentAddress, setProjectPaymentAddress] = useState<
2015
PaymentAddressDto | undefined
2116
>();

src/app/(dashboard)/projects/[projectId]/payments/paymentCreateModal.tsx

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { PaymentSplitDto } from "@/app/api/payments/service/paymentSplitsService";
22
import { Button } from "@/components/ui/button";
33
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
4+
import { useSplitsClient } from "@0xsplits/splits-sdk-react";
5+
import { useAccount } from "wagmi";
46

57
type CreatePaymentAddressModalProps = {
68
projectId: string;
@@ -11,14 +13,59 @@ export function CreatePaymentAddressModal({
1113
projectId,
1214
paymentSplits,
1315
}: CreatePaymentAddressModalProps) {
16+
const account = useAccount();
17+
18+
const splitsClient = useSplitsClient({
19+
// TODO: Use connected chainId
20+
chainId: 8453,
21+
publicClient: window.ethereum!,
22+
});
23+
24+
const handleCreateSplit = async () => {
25+
const recipients = paymentSplits
26+
.filter((split) => {
27+
return split.paymentSplit != 0 || split.walletAddress == undefined;
28+
})
29+
.map((split) => ({
30+
address: split.walletAddress!,
31+
percentAllocation: Number.parseFloat(
32+
split.paymentSplit!.toPrecision(2),
33+
),
34+
}));
35+
const createSplitReq = {
36+
recipients: recipients.filter(
37+
(recipient) => recipient.address != undefined,
38+
),
39+
distributorFeePercent: 0,
40+
controller: account.address,
41+
};
42+
try {
43+
const args = {
44+
splitAddress: "0x881985d5B0690598b84bcD7348c4A8c842e79419",
45+
};
46+
const response = await splitsClient.getSplitMetadata(args);
47+
console.log(response);
48+
} catch (error) {
49+
console.log(error);
50+
}
51+
};
52+
1453
function missingContributionWallets(): number {
1554
return paymentSplits.filter((split) => split.walletAddress == null).length;
1655
}
1756

1857
return (
1958
<Dialog>
2059
<DialogTrigger asChild>
21-
<Button className="mr-2">Create Payment Address</Button>
60+
<Button className="mr-2" disabled={!account.isConnected}>
61+
{account.isConnected ? (
62+
<>Create Payment Address</>
63+
) : account.isConnecting || account.isReconnecting ? (
64+
<>Connecting...</>
65+
) : (
66+
<>Connect wallet</>
67+
)}
68+
</Button>
2269
</DialogTrigger>
2370
<DialogContent className="sm:max-w-md">
2471
<div className="flex flex-col items-center space-x-2 pt-6 pb-6">
@@ -46,11 +93,12 @@ export function CreatePaymentAddressModal({
4693

4794
<Button
4895
className="w-1/2 ml-2"
96+
disabled={!account.isConnected}
4997
onClick={() => {
50-
console.log("Hi");
98+
handleCreateSplit();
5199
}}
52100
>
53-
Continue
101+
<>Continue</>
54102
</Button>
55103
</div>
56104
</div>

src/app/api/payments/service/paymentSplitsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function removeNoWalletContributors(
110110
contributionScore: armitageScore,
111111
contributionScorePercentage: 3,
112112
paymentSplit: 3,
113-
walletAddress: "mywalletaddress",
113+
walletAddress: "0xb5685343ed45d8b896633f9c128c55f758feb0aa",
114114
});
115115
return userScoresArray;
116116
}

src/app/providers/providers.tsx

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"use client";
22
import React from "react";
3-
import { ThemeProvider, useTheme } from "next-themes";
3+
import { ThemeProvider } from "next-themes";
44

55
import { WagmiProvider } from "wagmi";
66
import {
77
darkTheme,
8-
lightTheme,
98
getDefaultConfig,
109
RainbowKitProvider,
1110
} from "@rainbow-me/rainbowkit";
1211
import { base, sepolia } from "viem/chains";
1312
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
13+
import { SplitsProvider } from "@0xsplits/splits-sdk-react";
1414

1515
const queryClient = new QueryClient();
1616
const config = getDefaultConfig({
@@ -21,46 +21,22 @@ const config = getDefaultConfig({
2121
});
2222

2323
export default function Providers({ children }: { children: React.ReactNode }) {
24-
const { resolvedTheme } = useTheme();
2524
return (
2625
<>
2726
<WagmiProvider config={config}>
2827
<QueryClientProvider client={queryClient}>
29-
{resolvedTheme === "dark" ? (
30-
<RainbowKitProvider
31-
theme={darkTheme({
32-
accentColor: "#84cc16",
33-
accentColorForeground: "black",
34-
borderRadius: "medium",
35-
fontStack: "system",
36-
})}
37-
>
38-
<ThemeProvider
39-
attribute="class"
40-
defaultTheme="system"
41-
enableSystem
42-
>
43-
{children}
44-
</ThemeProvider>
45-
</RainbowKitProvider>
46-
) : (
47-
<RainbowKitProvider
48-
theme={lightTheme({
49-
accentColor: "#84cc16",
50-
accentColorForeground: "black",
51-
borderRadius: "medium",
52-
fontStack: "system",
53-
})}
54-
>
55-
<ThemeProvider
56-
attribute="class"
57-
defaultTheme="system"
58-
enableSystem
59-
>
60-
{children}
61-
</ThemeProvider>
62-
</RainbowKitProvider>
63-
)}
28+
<RainbowKitProvider
29+
theme={darkTheme({
30+
accentColor: "#84cc16",
31+
accentColorForeground: "black",
32+
borderRadius: "medium",
33+
fontStack: "system",
34+
})}
35+
>
36+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
37+
<SplitsProvider>{children}</SplitsProvider>
38+
</ThemeProvider>
39+
</RainbowKitProvider>
6440
</QueryClientProvider>
6541
</WagmiProvider>
6642
</>

src/components/payments/contributors/paymentSplitsTable.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { useEffect, useState } from "react";
55
import { PaymentSplitsDataTable } from "./paymentSplitsDataTable";
66
import { PaymentSplitsColumns } from "./paymentSplitsColumns";
77
import { Heading } from "@/components/ui/heading";
8-
import { Button } from "@/components/ui/button";
9-
import { CreatePaymentAddressModal } from "@/app/(dashboard)/projects/[projectId]/payments/paymentCreateModal";
108

119
interface ProjectContributionTableProps {
1210
projectId: string;

0 commit comments

Comments
 (0)