Skip to content

Commit

Permalink
add passport loadin
Browse files Browse the repository at this point in the history
  • Loading branch information
happylolonly committed May 29, 2024
1 parent c56bfa4 commit da876c8
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 47 additions & 0 deletions front/src/hooks/useCyberPassport.tsx
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions front/src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -28,6 +35,29 @@ const Main = () => {

<br />

<Input
value={nickname}
placeholder="enter passport..."
onChange={(e) => {
const value = e.target.value;

setNickname(value);
}}
/>

<button onClick={fetchData}>Load</button>

{passport && (
<div
style={{
fontSize: 14,
wordBreak: "break-all",
}}
>
{JSON.stringify(passport)}
</div>
)}

{tonProof && (
<div
style={{
Expand Down
24 changes: 24 additions & 0 deletions front/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,15 @@
"@babel/helper-validator-identifier" "^7.22.5"
to-fast-properties "^2.0.0"

"@cosmjs/encoding@^0.32.3":
version "0.32.3"
resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.32.3.tgz#e245ff511fe4a0df7ba427b5187aab69e3468e5b"
integrity sha512-p4KF7hhv8jBQX3MkB3Defuhz/W0l3PwWVYU2vkVuBJ13bJcXyhU9nJjiMkaIv+XP+W2QgRceqNNgFUC5chNR7w==
dependencies:
base64-js "^1.3.0"
bech32 "^1.1.4"
readonly-date "^1.0.0"

"@emotion/babel-plugin@^11.11.0":
version "11.11.0"
resolved "https://registry.yarnpkg.com/@emotion/babel-plugin/-/babel-plugin-11.11.0.tgz#c2d872b6a7767a9d176d007f5b31f7d504bb5d6c"
Expand Down Expand Up @@ -2060,6 +2069,16 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

base64-js@^1.3.0:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==

bech32@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
Expand Down Expand Up @@ -3225,6 +3244,11 @@ readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"

readonly-date@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/readonly-date/-/readonly-date-1.0.0.tgz#5af785464d8c7d7c40b9d738cbde8c646f97dcd9"
integrity sha512-tMKIV7hlk0h4mO3JTmmVuIlJVXjKk3Sep9Bf5OH0O+758ruuVkUy2J9SttDLm91IEX/WHlXPSpxMGjPj4beMIQ==

recoil-persist@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/recoil-persist/-/recoil-persist-5.1.0.tgz#c4232fe04f2e4b6afcc815baff56f2521f6dcde1"
Expand Down

0 comments on commit da876c8

Please sign in to comment.