icns-frontend/pages/verification/index.tsx

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-12-01 08:33:51 +00:00
import { useEffect, useState } from "react";
import {
2022-12-05 15:02:30 +00:00
IcnsVerificationResponse,
TwitterAuthInfoResponse,
} from "../../types/api-response";
import { VerifierMsg } from "../../types/msg";
import { request } from "../../utils/url";
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
useEffect(() => {
const handleVerification = async () => {
const [, state, code] =
window.location.search.match(
/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/,
) || [];
const newTwitterAuthInfo = await request<TwitterAuthInfoResponse>(
`/api/twitter-auth-info?state=${state}&code=${code}`,
);
2022-12-01 08:33:51 +00:00
console.log(newTwitterAuthInfo);
2022-12-01 08:33:51 +00:00
setTwitterAuthInfo(newTwitterAuthInfo);
const verifierMsg: VerifierMsg = {
2022-12-05 15:02:30 +00:00
unique_twitter_id: newTwitterAuthInfo.id,
name: newTwitterAuthInfo.username,
claimer: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq",
contract_address: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq",
chain_id: "osmosis-1",
};
2022-12-05 15:02:30 +00:00
const icnsVerification = await request<IcnsVerificationResponse>(
"/api/icns-verification",
{
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
msg: JSON.stringify(verifierMsg),
authToken: newTwitterAuthInfo.accessToken,
}),
},
);
2022-12-05 15:02:30 +00:00
console.log(icnsVerification);
};
2022-12-01 08:33:51 +00:00
handleVerification();
2022-12-01 08:33:51 +00:00
}, []);
return (
<div>
<div>{twitterAuthInfo?.username}</div>
2022-12-01 08:33:51 +00:00
</div>
);
}