Skip to content

Commit

Permalink
Merge pull request #13 from Aut-Labs/twitter-github-integration
Browse files Browse the repository at this point in the history
Twitter GitHub integration
  • Loading branch information
AntGe authored Oct 29, 2024
2 parents a9df925 + 0384210 commit 5a7be15
Show file tree
Hide file tree
Showing 26 changed files with 7,376 additions and 3,391 deletions.
5,057 changes: 1,693 additions & 3,364 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { lazy, useEffect, useMemo, useState } from "react";
import { useSelector } from "react-redux";
import { Box } from "@mui/material";
Expand All @@ -13,6 +12,8 @@ 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"));

Expand All @@ -34,11 +35,8 @@ function App() {
const returnUrl = useMemo(() => {
if (!hubData) return "/";
const shouldGoToDashboard =
location.pathname === "/" ||
!location.pathname.includes(hubData?.name);
const goTo = shouldGoToDashboard
? `/${hubData?.name}`
: location.pathname;
location.pathname === "/" || !location.pathname.includes(hubData?.name);
const goTo = shouldGoToDashboard ? `/${hubData?.name}` : location.pathname;
const url = location.state?.from;
return url || goTo;
}, [hubData]);
Expand Down Expand Up @@ -100,7 +98,8 @@ function App() {
) : (
<>
<Routes>
{/* <Route path="callback" element={<Callback />} /> */}
<Route path="callback" element={<Callback />} />
<Route path="claim-discord-role" element={<ClaimRole />} />
{!hubData && (
<>
<Route path="/" element={<GetStarted />} />
Expand Down
18 changes: 17 additions & 1 deletion src/api/ProviderFactory/web3-daut-connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { EnvMode, autUrls, environment } from "@api/environment";
import AutSDK from "@aut-labs/sdk";
import { MultiSigner } from "@aut-labs/sdk/dist/models/models";
import { NetworkConfig } from "./network.config";
import { useAutConnector } from "@aut-labs/connector";
import { AutWalletConnector, useAutConnector } from "@aut-labs/connector";
import { hubUpdateState } from "@store/Hub/hub.reducer";
import { resetState } from "@store/store";
import { AUTH_TOKEN_KEY } from "@api/auth.api";
import { HubOSAutID } from "@api/aut.model";
import { AppTitle } from "@store/ui-reducer";
import AutLoading from "@components/AutLoading";

function Web3DautConnect({
setLoading
Expand Down Expand Up @@ -177,6 +179,20 @@ function Web3DautConnect({

return (
<>
<AutWalletConnector
connect={connect}
titleContent={
<AppTitle
mb={{
xs: "16px",
lg: "24px",
xxl: "32px"
}}
variant="h2"
/>
}
loadingContent={<AutLoading width="130px" height="130px" />}
/>
<d-aut
style={{
display: "none",
Expand Down
88 changes: 87 additions & 1 deletion src/api/contribution.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
import { BaseNFTModel, TaskContributionNFT, TaskContributionProperties } from "@aut-labs/sdk";
import {
BaseNFTModel,
TaskContributionNFT,
TaskContributionProperties
} from "@aut-labs/sdk";
import { duration } from "@mui/material";

export class RetweetContributionProperties extends TaskContributionProperties {
tweetUrl: string;
constructor(data: RetweetContributionProperties) {
super(data);
this.tweetUrl = data.tweetUrl;
}
}

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

export class OpenTaskContributionProperties extends TaskContributionProperties {
attachmentRequired: boolean;
Expand Down Expand Up @@ -70,3 +106,53 @@ export class QuizTaskContribution<
) as T;
}
}

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

constructor(data: DiscordGatheringContributionProperties) {
super(data);
this.taskId = data.taskId;
this.role = data.role;
this.startDate = data.startDate;
this.channelId = data.channelId;
this.points = data.points;
this.quantity = data.quantity;
this.uri = data.uri;
}
}

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,
image: "",
properties: {
taskId: taskContribution.properties.taskId,
role: taskContribution.properties.role,
startDate: taskContribution.properties.startDate,
duration: taskContribution.properties.duration,
channelId: taskContribution.properties.channelId,
points: taskContribution.properties.points,
quantity: taskContribution.properties.quantity,
uri: taskContribution.properties.uri
}
} as BaseNFTModel<any>;
}

constructor(
data: DiscordGatheringContribution<T> = {} as DiscordGatheringContribution<T>
) {
super(data);
this.properties = new DiscordGatheringContributionProperties(
data.properties as DiscordGatheringContributionProperties
) as T;
}
}
57 changes: 55 additions & 2 deletions src/api/contributions.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import AutSDK, {
TaskContributionNFT
} from "@aut-labs/sdk";
import { BaseQueryApi, createApi } from "@reduxjs/toolkit/query/react";
import { OpenTaskContribution } from "./contribution.model";
import {
DiscordGatheringContribution,
OpenTaskContribution,
RetweetContribution
} from "./contribution.model";
import { TaskFactoryContractEventType } from "@aut-labs/abi-types";

const hubServiceCache: Record<string, Hub> = {};
Expand Down Expand Up @@ -94,13 +98,36 @@ const createOpenTaskContribution = async (
return createContribution(openTaskContribution, nft, api);
};

const createTwitterRetweetContribution = async (
retweetContribution: RetweetContribution,
api: BaseQueryApi
) => {
const nft = RetweetContribution.getContributionNFT(retweetContribution);
return createContribution(retweetContribution, nft, api);
};

const createDiscordGatheringContribution = async (
openTaskContribution: DiscordGatheringContribution,
api: BaseQueryApi
) => {
const nft =
DiscordGatheringContribution.getContributionNFT(openTaskContribution);
return createContribution(openTaskContribution, nft, api);
};

export const contributionsApi = createApi({
reducerPath: "contributionsApi",
baseQuery: (args, api, extraOptions) => {
const { url, body } = args;
if (url === "createOpenTaskContribution") {
return createOpenTaskContribution(body, api);
}
if (url === "createDiscordGatheringContribution") {
return createDiscordGatheringContribution(body, api);
}
if (url === "createTwitterRetweetContribution") {
return createTwitterRetweetContribution(body, api);
}
return {
data: "Test"
};
Expand All @@ -114,8 +141,34 @@ export const contributionsApi = createApi({
url: "createOpenTaskContribution"
};
}
}),
createDiscordGatheringContribution: builder.mutation<
void,
DiscordGatheringContribution
>({
query: (body) => {
return {
body,
url: "createDiscordGatheringContribution"
};
}
}),
createTwitterRetweetContribution: builder.mutation<
void,
RetweetContribution
>({
query: (body) => {
return {
body,
url: "createTwitterRetweetContribution"
};
}
})
})
});

export const { useCreateOpenTaskContributionMutation } = contributionsApi;
export const {
useCreateTwitterRetweetContributionMutation,
useCreateOpenTaskContributionMutation,
useCreateDiscordGatheringContributionMutation
} = contributionsApi;
5 changes: 4 additions & 1 deletion src/api/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export const swEnvVariables = {
discordRedirectUri: "VITE_DISCORD_REDIRECT_URL",
discordApiUrl: "VITE_DISCORD_API_URL",
discordBotAddress: "VITE_DISCORD_BOT_ADDRESS",
discordBotUrl: "VITE_DISCORD_BOT_API_URL"
discordBotUrl: "VITE_DISCORD_BOT_API_URL",

twitterClientId: "VITE_TWITTER_CLIENT_ID",
githubClientId: "VITE_GITHUB_CLIENT_ID"
};

export const environment: typeof swEnvVariables =
Expand Down
Loading

0 comments on commit 5a7be15

Please sign in to comment.