Skip to content

Commit

Permalink
cid fix
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Dec 15, 2023
1 parent 35294f2 commit 0a85cb0
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
6 changes: 4 additions & 2 deletions packages/hardhat/contracts/Nostr3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ contract Nostr3 {
owner = msg.sender;
}


function join(bytes memory publicKey,address evmAddress) public {
Nostr3Account memory account;
account.publicKey = publicKey;
Expand All @@ -47,6 +46,8 @@ contract Nostr3 {
owner = _newOwner;
}


// TODO : Add reentrancy
function deposit(bytes32 encryptedHash) public payable {
uint256 feeAmount = msg.value * FEE / 10000;
uint256 depositAmount = msg.value - feeAmount;
Expand All @@ -57,8 +58,9 @@ contract Nostr3 {
function withdraw(string calldata key) public {
bytes32 hashed = keccak256(abi.encode(key));
uint amount = encryptedDeposits[hashed];
payable(msg.sender).transfer(amount);
encryptedDeposits[hashed] = 0;
payable(msg.sender).transfer(amount);

}

function withdrawFees() public {
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/pages/api/[pubkey].ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default async function handler(
let cid;
let state;

if (fse.existsSync(process.cwd() + "/pages/api/cids.json")) {
const rawData = fse.readFileSync(process.cwd() + "/pages/api/cids.json", "utf8");
if (fse.existsSync(process.cwd() + "/public/cids.json")) {
const rawData = fse.readFileSync(process.cwd() + "/public/cids.json", "utf8");
cid = JSON.parse(rawData);
}

Expand Down
1 change: 0 additions & 1 deletion packages/nextjs/pages/api/cids.json

This file was deleted.

6 changes: 3 additions & 3 deletions packages/nextjs/pages/api/getAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ export default async function handler(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
process.env.NEXT_PUBLIC_PINATA_GATEWAY,
);

let cid;
const cidFilePath = process.cwd() + "/pages/api/cids.json";
const cidFilePath = process.cwd() + "/public/cids.json";

if (fse.existsSync(cidFilePath)) {
const rawData = fse.readFileSync(cidFilePath, "utf8");
cid = JSON.parse(rawData);
console.log(cid)
console.log(cid);
} else {
throw new Error("CID file not found.");
}
Expand Down
14 changes: 7 additions & 7 deletions packages/nextjs/pages/api/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const mogu = new Mogu(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
process.env.NEXT_PUBLIC_PINATA_GATEWAY,
);

export default async function handler(
Expand All @@ -34,8 +34,8 @@ export default async function handler(
let cid;
let state;

if (fse.existsSync(process.cwd() + "/pages/api/cids.json")) {
const rawData = fse.readFileSync(process.cwd() + "/pages/api/cids.json", "utf8");
if (fse.existsSync(process.cwd() + "/public/cids.json")) {
const rawData = fse.readFileSync(process.cwd() + "/public/cids.json", "utf8");
cid = JSON.parse(rawData);
}

Expand Down Expand Up @@ -68,7 +68,7 @@ export default async function handler(
const hash = await mogu.store();
console.log("CID:", hash);

fse.writeFileSync(process.cwd() + "/pages/api/cids.json", JSON.stringify(hash));
fse.writeFileSync(process.cwd() + "/public/cids.json", JSON.stringify(hash));

return res.status(200).json({
message: "Key stored and pinned to IPFS via Pinata successfully",
Expand All @@ -94,7 +94,7 @@ export default async function handler(
const hash = await mogu.store();
console.log("New CID", hash);

fse.writeFileSync(process.cwd() + "/pages/api/cids.json", JSON.stringify(hash));
fse.writeFileSync(process.cwd() + "/public/cids.json", JSON.stringify(hash));

return res.status(200).json({
message: "Key stored and pinned to IPFS via Pinata successfully",
Expand All @@ -112,7 +112,7 @@ export default async function handler(
const hash = await mogu.store();
console.log("New CID", hash);

fse.writeFileSync(process.cwd() + "/pages/api/cids.json", JSON.stringify(hash));
fse.writeFileSync(process.cwd() + "/public/cids.json", JSON.stringify(hash));

return res.status(200).json({
message: "Key stored and pinned to IPFS via Pinata successfully",
Expand All @@ -132,7 +132,7 @@ export default async function handler(
process.env.NEXT_PUBLIC_PINATA_API_KEY,
process.env.NEXT_PUBLIC_PINATA_API_SECRET,
process.env.NEXT_PUBLIC_DB_NAME,
process.env.NEXT_PUBLIC_PINATA_GATEWAY
process.env.NEXT_PUBLIC_PINATA_GATEWAY,
);

const { evmAddress } = req.query;
Expand Down
11 changes: 5 additions & 6 deletions packages/nextjs/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ const Login: NextPage = () => {
const [eventId, setEventId] = useState("");
const [searchTerm, setSearchTerm] = useState("");
const runTx = useTransactor(signer as WalletClient);
const [isSecretTip, setIsSecretTip] = useState("false");
const [isHide, setIsHide] = useState("false")
const [isHide, setIsHide] = useState(true)

const { data: nostr3ctx } = useScaffoldContract({
contractName: "Nostr3",
Expand Down Expand Up @@ -170,8 +169,8 @@ const Login: NextPage = () => {
</button>
{privateKey && !isHide && nostrPrivateKey ? (
<div>
<li id="privateKeyItem" class="font-bold border-b border-primary-content p-2 bl">
Private Key: <span id="privateKey" class="font-normal">{privateKey}</span>
<li id="privateKeyItem" className="font-bold border-b border-primary-content p-2 bl">
Private Key: <span id="privateKey" className="font-normal">{privateKey}</span>
</li>
<li className="font-bold border-b border-primary-content p-2">
NIP19 Private Key: <span className="font-normal">{nostrPrivateKey}</span>
Expand All @@ -180,8 +179,8 @@ const Login: NextPage = () => {
) : (
<div>

<li id="privateKeyItem" class="font-bold border-b border-primary-content p-2 bl">
Private Key: <span id="privateKey" class="font-normal"></span>
<li id="privateKeyItem" className="font-bold border-b border-primary-content p-2 bl">
Private Key: <span id="privateKey" className="font-normal"></span>
</li>
<li className="font-bold border-b border-primary-content p-2">
NIP19 Private Key: <span className="font-normal"></span>
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/public/cids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Qmd4ef5FeF4s6rUDYD8zWFRRHJBHMmfdrvmpkJMM46FQBa"
4 changes: 4 additions & 0 deletions packages/nextjs/services/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type TGlobalState = {
setEvent: (newEvent: any) => void;
followerAuthors: string[];
setFollowerAuthors: (newFollowerAuthors: string[]) => void;
cid: string;
setCid: (newCid: string) => void;
};

export const useGlobalState = create<TGlobalState>(set => ({
Expand All @@ -33,4 +35,6 @@ export const useGlobalState = create<TGlobalState>(set => ({
setEvent: (newEvent: any): void => set(() => ({ event: newEvent })),
followerAuthors: [],
setFollowerAuthors: (newFollowerAuthors: any): void => set(() => ({ followerAuthors: newFollowerAuthors })),
cid: "",
setCid: (newCid: any): void => set(() => ({ cid: newCid })),
}));

0 comments on commit 0a85cb0

Please sign in to comment.