import React, { useEffect, useState } from "react";
import { useLocation } from "react-router-dom";
import {
DynamicContextProvider,
DynamicWidget,
} from "@dynamic-labs/sdk-react-core";
import { SdkViewSectionType, SdkViewType } from "@dynamic-labs/sdk-api";
const FACEBOOK_VIEW = {
type: SdkViewType.Login,
sections: [
{
type: SdkViewSectionType.Social,
defaultItem: "facebook",
},
],
};
const WEB3_VIEW = {
type: SdkViewType.Login,
sections: [
{ type: SdkViewSectionType.Wallet },
{
type: SdkViewSectionType.Separator,
label: "Or",
},
{
type: SdkViewSectionType.Email,
},
{
type: SdkViewSectionType.Separator,
label: "Or",
},
{
type: SdkViewSectionType.Social,
defaultItem: "twitter",
},
],
};
const App = () => {
const [source, setSource] = useState("");
const [viewOverrides, setViewOverrides] = useState([]);
const location = useLocation();
const isFacebookCampaign = location.pathname === "/landing-page/facebook";
const isWeb3Campaign = location.pathname === "/landing-page/web3";
useEffect(() => {
setSource(isFacebookCampaign ? "facebook" : isWeb3Campaign ? "web3" : "");
}, [isFacebookCampaign, isWeb3Campaign]);
useEffect(() => {
if (source === "facebook") {
setViewOverrides([FACEBOOK_VIEW]);
} else if (source === "web3") {
setViewOverrides([WEB3_VIEW]);
} else {
setViewOverrides([]);
}
}, [source]);
return (
<DynamicContextProvider
settings={{
environmentId: "fba5127c-21c0-430e-bb03-7dc8f6b11397",
overrides: { views: viewOverrides },
}}
>
<DynamicWidget />
</DynamicContextProvider>
);
};
export default App;