Add web3app validation using user settings

feat/add_web3app_validation
Edward Fernandez 2022-01-10 14:29:32 -05:00
parent 036224f7bd
commit 20beb961c6
3 changed files with 53 additions and 33 deletions

View File

@ -39,6 +39,7 @@ import updateEventType from "@lib/mutations/event-types/update-event-type";
import showToast from "@lib/notification"; import showToast from "@lib/notification";
import prisma from "@lib/prisma"; import prisma from "@lib/prisma";
import { defaultAvatarSrc } from "@lib/profile"; import { defaultAvatarSrc } from "@lib/profile";
import { trpc } from "@lib/trpc";
import { AdvancedOptions, EventTypeInput } from "@lib/types/event-type"; import { AdvancedOptions, EventTypeInput } from "@lib/types/event-type";
import { inferSSRProps } from "@lib/types/inferSSRProps"; import { inferSSRProps } from "@lib/types/inferSSRProps";
import { WorkingHours } from "@lib/types/schedule"; import { WorkingHours } from "@lib/types/schedule";
@ -62,10 +63,6 @@ import bloxyApi from "../../web3/dummyResps/bloxyApi";
dayjs.extend(utc); dayjs.extend(utc);
dayjs.extend(timezone); dayjs.extend(timezone);
// TODO @danfesi we need to get this boolean from user_settings
// we should also disable the other API calls for web3 if it's disabled
const web3App = true;
interface Token { interface Token {
name?: string; name?: string;
address: string; address: string;
@ -167,6 +164,9 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
const [advancedSettingsVisible, setAdvancedSettingsVisible] = useState(false); const [advancedSettingsVisible, setAdvancedSettingsVisible] = useState(false);
useEffect(() => { useEffect(() => {
const { data } = trpc.useQuery(["viewer.userSettings"]);
if (data?.web3App) {
const fetchTokens = async () => { const fetchTokens = async () => {
// Get a list of most popular ERC20s and ERC777s, combine them into a single list, set as tokensList // Get a list of most popular ERC20s and ERC777s, combine them into a single list, set as tokensList
try { try {
@ -199,6 +199,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
console.log(tokensList); // Just here to make sure it passes the gc hook. Can remove once actual use is made of tokensList. console.log(tokensList); // Just here to make sure it passes the gc hook. Can remove once actual use is made of tokensList.
fetchTokens(); fetchTokens();
}
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -519,6 +520,8 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
); );
}; };
const { data } = trpc.useQuery(["viewer.userSettings"]);
return ( return (
<div> <div>
<Shell <Shell
@ -778,7 +781,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
</div> </div>
</div> </div>
</div> </div>
{web3App && ( {data?.web3App && (
<div className="items-center block sm:flex"> <div className="items-center block sm:flex">
<div className="mb-4 min-w-48 sm:mb-0"> <div className="mb-4 min-w-48 sm:mb-0">
<label <label

View File

@ -571,6 +571,7 @@ function Web3Container() {
export default function IntegrationsPage() { export default function IntegrationsPage() {
const { t } = useLocale(); const { t } = useLocale();
const { data } = trpc.useQuery(["viewer.userSettings"]);
return ( return (
<Shell heading={t("integrations")} subtitle={t("connect_your_favourite_apps")}> <Shell heading={t("integrations")} subtitle={t("connect_your_favourite_apps")}>
@ -579,7 +580,7 @@ export default function IntegrationsPage() {
<CalendarListContainer /> <CalendarListContainer />
<WebhookListContainer /> <WebhookListContainer />
<IframeEmbedContainer /> <IframeEmbedContainer />
<Web3Container /> {data?.web3App && <Web3Container />}
</ClientSuspense> </ClientSuspense>
</Shell> </Shell>
); );

View File

@ -499,6 +499,22 @@ const loggedInViewerRouter = createProtectedRouter()
}; };
}, },
}) })
.query("userSettings", {
async resolve({ ctx }) {
const { prisma, user } = ctx;
const web3AppConfiguration = await prisma.userSettings.findFirst({
where: {
userId: user.id,
key: "web3App",
},
});
return {
web3App: (web3AppConfiguration?.value || "false") === "true",
};
},
})
.mutation("updateProfile", { .mutation("updateProfile", {
input: z.object({ input: z.object({
username: z.string().optional(), username: z.string().optional(),