Skip to content

Commit 2ff0701

Browse files
committed
make the component more intuitive to use while maintaining all
functionality. The network prop is now used consistently across components. - Replace chainId prop with network prop - Add network name to chain ID resolution - Remove manual provider selection in favor of auto-detection - Update documentation and examples to reflect new API - Simplify preset builders to use network names - Add fallback to Ethereum mainnet for unknown networks
1 parent 59191db commit 2ff0701

4 files changed

Lines changed: 42 additions & 139 deletions

File tree

components/nft-mint-examples.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface NFTMintExample {
1010
instanceId: string;
1111
tokenId: string;
1212
buttonText?: string;
13-
chainId?: number;
13+
network?: string;
1414
}
1515

1616
const nftExamples: NFTMintExample[] = [
@@ -21,7 +21,7 @@ const nftExamples: NFTMintExample[] = [
2121
instanceId: "",
2222
tokenId: "",
2323
buttonText: "Mint Thirdweb NFT",
24-
chainId: 42220, // Celo
24+
network: "celo"
2525
},
2626
{
2727
title: "Test NFT - No Image",
@@ -78,7 +78,7 @@ const nftExamples: NFTMintExample[] = [
7878
instanceId: "3763024112",
7979
tokenId: "1",
8080
buttonText: "Mint Video NFT",
81-
chainId: 8453, // Base
81+
network: "base"
8282
},
8383
];
8484

@@ -120,19 +120,14 @@ export function NFTMintExamples({
120120
{example.instanceId && (
121121
<div>Instance: {example.instanceId}</div>
122122
)}
123-
{example.chainId && example.chainId !== 8453 && (
124-
<div>Chain: {example.chainId === 42220 ? "Celo" : `ID ${example.chainId}`}</div>
123+
{example.network && example.network !== "base" && (
124+
<div>Network: {example.network}</div>
125125
)}
126126
</div>
127127

128128
<NFTMintButton
129129
contractAddress={example.contractAddress}
130-
chainId={example.chainId || 8453} // Use example chainId or default to Base
131-
forceProvider={
132-
example.instanceId
133-
? "manifold"
134-
: undefined
135-
}
130+
network={example.network || "base"} // Use example network or default to Base
136131
manifoldParams={
137132
example.instanceId
138133
? {

public/r/nft-mint-flow.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

registry/mini-app/blocks/nft-mint-flow/nft-mint-button.tsx

Lines changed: 31 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
validateParameters,
3535
getClientForChain,
3636
} from "@/registry/mini-app/blocks/nft-mint-flow/lib/provider-detector";
37-
import { getChainById } from "@/registry/mini-app/lib/chains";
37+
import { getChainById, findChainByName } from "@/registry/mini-app/lib/chains";
3838
import { getProviderConfig } from "@/registry/mini-app/blocks/nft-mint-flow/lib/provider-configs";
3939
import { fetchPriceData } from "@/registry/mini-app/blocks/nft-mint-flow/lib/price-optimizer";
4040
import {
@@ -52,36 +52,27 @@ import {
5252
* NFTMintButton - Universal NFT minting button with automatic provider detection and ERC20 approval handling
5353
*
5454
* The button automatically detects the NFT provider (Manifold, OpenSea, Zora, etc.) by analyzing
55-
* the contract. You only need to specify the provider if auto-detection fails or you want to
56-
* override the detection.
55+
* the contract. Provider detection is fully automatic - no need to specify the provider manually.
5756
*
5857
* @example
5958
* ```tsx
6059
* // Basic mint - auto-detects provider and handles everything
6160
* <NFTMintButton
6261
* contractAddress="0x5b97886E4e1fC0F7d19146DEC03C917994b3c3a4"
63-
* chainId={1}
62+
* network="ethereum"
6463
* />
6564
*
6665
* // Manifold NFT - auto-detected, just provide the required params
6766
* <NFTMintButton
6867
* contractAddress="0x32dd0a7190b5bba94549a0d04659a9258f5b1387"
69-
* chainId={8453}
68+
* network="base"
7069
* manifoldParams={{ instanceId: "4293509360" }}
7170
* />
7271
*
73-
* // Force specific provider (only if auto-detection is wrong)
74-
* <NFTMintButton
75-
* contractAddress="0x..."
76-
* chainId={8453}
77-
* forceProvider="manifold"
78-
* manifoldParams={{ instanceId: "123" }}
79-
* />
80-
*
8172
* // Multiple NFTs with success callback
8273
* <NFTMintButton
8374
* contractAddress="0x..."
84-
* chainId={8453}
75+
* network="base"
8576
* amount={5}
8677
* buttonText="Mint 5 NFTs"
8778
* onMintSuccess={(txHash) => console.log("Minted!", txHash)}
@@ -96,25 +87,11 @@ type NFTMintFlowProps = {
9687
contractAddress: Address;
9788

9889
/**
99-
* Blockchain network ID
100-
* Supports any valid chain ID
101-
*/
102-
chainId: number;
103-
104-
/**
105-
* Force a specific NFT provider instead of auto-detection
106-
*
107-
* By default, the component auto-detects the provider by analyzing the contract.
108-
* Only use this prop if:
109-
* - Auto-detection is returning the wrong provider
110-
* - You need to test a specific provider's flow
111-
* - The contract has non-standard implementation
112-
*
113-
* Note: "generic" is not an option here - it's used internally as a fallback.
114-
*
115-
* @default undefined (auto-detect)
90+
* Blockchain network name (e.g., "ethereum", "base", "arbitrum", "optimism", "polygon", "zora")
91+
* This matches the network prop used by NFTCard for consistency.
92+
* @default "ethereum"
11693
*/
117-
forceProvider?: "manifold" | "opensea" | "zora";
94+
network?: string;
11895

11996
/**
12097
* Number of NFTs to mint. Defaults to 1.
@@ -125,8 +102,8 @@ type NFTMintFlowProps = {
125102
/**
126103
* Manifold-specific parameters
127104
*
128-
* Required when minting Manifold NFTs (auto-detected or forced).
129-
* The component will show an error if these are missing for Manifold contracts.
105+
* These are auto-detected when possible, but can be provided if known.
106+
* The component will show helpful error messages if required params are missing.
130107
*
131108
* @example
132109
* // For claim-based mints (most common)
@@ -176,8 +153,7 @@ type NFTMintFlowProps = {
176153

177154
export function NFTMintButton({
178155
contractAddress,
179-
chainId,
180-
forceProvider,
156+
network = "ethereum",
181157
amount = 1,
182158
manifoldParams,
183159
className,
@@ -194,32 +170,26 @@ export function NFTMintButton({
194170
null,
195171
);
196172

197-
// Prop validation with helpful errors
198-
React.useEffect(() => {
199-
if (
200-
forceProvider === "manifold" &&
201-
!manifoldParams?.instanceId &&
202-
!manifoldParams?.tokenId
203-
) {
204-
console.error(
205-
"NFTMintButton: When forceProvider=\"manifold\", you must provide manifoldParams with either instanceId or tokenId. " +
206-
"Example: manifoldParams={{ instanceId: \"4293509360\" }}",
207-
);
173+
// Convert network name to chainId
174+
const chain = React.useMemo(() => {
175+
const foundChain = findChainByName(network);
176+
if (!foundChain) {
177+
console.warn(`NFTMintButton: Network "${network}" not recognized, defaulting to Ethereum mainnet`);
178+
return getChainById(1); // Default to Ethereum mainnet
208179
}
180+
return foundChain;
181+
}, [network]);
209182

210-
if (manifoldParams && forceProvider && forceProvider !== "manifold") {
211-
console.warn(
212-
"NFTMintButton: manifoldParams provided but forceProvider is not \"manifold\". " +
213-
"These params will be ignored for non-Manifold providers.",
214-
);
215-
}
183+
const chainId = chain.id;
216184

185+
// Prop validation with helpful errors
186+
React.useEffect(() => {
217187
if (!contractAddress || !contractAddress.match(/^0x[a-fA-F0-9]{40}$/)) {
218188
console.error(
219189
"NFTMintButton: Invalid contract address. Must be a valid Ethereum address (0x...)",
220190
);
221191
}
222-
}, [forceProvider, manifoldParams, chainId, contractAddress]);
192+
}, [contractAddress]);
223193

224194
// Destructure commonly used values
225195
const {
@@ -250,13 +220,13 @@ export function NFTMintButton({
250220
() => ({
251221
contractAddress,
252222
chainId,
253-
provider: forceProvider,
223+
provider: undefined, // Let auto-detection handle this
254224
amount,
255225
instanceId: manifoldParams?.instanceId,
256226
tokenId: manifoldParams?.tokenId,
257227
recipient: address,
258228
}),
259-
[contractAddress, chainId, forceProvider, amount, manifoldParams, address],
229+
[contractAddress, chainId, amount, manifoldParams, address],
260230
);
261231

262232
// Watch for transaction completion
@@ -1069,13 +1039,13 @@ NFTMintButton.presets = {
10691039
* ```tsx
10701040
* <NFTMintButton {...NFTMintButton.presets.auto({
10711041
* contractAddress: "0x5b97886E4e1fC0F7d19146DEC03C917994b3c3a4",
1072-
* chainId: 1
1042+
* network: "ethereum"
10731043
* })} />
10741044
* ```
10751045
*/
10761046
auto: (props: {
10771047
contractAddress: Address;
1078-
chainId: number;
1048+
network: string;
10791049
amount?: number;
10801050
buttonText?: string;
10811051
manifoldParams?: { instanceId?: string; tokenId?: string };
@@ -1092,14 +1062,14 @@ NFTMintButton.presets = {
10921062
* ```tsx
10931063
* <NFTMintButton {...NFTMintButton.presets.manifold({
10941064
* contractAddress: "0x32dd0a7190b5bba94549a0d04659a9258f5b1387",
1095-
* chainId: 8453,
1065+
* network: "base",
10961066
* instanceId: "4293509360"
10971067
* })} />
10981068
* ```
10991069
*/
11001070
manifold: (props: {
11011071
contractAddress: Address;
1102-
chainId: number;
1072+
network: string;
11031073
instanceId: string;
11041074
tokenId?: string;
11051075
amount?: number;
@@ -1108,8 +1078,7 @@ NFTMintButton.presets = {
11081078
onMintError?: (error: string) => void;
11091079
}): NFTMintFlowProps => ({
11101080
contractAddress: props.contractAddress,
1111-
chainId: props.chainId,
1112-
forceProvider: "manifold",
1081+
network: props.network,
11131082
manifoldParams: {
11141083
instanceId: props.instanceId,
11151084
tokenId: props.tokenId,
@@ -1119,35 +1088,4 @@ NFTMintButton.presets = {
11191088
onMintSuccess: props.onMintSuccess,
11201089
onMintError: props.onMintError,
11211090
}),
1122-
1123-
/**
1124-
* Force a specific provider (only use if auto-detection fails)
1125-
* @example
1126-
* ```tsx
1127-
* <NFTMintButton {...NFTMintButton.presets.forceProvider({
1128-
* contractAddress: "0x...",
1129-
* chainId: 8453,
1130-
* provider: "opensea"
1131-
* })} />
1132-
* ```
1133-
*/
1134-
forceProvider: (props: {
1135-
contractAddress: Address;
1136-
chainId: number;
1137-
provider: "manifold" | "opensea" | "zora";
1138-
amount?: number;
1139-
buttonText?: string;
1140-
manifoldParams?: { instanceId?: string; tokenId?: string };
1141-
onMintSuccess?: (txHash: string) => void;
1142-
onMintError?: (error: string) => void;
1143-
}): NFTMintFlowProps => ({
1144-
contractAddress: props.contractAddress,
1145-
chainId: props.chainId,
1146-
forceProvider: props.provider,
1147-
amount: props.amount || 1,
1148-
buttonText: props.buttonText,
1149-
manifoldParams: props.manifoldParams,
1150-
onMintSuccess: props.onMintSuccess,
1151-
onMintError: props.onMintError,
1152-
}),
11531091
};

registry/mini-app/blocks/nft-mint-flow/nft-mint-flow.tsx

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,12 @@ interface NFTMintPageProps {
2828
tokenId: string;
2929

3030
/**
31-
* Network name for display purposes (e.g., "base", "ethereum")
31+
* Network name (e.g., "base", "ethereum", "arbitrum")
32+
* Used for both NFTCard display and NFTMintButton chain resolution
3233
* @default "ethereum"
3334
*/
3435
network?: string;
3536

36-
/**
37-
* Chain ID for the blockchain network
38-
* Note: Supports any chain ID, not limited to specific values
39-
* @example 1 (Ethereum), 8453 (Base), 42220 (Celo)
40-
*/
41-
chainId: number;
42-
43-
/**
44-
* Force a specific NFT provider instead of auto-detection
45-
*
46-
* Leave undefined for automatic provider detection (recommended).
47-
* Only use this if auto-detection fails or you need to override it.
48-
*
49-
* @default undefined (auto-detect)
50-
*/
51-
forceProvider?: "manifold" | "opensea" | "zora";
52-
5337
/**
5438
* Parameters specific to Manifold NFTs
5539
* Required when forceProvider="manifold" or when minting Manifold contracts
@@ -85,36 +69,23 @@ interface NFTMintPageProps {
8569
* contractAddress="0x5b97886E4e1fC0F7d19146DEC03C917994b3c3a4"
8670
* tokenId="1"
8771
* network="ethereum"
88-
* chainId={1}
8972
* />
9073
*
9174
* // Manifold NFT - just provide the required params
9275
* <NFTMintFlow
9376
* contractAddress="0x32dd0a7190b5bba94549a0d04659a9258f5b1387"
9477
* tokenId="2"
9578
* network="base"
96-
* chainId={8453}
9779
* manifoldParams={{
9880
* instanceId: "4293509360"
9981
* }}
10082
* />
101-
*
102-
* // Force specific provider (rarely needed)
103-
* <NFTMintFlow
104-
* contractAddress="0x..."
105-
* tokenId="1"
106-
* chainId={8453}
107-
* forceProvider="manifold"
108-
* manifoldParams={{ instanceId: "123" }}
109-
* />
11083
* ```
11184
*/
11285
export function NFTMintFlow({
11386
contractAddress,
11487
tokenId,
11588
network = "ethereum",
116-
chainId,
117-
forceProvider,
11889
manifoldParams,
11990
buttonText = "Mint NFT",
12091
}: NFTMintPageProps) {
@@ -151,8 +122,7 @@ export function NFTMintFlow({
151122

152123
<NFTMintButton
153124
contractAddress={contractAddress}
154-
chainId={chainId}
155-
forceProvider={forceProvider}
125+
network={network}
156126
manifoldParams={manifoldParams}
157127
buttonText={buttonText}
158128
variant="default"

0 commit comments

Comments
 (0)