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

policies testjam #11

Open
wants to merge 5 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
6 changes: 3 additions & 3 deletions components/cat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useCallback, useContext, useEffect, useState } from "react";
import { EventContext } from "../contexts/event-context";
import { GameContext } from "../contexts/game-context";
import { CONTRACT_ADDR } from "../utils/constants";
import { isOwnEvent } from "../utils/utils";
import { isOwnEvent, parseError } from "../utils/utils";
import { Event, EventProps } from "./events";

type ModalProps = {
Expand Down Expand Up @@ -153,8 +153,8 @@ const Modal: React.FC<ModalProps> = ({ isOpen, close, level }) => {
</Web3Button>
</div>
{error && (
<p className="mt-2 text-xs first-letter:capitalize text-red-400 max-w-xs text-center">
{(error as TransactionError).reason}
<p className="mt-2 text-xs first-letter:capitalize text-red-400 text-center">
{parseError((error as TransactionError).reason)}
</p>
)}
</div>
Expand Down
3 changes: 2 additions & 1 deletion components/claim-kitten-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TransactionError } from "@thirdweb-dev/sdk";
import { useContext, useState } from "react";
import { GameContext } from "../contexts/game-context";
import { CONTRACT_ADDR } from "../utils/constants";
import { parseError } from "../utils/utils";

const ClaimKittenButton: React.FC = () => {
const { refetch } = useContext(GameContext);
Expand All @@ -24,7 +25,7 @@ const ClaimKittenButton: React.FC = () => {
</Web3Button>
{error && (
<p className="mt-2 text-xs first-letter:capitalize text-red-400 max-w-xs text-center">
{(error as TransactionError).reason}
{parseError((error as TransactionError).reason)}
</p>
)}
</div>
Expand Down
28 changes: 27 additions & 1 deletion components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { ConnectWallet, useAddress } from "@thirdweb-dev/react";
import Image from "next/image";
import { Aurora } from "./Aurora";
import { useEffect, useState } from "react";
import { CLIENT_ID } from "../utils/constants";

const Header: React.FC = () => {
const address = useAddress();
const [clientId, setClientId] = useState<string | null>(null);
useEffect(() => {
setClientId(localStorage.getItem("TW_CLIENT_ID") || CLIENT_ID);
}, []);
return (
<header className="w-full p-4 mb-12">
<Aurora
Expand All @@ -28,9 +34,29 @@ const Header: React.FC = () => {
alt="thirdweb"
/>
</div>

<div className="max-w-xs">{address ? <ConnectWallet /> : null}</div>
</div>
<div className="mt-8">
<p>Dev Client Id</p>
<div className="flex flex-row content-center gap-4">
<input
className="border border-gray-500 bg-transparent rounded-xl p-4 font-medium placeholder:text-gray-500"
defaultValue={clientId || ""}
onChange={(e) => {
setClientId(e.target.value);
}}
/>
<button
className="border border-gray-500 bg-transparent rounded-xl p-4"
onClick={() => {
localStorage.setItem("TW_CLIENT_ID", clientId || "");
window.location.reload();
}}
>
Apply
</button>
</div>
</div>
</header>
);
};
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"prettier": "prettier --write ."
},
"dependencies": {
"@thirdweb-dev/chains": "^0.1.65",
"@thirdweb-dev/react": "^4.4.0",
"@thirdweb-dev/sdk": "^4.0.28",
"@thirdweb-dev/chains": "^0.1.67",
"@thirdweb-dev/react": "^4.4.2",
"@thirdweb-dev/sdk": "^4.0.30",
"ethers": "^5",
"next": "^13",
"react": "^18.2",
Expand Down
35 changes: 26 additions & 9 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
SmartWalletConfigOptions,
ThirdwebProvider,
embeddedWallet,
localWallet,
Expand All @@ -8,6 +9,7 @@ import type { AppProps } from "next/app";
import { Inter } from "next/font/google";
import "tailwindcss/tailwind.css";
import { CHAIN, CLIENT_ID, FACTORY_ADDR } from "../utils/constants";
import { useEffect, useState } from "react";

const inter = Inter({
subsets: ["latin"],
Expand All @@ -16,20 +18,35 @@ const inter = Inter({
display: "swap",
});

const swConfig: SmartWalletConfigOptions = {
factoryAddress: FACTORY_ADDR,
gasless: true,
bundlerUrl: `https://${CHAIN.chainId}.bundler.thirdweb-dev.com`,
paymasterUrl: `https://${CHAIN.chainId}.bundler.thirdweb-dev.com`,
// bundlerUrl: `http://0.0.0.0:8787?chain=${CHAIN.chainId}`,
// paymasterUrl: `http://0.0.0.0:8787/v2?chain=${CHAIN.chainId}`,
};

function MyApp({ Component, pageProps }: AppProps) {
const [clientId, setClientId] = useState<string | null>(null);
useEffect(() => {
setClientId(localStorage.getItem("TW_CLIENT_ID") || CLIENT_ID);
localStorage.setItem("IS_THIRDWEB_DEV", "true");
localStorage.setItem(
"THIRDWEB_DEV_URL",
"https://embedded-wallet.thirdweb-dev.com"
);
}, []);
return (
<ThirdwebProvider
activeChain={CHAIN}
clientId={CLIENT_ID}
clientId={clientId || CLIENT_ID}
sdkOptions={{
gatewayUrls: ["https://ipfs.io/ipfs/"],
}}
supportedWallets={[
smartWallet(embeddedWallet(), {
factoryAddress: FACTORY_ADDR,
gasless: true,
}),
smartWallet(localWallet(), {
factoryAddress: FACTORY_ADDR,
gasless: true,
}),
// smartWallet(embeddedWallet(), swConfig),
smartWallet(localWallet(), swConfig),
]}
>
<div className={inter.className}>
Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useOwnedNFTs,
} from "@thirdweb-dev/react";
import type { NextPage } from "next";
import { useState } from "react";
import { useEffect, useState } from "react";
import Header from "../components/header";
import Events from "../components/events";
import Welcome from "../components/welcome";
Expand Down
8 changes: 4 additions & 4 deletions utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseGoerli } from "@thirdweb-dev/chains";
import { Base } from "@thirdweb-dev/chains";

export const CLIENT_ID = process.env.NEXT_PUBLIC_THIRDWEB_CLIENT_ID || "";
export const CHAIN = BaseGoerli;
export const CONTRACT_ADDR = "0x5370B740616502979Fb1122E5e3896D41f6DAA1B";
export const FACTORY_ADDR = "0x7f2A5F9C7B90C6B4F46038445118a9EB288722dd";
export const CHAIN = Base;
export const CONTRACT_ADDR = "0xBE2fDc35410E268e41Bec62DBb01AEb43245c7d5";
export const FACTORY_ADDR = "0x2dF9851af45dd41C8584ac55D983C604da985Bc7";
6 changes: 6 additions & 0 deletions utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export function isOwnEvent(
(data.victim === address || data.attacker === address))
);
}

export const parseError = (reason: string) => {
if (reason.includes("AA21 didn't pay prefund"))
return "You ran out of sponsored transactions! Fund your wallet to continue playing.";
return reason;
};
Loading