-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Add Farcaster miniapp support for identity verification flow #10 #14
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
25ee077
42fc37e
9557dce
42e08a9
64d56a8
3323d82
8bff2fe
f3940b2
53564da
60eb1cb
c105e1b
e10b584
8edaca1
c34de25
f6889fd
8616d89
36dfa32
5ed0e06
5bdab21
cd6d40f
f1e9b8d
b7de6cb
304c15a
9841794
d19d211
158465a
4060809
e6ba4d0
8cf55a7
c1486dc
04ff59c
3dd1832
59484bc
f620a1c
c38476f
20d0905
9a9dbbc
7a7a921
994b4f3
75a9b45
6377bf0
359e2c2
4ad2886
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import { config } from "@tamagui/config/v3" | |
| import { useLocation } from "react-router-dom" | ||
| import { useAccount } from "wagmi" | ||
| import { useIdentitySDK } from "@goodsdks/react-hooks" | ||
| import { handleVerificationResponse, isInFarcasterMiniApp, isInFarcasterMiniAppSync } from "@goodsdks/citizen-sdk" | ||
|
|
||
| import { VerifyButton } from "./components/VerifyButton" | ||
| import { IdentityCard } from "./components/IdentityCard" | ||
|
|
@@ -31,6 +32,7 @@ const App: React.FC = () => { | |
| const [loadingWhitelist, setLoadingWhitelist] = useState<boolean | undefined>( | ||
| undefined, | ||
| ) | ||
| const [isFarcasterMode, setIsFarcasterMode] = useState<boolean>(false) | ||
|
|
||
| const location = useLocation() | ||
| const { address, isConnected } = useAccount() | ||
|
|
@@ -40,13 +42,33 @@ const App: React.FC = () => { | |
| const { sdk: identitySDK } = useIdentitySDK("development") | ||
|
|
||
| useEffect(() => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Lewis, I don't fully understand this, mind explaining deeper please?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean I should revert the file to how it was initially? and remove every code I added relating to the forecaster support? |
||
| const urlParams = new URLSearchParams(location.search) | ||
| const verified = urlParams.get("verified") | ||
|
|
||
| if (verified === "true") { | ||
| // Check if running in Farcaster miniapp mode (async) | ||
| const checkFarcasterMode = async () => { | ||
| try { | ||
| const isFarcaster = await isInFarcasterMiniApp() | ||
| setIsFarcasterMode(isFarcaster) | ||
| } catch (error) { | ||
| // Fallback to sync version if async fails | ||
| console.warn('Async Farcaster detection failed, using sync fallback:', error) | ||
| setIsFarcasterMode(isInFarcasterMiniAppSync()) | ||
| } | ||
| } | ||
|
|
||
| checkFarcasterMode() | ||
|
|
||
| // Use the new verification response handler | ||
| const verificationResult = handleVerificationResponse() | ||
|
|
||
| if (verificationResult.isVerified) { | ||
| setIsVerified(true) | ||
| // Clean up URL parameters | ||
| window.history.replaceState({}, document.title, window.location.pathname) | ||
| } | ||
|
|
||
| // Log additional verification parameters for debugging | ||
| if (verificationResult.params.size > 0) { | ||
| console.log("Verification response parameters:", Object.fromEntries(verificationResult.params)) | ||
| } | ||
| }, [location.search]) | ||
|
|
||
| //ref: https://github.com/wevm/wagmi/discussions/1806#discussioncomment-12130996 | ||
|
|
@@ -108,6 +130,22 @@ const App: React.FC = () => { | |
| > | ||
| GoodDollar Identity Verification | ||
| </Text> | ||
|
|
||
| {isFarcasterMode && ( | ||
| <YStack | ||
| padding="$2" | ||
| backgroundColor="#E3F2FD" | ||
| borderRadius="$3" | ||
| borderWidth={1} | ||
| borderColor="#2196F3" | ||
| marginVertical={8} | ||
| > | ||
| <Text fontSize={12} color="#1976D2" textAlign="center" fontWeight="bold"> | ||
| Farcaster MiniApp Mode Detected | ||
| </Text> | ||
|
|
||
| </YStack> | ||
| )} | ||
|
|
||
| {/* Disclaimer Section */} | ||
| <YStack | ||
|
|
@@ -263,4 +301,4 @@ const App: React.FC = () => { | |
| ) | ||
| } | ||
|
|
||
| export default App | ||
| export default App | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ import { useIdentitySDK } from "@goodsdks/react-hooks" | |
| import { useAccount } from "wagmi" | ||
|
|
||
| interface VerifyButtonProps { | ||
| onVerificationSuccess: () => void | ||
| onVerificationSuccess?: () => void | ||
| } | ||
|
|
||
| export const VerifyButton: React.FC<VerifyButtonProps> = ({ | ||
|
|
@@ -17,13 +17,13 @@ export const VerifyButton: React.FC<VerifyButtonProps> = ({ | |
| if (!identitySDK || !address) return | ||
|
|
||
| try { | ||
| const fvLink = await identitySDK.generateFVLink( | ||
| // Use the SDK's navigation method which now uses the shared utility | ||
| await identitySDK.navigateToFaceVerification( | ||
| false, | ||
| window.location.href, | ||
| 42220, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this removed |
||
| 42220 | ||
| ) | ||
|
|
||
| window.location.href = fvLink | ||
| onVerificationSuccess?.() | ||
| } catch (error) { | ||
| console.error("Verification failed:", error) | ||
| // Handle error (e.g., show toast) | ||
|
|
@@ -42,4 +42,4 @@ export const VerifyButton: React.FC<VerifyButtonProps> = ({ | |
| Verify Me | ||
| </Button> | ||
| ) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { builtinModules } from "module" | ||
L03TJ3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Generate list of Node.js built-in modules for external configuration | ||
| * Includes both standard names and node: prefixed versions | ||
| */ | ||
| export function getNodeBuiltins(): string[] { | ||
| return [ | ||
| ...builtinModules, | ||
| ...builtinModules.map((m) => `node:${m}`) | ||
| ] | ||
| } | ||
|
|
||
| /** | ||
| * Generate globals mapping for Node.js built-ins | ||
| * Maps both `foo` and `node:foo` to global `foo` | ||
| */ | ||
| export function getNodeBuiltinGlobals(): Record<string, string> { | ||
| const builtins = getNodeBuiltins() | ||
| return builtins.reduce((acc, name) => { | ||
| // Strip the `node:` prefix for the global key if present | ||
| const key = name.startsWith('node:') ? name.slice(5) : name | ||
| // Map both `foo` and `node:foo` → global `foo` | ||
| acc[name] = key | ||
| return acc | ||
| }, {} as Record<string, string>) | ||
| } | ||
|
|
||
| /** | ||
| * Common external dependencies for browser builds | ||
| */ | ||
| export const COMMON_EXTERNALS = [ | ||
| "@goodsdks/citizen-sdk", | ||
| "viem", | ||
| ...getNodeBuiltins() | ||
| ] | ||
|
|
||
| /** | ||
| * Regex pattern to match all node: imports | ||
| */ | ||
| export const NODE_MODULES_REGEX = /^node:/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "name": "@repo/build-config", | ||
| "version": "0.0.0", | ||
| "type": "module", | ||
| "private": true, | ||
| "main": "./index.ts", | ||
| "exports": { | ||
| ".": "./index.ts" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.0.0", | ||
| "typescript": "^5.0.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| export * from "./sdks" | ||
| export * from "./constants" | ||
| export * from "./utils/auth" | ||
| export * from "./utils/farcaster-navigation" |
L03TJ3 marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be devdep/peerdep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vortex-hue this is not done