From d8eaf63b69e4d7b4d610cb9e096a19cfcf394500 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 3 Oct 2024 19:09:25 +0300 Subject: [PATCH 1/3] setting additional discord props into metadata, added server picker --- package-lock.json | 16 +- package.json | 2 +- src/api/discord.api.ts | 70 ++- src/api/hub.api.ts | 31 +- src/components/AutEditHubDialog.tsx | 290 ++++++------ .../Dialog/DiscordServerVerificationPopup.tsx | 428 ++++++++++++------ src/components/Oauth2/oauth2.tsx | 5 +- 7 files changed, 534 insertions(+), 308 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9ead49d..58411e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@aut-labs/abi-types": "^0.0.81-dev", "@aut-labs/connector": "^0.0.203", "@aut-labs/d-aut": "^1.0.202-dev", - "@aut-labs/sdk": "^0.0.202-dev", + "@aut-labs/sdk": "^0.0.210-dev", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.7", @@ -172,16 +172,20 @@ "integrity": "sha512-ocqU6ousVfW/ffOz8IIpx8Kr8OjS2xKTyPR/y4PgLetEb0rC7BJKDztTd6ztHMvTddsH24OvdHp4oiN0EgdmJQ==" }, "node_modules/@aut-labs/sdk": { - "version": "0.0.202-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/sdk/-/sdk-0.0.202-dev.tgz", - "integrity": "sha512-e7GK257fmXEq62g3NYvo5ve9O6lVXsRUvw3SCLBKeyh8y7E5C6jn+/tMC1n8glq1x0q0+SAZIq8QUcUXvAPSKg==", - "license": "MIT", + "version": "0.0.210-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/sdk/-/sdk-0.0.210-dev.tgz", + "integrity": "sha512-9O1PfK9PAS4P4feIwmcIQ9QIVL0u6r+vue1Mwn885uXX6ImFi4Xob46WvelWDXUYd3Otw1smX4NuoQ5F+ykW+g==", "dependencies": { - "@aut-labs/abi-types": "^0.0.81-dev", + "@aut-labs/abi-types": "^0.0.83-dev", "date-fns": "^2.29.3", "ethers": "^6.10.0" } }, + "node_modules/@aut-labs/sdk/node_modules/@aut-labs/abi-types": { + "version": "0.0.83-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/abi-types/-/abi-types-0.0.83-dev.tgz", + "integrity": "sha512-TYdWEyJ5rAM5uJSF4HwsKbSpygfDhg7PTyahXwEO2cyT4cDz65VAu9B5kA2FOum0teraKrbxHA+5gILVHYzeig==" + }, "node_modules/@aut-labs/sdk/node_modules/date-fns": { "version": "2.30.0", "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", diff --git a/package.json b/package.json index 317230a..4f34d58 100755 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@aut-labs/abi-types": "^0.0.81-dev", "@aut-labs/connector": "^0.0.203", "@aut-labs/d-aut": "^1.0.202-dev", - "@aut-labs/sdk": "^0.0.202-dev", + "@aut-labs/sdk": "^0.0.210-dev", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.7", diff --git a/src/api/discord.api.ts b/src/api/discord.api.ts index 5e738c8..96211ac 100644 --- a/src/api/discord.api.ts +++ b/src/api/discord.api.ts @@ -1,6 +1,7 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import axios from "axios"; import { environment } from "./environment"; +import { useMutation, UseMutationOptions } from "@tanstack/react-query"; export interface TaskData { role: string; @@ -19,7 +20,7 @@ export const oauthGetToken = (code: string) => { params.append("client_secret", environment.discordClientSecret); params.append("grant_type", "authorization_code"); params.append("redirect_uri", environment.discordRedirectUri); - params.append("scope", "identify"); + params.append("scope", "identify guilds"); params.append("code", code); return fetch("https://discord.com/api/oauth2/token", { method: "POST", @@ -56,21 +57,62 @@ export const getUserGuilds = (accessToken: string) => { .then((res) => res.data); }; -export const verifyDiscordServerOwnership = createAsyncThunk( - "discord/verify", - async ( - guildVerificationData: GuildVerificationData, - { rejectWithValue, getState } - ) => { - const guilds = await getUserGuilds(guildVerificationData.accessToken); - const guild = guilds.find((g) => g.id === guildVerificationData.guildId); - if (!guild.owner) { - return rejectWithValue("User is not the owner."); - } - return true; +// export const verifyDiscordServerOwnership = createAsyncThunk( +// "discord/verify", +// async ( +// guildVerificationData: GuildVerificationData, +// { rejectWithValue, getState } +// ) => { +// const guilds = await axios +// .get(`${environment.discordApiUrl}/users/@me/guilds`, { +// headers: { +// Authorization: `Bearer ${accessToken}` +// } +// }) +// .then((res) => res.data); +// const guild = guilds.find((g) => g.id === guildVerificationData.guildId); +// if (!guild.owner) { +// return false; +// } +// return true; +// } +// ); + +const verifyGuildOwnership = async ( + guildVerificationData: GuildVerificationData +): Promise => { + const { accessToken, guildId } = guildVerificationData; + + const guilds: any[] = await axios + .get(`${environment.discordApiUrl}/users/@me/guilds`, { + headers: { + Authorization: `Bearer ${accessToken}` + } + }) + .then((res) => res.data); + + const guild = guilds.find((g) => g.id === guildId); + + if (!guild || !guild.owner) { + return { isAdmin: false }; } -); + return { isAdmin: true, guild }; +}; + +interface VerificationResult { + isAdmin: boolean; + guild?: any; +} + +export const useVerifyGuildOwnershipMutation = ( + options?: UseMutationOptions +) => { + return useMutation({ + ...options, + mutationFn: verifyGuildOwnership + }); +}; export interface DiscordMessageInputField { name: string; value: string; diff --git a/src/api/hub.api.ts b/src/api/hub.api.ts index 4e9578a..bf6e942 100644 --- a/src/api/hub.api.ts +++ b/src/api/hub.api.ts @@ -1,9 +1,9 @@ - import { HubOSHub } from "./hub.model"; import { HubOSAutID } from "./aut.model"; import AutSDK, { AutIDNFT, fetchMetadata, + getOverrides, Hub, HubArchetype, HubArchetypeParameters, @@ -413,18 +413,33 @@ export const updateHub = async (body: HubOSHub, api: BaseQueryApi) => { const sdk = await AutSDK.getInstance(); const updatedHub = HubOSHub.updateHubNFT(body); const uri = await sdk.client.sendJSONToIPFS(updatedHub as any); + console.log("uri", uri); const hubService: Hub = sdk.initService(Hub, body.properties.address); - const result = await hubService.contract.metadata.setMetadataUri(uri); + const overrides = await getOverrides(sdk.signer, 4000); + const getMDres = await hubService.contract.metadata.getMetadataUri(); + console.log("getMDres", getMDres); + const tx = await ( + await hubService.contract.metadata.functions.setMetadataUri( + uri, + overrides + ) + ).wait(); + console.log("tx", tx); - if (!result?.isSuccess) { - return { - error: result?.errorMessage - }; - } + const result = tx.getResult(); + console.log("tx", result); + // const result = await hubService.contract.metadata.setMetadataUri(uri); + + // if (!result?.isSuccess) { + // return { + // error: result?.errorMessage + // }; + // } return { - data: body + data: { body } }; } catch (error) { + console.log("error", error); return { error: error?.message }; diff --git a/src/components/AutEditHubDialog.tsx b/src/components/AutEditHubDialog.tsx index 2602770..0634237 100644 --- a/src/components/AutEditHubDialog.tsx +++ b/src/components/AutEditHubDialog.tsx @@ -28,6 +28,8 @@ import { HubOSHub } from "@api/hub.model"; import ErrorDialog from "./Dialog/ErrorPopup"; import LoadingDialog from "./Dialog/LoadingPopup"; import { useUpdateHubMutation } from "@api/hub.api"; +import DiscordServerVerificationPopup from "./Dialog/DiscordServerVerificationPopup"; +import { getServerDetails } from "@api/discord.api"; export interface EditDialogProps { title: string; @@ -144,6 +146,7 @@ export enum SocialLinkPrefixes { export function AutEditHubDialog(props: EditDialogProps) { const { getAuthGithub, getAuthX, getAuthDiscord, authenticating } = useOAuthSocials(); + const [discordDialogOpen, setDiscordDialogOpen] = useState(false); const theme = useTheme(); const desktop = useMediaQuery(theme.breakpoints.up("md")); const dispatch = useAppDispatch(); @@ -168,6 +171,8 @@ export function AutEditHubDialog(props: EditDialogProps) { social.type !== "ens" ) || []; + console.log("hub", props.hub); + function displaySocialUsername(value, field) { let prefix = ""; @@ -217,6 +222,15 @@ export function AutEditHubDialog(props: EditDialogProps) { }; const onEditHub = async (data: any) => { + console.log("hub submit", { + ...props.hub, + name: data.name, + description: data.description, + properties: { + ...props.hub.properties, + socials: data.socials + } + }); updateHub({ ...props.hub, name: data.name, @@ -426,149 +440,163 @@ export function AutEditHubDialog(props: EditDialogProps) { control={control} render={({ field: { name, value, onChange } }) => { return ( - { - if (field.type === "discord") { - getAuthDiscord( - async (data) => { - const { access_token } = data; - const response = await fetch( - "https://discord.com/api/v10/users/@me", - { - headers: { - Authorization: `Bearer ${access_token}` - } - } - ); - const responseData = - await response.json(); - const username = responseData.username; - onChange(username); - const fullLink = `${SocialLinkPrefixes.Discord}${username}`; - setValue( - `socials.${index}.link`, - fullLink - ); - }, - () => { - // setLoading(false); - } - ); - } - if (field.type === "twitter") { - getAuthX( - async (data) => { - const { access_token } = data; - const response = await fetch( - "https://api.twitter.com/2/users/me", - { - headers: { - Authorization: `Bearer ${access_token}` + <> + {field.type === "discord" && ( + setDiscordDialogOpen(false)} + hub={props.hub} + onChange={onChange} + setValue={setValue} + index={index} + /> + )} + { + if (field.type === "discord") { + setDiscordDialogOpen(true); + // getAuthDiscord( + // async (data) => { + // const { access_token } = data; + // const response = await fetch( + // "https://discord.com/api/v10/users/@me", + // { + // headers: { + // Authorization: `Bearer ${access_token}` + // } + // } + // ); + // const responseData = + // await response.json(); + // const username = responseData.username; + // onChange(username); + // const fullLink = `${SocialLinkPrefixes.Discord}${username}`; + // setValue( + // `socials.${index}.link`, + // fullLink + // ); + // }, + // () => { + // // setLoading(false); + // } + // ); + } + if (field.type === "twitter") { + getAuthX( + async (data) => { + const { access_token } = data; + const response = await fetch( + "https://api.twitter.com/2/users/me", + { + headers: { + Authorization: `Bearer ${access_token}` + } } - } - ); - const responseData = - await response.json(); - const username = responseData.screen_name; - onChange(username); - const fullLink = `${SocialLinkPrefixes.X}${username}`; - setValue( - `socials.${index}.link`, - fullLink - ); - }, - () => { - // setLoading(false); - } - ); - } - if (field.type === "github") { - getAuthGithub( - async (data) => { - const { access_token } = data; - const response = await fetch( - "https://api.github.com/user", - { - headers: { - Authorization: `Bearer ${access_token}` + ); + const responseData = + await response.json(); + const username = + responseData.screen_name; + onChange(username); + const fullLink = `${SocialLinkPrefixes.X}${username}`; + setValue( + `socials.${index}.link`, + fullLink + ); + }, + () => { + // setLoading(false); + } + ); + } + if (field.type === "github") { + getAuthGithub( + async (data) => { + const { access_token } = data; + const response = await fetch( + "https://api.github.com/user", + { + headers: { + Authorization: `Bearer ${access_token}` + } } - } - ); - const responseData = - await response.json(); - const username = responseData.login; - onChange(username); - const fullLink = `${SocialLinkPrefixes.GitHub}${username}`; - setValue( - `socials.${index}.link`, - fullLink - ); - }, - () => { - // setLoading(false); - } - ); - } - }} - sx={{ cursor: "pointer" }} - > - { + // setLoading(false); + } + ); + } + }} + sx={{ cursor: "pointer" }} > - - - + - {value - ? displaySocialUsername(value, field) - : "connect"} - - {value && ( + key={`socials.${index}.icon`} + component={AutIcon} + /> + - {social} + {value + ? displaySocialUsername(value, field) + : "connect"} - )} + {value && ( + + {social} + + )} + - - {value && ( - - )} - + {value && ( + + )} + + ); }} /> diff --git a/src/components/Dialog/DiscordServerVerificationPopup.tsx b/src/components/Dialog/DiscordServerVerificationPopup.tsx index a3a19dc..c9676a3 100644 --- a/src/components/Dialog/DiscordServerVerificationPopup.tsx +++ b/src/components/Dialog/DiscordServerVerificationPopup.tsx @@ -1,191 +1,329 @@ +import { useSelector } from "react-redux"; +import { useForm, Controller } from "react-hook-form"; +import { useAppDispatch } from "@store/store.model"; +import { useOAuth, useOAuthSocials } from "@components/Oauth2/oauth2"; import { getServerDetails, - verifyDiscordServerOwnership + useVerifyGuildOwnershipMutation } from "@api/discord.api"; -import { AutButton } from "@components/buttons"; -import { FormHelperText } from "@components/Fields"; -import { useOAuth } from "@components/Oauth2/oauth2"; -import { Typography } from "@mui/material"; import { HubData } from "@store/Hub/hub.reducer"; -import { useAppDispatch } from "@store/store.model"; +import { + Dialog, + DialogContent, + DialogActions, + Typography, + Box, + styled, + useTheme, + useMediaQuery +} from "@mui/material"; +import { SvgIcon } from "@mui/material"; +import CloseIcon from "@assets/autos/close-icon.svg?react"; +import PerfectScrollbar from "react-perfect-scrollbar"; import { AutTextField } from "@theme/field-text-styles"; -import { pxToRem } from "@utils/text-size"; import { useState } from "react"; -import { Controller, useForm } from "react-hook-form"; -import { useSelector } from "react-redux"; -import AutLoading from "../AutLoading"; -import DialogWrapper from "./DialogWrapper"; +import { AutOsButton } from "@components/AutButton"; +import { useMutation } from "@tanstack/react-query"; -const errorTypes = { - pattern: "Invalid discord invite link" -}; +const AutStyledDialog = styled(Dialog)(({ theme }) => ({ + ".MuiPaper-root": { + margin: "0", + width: "620px", + height: "720px", + border: "none", + position: "relative", + flexDirection: "column-reverse", + backgroundColor: "#1E2430", + borderRadius: "30px", + padding: "30px 0px", + boxShadow: + "0px 16px 80px 0px #2E90FA, 0px 0px 16px 0px rgba(20, 200, 236, 0.64), 0px 0px 16px 0px rgba(20, 200, 236, 0.32)" + }, + [theme.breakpoints.down("md")]: { + ".MuiPaper-root": { + margin: "0", + height: "100%", + width: "100%", + border: "none", + borderRadius: "0", + boxShadow: "none" + } + } +})); + +const StyledTextField = styled(AutTextField)(({ theme }) => ({ + width: "100%", + ".MuiInputBase-input": { + fontSize: "16px", + color: theme.palette.offWhite.main, + "&::placeholder": { + color: theme.palette.offWhite.main, + opacity: 0.5 + }, + "&.Mui-disabled": { + color: "#7C879D", + textFillColor: "#7C879D" + } + }, + ".MuiInputBase-root": { + caretColor: theme.palette.primary.main, + fieldset: { + border: "1.5px solid #576176 !important", + borderRadius: "6px" + }, + borderRadius: "6px", + background: "#2F3746" + }, + ".MuiInputLabel-root": { + color: "#7C879D" + } +})); + +const FormWrapper = styled("form")(({ theme }) => ({ + display: "flex", + flexDirection: "column", + gap: theme.spacing(2), + alignItems: "flex-start", + width: "100%", + [theme.breakpoints.down("lg")]: { + alignItems: "center", + justifyContent: "center", + alignContent: "center" + }, + [theme.breakpoints.down("md")]: { + width: `calc(100% - 100px)` + }, + [theme.breakpoints.down("sm")]: { + width: `calc(100% - 20px)` + } +})); const DiscordServerVerificationPopup = ({ open, - fullScreen = false, - handleClose -}: any) => { - const hubData = useSelector(HubData); - const { getAuth, authenticating } = useOAuth(); + onClose, + hub, + onChange, + setValue, + index +}) => { + const theme = useTheme(); + const desktop = useMediaQuery(theme.breakpoints.up("md")); + const { getAuthDiscord, authenticating } = useOAuthSocials(); const [loading, setLoading] = useState(false); const dispatch = useAppDispatch(); - const { control, formState, handleSubmit, getValues } = useForm({ + const { mutateAsync } = useVerifyGuildOwnershipMutation({ + // onSuccess: (data) => { + // if (data.isAdmin) { + // console.log("Verification successful! User is the guild owner."); + // } else { + // console.log("Verification failed. User is not the guild owner."); + // } + // }, + // onError: (error) => { + // console.error("An error occurred during verification:", error); + // } + }); + + const { control, handleSubmit, formState } = useForm({ mode: "onChange", defaultValues: { inviteLink: "" } }); - const authenticateDiscord = async () => { - const values = getValues(); - const { inviteLink } = values; - setLoading(true); + const authenticateDiscord = async (data) => { + const { inviteLink } = data; + // setLoading(true); const serverDetails = await getServerDetails(inviteLink); - await getAuth( + console.log(serverDetails); + getAuthDiscord( async (data) => { + console.log(data); const { access_token } = data; - const result = await dispatch( - verifyDiscordServerOwnership({ - accessToken: access_token, - guildId: serverDetails.guild.id - }) - ); - if (result.meta.requestStatus === "rejected") { - setLoading(false); - } else { - const hub = { ...hubData }; + console.log("access_token", access_token); + const result = await mutateAsync({ + accessToken: access_token, + guildId: serverDetails.guild.id + }); + console.log(result); + if (result.isAdmin) { for (let i = 0; i < hub.properties.socials.length; i++) { const element = hub.properties.socials[i]; if (element.type === "discord") { - element.link = values.inviteLink; + element.link = inviteLink; + element.metadata.guildId = serverDetails.guild_id; + element.metadata.guildName = serverDetails.guild.name; } } - // const hubUpdateResult = await dispatch( - // updateDiscordSocials({ hub, inviteLink }) - // ); - // if (hubUpdateResult.meta.requestStatus !== "rejected") { - // handleClose(); - // } - setLoading(false); } + onChange(serverDetails.guild.name); + setValue(`socials.${index}.link`, inviteLink); + setValue(`socials.${index}.metadata`, { + guildId: serverDetails.guild.id, + guildName: serverDetails.guild.name + }); + console.log("hub", hub); + onClose(); }, () => { setLoading(false); } ); + // await getAuth( + // async (authData) => { + // const { access_token } = authData; + // const result = await verifyDiscordServerOwnership({ + // accessToken: access_token, + // guildId: serverDetails.guild.id + // }); + + // if (result.meta.requestStatus === "rejected") { + // setLoading(false); + // } else { + // for (let i = 0; i < hub.properties.socials.length; i++) { + // const element = hub.properties.socials[i]; + // if (element.type === "discord") { + // element.link = inviteLink; + // element.guildId = serverDetails.guild_id; + // } + // } + // setLoading(false); + // onClose(); + // } + // }, + // () => { + // setLoading(false); + // } + // ); }; return ( - handleClose()} > -
-
+ + + + Verify Discord Server ownership + + + Enter an invite link and authorize with Discord. + + ( + + )} + /> + + + + + + + + + + Verify Discord Server + + + - {loading || authenticating ? ( - <> - - Verifying.. - - - - ) : ( - <> -
- - Verify Discord Server ownership - - - Enter an invite link and authorize with discord. - -
- { - return ( - - } - /> - ); - }} - /> -
- - Verify - -
- - )} -
-
-
+ + + {loading || authenticating ? "Verifying..." : "Verify"} + + + + + ); }; diff --git a/src/components/Oauth2/oauth2.tsx b/src/components/Oauth2/oauth2.tsx index 7586e44..32430f9 100644 --- a/src/components/Oauth2/oauth2.tsx +++ b/src/components/Oauth2/oauth2.tsx @@ -1,4 +1,3 @@ - import { environment } from "@api/environment"; import axios from "axios"; import { useCallback, useState, useRef } from "react"; @@ -118,7 +117,7 @@ export const useOAuthSocials = () => { const callbackUrl = encodeURI(`${window.location.origin}/callback`); popupRef.current = openPopup( - `https://discord.com/oauth2/authorize?client_id=1080508975780474900&response_type=code&redirect_uri=${callbackUrl}&scope=identify` + `https://discord.com/oauth2/authorize?client_id=${environment.discordClientId}&response_type=code&redirect_uri=${callbackUrl}&scope=identify+guilds` ) as any; async function handleMessageListener(message) { @@ -130,7 +129,7 @@ export const useOAuthSocials = () => { onFailure(error); } else { const response = await axios.post( - `${environment.apiUrl}/aut/config/oauth2AccessTokenDiscord`, + `http://localhost:4005/api/aut/config/oauth2AccessTokenDiscord`, { code: message.data.payload.code, callbackUrl From d8e16ce83d68780e7b16947bb1d19575778527fe Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 28 Oct 2024 23:02:32 +0200 Subject: [PATCH 2/3] extracted env variables --- src/api/environment.ts | 6 +++++- src/components/AutEditHubDialog.tsx | 9 --------- src/components/Oauth2/oauth2.tsx | 6 +++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/api/environment.ts b/src/api/environment.ts index 8134832..8b0dc04 100644 --- a/src/api/environment.ts +++ b/src/api/environment.ts @@ -25,7 +25,11 @@ export const swEnvVariables = { // IPFS storage ipfsApiKey: "VITE_IPFS_API_KEY", ipfsApiSecret: "VITE_IPFS_API_SECRET", - ipfsGatewayUrl: "VITE_IPFS_GATEWAY_URL" + ipfsGatewayUrl: "VITE_IPFS_GATEWAY_URL", + + + twitterClientId: "VITE_TWITTER_CLIENT_ID", + githubClientId: "VITE_GITHUB_CLIENT_ID" }; export const environment: typeof swEnvVariables = diff --git a/src/components/AutEditHubDialog.tsx b/src/components/AutEditHubDialog.tsx index 0634237..37c54c3 100644 --- a/src/components/AutEditHubDialog.tsx +++ b/src/components/AutEditHubDialog.tsx @@ -222,15 +222,6 @@ export function AutEditHubDialog(props: EditDialogProps) { }; const onEditHub = async (data: any) => { - console.log("hub submit", { - ...props.hub, - name: data.name, - description: data.description, - properties: { - ...props.hub.properties, - socials: data.socials - } - }); updateHub({ ...props.hub, name: data.name, diff --git a/src/components/Oauth2/oauth2.tsx b/src/components/Oauth2/oauth2.tsx index 32430f9..a32231b 100644 --- a/src/components/Oauth2/oauth2.tsx +++ b/src/components/Oauth2/oauth2.tsx @@ -129,7 +129,7 @@ export const useOAuthSocials = () => { onFailure(error); } else { const response = await axios.post( - `http://localhost:4005/api/aut/config/oauth2AccessTokenDiscord`, + `${environment.apiUrl}/aut/config/oauth2AccessTokenDiscord`, { code: message.data.payload.code, callbackUrl @@ -177,7 +177,7 @@ export const useOAuthSocials = () => { const callbackUrl = encodeURI(`${window.location.origin}/callback`); popupRef.current = openPopup( - `https://twitter.com/i/oauth2/authorize?response_type=code&client_id=YTFySXpsSVZMblIxbGFSVzhGN1I6MTpjaQ&state=state&scope=tweet.read%20users.read%20offline.access&redirect_uri=${callbackUrl}&code_challenge=challenge&code_challenge_method=plain` + `https://twitter.com/i/oauth2/authorize?response_type=code&client_id=${environment.twitterClientId}&state=state&scope=tweet.read%20users.read%20offline.access&redirect_uri=${callbackUrl}&code_challenge=challenge&code_challenge_method=plain` ) as any; async function handleMessageListener(message) { @@ -267,7 +267,7 @@ export const useOAuthSocials = () => { const callbackUrl = encodeURI(`${window.location.origin}/callback`); popupRef.current = openPopup( - `https://github.com/login/oauth/authorize?response_type=code&client_id=Ov23lilzR4TMABVhvR6W&state=state&scope=read:user&redirect_uri=${callbackUrl}` + `https://github.com/login/oauth/authorize?response_type=code&client_id=${environment.githubClientId}&state=state&scope=read:user&redirect_uri=${callbackUrl}` ) as any; async function handleMessageListener(message) { From eebba2c1854305854effff9bdad322e6544749f0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 29 Oct 2024 02:34:54 +0200 Subject: [PATCH 3/3] fixed oauth edit X --- package-lock.json | 33 +++++++++++----------------- package.json | 6 ++--- src/api/hub.api.ts | 34 ++++++++++++++--------------- src/components/AutEditHubDialog.tsx | 17 ++++++++++----- 4 files changed, 44 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index 58411e8..c91cf37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,10 @@ "version": "0.1.0", "dependencies": { "@apollo/client": "^3.9.1", - "@aut-labs/abi-types": "^0.0.81-dev", + "@aut-labs/abi-types": "^0.0.86-dev", "@aut-labs/connector": "^0.0.203", - "@aut-labs/d-aut": "^1.0.202-dev", - "@aut-labs/sdk": "^0.0.210-dev", + "@aut-labs/d-aut": "^1.0.204-dev", + "@aut-labs/sdk": "^0.0.221-dev", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.7", @@ -137,16 +137,14 @@ } }, "node_modules/@aut-labs/abi-types": { - "version": "0.0.81-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/abi-types/-/abi-types-0.0.81-dev.tgz", - "integrity": "sha512-/I+6aL353cYrp220yASBHM9KONRd7NFWutonAoRIkZnEzh2fixEHEskkEYB9+3jAAN4LnwKt+/tnKheja8uv9g==", - "license": "ISC" + "version": "0.0.86-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/abi-types/-/abi-types-0.0.86-dev.tgz", + "integrity": "sha512-I9VNsYN8smW516wPQeDWhJaw4OWiIc7WxRBIn2GkqKw4oYKaLbDRzTV2XXVrMlvVCo7V82V51SlV+fC0Hajq/w==" }, "node_modules/@aut-labs/connector": { "version": "0.0.203", "resolved": "https://registry.npmjs.org/@aut-labs/connector/-/connector-0.0.203.tgz", "integrity": "sha512-bUXlRb1YviVb6jpnTLnZs3HaZhABItep+knkbCsrKAAZcPH0bcsnJsjCfLOH2PsZX+BcTafxUrT2FDmy92aeZw==", - "license": "MIT", "dependencies": { "@web3auth/base": "^8.0.0", "@web3auth/ethereum-provider": "^8.0.1", @@ -167,25 +165,20 @@ } }, "node_modules/@aut-labs/d-aut": { - "version": "1.0.202-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/d-aut/-/d-aut-1.0.202-dev.tgz", - "integrity": "sha512-ocqU6ousVfW/ffOz8IIpx8Kr8OjS2xKTyPR/y4PgLetEb0rC7BJKDztTd6ztHMvTddsH24OvdHp4oiN0EgdmJQ==" + "version": "1.0.204-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/d-aut/-/d-aut-1.0.204-dev.tgz", + "integrity": "sha512-sDEu6yyvqu/KjqobI6nBoovrHWwhA4DoXPWObQLcGRs1Isuxg/d2HhP2/9k6Xz5zjFDo/w3MDI3XDvpVos20dg==" }, "node_modules/@aut-labs/sdk": { - "version": "0.0.210-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/sdk/-/sdk-0.0.210-dev.tgz", - "integrity": "sha512-9O1PfK9PAS4P4feIwmcIQ9QIVL0u6r+vue1Mwn885uXX6ImFi4Xob46WvelWDXUYd3Otw1smX4NuoQ5F+ykW+g==", + "version": "0.0.221-dev", + "resolved": "https://registry.npmjs.org/@aut-labs/sdk/-/sdk-0.0.221-dev.tgz", + "integrity": "sha512-W6R0oneKaSvc9kYIicSoPvygP1c4UlWrWu884FtAPPrrRQpucEvo9NG2FzsKa/Ku+nKV6APf6YoG3Zjib1vLvQ==", "dependencies": { - "@aut-labs/abi-types": "^0.0.83-dev", + "@aut-labs/abi-types": "^0.0.86-dev", "date-fns": "^2.29.3", "ethers": "^6.10.0" } }, - "node_modules/@aut-labs/sdk/node_modules/@aut-labs/abi-types": { - "version": "0.0.83-dev", - "resolved": "https://registry.npmjs.org/@aut-labs/abi-types/-/abi-types-0.0.83-dev.tgz", - "integrity": "sha512-TYdWEyJ5rAM5uJSF4HwsKbSpygfDhg7PTyahXwEO2cyT4cDz65VAu9B5kA2FOum0teraKrbxHA+5gILVHYzeig==" - }, "node_modules/@aut-labs/sdk/node_modules/date-fns": { "version": "2.30.0", "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", diff --git a/package.json b/package.json index 4f34d58..66a5d8e 100755 --- a/package.json +++ b/package.json @@ -33,10 +33,10 @@ }, "dependencies": { "@apollo/client": "^3.9.1", - "@aut-labs/abi-types": "^0.0.81-dev", + "@aut-labs/abi-types": "^0.0.86-dev", "@aut-labs/connector": "^0.0.203", - "@aut-labs/d-aut": "^1.0.202-dev", - "@aut-labs/sdk": "^0.0.210-dev", + "@aut-labs/d-aut": "^1.0.204-dev", + "@aut-labs/sdk": "^0.0.221-dev", "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.7", diff --git a/src/api/hub.api.ts b/src/api/hub.api.ts index bf6e942..c3b7926 100644 --- a/src/api/hub.api.ts +++ b/src/api/hub.api.ts @@ -418,23 +418,23 @@ export const updateHub = async (body: HubOSHub, api: BaseQueryApi) => { const overrides = await getOverrides(sdk.signer, 4000); const getMDres = await hubService.contract.metadata.getMetadataUri(); console.log("getMDres", getMDres); - const tx = await ( - await hubService.contract.metadata.functions.setMetadataUri( - uri, - overrides - ) - ).wait(); - console.log("tx", tx); - - const result = tx.getResult(); - console.log("tx", result); - // const result = await hubService.contract.metadata.setMetadataUri(uri); - - // if (!result?.isSuccess) { - // return { - // error: result?.errorMessage - // }; - // } + // const tx = await ( + // await hubService.contract.metadata.functions.setMetadataUri( + // uri, + // overrides + // ) + // ).wait(); + // console.log("tx", tx); + + // const result = tx.getResult(); + // console.log("tx", result); + const result = await hubService.contract.metadata.setMetadataUri(uri); + + if (!result?.isSuccess) { + return { + error: result?.errorMessage + }; + } return { data: { body } }; diff --git a/src/components/AutEditHubDialog.tsx b/src/components/AutEditHubDialog.tsx index 37c54c3..d0c7f00 100644 --- a/src/components/AutEditHubDialog.tsx +++ b/src/components/AutEditHubDialog.tsx @@ -30,6 +30,7 @@ import LoadingDialog from "./Dialog/LoadingPopup"; import { useUpdateHubMutation } from "@api/hub.api"; import DiscordServerVerificationPopup from "./Dialog/DiscordServerVerificationPopup"; import { getServerDetails } from "@api/discord.api"; +import axios from "axios"; export interface EditDialogProps { title: string; @@ -476,18 +477,22 @@ export function AutEditHubDialog(props: EditDialogProps) { getAuthX( async (data) => { const { access_token } = data; - const response = await fetch( + const userMeResponse = await axios.get( "https://api.twitter.com/2/users/me", { headers: { - Authorization: `Bearer ${access_token}` - } + Authorization: `Bearer ${access_token}`, + }, } ); - const responseData = - await response.json(); + const responseData = userMeResponse.data; + // const responseData = { + // id: "4889475844", + // name: "Antonio", + // username: "Antonio69459346" + // }; const username = - responseData.screen_name; + responseData.username; onChange(username); const fullLink = `${SocialLinkPrefixes.X}${username}`; setValue(