From da876c8c36264f075440402ae44b1c40bf5f422e Mon Sep 17 00:00:00 2001 From: Cheslav Zhuravsky Date: Wed, 29 May 2024 13:33:56 +0700 Subject: [PATCH] add passport loadin --- front/package.json | 1 + front/src/hooks/useCyberPassport.tsx | 47 ++++++++++++++++++++++++++++ front/src/pages/Main/Main.tsx | 30 ++++++++++++++++++ front/yarn.lock | 24 ++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 front/src/hooks/useCyberPassport.tsx diff --git a/front/package.json b/front/package.json index a0743fca..80013f06 100644 --- a/front/package.json +++ b/front/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "@aws-crypto/sha256-js": "^5.0.0", + "@cosmjs/encoding": "^0.32.3", "@emotion/react": "^11.11.1", "@emotion/styled": "^11.11.0", "@esbuild-plugins/node-globals-polyfill": "^0.2.3", diff --git a/front/src/hooks/useCyberPassport.tsx b/front/src/hooks/useCyberPassport.tsx new file mode 100644 index 00000000..64cf40a5 --- /dev/null +++ b/front/src/hooks/useCyberPassport.tsx @@ -0,0 +1,47 @@ +import React, { useEffect, useState } from "react"; + +import { toAscii, toBase64 } from "@cosmjs/encoding"; + +import axios from "axios"; + +export async function getPassport(query) { + const response = await axios.get( + `${"https://lcd.bostrom.cybernode.ai"}/cosmwasm/wasm/v1/contract/${"bostrom1xut80d09q0tgtch8p0z4k5f88d3uvt8cvtzm5h3tu3tsy4jk9xlsfzhxel"}/smart/${toBase64( + toAscii(JSON.stringify(query)) + )}` + ); + return response.data.data; +} + +function useCyberPassport({ nickname }) { + const [data, setData] = useState(); + + function fetchData() { + const query = { + passport_by_nickname: { + nickname: nickname, + }, + }; + + getPassport(query) + .then((res) => { + setData(res); + }) + .catch((e) => { + console.log(e); + + setData(null); + }); + } + + // useEffect(() => { + + // }, [nickname]); + + return { + fetchData, + data, + }; +} + +export default useCyberPassport; diff --git a/front/src/pages/Main/Main.tsx b/front/src/pages/Main/Main.tsx index 34eb9ce3..385d40dd 100644 --- a/front/src/pages/Main/Main.tsx +++ b/front/src/pages/Main/Main.tsx @@ -4,14 +4,21 @@ import styled from "styled-components"; import Header from "@/components/common/Header"; import TonWallet from "@/components/main/TonWallet"; import useTonConnect from "@/hooks/contract/useTonConnect"; +import useCyberPassport from "@/hooks/useCyberPassport"; const tele = (window as any).Telegram.WebApp; const Main = () => { const { address, tonConnectUI, wallet } = useTonConnect(); + const [nickname, setNickname] = useState("congress"); + const tonProof = wallet?.connectItems?.tonProof; + const { data: passport, fetchData } = useCyberPassport({ + nickname, + }); + useEffect(() => { if (tele) { tele.ready(); @@ -28,6 +35,29 @@ const Main = () => {
+ { + const value = e.target.value; + + setNickname(value); + }} + /> + + + + {passport && ( +
+ {JSON.stringify(passport)} +
+ )} + {tonProof && (