icns-frontend/pages/verification/index.tsx

151 lines
3.4 KiB
TypeScript
Raw Normal View History

2022-12-07 09:17:59 +00:00
// React
2022-12-01 08:33:51 +00:00
import { useEffect, useState } from "react";
2022-12-07 09:17:59 +00:00
// Types
2022-12-12 07:10:11 +00:00
import { IcnsVerificationResponse, TwitterAuthInfoResponse } from "../../types";
import { request } from "../../utils/url";
2022-12-01 08:33:51 +00:00
2022-12-07 09:17:59 +00:00
// Styles
2022-12-07 13:55:22 +00:00
import styled from "styled-components";
2022-12-06 14:53:31 +00:00
import color from "../../styles/color";
2022-12-01 08:33:51 +00:00
2022-12-07 09:17:59 +00:00
// Components
import { Logo } from "../../components/logo";
2022-12-09 11:59:52 +00:00
import { SkeletonChainList } from "../../components/skeleton";
2022-12-07 09:17:59 +00:00
import { PrimaryButton } from "../../components/primary-button";
2022-12-07 11:18:10 +00:00
import { AccountInfos } from "../../config";
2022-12-12 07:10:11 +00:00
import { TwitterProfile } from "../../components/twitter-profile";
2022-12-09 11:59:52 +00:00
import { ChainList } from "../../components/chain-list";
2022-12-07 09:17:59 +00:00
2022-12-01 08:33:51 +00:00
export default function VerificationPage() {
const [twitterAuthInfo, setTwitterAuthInfo] =
useState<TwitterAuthInfoResponse | null>();
2022-12-01 08:33:51 +00:00
2022-12-07 09:17:59 +00:00
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const handleVerification = async () => {
if (window.location.search) {
const [, state, code] =
window.location.search.match(
/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/,
) || [];
const newTwitterAuthInfo = await request<TwitterAuthInfoResponse>(
`/api/twitter-auth-info?state=${state}&code=${code}`,
);
setTwitterAuthInfo(newTwitterAuthInfo);
2022-12-12 06:31:52 +00:00
const icnsVerificationList = (
await request<IcnsVerificationResponse>("/api/icns-verification", {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
claimer: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq",
authToken: newTwitterAuthInfo.accessToken,
}),
})
).verificationList;
console.log(icnsVerificationList);
setIsLoading(false);
}
};
2022-12-01 08:33:51 +00:00
handleVerification();
2022-12-01 08:33:51 +00:00
}, []);
return (
2022-12-06 14:53:31 +00:00
<Container>
<Logo />
2022-12-01 08:33:51 +00:00
2022-12-06 14:53:31 +00:00
<MainContainer>
2022-12-07 09:17:59 +00:00
{isLoading ? (
2022-12-09 11:59:52 +00:00
<SkeletonChainList />
2022-12-07 09:17:59 +00:00
) : (
<ContentContainer>
2022-12-09 11:59:52 +00:00
<TwitterProfile twitterProfileInformation={twitterAuthInfo} />
2022-12-07 09:17:59 +00:00
<ChainListTitleContainer>
<ChainListTitle>Chain List</ChainListTitle>
<SearchContainer>Search</SearchContainer>
</ChainListTitleContainer>
2022-12-09 11:59:52 +00:00
<ChainList chainList={AccountInfos} />
2022-12-07 09:17:59 +00:00
<ButtonContainer>
<PrimaryButton>Register</PrimaryButton>
</ButtonContainer>
</ContentContainer>
)}
2022-12-06 14:53:31 +00:00
</MainContainer>
</Container>
2022-12-01 08:33:51 +00:00
);
}
2022-12-07 13:55:22 +00:00
const Container = styled.div`
width: 100vw;
height: 100vh;
`;
const MainContainer = styled.div`
display: flex;
justify-content: center;
color: white;
`;
2022-12-09 11:59:52 +00:00
export const ContentContainer = styled.div`
2022-12-07 13:55:22 +00:00
display: flex;
flex-direction: column;
align-items: center;
width: 40rem;
margin-top: 5rem;
`;
2022-12-09 11:59:52 +00:00
export const ButtonContainer = styled.div`
2022-12-07 13:55:22 +00:00
width: 12rem;
height: 4rem;
2022-12-09 11:59:52 +00:00
margin-top: 2rem;
2022-12-07 13:55:22 +00:00
`;
2022-12-09 11:59:52 +00:00
export const ChainListTitleContainer = styled.div`
2022-12-07 13:55:22 +00:00
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
margin-top: 2rem;
margin-bottom: 1rem;
`;
const ChainListTitle = styled.div`
font-weight: 700;
font-size: 1.5rem;
line-height: 1.9rem;
color: ${color.white};
`;
const SearchContainer = styled.div`
display: flex;
align-items: center;
border-radius: 3rem;
min-width: 10rem;
height: 2rem;
background-color: ${color.grey["700"]};
`;