Skip to content

Commit

Permalink
edit index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
scobru committed Dec 12, 2023
1 parent 3a1442b commit 0f25dba
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/nextjs/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ScaffoldEthApp = ({ Component, pageProps }: AppProps) => {
avatar={BlockieAvatar}
theme={isDarkTheme ? darkTheme() : lightTheme()}
>
<div className="flex flex-col min-h-screen font-raleway ">
<div className="flex flex-col min-h-screen font-satoshi ">
<Header />
<main className="relative flex flex-col flex-1 ">
<Component {...pageProps} />
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/pages/api/cids.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"QmZ3GevxrWcELDhFU94bS8mLnoH8ngNzuyDH3JR8n7T9ap"
"Qmaxaxmhzux47opqBK1NTAKZoyV89BzU28dcQunKXCchkg"
7 changes: 4 additions & 3 deletions packages/nextjs/pages/claim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NextPage } from "next";
import { useWalletClient } from "wagmi";
import { RainbowKitCustomConnectButton } from "~~/components/scaffold-eth";
import { useScaffoldContractWrite } from "~~/hooks/scaffold-eth";

const Claim: NextPage = () => {
const [claimValue, setClaimValue] = useState("");
const [isModalOpen, setIsModalOpen] = useState(false);
Expand All @@ -11,16 +12,16 @@ const Claim: NextPage = () => {
const { writeAsync: withdraw } = useScaffoldContractWrite({
contractName: "Nostr3",
functionName: "withdraw",
args: [claimValue]
})
args: [claimValue],
});

useEffect(() => {
setIsModalOpen(true);
}, []);

const handleSubmit = () => {
console.log("Claim Value:", claimValue);
withdraw()
withdraw();
setIsModalOpen(false); // Chiudi il modal dopo il submit
};

Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Image from "next/image";
import "daisyui/dist/full.css";
import type { NextPage } from "next";
import { MetaHeader } from "~~/components/MetaHeader";
import 'daisyui/dist/full.css'; // Importa lo stile completo di DaisyUI

// Importa lo stile completo di DaisyUI

const Home: NextPage = () => {
return (
Expand All @@ -10,7 +12,9 @@ const Home: NextPage = () => {
<div className="w-full">
<Image className="mb-5 mx-auto" src="/assets/nostr3.png" width={400} height={400} alt="nostr3" />
<div className="m-5 mx-auto w-5/6">
<h1 className="text-4xl w-2/4 justify-center items-centert text-center mb-5 mx-auto">Generate Keys for <strong> NOSTR </strong> Protocol with Your <strong>EVM</strong> Address</h1>
<h1 className="text-4xl w-2/4 justify-center items-centert text-center mb-5 mx-auto">
Generate Keys for <strong> NOSTR </strong> Protocol with Your <strong>EVM</strong> Address
</h1>
{/* <p className="text-xl">
<strong>Nostr3</strong> is here to make your life easier when dealing with the Nostr protocol! It cleverly generates private keys
right from your EVM address, taking the hassle out of key storage. Need your keys? Just a quick interaction
Expand Down
51 changes: 20 additions & 31 deletions packages/nextjs/pages/login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable react/no-unescaped-entities */

/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useEffect, useState } from "react";
import Link from "next/link";
Expand All @@ -25,14 +26,9 @@ import { nip05 } from "nostr-tools";
import { ProfilePointer } from "nostr-tools/lib/types/nip19";
import { LazyLoadImage } from "react-lazy-load-image-component";
import "react-lazy-load-image-component/src/effects/blur.css";
import {
createWalletClient,
http,
isAddress,
keccak256,
parseEther
} from "viem";
import { createWalletClient, http, isAddress, keccak256, parseEther } from "viem";
import { toHex } from "viem";
import { encodeAbiParameters, parseAbiParameters } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { optimism } from "viem/chains";
import { WalletClient, useEnsName, usePublicClient, useWalletClient } from "wagmi";
Expand All @@ -41,14 +37,15 @@ import { useScaffoldContract } from "~~/hooks/scaffold-eth";
import { useTransactor } from "~~/hooks/scaffold-eth";
import { useGlobalState } from "~~/services/store/store";
import { notification } from "~~/utils/scaffold-eth";
import { encodeAbiParameters, parseAbiParameters } from 'viem'

declare global {
interface Window {
nostr: {
nip04: any;
getPublicKey: () => Promise<any>;
signEvent: (event: any) => Promise<any>;
encrypt: (data: string, key: string) => Promise<any>;
decrypt: (data: string, key: string) => Promise<any>;
};
}
}
Expand Down Expand Up @@ -151,7 +148,7 @@ const Login: NextPage = () => {
<p className="text-md">{profileDetails.about}</p>
</div>
)}
<button className="btn text-left mb-5" onClick={() => openKeysModal()}>
<button className="btn text-left mb-5 mt-5" onClick={() => openKeysModal()}>
Show Keys
</button>
<dialog id="keys_modal" className="modal bg-gradient-to-br from-primary to-secondary">
Expand Down Expand Up @@ -220,14 +217,10 @@ const Login: NextPage = () => {
</div>

<div>
<button
className="btn btn-base btn-md mr-2 md:mr-4 lg:mr-6 mt-10 mb-10 "
onClick={() => openTipModal()}
>
<button className="btn btn-base btn-md mr-2 md:mr-4 lg:mr-6 mt-10 mb-10 " onClick={() => openTipModal()}>
Tip
</button>
</div>

</div>
);
};
Expand Down Expand Up @@ -269,7 +262,7 @@ const Login: NextPage = () => {
let message;
let newEvent;

console.log("Tipping")
console.log("Tipping");
try {
const txResponse = await signer?.sendTransaction({
to: receiver,
Expand Down Expand Up @@ -734,11 +727,11 @@ const Login: NextPage = () => {
if (response.ok) {
const resultData = await response.json();
console.log(resultData);
notification.remove(id)
notification.remove(id);
notification.success("Stored");
} else {
console.error("Server response was not OK:", response.status);
notification.remove(id)
notification.remove(id);
notification.error("Error storing data");
}
} else {
Expand Down Expand Up @@ -766,7 +759,6 @@ const Login: NextPage = () => {
notification.error("Error storing data");
}
}

};

const handleGenerateRandomKeys = async () => {
Expand Down Expand Up @@ -880,8 +872,8 @@ const Login: NextPage = () => {
: pubKeyEthAddressList;

function generateRandomPassword(maxLength = 20) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+';
let password = '';
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
let password = "";

for (let i = 0; i < maxLength; i++) {
password += characters.charAt(Math.floor(Math.random() * characters.length));
Expand Down Expand Up @@ -1077,8 +1069,8 @@ const Login: NextPage = () => {
name="secret_tip"
id="isSecretTip"
placeholder="Secret"
onClick={(e: EventTarget) => {
setIsSecretTip(Boolean(e.target.checked));
onClick={(e: any) => {
setIsSecretTip(e.target.checked);
}}
/>{" "}
Check this if you don't know if the pubkey receiver is registred to nostr3.
Expand Down Expand Up @@ -1110,15 +1102,15 @@ const Login: NextPage = () => {
const receiver = pubKeyEthAddressList.find(
(item: { pubkey: string }) => item.pubkey === decodedPubKey.data,
)?.evmAddress;
console.log(receiver, evmAddress)
console.log(receiver, evmAddress);
setEvmAddress(evmAddress);
if (receiver) {
await handleTip(receiver);
} else {
notification.error("Profile not registred");
}
} else {
const key = generateRandomPassword()
const key = generateRandomPassword();

if (!isExtension) {
console.log("Not Extension");
Expand All @@ -1136,17 +1128,14 @@ const Login: NextPage = () => {
pubkey: publicKey,
};

const encoded = encodeAbiParameters(
parseAbiParameters('string'),
[key]
)
const encoded = encodeAbiParameters(parseAbiParameters("string"), [key]);

// Deposit on the contract with HASH
const hash = keccak256(encoded);

await nostr3ctx?.write?.deposit([hash], { value: parseEther(amountToTip) });
await nostr3ctx?.write?.deposit([hash], { value: parseEther(String(amountToTip)) });
const publish = await publishEvent(newEvent as UnsignedEvent, privateKey);
console.log(publish)
console.log(publish);
} else {
const message = `Tip ${amountToTip} ETH to ${pubKeyReceiver}. Use this key to retrive your tip: ${key}`;
const decodedPubKey = nip19.decode(pubKeyReceiver);
Expand All @@ -1159,7 +1148,7 @@ const Login: NextPage = () => {
pubkey: publicKey,
};

const hash = keccak256(String(key));
const hash = keccak256(String(key) as any);
await nostr3ctx?.write?.deposit([hash], { value: parseEther(String(amountToTip)) });

const signedEvent = await window.nostr.signEvent(newEvent);
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/styles/globals.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import url("https://fonts.googleapis.com/css2?family=Lato:wght@300&family=Raleway&display=swap");
@import url("https://api.fontshare.com/v2/css?f[]=satoshi@900,700,500,301,701,300,501,401,901,400&display=swap");
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
lato: ["Lato", "sans-serif"],
mono: ["Roboto Mono", "monospace"],
raleway: ["Raleway", "sans-serif"],
satoshi: ["Satoshi", "sans-serif"],
},
},
},
Expand Down
23 changes: 5 additions & 18 deletions packages/nextjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"compilerOptions": {
"target": "es2020",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
Expand All @@ -19,18 +15,9 @@
"jsx": "preserve",
"incremental": true,
"paths": {
"~~/*": [
"./*"
]
"~~/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"pages/tip/[npub]/[nnote].tsx"
],
"exclude": [
"node_modules"
]
}
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "pages/tip/[npub]/[nnote].tsx"],
"exclude": ["node_modules"]
}

0 comments on commit 0f25dba

Please sign in to comment.