Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
happylolonly committed May 29, 2024
1 parent 206a39b commit 8242fc9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 11 deletions.
2 changes: 1 addition & 1 deletion front/src/components/main/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Modal = (props: ModalProps) => {

const clearStorage = () => {
window.localStorage.clear();
window.location.reload();
// window.location.reload();
};

return (
Expand Down
38 changes: 32 additions & 6 deletions front/src/components/main/TonWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@ import IcWalletDisconnect from "../../assets/icons/Landing/ic_wallet_disconnect.
import useTonConnect from "./../../hooks/contract/useTonConnect";
import { toBase64, fromBase64, fromAscii, toAscii } from "@cosmjs/encoding";

const TonWallet = ({ nickname, message }) => {
const TonWallet = ({ nickname, message, type }) => {
const { connected, tonConnectUI } = useTonConnect();

const isPassportType = type === "passport";

let data;
if (isPassportType) {
data = JSON.stringify({
msg_type: "map_nickname",
msg_data: nickname,
});
} else if (message) {
data = JSON.stringify({
msg_type: "add_post",
msg_data: message,
});
}

const handleSwitchWalletFunction = () => {
if (connected) {
console.log(">>> Send message to bacend");
} else {
const dat = JSON.stringify([{ nickname }, { post: message }]);
const t = toBase64(toAscii(dat));
const d = toBase64(toAscii(data));

tonConnectUI.setConnectRequestParameters({
state: "ready",
value: {
tonProof: t,
tonProof: d,
},
});

Expand All @@ -38,10 +52,22 @@ const TonWallet = ({ nickname, message }) => {
)}
</TonConnectStatusBox>
{connected ? (
<TonConnectCenterBox> Create link</TonConnectCenterBox>
""
) : (
<TonConnectCenterBox>Connect wallet</TonConnectCenterBox>
// <TonConnectCenterBox> Create link</TonConnectCenterBox>
<TonConnectCenterBox>
{isPassportType ? "Passport" : "Text"} proof
</TonConnectCenterBox>
)}

<p
style={{
position: "absolute",
bottom: "-5px",
}}
>
{JSON.stringify(data)}
</p>
</TonWalletWrapper>
);
};
Expand Down
62 changes: 58 additions & 4 deletions front/src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,45 @@ const tele = (window as any).Telegram.WebApp;
const Main = () => {
const { address, tonConnectUI, wallet, connected } = useTonConnect();

const [passportProof, setPassportProof] = useState();
const [textProof, setTextProof] = useState();

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

const [nickname, setNickname] = useState("congress");

console.log(wallet);

const tonProof = wallet?.connectItems?.tonProof;

// @ts-ignore
const body = tonProof && fromAscii(fromBase64(tonProof?.proof?.payload));

if (body) {
const p = JSON.parse(body);

const type = p.msg_type;
const data = p.msg_data;

if (type === "map_nickname" && !passportProof) {
debugger;
setPassportProof({
...tonProof,
data: p,
});
tonConnectUI.disconnect();
}

if (type === "add_post" && !textProof) {
debugger;
setTextProof({
...tonProof,
data: p,
});
tonConnectUI.disconnect();
}
}

const { data: passport, fetchData } = useCyberPassport({
nickname,
});
Expand All @@ -44,7 +77,18 @@ const Main = () => {
setMessage(e.target.value);
}}
/>
<TonWallet message={message} nickname={nickname} />
<TonWallet message={message} nickname={nickname} type="text" />

{textProof && (
<div
style={{
fontSize: 14,
}}
>
<br />
{JSON.stringify(textProof)}
</div>
)}

<br />

Expand Down Expand Up @@ -75,15 +119,25 @@ const Main = () => {
</div>
)}

{tonProof && (
<TonWallet nickname={nickname} type="passport" />

{passportProof && (
<div
style={{
fontSize: 14,
}}
>
{/* @ts-ignore */}
{fromAscii(fromBase64(tonProof?.proof?.payload))}
<br />
{JSON.stringify(passportProof)}
</div>
)}

{tonProof && (
<div
style={{
fontSize: 14,
}}
>
<br />
{JSON.stringify(tonProof)}
</div>
Expand Down

0 comments on commit 8242fc9

Please sign in to comment.