-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Aut-Labs/contributions
Contributions [WIP]
- Loading branch information
Showing
38 changed files
with
2,593 additions
and
1,160 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,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
45
src/api/models/contribution-types/discord-gathering.model.ts
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,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"; | ||
} |
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 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"; | ||
} |
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,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"; | ||
} |
Oops, something went wrong.