Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
happylolonly committed May 30, 2024
1 parent 7265b8e commit 0de9969
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
12 changes: 7 additions & 5 deletions front/src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const Header = (props: HeaderProps) => {
<>
{isOpenModal && <Modal handleModalState={handleModalState} />}
<HeaderWrapper $isOpen={isOpen} $backgroundType={backgroundType}>
<HeaderTitle onClick={() => navigate("/")}>{text}</HeaderTitle>
<HeaderTitle onClick={() => navigate("/")}>
cyber <br /> ton
</HeaderTitle>

<HeaderRightBox>
{address && trimString(address, 6, 4)}
Expand Down Expand Up @@ -99,9 +101,9 @@ const DisconnectButton = styled.button<{ $connect: boolean }>`
justify-content: center;
align-items: center;
width: 4.4rem;
height: 4.4rem;
padding: 1.2rem;
width: 2.4rem;
height: 2.4rem;
padding: 0.8rem;
color: #36d6ae;
border: none;
Expand All @@ -112,7 +114,7 @@ const DisconnectButton = styled.button<{ $connect: boolean }>`
? `#2F3038`
: `linear-gradient(160deg, #f3f6fc 11.73%, #e6e7f7 98.61%)`}; */
cursor: pointer;
/* cursor: pointer; */
`;

const MenuButton = styled.button<{ $isOpen: boolean }>`
Expand Down
9 changes: 6 additions & 3 deletions front/src/hooks/useCyberPassport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { toAscii, toBase64 } from "@cosmjs/encoding";

import axios from "axios";
import { useQuery } from "@tanstack/react-query";
import { useQueryClientPussy } from "@/queryClientPussy";

export async function getPassport(query) {
const response = await axios.get(
Expand All @@ -14,21 +15,23 @@ export async function getPassport(query) {
return response.data.data;
}

function useCyberPassport({ nickname }) {
function useCyberPassport({ nickname, publicKey }) {
const [data, setData] = useState();

// const data = useQuery("passport", fetchData, {
// enabled: false,
// });

console.log(nickname);

useEffect(() => {
setData(null);
}, [nickname]);

function fetchData() {
function fetchData(n) {
const query = {
passport_by_nickname: {
nickname: nickname,
nickname: n || nickname,
},
};

Expand Down
69 changes: 50 additions & 19 deletions front/src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { sendProof } from "@/api/cyber";
import { trimString } from "@/utils/trimString";
import styles from "./Main.module.scss";
import Posts from "./Posts/Posts";
import { useQueryClientPussy } from "@/queryClientPussy";
import { useQuery } from "@tanstack/react-query";

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

Expand All @@ -31,8 +33,6 @@ enum Steps {
TX,
}

const LS_KEY = "lastPassport";

const Main = () => {
const { address, tonConnectUI, wallet, connected } = useTonConnect();

Expand All @@ -44,10 +44,28 @@ const Main = () => {

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

const client = useQueryClientPussy();

const publicKey = wallet?.account?.publicKey;
const contractQuery = useQuery({
queryKey: ["passport", publicKey],
// refetchInterval: 10 * 1000,
queryFn: async () => {
return client!.queryContractSmart(
"pussy15s8v0pa5g60uhvmjpfj73p6nem6t597e8qnkgpsuck5tje3se7ps3ll7kl",
{
get_nickname: {
pubkey: publicKey,
},
}
);
},
enabled: !!publicKey,
});

const [txHash, setTxHash] = useState();

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

console.log(wallet);
console.log("PK", wallet?.account?.publicKey);
Expand Down Expand Up @@ -115,30 +133,43 @@ const Main = () => {
nickname,
});

const passport = dat2 as Citizenship;

useEffect(() => {
if (lastPassport) {
if (!(passport && passport.extension.nickname === lastPassport)) {
fetchData();
}

if (passport) {
setStep(Steps.ENTER_MESSAGE);
if (contractQuery.data) {
const nick = contractQuery.data;
if (nick !== nickname) {
setNickname(nick);

setTimeout(() => {
fetchData(nick);
}, 1000);
}

return;
setStep(Steps.ENTER_MESSAGE);
}
}, [contractQuery.data, nickname, fetchData]);

if (passport) {
setStep(Steps.ADD_PASSPORT);
}
}, [lastPassport, passport]);
const passport = dat2 as Citizenship;

console.log(passport);

// useEffect(() => {
// if (lastPassport) {

// if (passport) {
// setStep(Steps.ENTER_MESSAGE);
// }

// return;
// }

// if (passport) {
// setStep(Steps.ADD_PASSPORT);
// }
// }, [lastPassport, passport]);

useEffect(() => {
if (passportProof) {
setStep(Steps.ENTER_MESSAGE);
localStorage.setItem(LS_KEY, passport.extension.nickname);
}
}, [passportProof, passport]);

Expand Down

0 comments on commit 0de9969

Please sign in to comment.