Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix errors / ui updates #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions const/contractToDisplayMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const contractTypeToDisplayNameMapping = {
token: "Token",
vote: "Vote",
split: "Split",
marketplace: "Marketplace",
pack: "Pack",
custom: "Custom",
multiwrap: "Multiwrap",
"signature-drop": "Signature Drop",
"marketplace-v3": "Marketplace v3",
"marketplace": "Marketplace",
};

const contractTypeToImageMapping = {
Expand All @@ -24,7 +25,8 @@ const contractTypeToImageMapping = {
"token-drop": `icons/token.webp`,
split: `icons/splits.webp`,
vote: `icons/vote.webp`,
marketplace: `icons/marketplace.webp`,
"marketplace-v3": `icons/marketplace.webp`,
"marketplace": `icons/marketplace.webp`,
pack: `icons/pack.webp`,
multiwrap: `icons/general.webp`,
custom: `icons/custom.svg`,
Expand All @@ -40,8 +42,8 @@ const contractsToShowOnDeploy = [
"edition-drop",
"token-drop",
"vote",
"marketplace",
"nft-drop",
"marketplace-v3",
// "multi-wrap",
// "signature-drop",
];
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@thirdweb-dev/react": "^3",
"@thirdweb-dev/sdk": "^3",
"@thirdweb-dev/react": "^3.14.32",
"@thirdweb-dev/sdk": "^3.10.51",
"ethers": "^5.7.2",
"next": "^13",
"react": "^18.2",
Expand Down
6 changes: 4 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import Head from "next/head";
import "../styles/globals.css";

// This is the chainId your dApp will work on.
const activeChainId = ChainId.Mumbai;
const activeChain = "mumbai";

function MyApp({ Component, pageProps }: AppProps) {
return (
<ThirdwebProvider desiredChainId={activeChainId}>
<ThirdwebProvider
activeChain={activeChain}
clientId={process.env.NEXT_PUBLIC_THIRDWEB_CLIENTID}>
<Head>
<title>thirdweb Custom Dashboard Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
57 changes: 47 additions & 10 deletions pages/deploy.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { ConnectWallet, useAddress, useSDK } from "@thirdweb-dev/react";
import { ContractType } from "@thirdweb-dev/sdk";
import React, { useState } from "react";
import { ConnectWallet, useAddress, useChainId, useSDK } from "@thirdweb-dev/react";
import { ChainId, ContractType } from "@thirdweb-dev/sdk";
import styles from "../styles/Home.module.css";
import {
contractsToShowOnDeploy as contracts,
Expand All @@ -13,14 +13,33 @@ export default function Deploy() {
const router = useRouter();
const address = useAddress();
const sdk = useSDK();
const [isLoading, setIsLoading] = useState(false);
const [isBlurred, setIsBlurred] = useState(false);

const chainId = useChainId();
let chainName = "";
if (chainId === ChainId.Mumbai) {
chainName = "mumbai";
} else if (chainId === ChainId.Polygon) {
chainName = "polygon";
} else if (chainId === ChainId.Mainnet) {
chainName = "ethereum";
} else if (chainId === ChainId.BinanceSmartChainMainnet) {
chainName = "binance";
} else if (chainId === 8453) {
chainName = "base"
}

// Function to deploy the proxy contract
async function deployContract(contractSelected: ContractType) {
if (!address || !sdk) {
return;
}

const contractAddress = await sdk.deployer.deployBuiltInContract(
try {
setIsLoading(true);
setIsBlurred(true);

const contractAddress = await sdk.deployer.deployBuiltInContract(
// @ts-ignore - we're excluding custom contracts from the demo
contractSelected,
{
Expand All @@ -39,18 +58,31 @@ export default function Deploy() {
);

// This is the contract address of the contract you just deployed
console.log(contractAddress);
setIsLoading(false);
setIsBlurred(false);

alert(`Successfully deployed ${contractSelected} at ${contractAddress}`);

alert(`Succesfully deployed ${contractSelected} at ${contractAddress}`);
const newTabUrl = `https://thirdweb.com/${chainName}/${contractAddress}`;
const newTab = window.open(newTabUrl, "_blank");

if (newTab) {
newTab.focus();
}

router.push(`/`);
} catch (error) {
setIsLoading(false);
setIsBlurred(false);
console.error("Error deploying contract:", error);
// Handle error, display error message, etc.
}
}

return (
<>
{/* Content */}
<div className={styles.container}>
{/* Top Section */}
<div className={`${styles.container} ${isBlurred ? styles.blurred : ""}`}>
<h1 className={styles.h1}>thirdweb Custom Dashboard</h1>
<p className={styles.explain}>
Learn how to dynamically create smart contracts using the thirdweb SDK
Expand All @@ -76,7 +108,7 @@ export default function Deploy() {
<p>
<b>Connect Your Wallet to deploy a contract</b>
</p>
<ConnectWallet accentColor="#F213A4" />
<ConnectWallet />
</>
) : (
<>
Expand All @@ -99,6 +131,11 @@ export default function Deploy() {
</>
)}
</div>
{isLoading && (
<div className={styles.loadingOverlay}>
<div className={styles.spinner}></div>
</div>
)}
</>
);
}
5 changes: 1 addition & 4 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ const Home: NextPage = () => {
// Fetch the contracts for this address and set them in state
sdk
.getContractList(address)
.then((contracts) => {
setExistingContracts(contracts);
})
.finally(() => setLoading(false));
}, [address, sdk]);

Expand Down Expand Up @@ -69,7 +66,7 @@ const Home: NextPage = () => {
<p>
<b>Connect Your Wallet to view your contracts</b>
</p>
<ConnectWallet accentColor="#F213A4" />
<ConnectWallet />
</>
) : (
<>
Expand Down
35 changes: 35 additions & 0 deletions styles/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,38 @@
.noGapBottom {
margin-bottom: 0px;
}

.blurred {
filter: blur(5px); /* Apply the blur effect */
pointer-events: none; /* Disable pointer events on blurred content */
}

.loadingOverlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 1000; /* Ensure the loading spinner is on top */
}

.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #333;
animation: spin 1s infinite linear;
width: 40px;
height: 40px;
border-radius: 50%;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
Loading