Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sponsorship information in post editor #531

Merged
merged 5 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/devhub/entity/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,25 @@ const toggleEditor = () => {
State.update({ showEditor: !state.showEditor });
};

let amount = null;
let token = null;
let supervisor = null;

if (state.postType === "Solution") {
const amountMatch = post.snapshot.description.match(
/Requested amount: (\d+(\.\d+)?) (\w+)/
);
amount = amountMatch ? parseFloat(amountMatch[1]) : null;
token = amountMatch ? amountMatch[3] : null;

const sponsorMatch = post.snapshot.description.match(
/Requested sponsor: @([^\s]+)/
);
supervisor = sponsorMatch ? sponsorMatch[1] : null;
}

const seekingFunding = amount !== null || token !== null || supervisor !== null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be problematic: if state.postType is not Solution, then amount, token and supervisor is all undefined, and this will be true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made these variables null by default to avoid this case


function Editor() {
return (
<div class="row" id={`accordion${postId}`} key="editors-footer">
Expand Down Expand Up @@ -595,9 +614,11 @@ function Editor() {
labels: post.snapshot.labels,
name: post.snapshot.name,
description: post.snapshot.description,
amount: post.snapshot.amount,
token: tokenResolver(post.snapshot.sponsorship_token),
supervisor: post.snapshot.supervisor,
amount: post.snapshot.amount || amount,
token: tokenResolver(post.snapshot.sponsorship_token || token),
supervisor:
post.snapshot.post.snapshot.supervisor || supervisor,
seekingFunding: seekingFunding,
githubLink: post.snapshot.github_link,
onDraftStateChange,
draftState:
Expand Down
14 changes: 12 additions & 2 deletions src/devhub/entity/post/PostEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ const labels = labelStrings.map((s) => {
return { name: s };
});

const cleanDescription = (description) => {
return description.replace(
/###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g,
""
);
};

initState({
seekingFunding: false,
seekingFunding: props.seekingFunding ?? false,
author_id: context.accountId,
// Should be a list of objects with field "name".
labels,
Expand All @@ -52,7 +59,10 @@ initState({
labelStrings,
postType,
name: props.name ?? "",
description: props.description ?? "",
description:
(props.postType === "Solution"
? cleanDescription(props.description)
: props.description) ?? "",
amount: props.amount ?? "0",
token: props.token ?? "USDT",
supervisor: props.supervisor ?? "neardevdao.near",
Expand Down