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 da876c8 commit 0839faf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
7 changes: 0 additions & 7 deletions front/src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ const Header = (props: HeaderProps) => {
const navigate = useNavigate();
const { pathname } = useLocation();

tonConnectUI.setConnectRequestParameters({
state: "ready",
value: {
tonProof: "<your-proof-payload>",
},
});

const handleModalState = () => {
setIsOpenModal(!isOpenModal);
};
Expand Down
19 changes: 17 additions & 2 deletions front/src/components/main/TonWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ import IcWalletConnect from "../../assets/icons/Landing/ic_wallet_connect.svg";
import IcWalletDisconnect from "../../assets/icons/Landing/ic_wallet_disconnect.svg";

import useTonConnect from "./../../hooks/contract/useTonConnect";
import { toBase64, fromBase64, fromAscii, toAscii } from "@cosmjs/encoding";

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

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

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

tonConnectUI.connectWallet();
}
};

return (
<TonWalletWrapper onClick={handleSwitchWalletFunction}>
<TonConnectStatusBox>
{connected ? <img src={IcWalletConnect} alt="connect" /> : <img src={IcWalletDisconnect} alt="disconnect" />}
{connected ? (
<img src={IcWalletConnect} alt="connect" />
) : (
<img src={IcWalletDisconnect} alt="disconnect" />
)}
</TonConnectStatusBox>
{connected ? (
<TonConnectCenterBox> Create link</TonConnectCenterBox>
Expand Down
26 changes: 23 additions & 3 deletions front/src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import Header from "@/components/common/Header";
import TonWallet from "@/components/main/TonWallet";
import useTonConnect from "@/hooks/contract/useTonConnect";
import useCyberPassport from "@/hooks/useCyberPassport";
import { fromAscii, fromBase64 } from "@cosmjs/encoding";

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

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

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

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

Expand All @@ -30,8 +33,18 @@ const Main = () => {
<>
<MainWrapper>
<Header isOpen={false} text="CYBER-TON" backgroundType={false} />
<Input placeholder="enter message..." />
<TonWallet />
<Input
placeholder="enter message..."
value={message}
onChange={(e) => {
if (connected) {
tonConnectUI.disconnect();
}

setMessage(e.target.value);
}}
/>
<TonWallet message={message} nickname={nickname} />

<br />

Expand All @@ -41,6 +54,10 @@ const Main = () => {
onChange={(e) => {
const value = e.target.value;

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

setNickname(value);
}}
/>
Expand All @@ -64,6 +81,9 @@ const Main = () => {
fontSize: 14,
}}
>
{fromAscii(fromBase64(tonProof?.proof?.payload))}

<br />
{JSON.stringify(tonProof)}
</div>
)}
Expand Down

0 comments on commit 0839faf

Please sign in to comment.