Skip to content

Commit

Permalink
Merge pull request #7 from Aut-Labs/contributions
Browse files Browse the repository at this point in the history
Contributions [WIP]
  • Loading branch information
AntGe authored Dec 4, 2024
2 parents b831f7e + 5656e36 commit cecb42d
Show file tree
Hide file tree
Showing 38 changed files with 2,593 additions and 1,160 deletions.
3 changes: 2 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default tseslint.config(
"@typescript-eslint/no-unused-vars": "off",
"react-refresh/only-export-components": "off",
"react-hooks/exhaustive-deps": "off",
"@typescript-eslint/no-unused-expressions": "off"
"@typescript-eslint/no-unused-expressions": "off",
"no-debugger":"off"
}
}
);
29 changes: 16 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
},
"dependencies": {
"@apollo/client": "^3.11.5",
"@aut-labs/abi-types": "^0.0.86-dev",
"@aut-labs/connector": "^0.0.203",
"@aut-labs/abi-types": "^0.0.87-dev",
"@aut-labs/connector": "^0.0.205",
"@aut-labs/d-aut": "^1.0.204-dev",
"@aut-labs/sdk": "^0.0.221-dev",
"@aut-labs/sdk": "^0.0.228-dev",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@marker.io/browser": "^0.19.0",
Expand Down
8 changes: 8 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Route, Routes, Navigate } from "react-router-dom";
import { Box, useMediaQuery, useTheme } from "@mui/material";
import { useAppDispatch } from "@store/store.model";
import { updateWalletProviderState } from "@store/WalletProvider/WalletProvider";
import useQueryTaskTypes from "@utils/hooks/useQueryTaskTypes";
import AutLoading from "@components/AutLoading";
import Web3DautConnect from "@components/DAutConnect";
import SWSnackbar from "./components/snackbar";
Expand All @@ -22,6 +23,13 @@ function App() {
const theme = useTheme();
const mobile = useMediaQuery(theme.breakpoints.down("md"));

const { refetch } = useQueryTaskTypes({
variables: {
skip: 0,
take: 1000
}
});

useEffect(() => {
getAppConfig()
.then(async (networks) => {
Expand Down
13 changes: 13 additions & 0 deletions src/api/aut.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ import { NetworkConfig } from "./models/network.config";
import { extractDomain } from "@utils/helpers";
import { useAutConnector, useWalletConnector } from "@aut-labs/connector";
import { useEffect, useState } from "react";
import { AuthSig } from "@aut-labs/connector/lib/esm/aut-sig";

export const getAppConfig = (): Promise<NetworkConfig[]> => {
return axios
.get(`${environment.apiUrl}/aut/config/network/${environment.networkEnv}`)
.then((r) => r.data);
};

interface EncryptRequest {
autSig: AuthSig;
message: string;
hubAddress: string;
}

export const encryptMessage = (body: EncryptRequest): Promise<string> => {
return axios
.post(`${environment.apiUrl}/task/encrypt`, body)
.then((r) => r.data);
};

export const useAuthenticatedApi = () => {
const {
state: { multiSigner, address }
Expand Down
97 changes: 97 additions & 0 deletions src/api/contributions.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { TaskContributionNFT } from "@aut-labs/sdk";
import { BaseQueryApi, createApi } from "@reduxjs/toolkit/query/react";
import { AuthSig } from "@aut-labs/connector/lib/esm/aut-sig";
import axios from "axios";
import { environment } from "./environment";

interface CommitRequest {
autSig: AuthSig;
message: string;
hubAddress: string;
contributionId: string;
}

export const _commitContribution = async (
body: CommitRequest
): Promise<string> => {
const r = await axios.post(
`${environment.apiUrl}/task/contribution/commit`,
body
);
return r.data;
};

const commitContribution = async (
autSig: AuthSig,
contribution: TaskContributionNFT,
message: string,
hubAddress: string,
api: BaseQueryApi
) => {
try {
const response = _commitContribution({
autSig: autSig,
message: message,
hubAddress: hubAddress,
contributionId: contribution.properties.id
});
return {
data: response
};
} catch (error) {
return {
error: error.message
};
}
};

const commitAnyContribution = async (
{
contribution,
autSig,
message,
hubAddress
}: {
contribution: TaskContributionNFT;
autSig: AuthSig;
message: string;
hubAddress: string;
},
api: BaseQueryApi
) => {
return commitContribution(autSig, contribution, message, hubAddress, api);
};

export const contributionsApi = createApi({
reducerPath: "contributionsApi",
baseQuery: (args, api) => {
const { url, body } = args;
if (url === "commitAnyContribution") {
return commitAnyContribution(body, api);
}
return {
data: "Test"
};
},
tagTypes: [],
endpoints: (builder) => ({
commitAnyContribution: builder.mutation<
void,
{
autSig: AuthSig;
contribution: TaskContributionNFT;
message: string;
hubAddress: string;
}
>({
query: (body) => {
return {
body,
url: "commitAnyContribution"
};
}
})
})
});

export const { useCommitAnyContributionMutation } = contributionsApi;
45 changes: 45 additions & 0 deletions src/api/models/contribution-types/discord-gathering.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
BaseNFTModel,
TaskContributionNFT,
TaskContributionProperties
} from "@aut-labs/sdk";

export class DiscordGatheringContributionProperties extends TaskContributionProperties {
channelId: string;
duration: number;

constructor(data: DiscordGatheringContributionProperties) {
super(data);
this.channelId = data.channelId;
this.duration = data.duration;
}
}

export class DiscordGatheringContribution<
T = DiscordGatheringContributionProperties
> extends TaskContributionNFT<T> {
static getContributionNFT(
contribution: DiscordGatheringContribution
): BaseNFTModel<any> {
const taskContribution = new DiscordGatheringContribution(contribution);
return {
name: taskContribution.name,
description: taskContribution.description,
properties: {
duration: taskContribution.properties.duration,
channelId: taskContribution.properties.channelId
}
} as BaseNFTModel<any>;
}

constructor(
data: DiscordGatheringContribution<T> = {} as DiscordGatheringContribution<T>
) {
super(data);
this.properties = new DiscordGatheringContributionProperties(
data.properties as DiscordGatheringContributionProperties
) as T;
}

contributionType? = "Discord Gatherings";
}
43 changes: 43 additions & 0 deletions src/api/models/contribution-types/github-commit.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
BaseNFTModel,
TaskContributionNFT,
TaskContributionProperties
} from "@aut-labs/sdk";

export class GithubCommitContributionProperties extends TaskContributionProperties {
branch: string;
repository: string;
organisation: string;
constructor(data: GithubCommitContributionProperties) {
super(data);
this.branch = data.branch;
this.repository = data.repository;
this.organisation = data.organisation;
}
}

export class GithubCommitContribution<
T = GithubCommitContributionProperties
> extends TaskContributionNFT<T> {
static getContributionNFT(
contribution: GithubCommitContribution
): BaseNFTModel<any> {
const taskContribution = new GithubCommitContribution(contribution);
return {
name: taskContribution.name,
description: taskContribution.description,
properties: {
branch: taskContribution.properties.branch,
repository: taskContribution.properties.repository,
organisation: taskContribution.properties.organisation
}
} as BaseNFTModel<any>;
}
constructor(data: GithubCommitContribution<T> = {} as GithubCommitContribution<T>) {
super(data);
this.properties = new GithubCommitContributionProperties(
data.properties as GithubCommitContributionProperties
) as T;
}
contributionType? = "Commit";
}
47 changes: 47 additions & 0 deletions src/api/models/contribution-types/github-pr.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
BaseNFTModel,
TaskContributionNFT,
TaskContributionProperties
} from "@aut-labs/sdk";

export class GithubPullRequestContributionProperties extends TaskContributionProperties {
branch: string;
repository: string;
organisation: string;
constructor(data: GithubPullRequestContributionProperties) {
super(data);
this.branch = data.branch;
this.repository = data.repository;
this.organisation = data.organisation;
}
}

export class GithubPullRequestContribution<
T = GithubPullRequestContributionProperties
> extends TaskContributionNFT<T> {
static getContributionNFT(
contribution: GithubPullRequestContribution
): BaseNFTModel<any> {
const taskContribution = new GithubPullRequestContribution(
contribution
);
return {
name: taskContribution.name,
description: taskContribution.description,
properties: {
branch: taskContribution.properties.branch,
repository: taskContribution.properties.repository,
organisation: taskContribution.properties.organisation
}
} as BaseNFTModel<any>;
}
constructor(
data: GithubPullRequestContribution<T> = {} as GithubPullRequestContribution<T>
) {
super(data);
this.properties = new GithubPullRequestContributionProperties(
data.properties as GithubPullRequestContributionProperties
) as T;
}
contributionType? = "Pull Request";
}
Loading

0 comments on commit cecb42d

Please sign in to comment.