Skip to content

Commit

Permalink
updats
Browse files Browse the repository at this point in the history
  • Loading branch information
happylolonly committed May 30, 2024
1 parent 93d7c26 commit 99c60ea
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 38 deletions.
Binary file added front/public/logo-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion front/public/tonconnect-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"url": "https://ton-wasm-cyber-hackathon.netlify.app/",
"name": "Cyber",
"iconUrl": "https://ton-wasm-cyber-hackathon.netlify.app/logo.png"
"iconUrl": "https://ton-wasm-cyber-hackathon.netlify.app/logo-black.png"
}
11 changes: 7 additions & 4 deletions front/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { network } from "@/hooks/contract/useTonClient";
import GlobalStyle from "@/styles/globalStyles";
import theme from "@/styles/theme";
import QueryClientProvider2 from "./queryClient";
import QueryClientProviderPussy from "./queryClientPussy";
import "./styles/index.scss";

import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
Expand All @@ -26,10 +27,12 @@ const App = () => {
<ThemeProvider theme={theme}>
<QueryClientProvider client={queryClient}>
<QueryClientProvider2>
<RecoilRoot>
<GlobalStyle />
<Router />
</RecoilRoot>
<QueryClientProviderPussy>
<RecoilRoot>
<GlobalStyle />
<Router />
</RecoilRoot>
</QueryClientProviderPussy>
</QueryClientProvider2>
</QueryClientProvider>
</ThemeProvider>
Expand Down
16 changes: 11 additions & 5 deletions front/src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import IcWalletConnect from "../../assets/icons/Landing/ic_landing_wallet.svg";
import IcWalletDisconnect from "../../assets/icons/Landing/ic_landing_wallet_disconnect.svg";
import useTonConnect from "../../hooks/contract/useTonConnect";
import Modal from "../main/Modal/Modal";
import { trimString } from "@/utils/trimString";

interface HeaderProps {
isOpen: boolean;
Expand All @@ -14,7 +15,7 @@ interface HeaderProps {
}

const Header = (props: HeaderProps) => {
const { connected, tonConnectUI } = useTonConnect();
const { connected, tonConnectUI, wallet } = useTonConnect();
const { isOpen, text, backgroundType } = props;
const [isOpenModal, setIsOpenModal] = useState(false);
const navigate = useNavigate();
Expand All @@ -32,13 +33,16 @@ const Header = (props: HeaderProps) => {
}
};

const { address } = wallet?.account || {};
return (
<>
{isOpenModal && <Modal handleModalState={handleModalState} />}
<HeaderWrapper $isOpen={isOpen} $backgroundType={backgroundType}>
<HeaderTitle onClick={() => navigate("/")}>{text}</HeaderTitle>

<HeaderRightBox>
{/* {pathname === "/" && (
{address && trimString(address, 6, 4)}
{pathname === "/" && (
<DisconnectButton $connect={connected}>
{connected ? (
<img
Expand All @@ -54,7 +58,7 @@ const Header = (props: HeaderProps) => {
/>
)}
</DisconnectButton>
)} */}
)}
<MenuButton onClick={handleRouter} $isOpen={isOpen}>
<span></span>
<span></span>
Expand Down Expand Up @@ -99,12 +103,14 @@ const DisconnectButton = styled.button<{ $connect: boolean }>`
height: 4.4rem;
padding: 1.2rem;
color: #36d6ae;
border: none;
border-radius: 1.8rem;
background: ${({ $connect }) =>
background: transparent;
/* background: ${({ $connect }) =>
$connect
? `#2F3038`
: `linear-gradient(160deg, #f3f6fc 11.73%, #e6e7f7 98.61%)`};
: `linear-gradient(160deg, #f3f6fc 11.73%, #e6e7f7 98.61%)`}; */
cursor: pointer;
`;
Expand Down
10 changes: 6 additions & 4 deletions front/src/components/main/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { styled } from "styled-components";

import IcWalletDisconnect from "@/assets/icons/Landing/ic_landing_wallet_disconnect.svg";
import ModalWrapper from "@/components/common/Modal/ModalWrapper";
import Button from "../btnGrd";

interface ModalProps {
handleModalState: () => void;
Expand All @@ -27,12 +28,13 @@ const Modal = (props: ModalProps) => {
<p>from CYBER-TON.</p>
</ModalDesc>
<ModalButtonWrapper>
<ModalButton type="yes" onClick={clearStorage}>
<Button type="yes" onClick={clearStorage}>
Yes
</ModalButton>
<ModalButton type="no" onClick={handleModalState}>
</Button>

<Button type="no" onClick={handleModalState}>
Not Now
</ModalButton>
</Button>
</ModalButtonWrapper>
</ModalWhiteBox>
</ModalWrapper>
Expand Down
4 changes: 3 additions & 1 deletion front/src/components/main/TonWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const TonWallet = ({ nickname, message, type }) => {
if (connected) {
console.log(">>> Send message to bacend");
} else {
tonConnectUI.disconnect();

const d = toBase64(toAscii(data));

tonConnectUI.setConnectRequestParameters({
Expand All @@ -53,7 +55,7 @@ const TonWallet = ({ nickname, message, type }) => {
>
<Button onClick={handleSwitchWalletFunction}>
{/* <TonConnectCenterBox> */}
{isPassportType ? "Add passport" : "Cyberlink"}
{isPassportType ? "Link passport" : "Cyberlink"}
{/* </TonConnectCenterBox> */}
</Button>
{/* <p
Expand Down
9 changes: 9 additions & 0 deletions front/src/pages/Main/Main.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@
opacity: 0.8;
}
}

.tx {
color: var(--primary-color);
text-decoration: none;

&:hover {
text-decoration: underline;
}
}
66 changes: 43 additions & 23 deletions front/src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import ActionBar from "@/components/ActionBar/ActionBar";
import { sendProof } from "@/api/cyber";
import { trimString } from "@/utils/trimString";
import styles from "./Main.module.scss";
import Posts from "./Posts/Posts";

const tele = (window as any).Telegram.WebApp;

Expand All @@ -27,6 +28,7 @@ enum Steps {
ENTER_PASSPORT,
ADD_PASSPORT,
ENTER_MESSAGE,
TX,
}

const LS_KEY = "lastPassport";
Expand All @@ -41,6 +43,10 @@ const Main = () => {

const [message, setMessage] = useState("");

const [txHash, setTxHash] = useState(
"0B95D616B429988F1E198F6AD99F9FA29E29A64C9E76E81992796F3F0E9D97B6"
);

const lastPassport = localStorage.getItem(LS_KEY) || "";
const [nickname, setNickname] = useState(lastPassport);

Expand Down Expand Up @@ -69,6 +75,9 @@ const Main = () => {
const data = await sendProof(d);

console.log(data.data);
const tx = data.data.tx.hash;

setTxHash(tx);
} catch (error) {
console.error(error);
}
Expand All @@ -89,7 +98,6 @@ const Main = () => {
...tonProof,
data: p,
});
tonConnectUI.disconnect();
}

if (type === "add_post" && !textProof) {
Expand All @@ -98,7 +106,7 @@ const Main = () => {
...tonProof,
data: p,
});
tonConnectUI.disconnect();
setMessage("");
}
}

Expand Down Expand Up @@ -159,10 +167,6 @@ const Main = () => {
onChange={(e) => {
const value = e.target.value;

if (connected) {
tonConnectUI.disconnect();
}

setNickname(value);
}}
/>
Expand All @@ -188,23 +192,39 @@ const Main = () => {
</>
);
} else if (step === Steps.ENTER_MESSAGE) {
actionBarContent = (
<>
<Input
color="pink"
placeholder="enter message..."
value={message}
onChange={(e) => {
if (connected) {
tonConnectUI.disconnect();
}

setMessage(e.target.value);
}}
/>
<TonWallet message={message} nickname={nickname} type="text" />
</>
);
centerContent = <Posts publicKey={wallet?.account?.publicKey || ""} />;

if (txHash) {
actionBarContent = (
<>
<a
className={styles.tx}
target="_blank"
rel="noreferrer noopener"
href={"https://spacepussy.ai/network/bostrom/tx/" + txHash}
>
{" "}
{trimString(txHash, 6, 6)}
</a>

<Button onClick={() => setTxHash(null)}>Close</Button>
</>
);
} else {
actionBarContent = (
<>
<Input
color="pink"
placeholder="enter message..."
value={message}
onChange={(e) => {
setMessage(e.target.value);
}}
/>
<TonWallet message={message} nickname={nickname} type="text" />
</>
);
}
}

console.log(step);
Expand Down
10 changes: 10 additions & 0 deletions front/src/pages/Main/Posts/Posts.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.wrapper {
display: grid;
gap: 20px 20px;

> div {
display: flex;
flex-direction: row-reverse;
justify-content: space-between;
}
}
55 changes: 55 additions & 0 deletions front/src/pages/Main/Posts/Posts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Display from "@/components/common/containerGradient/Display/Display";
import DisplayTitle from "@/components/common/containerGradient/DisplayTitle/DisplayTitle";
import { useQueryClientPussy } from "@/queryClientPussy";
import { useQuery } from "@tanstack/react-query";
import React from "react";
import styles from "./Posts.module.scss";

function Posts({ publicKey }) {
const client = useQueryClientPussy();

const { data, isLoading, error } = useQuery({
queryKey: ["posts", publicKey],
refetchInterval: 10 * 1000,
queryFn: async () => {
return client!.queryContractSmart(
"pussy15s8v0pa5g60uhvmjpfj73p6nem6t597e8qnkgpsuck5tje3se7ps3ll7kl",
{
get_posts: {
pubkey: publicKey,
},
}
);
},
});

console.log(error);

return (
<Display title={<DisplayTitle title="Your posts" />}>
{isLoading && <div>Loading...</div>}

{!data && !isLoading && <div>No data</div>}

<div className={styles.wrapper}>
{data?.map((post: any) => (
<div key={post.timestamp}>
<div>
{Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
}).format(post.timestamp * 1000)}
</div>

<p>{post.post}</p>
</div>
))}
</div>
</Display>
);
}

export default Posts;
40 changes: 40 additions & 0 deletions front/src/queryClientPussy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useContext } from "react";
import { CyberClient } from "@cybercongress/cyber-js";
import { Option } from "src/types";
import { useQuery } from "@tanstack/react-query";
// import { RPC_URL } from 'src/constants/config';

const RPC_URL = "https://rpc.space-pussy.cybernode.ai";

const QueryClientContext = React.createContext<Option<CyberClient>>(undefined);

export function useQueryClientPussy() {
return useContext(QueryClientContext);
}

function QueryClientProvider({ children }: { children: React.ReactNode }) {
const { data, error, isFetching } = useQuery({
queryKey: ["cyberClient", "connect"],
queryFn: async () => {
return CyberClient.connect(RPC_URL);
},
});

if (isFetching) {
// return null;
}

if (error) {
console.error("Error queryClient connect: ", error.message);
}

console.log(data);

return (
<QueryClientContext.Provider value={data}>
{children}
</QueryClientContext.Provider>
);
}

export default QueryClientProvider;

0 comments on commit 99c60ea

Please sign in to comment.