Skip to content

Commit

Permalink
Merge pull request #14 from Aut-Labs/github-task-final
Browse files Browse the repository at this point in the history
GitHub task final
  • Loading branch information
AntGe authored Nov 20, 2024
2 parents ec280ac + 9f77e31 commit fe8f1b0
Show file tree
Hide file tree
Showing 38 changed files with 1,312 additions and 2,208 deletions.
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 @@ -30,9 +30,9 @@
"dependencies": {
"@apollo/client": "^3.9.1",
"@aut-labs/abi-types": "^0.0.86-dev",
"@aut-labs/connector": "^0.0.203",
"@aut-labs/d-aut": "^1.0.204-dev",
"@aut-labs/sdk": "^0.0.220-dev",
"@aut-labs/connector": "^0.0.205",
"@aut-labs/d-aut": "^1.0.205-dev",
"@aut-labs/sdk": "^0.0.222-dev",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@leenguyen/react-flip-clock-countdown": "^1.4.0",
Expand Down
37 changes: 3 additions & 34 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { environment } from "@api/environment";
import { updateWalletProviderState } from "@store/WalletProvider/WalletProvider";
import { getAppConfig } from "@api/aut.api";
import AutSDK from "@aut-labs/sdk";
import GetStarted from "./pages/GetStarted/GetStarted";
import AutLoading from "@components/AutLoading";
import { HubData } from "@store/Hub/hub.reducer";
import ClaimRole from "./pages/DiscordBot/ClaimRole";
import Callback from "./pages/Oauth2Callback/Callback";

const AutDashboardMain = lazy(() => import("./pages/AutDashboardMain"));
const Callback = lazy(() => import("./pages/Oauth2Callback/Callback"));
const ClaimRole = lazy(() => import("./pages/DiscordBot/ClaimRole"));
const GetStarted = lazy(() => import("./pages/GetStarted/GetStarted"));

function App() {
const dispatch = useAppDispatch();
Expand All @@ -24,14 +24,6 @@ function App() {
const hubData = useSelector(HubData);
const location = useLocation();

// const isLoading = useMemo(
// () => !isAuthenticating && isInitialized,
// [isAuthenticating, isInitialized]
// );

console.log(isAuthenticating, "isAuthenticating");
console.log(isInitialized, "isInitialized");
// console.log(isLoading, "isLoading");
const returnUrl = useMemo(() => {
if (!hubData) return "/";
const shouldGoToDashboard =
Expand All @@ -40,7 +32,6 @@ function App() {
const url = location.state?.from;
return url || goTo;
}, [hubData]);
console.log(returnUrl, "returnUrl");

useEffect(() => {
getAppConfig().then(async (networks) => {
Expand All @@ -49,39 +40,17 @@ function App() {
networksConfig: networks
})
);

const sdk = new AutSDK({
ipfs: {
apiKey: environment.ipfsApiKey,
secretApiKey: environment.ipfsApiSecret,
gatewayUrl: environment.ipfsGatewayUrl
}
});
// await AutSDK.getInstance(true);
setInitialized(true);
});
// .finally(() => setLoading(false));
}, []);

// useEffect(() => {
// getAppConfig()
// .then(async (res) => {
// dispatch(setNetworks(res));
// const [network] = res.filter((d) => !d.disabled);
// setConfig(generateNetworkConfig(network));
// new AutSDK({
// ipfs: {
// apiKey: environment.ipfsApiKey,
// secretApiKey: environment.ipfsApiSecret,
// gatewayUrl: environment.ipfsGatewayUrl
// }
// });
// })
// .catch(() => {
// setError(true);
// });
// }, []);

return (
<>
<SWSnackbar />
Expand Down
13 changes: 13 additions & 0 deletions src/api/aut.api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import axios from "axios";
import { environment } from "./environment";
import { NetworkConfig } from "./ProviderFactory/network.config";
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);
};
2 changes: 2 additions & 0 deletions src/api/contribution-types/discord-gathering.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ export class DiscordGatheringContribution<
data.properties as DiscordGatheringContributionProperties
) as T;
}

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

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

export class CommitContribution<
T = CommitContributionProperties
> extends TaskContributionNFT<T> {
static getContributionNFT(
contribution: CommitContribution
): BaseNFTModel<any> {
const taskContribution = new CommitContribution(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: CommitContribution<T> = {} as CommitContribution<T>) {
super(data);
this.properties = new CommitContributionProperties(
data.properties as CommitContributionProperties
) as T;
}

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

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

export class PullRequestContribution<
T = PullRequestContributionProperties
> extends TaskContributionNFT<T> {
static getContributionNFT(
contribution: PullRequestContribution
): BaseNFTModel<any> {
const taskContribution = new PullRequestContribution(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: PullRequestContribution<T> = {} as PullRequestContribution<T>) {
super(data);
this.properties = new PullRequestContributionProperties(
data.properties as PullRequestContributionProperties
) as T;
}

contributionType? = "Pull Request";
}
2 changes: 2 additions & 0 deletions src/api/contribution-types/join-discord.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export class JoinDiscordContribution<
data.properties as JoinDiscordTaskContributionProperties
) as T;
}

contributionType? = "Join Discord";
}
2 changes: 2 additions & 0 deletions src/api/contribution-types/open-task.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ export class OpenTaskContributionProperties extends TaskContributionProperties {
data.properties as OpenTaskContributionProperties
) as T;
}

contributionType? = "Open Task";
}
27 changes: 27 additions & 0 deletions src/api/contribution-types/quiz.model.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,46 @@ import {
TaskContributionProperties
} from "@aut-labs/sdk";

interface QuizQuestionsAndAnswers {
question: string;
questionType: string;
answers: {
value: string;
correct: boolean;
}[];
}

export class QuizTaskContributionProperties extends TaskContributionProperties {
questions: QuizQuestionsAndAnswers[];
hash: string;
constructor(data: QuizTaskContributionProperties) {
super(data);
this.questions = data.questions;
this.hash = data.hash;
}
}

export class QuizTaskContribution<
T = QuizTaskContributionProperties
> extends TaskContributionNFT<T> {
static getContributionNFT(
contribution: QuizTaskContribution
): BaseNFTModel<any> {
const taskContribution = new QuizTaskContribution(contribution);
return {
name: taskContribution.name,
description: taskContribution.description,
properties: {
questions: taskContribution.properties.questions,
}
} as BaseNFTModel<any>;
}
constructor(data: QuizTaskContribution<T> = {} as QuizTaskContribution<T>) {
super(data);
this.properties = new QuizTaskContributionProperties(
data.properties as QuizTaskContributionProperties
) as T;
}

contributionType? = "Quiz";
}
2 changes: 2 additions & 0 deletions src/api/contribution-types/retweet.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export class RetweetContribution<
data.properties as RetweetContributionProperties
) as T;
}

contributionType? = "Retweet";
}
9 changes: 7 additions & 2 deletions src/api/contribution.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { BaseNFTModel } from "@aut-labs/sdk";
import { BaseNFTModel, TaskContributionNFT } from "@aut-labs/sdk";
import { TaskType } from "./models/task-type";
import { OpenTaskContribution } from "./contribution-types/open-task.model";
import { DiscordGatheringContribution } from "./contribution-types/discord-gathering.model";
import { RetweetContribution } from "./contribution-types/retweet.model";
import { JoinDiscordContribution } from "./contribution-types/join-discord.model";
import { QuizTaskContribution } from "./contribution-types/quiz.model.model";
import { CommitContribution } from "./contribution-types/github-commit.model";
import { PullRequestContribution } from "./contribution-types/github-pr.model";

export const ContributionFactory = (
metadata: BaseNFTModel<any>,
Expand Down Expand Up @@ -39,11 +41,14 @@ export const ContributionFactory = (
return new QuizTaskContribution(data);
case "TwitterLike":
case "GitHubCommit":
return new CommitContribution(data);
case "GitHubOpenPR":
return new PullRequestContribution(data);
case "DiscordPolls":
case "TwitterFollow":
case "TwitterComment":
throw new Error("Task type not implemented");
// throw new Error("Task type not implemented");
return new TaskContributionNFT(data);

default:
throw new Error("Task type not found");
Expand Down
Loading

0 comments on commit fe8f1b0

Please sign in to comment.