Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #111 from factchain/fix/not-undefined-address
Browse files Browse the repository at this point in the history
Fix/not undefined address
  • Loading branch information
YBadiss authored Mar 30, 2024
2 parents 6bb57a1 + c63b827 commit 982c728
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
17 changes: 15 additions & 2 deletions fc-community-backend/apps/api/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import {
Headers,
} from "@nestjs/common";
import { getNetworkConfig } from "./factchain-core/networks/config";

function validateInputAddress(address: string): boolean {
return (/^(0x){1}[0-9a-fA-F]{40}$/i.test(address));
}

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
Expand All @@ -38,6 +43,14 @@ export class AppController {
@Headers() headers: Record<string, any>,
): Promise<NotesResponse> {
const network = getNetworkConfig(headers["network"]);

if (creatorAddress && !validateInputAddress(creatorAddress)) {
throw new Error("Invalid creatorAddress");
}
if (awaitingRatingBy && !validateInputAddress(awaitingRatingBy)) {
throw new Error("Invalid awaitingRatingBy");
}

let notes = [];

// Double Query Params
Expand Down Expand Up @@ -90,7 +103,7 @@ export class AppController {
@Query("noteUrl") noteUrl: string,
@Headers() headers: Record<string, any>,
): Promise<XSignedNoteIDResponse> {
const network = getNetworkConfig(headers["Network"]);
const network = getNetworkConfig(headers["network"]);
console.log(`Get factchain ID for X note URL ${noteUrl}`);
const res = await this.appService.getXNoteID(network, noteUrl);
return res;
Expand All @@ -104,7 +117,7 @@ export class AppController {
@Body("content") content: string,
@Headers() headers: Record<string, any>,
): Promise<XSignedNoteIDResponse> {
const network = getNetworkConfig(headers["Network"]);
const network = getNetworkConfig(headers["network"]);
const res = await this.appService.createXNoteMetadata(
network,
noteUrl,
Expand Down
12 changes: 8 additions & 4 deletions fc-community-extension/src/pages/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ function FCProfile(props) {
}

function FCNotes(props) {
const [notes] = createResource(() =>
getNotesForAllSocials(props.queryparams)
);
const [notes] = createResource(props.loggedIn, (loggedIn) => {
if (loggedIn) {
return getNotesForAllSocials(props.queryparams);
} else {
return null;
}
});

return (
<FCContainer>
Expand All @@ -120,7 +124,7 @@ function FCNotes(props) {
<div>to view Factchain notes</div>
</div>
</Match>
<Match when={notes() !== undefined}>
<Match when={notes()}>
<Switch>
<Match when={notes().length > 0}>
<div class="space-y-4">
Expand Down
2 changes: 2 additions & 0 deletions fc-community-extension/src/utils/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const getXNoteId = async (noteUrl) => {
method: 'GET',
headers: {
'Content-Type': 'application/json',
network: 'ETHEREUM_SEPOLIA',
},
});
if (response.status === 404) {
Expand All @@ -98,6 +99,7 @@ export const createXNoteId = async (noteUrl, content) => {
method: 'POST',
headers: {
'Content-Type': 'application/json',
network: 'ETHEREUM_SEPOLIA',
},
body: JSON.stringify({ noteUrl, content }),
});
Expand Down

0 comments on commit 982c728

Please sign in to comment.