Skip to content

Small fixes for polygon testnet #31

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

Open
wants to merge 7 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
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dependencies": {
"@aa-sdk/core": "^4.24.0",
"@account-kit/infra": "^4.24.0",
"@account-kit/plugingen": "4.24.0",
"@account-kit/smart-contracts": "^4.24.0",
"viem": "2.28.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Home: NextPage = () => {
<div className="px-5">
<h1 className="text-center">
<span className="block text-2xl mb-2">Welcome to</span>
<span className="block text-4xl font-bold">Scaffold-Alchemy</span>
<span className="block text-4xl font-bold">ID-Ephyrian (w/ Alchemy)</span>
</h1>
<div className="flex justify-center items-center space-x-2 flex-col sm:flex-row">
{isConnected ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { useRef, useState } from "react";
import { NetworkOptions } from "./NetworkOptions";
import { useLogout } from "@account-kit/react";
Expand All @@ -12,9 +14,10 @@ import {
ChevronDownIcon,
DocumentDuplicateIcon,
QrCodeIcon,
ShieldCheckIcon, //feature_1
} from "@heroicons/react/24/outline";
import { BlockieAvatar, isENS } from "~~/components/scaffold-alchemy";
import { useOutsideClick } from "~~/hooks/scaffold-alchemy";
import { useOutsideClick, useAccountType } from "~~/hooks/scaffold-alchemy"; // 'useAccountType' is feature_1
import { getTargetNetworks } from "~~/utils/scaffold-alchemy";

const allowedNetworks = getTargetNetworks();
Expand All @@ -34,6 +37,7 @@ export const AddressInfoDropdown = ({
}: AddressInfoDropdownProps) => {
const checkSumAddress = getAddress(address);
const { logout } = useLogout();
const { accountType } = useAccountType(); //Feature_1

const [addressCopied, setAddressCopied] = useState(false);

Expand Down Expand Up @@ -108,6 +112,17 @@ export const AddressInfoDropdown = ({
</a>
</button>
</li>
<li className={selectingNetwork ? "hidden" : ""}>
<div className="btn-sm !rounded-xl flex gap-3 py-3 px-4 cursor-default hover:bg-base-200">
<ShieldCheckIcon className="h-6 w-4" />
<span className="whitespace-nowrap font-medium">
{accountType === "EOA" && "Upgrade to a Smart Wallet"}
{accountType === "EOA_7702" && "This is a Smart Wallet"}
{accountType === "SCA_4337" && "This is a Smart Account"}
{accountType === "UNKNOWN" && "Detecting account type..."}
</span>
</div>
</li>
{allowedNetworks.length > 1 ? (
<li className={selectingNetwork ? "hidden" : ""}>
<button
Expand Down
55 changes: 54 additions & 1 deletion packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@
*/
import { GenericContractsDeclaration } from "~~/utils/scaffold-alchemy/contract";

const deployedContracts = {} as const;
const deployedContracts = {
11155111: {
Counter: {
address: "0xab3f7a562d201a696fb316f39793c3736ff61866",
abi: [
{
type: "constructor",
stateMutability: "nonpayable",
inputs: [
{
name: "_x",
type: "uint256",
baseType: "uint256",
components: null,
arrayLength: null,
arrayChildren: null,
},
],
},
{
type: "function",
name: "decrement",
stateMutability: "nonpayable",
inputs: [],
outputs: [],
},
{
type: "function",
name: "increment",
stateMutability: "nonpayable",
inputs: [],
outputs: [],
},
{
type: "function",
name: "x",
stateMutability: "view",
inputs: [],
outputs: [
{
name: "",
type: "uint256",
baseType: "uint256",
components: null,
arrayLength: null,
arrayChildren: null,
},
],
},
],
inheritedFunctions: {},
},
},
} as const;

export default deployedContracts satisfies GenericContractsDeclaration;
1 change: 1 addition & 0 deletions packages/nextjs/hooks/scaffold-alchemy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from "./useTargetNetwork";
export * from "./useTransactor";
export * from "./useWatchBalance";
export * from "./useSelectedNetwork";
export * from "./useAccountType"; //feature_1
67 changes: 67 additions & 0 deletions packages/nextjs/hooks/scaffold-alchemy/useAccountType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable prettier/prettier */

// This code is part of feature_1: "Account Type Detection"
import { useEffect, useState } from "react";
import { useAccount } from "wagmi";
import { useClient } from "./useClient";

export type AccountType = "EOA" | "EOA_7702" | "SCA_4337" | "UNKNOWN";

export const useAccountType = () => {
const [accountType, setAccountType] = useState<AccountType>("UNKNOWN");
const [isLoading, setIsLoading] = useState(true);
const { isConnected, connector } = useAccount();
const { client, address } = useClient();


useEffect(() => {
const detectAccountType = async () => {

try {
// Debug logging
console.log("[useAccountType] Detection state:", {
isConnected,
hasClient: !!client,
hasAddress: !!address,
connectorType: connector?.type,
connectorName: connector?.name,
});

// If we have a client and address, check if it's from external wallet or not
if (client && address) {
// Check if connected via external wallet
const isExternalWallet =
connector?.type === "injected" ||
connector?.type === "walletConnect" ||
connector?.name?.toLowerCase().includes("wallet") ||
connector?.name?.toLowerCase().includes("metamask");

if (isExternalWallet) {
// External wallet with SCA (future: detect 7702)
setAccountType("EOA");
} else {
// Has SCA but no external wallet = email/social login
setAccountType("SCA_4337");
}
} else if (isConnected && !client) {
// Connected with external wallet but no SCA client
setAccountType("EOA");
} else if (!isConnected && address) {
// Has address but not connected via wagmi = likely email/social
setAccountType("SCA_4337");
} else {
setAccountType("UNKNOWN");
}
} catch (error) {
console.error("Error detecting account type:", error);
setAccountType("UNKNOWN");
} finally {
setIsLoading(false);
}
};

detectAccountType();
}, [isConnected, connector, client, address]);

return { accountType, isLoading };
};
2 changes: 1 addition & 1 deletion packages/nextjs/hooks/scaffold-alchemy/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RPC_CHAIN_NAMES } from "~~/utils/scaffold-alchemy";

export const useClient = (
config: UseSmartAccountClientProps = {
type: "LightAccount",
type: "MultiOwnerModularAccount",
},
) => {
const { client, address } = useSmartAccountClient(config);
Expand Down
10 changes: 9 additions & 1 deletion packages/nextjs/hooks/scaffold-alchemy/useTransactor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@ export const useTransactor = (): TransactionFunc => {
<TxnNotification message="Waiting for transaction to complete." blockExplorerLink={blockExplorerTxURL} />,
);

transactionReceipt = await publicClient.waitForTransactionReceipt({
const rawReceipt = await publicClient.waitForTransactionReceipt({
hash: transactionHash,
confirmations: options?.blockConfirmations,
});

transactionReceipt = {
...rawReceipt,
logs: rawReceipt.logs.map(log => ({
...log,
blockHash: log.blockHash || "", // Ensure blockHash is not null
})),
} as TransactionReceipt;
notification.remove(notificationId);

if (transactionReceipt.status === "reverted") throw new Error("Transaction reverted");
Expand Down
6 changes: 3 additions & 3 deletions packages/nextjs/utils/scaffold-alchemy/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const RPC_CHAIN_NAMES: Record<number, string> = {
[chains.arbitrumNova.id]: "arb-nova",
[chains.base.id]: "base-mainnet",
[chains.polygonZkEvm.id]: "polygon-zkevm",
[chains.polygon.id]: "polygon-mainnet",
[chains.polygon.id]: "polygon(pos)-mainnet",
[chains.optimism.id]: "opt-mainnet",
[chains.zora.id]: "zora-mainnet",
[chains.worldchain.id]: "worldchain-mainnet",
Expand All @@ -39,8 +39,8 @@ export const RPC_CHAIN_NAMES: Record<number, string> = {
[chains.optimismSepolia.id]: "opt-sepolia",
[chains.baseGoerli.id]: "base-goerli",
[chains.baseSepolia.id]: "base-sepolia",
[chains.polygonMumbai.id]: "polygon-mumbai",
[chains.polygonAmoy.id]: "polygon-amoy",
[chains.polygonMumbai.id]: "polygon-mumbai", // deprecated
[chains.polygonAmoy.id]: "polygon(pos)-amoy",
[chains.zoraSepolia.id]: "zora-sepolia",
[chains.worldchainSepolia.id]: "worldchain-sepolia",
[chains.shapeSepolia.id]: "shape-sepolia",
Expand Down
8 changes: 5 additions & 3 deletions packages/shared/src/chainUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
optimism,
optimismSepolia,
polygon,
polygonMumbai,
polygonMumbai, // deprecated
polygonAmoy,
sepolia,
worldChain,
worldChainSepolia,
Expand Down Expand Up @@ -36,7 +37,7 @@ export const allChains: ChainInfo[] = [
{ chain: arbitrum, name: "arb-mainnet" },
{ chain: optimism, name: "opt-mainnet" },
{ chain: base, name: "base-mainnet" },
{ chain: polygon, name: "polygon-mainnet" },
{ chain: polygon, name: "polygon(pos)-mainnet" },
{ chain: worldChain, name: "worldchain-mainnet" },
{ chain: shape, name: "shape-mainnet" },
{ chain: unichainMainnet, name: "unichain-mainnet" },
Expand All @@ -49,7 +50,8 @@ export const allChains: ChainInfo[] = [
{ chain: arbitrumSepolia, name: "arb-sepolia" },
{ chain: optimismSepolia, name: "opt-sepolia" },
{ chain: baseSepolia, name: "base-sepolia" },
{ chain: polygonMumbai, name: "polygon-mumbai" },
{ chain: polygonMumbai, name: "polygon-mumbai" }, // deprecated
{ chain: polygonAmoy, name: "polygon(pos)-amoy" },
{ chain: worldChainSepolia, name: "worldchain-sepolia" },
{ chain: shapeSepolia, name: "shape-sepolia" },
{ chain: unichainSepolia, name: "unichain-sepolia" },
Expand Down
18 changes: 9 additions & 9 deletions packages/shared/src/cw3d.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// THIS IS AN AUTOGENERATED FILE BY CREATE-WEB3-DAPP

export type CW3DConfig = {
mainnetName: string;
mainnetChainId: number;
testnetChainId: number;
testnetChainName: string;
mainnetName: string;
mainnetChainId: number;
testnetChainId: number;
testnetChainName: string;
};

export const chainConfig = {
mainnetName: "shape-mainnet",
mainnetChainId: 360,
testnetChainId: 11011,
testnetChainName: "shape-sepolia",
} as const satisfies CW3DConfig;
mainnetName: "eth-mainnet",
mainnetChainId: 1,
testnetChainId: 11155111,
testnetChainName: "eth-sepolia",
} as const satisfies CW3DConfig;
Loading