-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed issue with members not showing, refactored contribution model d…
…efintions, created contribution factory and switched fetching of contributions to subgraph
- Loading branch information
mrtmeeseeks
committed
Oct 30, 2024
1 parent
6968908
commit ec280ac
Showing
20 changed files
with
317 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
BaseNFTModel, | ||
TaskContributionNFT, | ||
TaskContributionProperties | ||
} from "@aut-labs/sdk"; | ||
|
||
export class JoinDiscordTaskContributionProperties extends TaskContributionProperties { | ||
inviteUrl: string; | ||
constructor(data: JoinDiscordTaskContributionProperties) { | ||
super(data); | ||
this.inviteUrl = data.inviteUrl; | ||
} | ||
} | ||
|
||
export class JoinDiscordContribution< | ||
T = JoinDiscordTaskContributionProperties | ||
> extends TaskContributionNFT<T> { | ||
static getContributionNFT( | ||
contribution: JoinDiscordContribution | ||
): BaseNFTModel<any> { | ||
const taskContribution = new JoinDiscordContribution(contribution); | ||
return { | ||
name: taskContribution.name, | ||
description: taskContribution.description, | ||
properties: { | ||
inviteUrl: taskContribution.properties.inviteUrl, | ||
} | ||
} as BaseNFTModel<any>; | ||
} | ||
constructor( | ||
data: JoinDiscordContribution<T> = {} as JoinDiscordContribution<T> | ||
) { | ||
super(data); | ||
this.properties = new JoinDiscordTaskContributionProperties( | ||
data.properties as JoinDiscordTaskContributionProperties | ||
) as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
BaseNFTModel, | ||
TaskContributionNFT, | ||
TaskContributionProperties | ||
} from "@aut-labs/sdk"; | ||
|
||
export class OpenTaskContributionProperties extends TaskContributionProperties { | ||
attachmentRequired: boolean; | ||
textRequired: boolean; | ||
attachmentType: string; | ||
constructor(data: OpenTaskContributionProperties) { | ||
super(data); | ||
this.attachmentRequired = data.attachmentRequired; | ||
this.textRequired = data.textRequired; | ||
this.attachmentType = data.attachmentType; | ||
} | ||
} | ||
|
||
export class OpenTaskContribution< | ||
T = OpenTaskContributionProperties | ||
> extends TaskContributionNFT<T> { | ||
static getContributionNFT( | ||
contribution: OpenTaskContribution | ||
): BaseNFTModel<any> { | ||
const taskContribution = new OpenTaskContribution(contribution); | ||
return { | ||
name: taskContribution.name, | ||
description: taskContribution.description, | ||
properties: { | ||
attachmentRequired: taskContribution.properties.attachmentRequired, | ||
textRequired: taskContribution.properties.textRequired, | ||
attachmentType: taskContribution.properties.attachmentType | ||
} | ||
} as BaseNFTModel<any>; | ||
} | ||
constructor(data: OpenTaskContribution<T> = {} as OpenTaskContribution<T>) { | ||
super(data); | ||
this.properties = new OpenTaskContributionProperties( | ||
data.properties as OpenTaskContributionProperties | ||
) as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
BaseNFTModel, | ||
TaskContributionNFT, | ||
TaskContributionProperties | ||
} from "@aut-labs/sdk"; | ||
|
||
export class QuizTaskContributionProperties extends TaskContributionProperties { | ||
constructor(data: QuizTaskContributionProperties) { | ||
super(data); | ||
} | ||
} | ||
|
||
export class QuizTaskContribution< | ||
T = QuizTaskContributionProperties | ||
> extends TaskContributionNFT<T> { | ||
constructor(data: QuizTaskContribution<T> = {} as QuizTaskContribution<T>) { | ||
super(data); | ||
this.properties = new QuizTaskContributionProperties( | ||
data.properties as QuizTaskContributionProperties | ||
) as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
BaseNFTModel, | ||
TaskContributionNFT, | ||
TaskContributionProperties | ||
} from "@aut-labs/sdk"; | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,158 +1,51 @@ | ||
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; | ||
textRequired: boolean; | ||
attachmentType: string; | ||
constructor(data: OpenTaskContributionProperties) { | ||
super(data); | ||
this.attachmentRequired = data.attachmentRequired; | ||
this.textRequired = data.textRequired; | ||
this.attachmentType = data.attachmentType; | ||
} | ||
} | ||
|
||
export class OpenTaskContribution< | ||
T = OpenTaskContributionProperties | ||
> extends TaskContributionNFT<T> { | ||
static getContributionNFT( | ||
contribution: OpenTaskContribution | ||
): BaseNFTModel<any> { | ||
const taskContribution = new OpenTaskContribution(contribution); | ||
return { | ||
name: taskContribution.name, | ||
description: taskContribution.description, | ||
properties: { | ||
attachmentRequired: taskContribution.properties.attachmentRequired, | ||
textRequired: taskContribution.properties.textRequired, | ||
attachmentType: taskContribution.properties.attachmentType | ||
} | ||
} as BaseNFTModel<any>; | ||
} | ||
constructor(data: OpenTaskContribution<T> = {} as OpenTaskContribution<T>) { | ||
super(data); | ||
this.properties = new OpenTaskContributionProperties( | ||
data.properties as OpenTaskContributionProperties | ||
) as T; | ||
} | ||
} | ||
|
||
export class JoinDiscordTaskContributionProperties extends TaskContributionProperties { | ||
constructor(data: JoinDiscordTaskContributionProperties) { | ||
super(data); | ||
} | ||
} | ||
|
||
export class JoinDiscordTaskContribution< | ||
T = JoinDiscordTaskContributionProperties | ||
> extends TaskContributionNFT<T> { | ||
constructor(data: OpenTaskContribution<T> = {} as OpenTaskContribution<T>) { | ||
super(data); | ||
this.properties = new JoinDiscordTaskContributionProperties( | ||
data.properties as JoinDiscordTaskContributionProperties | ||
) as T; | ||
} | ||
} | ||
|
||
export class QuizTaskContributionProperties extends TaskContributionProperties { | ||
constructor(data: QuizTaskContributionProperties) { | ||
super(data); | ||
} | ||
} | ||
|
||
export class QuizTaskContribution< | ||
T = QuizTaskContributionProperties | ||
> extends TaskContributionNFT<T> { | ||
constructor(data: OpenTaskContribution<T> = {} as OpenTaskContribution<T>) { | ||
super(data); | ||
this.properties = new QuizTaskContributionProperties( | ||
data.properties as QuizTaskContributionProperties | ||
) 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; | ||
} | ||
} | ||
import { BaseNFTModel } 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"; | ||
|
||
export const ContributionFactory = ( | ||
metadata: BaseNFTModel<any>, | ||
contribution: any, | ||
taskTypes: TaskType[] | ||
) => { | ||
const taskType = taskTypes.find( | ||
(taskType) => taskType.taskId === contribution.taskId | ||
); | ||
|
||
if (!taskType) { | ||
throw new Error("Task type not found"); | ||
} | ||
const taskName = taskType.metadata.properties.type; | ||
const data = { | ||
...metadata, | ||
properties: { | ||
...metadata.properties, | ||
...contribution | ||
}, | ||
} | ||
switch (taskName) { | ||
case "OpenTask": | ||
return new OpenTaskContribution(data); | ||
case "DiscordGatherings": | ||
return new DiscordGatheringContribution(data); | ||
case "TwitterRetweet": | ||
return new RetweetContribution(data); | ||
case "JoinDiscord": | ||
return new JoinDiscordContribution(data); | ||
case "Quiz": | ||
return new QuizTaskContribution(data); | ||
case "TwitterLike": | ||
case "GitHubCommit": | ||
case "GitHubOpenPR": | ||
case "DiscordPolls": | ||
case "TwitterFollow": | ||
case "TwitterComment": | ||
throw new Error("Task type not implemented"); | ||
|
||
default: | ||
throw new Error("Task type not found"); | ||
} | ||
}; |
Oops, something went wrong.