Skip to content

Commit 710dd89

Browse files
authored
Merge pull request #368 from oyingrace/fix/farcaster-miniapp-environment-detection
Fix/farcaster miniapp environment detection
2 parents 1844aea + 7be9f83 commit 710dd89

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

templates/base/apps/web/src/app/page.tsx.hbs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,24 @@ export default function Home() {
2222
const { address, isConnected, isConnecting } = useAccount();
2323
const { connect, connectors } = useConnect();
2424

25-
// Auto-connect wallet when miniapp is ready
25+
// Extract user data from context
26+
const user = context?.user;
27+
28+
// Check if we're in a Farcaster miniapp environment
29+
// We're in a miniapp if we have user data from the Farcaster SDK
30+
const isInMiniappEnvironment = !!user;
31+
32+
// Auto-connect wallet when miniapp is ready (only in miniapp environment)
2633
useEffect(() => {
27-
if (isMiniAppReady && !isConnected && !isConnecting && connectors.length > 0) {
34+
if (isMiniAppReady && isInMiniappEnvironment && !isConnected && !isConnecting && connectors.length > 0) {
2835
const farcasterConnector = connectors.find(c => c.id === 'farcaster');
2936
if (farcasterConnector) {
3037
connect({ connector: farcasterConnector });
3138
}
3239
}
33-
}, [isMiniAppReady, isConnected, isConnecting, connectors, connect]);
34-
35-
// Extract user data from context
36-
const user = context?.user;
37-
// Use connected wallet address if available, otherwise fall back to user custody/verification
38-
const walletAddress = address || user?.custody || user?.verifications?.[0] || "0x1e4B...605B";
40+
}, [isMiniAppReady, isInMiniappEnvironment, isConnected, isConnecting, connectors, connect]);
41+
// Use connected wallet address if available, otherwise show not connected
42+
const walletAddress = address || user?.custody || user?.verifications?.[0] || null;
3943
const displayName = user?.displayName || user?.username || "User";
4044
const username = user?.username || "@user";
4145
const pfpUrl = user?.pfpUrl;
@@ -70,7 +74,7 @@ export default function Home() {
7074

7175
{/* Status Message */}
7276
<p className="text-lg text-gray-600 mb-6">
73-
You are signed in!
77+
{user ? "You are signed in!" : "You are not signed in"}
7478
</p>
7579

7680
{/* User Wallet Address */}
@@ -84,11 +88,11 @@ export default function Home() {
8488
<div className={`w-2 h-2 rounded-full ${
8589
isConnected ? 'bg-green-500' : isConnecting ? 'bg-yellow-500' : 'bg-gray-400'
8690
}`}></div>
87-
{isConnected ? 'Connected' : isConnecting ? 'Connecting...' : 'Disconnected'}
91+
{isConnected ? 'Connected' : isConnecting ? 'Connecting...' : 'Not Connected'}
8892
</div>
8993
</div>
9094
<p className="text-sm text-gray-700 font-mono">
91-
{formatAddress(walletAddress)}
95+
{walletAddress ? formatAddress(walletAddress) : 'No wallet connected'}
9296
</p>
9397
</div>
9498
</div>
@@ -132,7 +136,7 @@ export default function Home() {
132136

133137
try {
134138
const result = await sdk.actions.addMiniApp();
135-
if (result.added) {
139+
if (result) {
136140
setAddMiniAppMessage("✅ Miniapp added successfully!");
137141
} else {
138142
setAddMiniAppMessage("ℹ️ Miniapp was not added (user declined or already exists)");

0 commit comments

Comments
 (0)