Compare commits

...

2 Commits

Author SHA1 Message Date
Ladd Hoffman 3eee257669 frontend: show post reputation
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 32s Details
2024-04-20 21:50:46 -05:00
Ladd Hoffman b4da0ec6e5 reduce logging and send HTTP 202 early rather than expecting the caller to wait 2024-04-20 21:50:23 -05:00
3 changed files with 15 additions and 12 deletions

View File

@ -35,7 +35,6 @@ const getContract = (name) => new ethers.Contract(
const fetchPaperInfo = async (paperId, retryDelay = 5000) => {
const url = `https://api.semanticscholar.org/graph/v1/paper/${paperId}?fields=title,url,authors,references`;
console.log('url:', url);
let retry = false;
let paper;
const response = await axios.get(url, {
@ -120,9 +119,6 @@ HREF ${paper.url}`;
contentToSign += `\n\n${JSON.stringify(embeddedData, null, 2)}`;
}
const signature = firstAuthorWallet.signMessageSync(contentToSign);
console.log({
authors, content, signature, embeddedData,
});
const verified = verifySignature({
authors, content, signature, embeddedData,
});
@ -149,6 +145,10 @@ module.exports = async (req, res) => {
// Read the paper info from SS
const paper = await fetchPaperInfo(paperId);
// Send HTTP code 202 - Accepted
res.status(202).end();
console.log('references count:', paper.references.length);
const eachCitationWeightPercent = Math.floor(30 / paper.references.length);
@ -176,19 +176,21 @@ module.exports = async (req, res) => {
hash, authors, content, signature, embeddedData,
} = await generatePost(paper);
console.log({
hash, authors, content, signature, embeddedData, citations,
});
// Write the new post to our database
await forum.put(hash, {
authors, content, signature, embeddedData, citations,
});
// Add the post to the form (on-chain)
await dao.addPost(authors, hash, citations);
try {
await dao.addPost(authors, hash, citations);
} catch (e) {
if (e.reason === 'A post with this contentId already exists') {
console.log(`Post already added for paper ${paperId}`);
return;
}
throw e;
}
console.log(`Added post to blockchain for paper ${paperId}`);
res.end();
};

View File

@ -9,7 +9,6 @@ const verifySignature = ({
}
try {
const account = recoverPersonalSignature({ data: contentToVerify, signature });
console.log(`recovered account: ${account}`);
const authorAddresses = authors.map((author) => author.authorAddress.toLowerCase());
if (!authorAddresses.includes(account.toLowerCase())) {
console.log('error: signer is not among the authors');

View File

@ -417,6 +417,7 @@ function App() {
<th>ID</th>
<th>Authors</th>
<th>Sender</th>
<th>Reputation</th>
<th>Actions</th>
</tr>
</thead>
@ -437,6 +438,7 @@ function App() {
</Stack>
</td>
<td>{getAddressName(chainId, post.sender)}</td>
<td>{post.reputation.toString()}</td>
<td>
<Button onClick={() => handleShowViewPost(post)}>
View Post