icns-frontend/pages/complete/index.tsx

258 lines
5.9 KiB
TypeScript
Raw Normal View History

2022-12-12 08:16:16 +00:00
import Image from "next/image";
import styled from "styled-components";
2022-12-12 08:40:36 +00:00
import Typed from "react-typed";
2022-12-12 08:16:16 +00:00
import { Logo } from "../../components/logo";
import color from "../../styles/color";
import AlertCircleOutlineIcon from "../../public/images/svg/alert-circle-outline.svg";
import TwitterIcon from "../../public/images/svg/twitter-icon.svg";
2022-12-14 07:52:05 +00:00
import { useRouter } from "next/router";
2022-12-15 15:43:18 +00:00
import { useEffect, useState } from "react";
2022-12-14 07:52:05 +00:00
import { TendermintTxTracer } from "@keplr-wallet/cosmos";
2022-12-15 15:43:18 +00:00
import { queryAddressesFromTwitterName } from "../../queries";
import { RegisteredAddresses } from "../../types";
import { SHARE_URL } from "../../constants/twitter";
2022-12-12 08:16:16 +00:00
export default function CompletePage() {
2022-12-14 07:52:05 +00:00
const router = useRouter();
2022-12-15 15:43:18 +00:00
const [registeredAddressed, setRegisteredAddressed] =
useState<RegisteredAddresses[]>();
const [availableAddress, setAvailableAddress] = useState("");
2022-12-14 07:52:05 +00:00
useEffect(() => {
2022-12-15 15:43:18 +00:00
const { txHash, twitterUsername } = router.query;
2022-12-14 07:52:05 +00:00
2022-12-15 15:43:18 +00:00
if (txHash && twitterUsername) {
initialize(txHash as string, twitterUsername as string);
2022-12-14 07:52:05 +00:00
}
2022-12-15 15:43:18 +00:00
}, [router.query]);
2022-12-14 07:52:05 +00:00
2022-12-15 15:43:18 +00:00
const initialize = async (txHash: string, twitterUserName: string) => {
2022-12-14 07:52:05 +00:00
const txTracer = new TendermintTxTracer(
"https://rpc.testnet.osmosis.zone",
"/websocket",
);
2022-12-15 15:43:18 +00:00
const result: { code?: number } = await txTracer.traceTx(
Buffer.from(txHash, "hex"),
);
2022-12-14 07:52:05 +00:00
2022-12-15 15:43:18 +00:00
if (result.code || result.code === 0) {
const addresses = await queryAddressesFromTwitterName(twitterUserName);
setRegisteredAddressed(addresses.data.addresses);
}
};
2022-12-15 10:06:44 +00:00
2022-12-15 15:43:18 +00:00
const onClickShareButton = () => {
const { twitterUsername } = router.query;
const width = 500;
const height = 700;
window.open(
`${SHARE_URL}?url=https://www.icns.xyz/&text=${twitterUsername}`,
"Share Twitter",
`top=${(window.screen.height - height) / 2}, left=${
(window.screen.width - width) / 2
}, width=${width}, height=${height}, status=no, menubar=no, toolbar=no, resizable=no`,
);
2022-12-14 07:52:05 +00:00
};
2022-12-12 08:16:16 +00:00
return (
<Container>
<Logo />
<MainContainer>
2022-12-15 15:43:18 +00:00
<MainTitle>
<div>Your Name is Active Now!</div>
</MainTitle>
2022-12-12 08:16:16 +00:00
<ContentContainer>
<RecipentContainer>
<RecipentTitle>Recipent</RecipentTitle>
2022-12-12 08:40:36 +00:00
<AddressContainer>
2022-12-15 15:43:18 +00:00
{`${router.query.twitterUsername}.`}
{registeredAddressed && (
<Typed
strings={registeredAddressed.map(
(address) => address.bech32_prefix,
)}
typeSpeed={150}
backSpeed={150}
backDelay={1000}
loop
smartBackspace
onStringTyped={(arrayPos: number) => {
setAvailableAddress(registeredAddressed[arrayPos].address);
}}
/>
)}
2022-12-12 08:40:36 +00:00
</AddressContainer>
2022-12-15 15:43:18 +00:00
<AvailableAddressText>{availableAddress}</AvailableAddressText>
2022-12-12 08:16:16 +00:00
</RecipentContainer>
</ContentContainer>
<DescriptionContainer>
<AlertIcon>
<Image src={AlertCircleOutlineIcon} fill={true} alt="alert icon" />
</AlertIcon>
<DescriptionText>
If you want to make that name address with same twitter account,
just go to home and start again.
</DescriptionText>
</DescriptionContainer>
2022-12-15 15:43:18 +00:00
<ShareButtonContainer onClick={onClickShareButton}>
2022-12-12 08:16:16 +00:00
<ShareButtonText>SHARE MY NAME</ShareButtonText>
<Image src={TwitterIcon} alt="twitter icon" />
</ShareButtonContainer>
</MainContainer>
</Container>
);
}
const Container = styled.div`
width: 100vw;
height: 100vh;
`;
const MainContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
padding-top: 10.1rem;
color: white;
`;
const MainTitle = styled.div`
2022-12-15 15:43:18 +00:00
display: flex;
align-items: center;
justify-content: center;
2022-12-12 08:16:16 +00:00
font-family: "Inter", serif;
font-style: normal;
font-weight: 700;
font-size: 2rem;
line-height: 2rem;
2022-12-15 15:43:18 +00:00
height: 5rem;
2022-12-12 08:16:16 +00:00
`;
const ContentContainer = styled.div`
width: 30rem;
padding: 2rem 2rem;
background-color: ${color.grey["900"]};
`;
const RecipentContainer = styled.div`
display: flex;
flex-direction: column;
gap: 0.5rem;
padding: 2rem;
`;
const RecipentTitle = styled.div`
font-family: "Inter", serif;
font-style: normal;
font-weight: 500;
font-size: 1rem;
line-height: 1rem;
color: ${color.grey["400"]};
`;
const AddressContainer = styled.div`
font-family: "Inter", serif;
font-style: normal;
font-weight: 600;
font-size: 0.9rem;
line-height: 0.9rem;
color: ${color.white};
padding: 1rem;
background-color: ${color.grey["600"]};
`;
const AvailableAddressText = styled.div`
font-family: "Inter", serif;
font-style: normal;
font-weight: 400;
font-size: 0.75rem;
line-height: 0.75rem;
2022-12-15 15:43:18 +00:00
min-height: 0.75rem;
2022-12-12 08:16:16 +00:00
color: ${color.blue};
`;
const DescriptionContainer = styled.div`
display: flex;
flex-direction: row;
2022-12-15 15:43:18 +00:00
align-items: center;
2022-12-12 08:16:16 +00:00
gap: 1rem;
width: 30rem;
margin-top: 1.5rem;
2022-12-15 15:43:18 +00:00
padding: 1.25rem 2rem;
2022-12-12 08:16:16 +00:00
background-color: ${color.grey["900"]};
`;
const AlertIcon = styled.div`
position: relative;
width: 1.5rem;
height: 1.5rem;
`;
const DescriptionText = styled.div`
width: 100%;
font-family: "Inter", serif;
font-style: normal;
font-weight: 400;
font-size: 0.8rem;
2022-12-15 15:43:18 +00:00
line-height: 140%;
2022-12-12 08:16:16 +00:00
color: ${color.grey["400"]};
`;
const ShareButtonContainer = styled.div`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 0.625rem;
width: 20rem;
height: 5rem;
margin-top: 2.5rem;
cursor: pointer;
user-select: none;
background-color: ${color.grey["700"]};
`;
const ShareButtonText = styled.div`
font-family: "Inter", serif;
font-style: normal;
font-weight: 700;
font-size: 1.25rem;
line-height: 1.25rem;
color: ${color.grey["100"]};
`;