From 9698c82662c0bea91cb3d3475d6596179a975802 Mon Sep 17 00:00:00 2001 From: "yongen.loong" Date: Thu, 14 Nov 2024 19:18:18 +0800 Subject: [PATCH] fix: captcha --- app/layout.tsx | 8 +- components/build-deploy-panel.tsx | 51 ++++-- lib/env.ts | 11 -- package-lock.json | 277 +++++++++++++++++++++++++++++- package.json | 1 + 5 files changed, 315 insertions(+), 33 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index 0f5cc7d..772c37a 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -7,7 +7,8 @@ import clsx from "clsx"; import { GoogleAnalytics } from "@next/third-parties/google"; import { getGoogleAnalyticsTag } from "@/lib/env"; import Providers from "@/components/providers"; -import { Toaster } from "@/components/ui/toaster" +import { Toaster } from "@/components/ui/toaster"; +import { PublicEnvScript } from 'next-runtime-env'; const font = Poppins({ weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"], @@ -25,7 +26,10 @@ export default function RootLayout({ children }: PropsWithChildren) { return ( - + + + +
diff --git a/components/build-deploy-panel.tsx b/components/build-deploy-panel.tsx index 97c5370..9712fb7 100644 --- a/components/build-deploy-panel.tsx +++ b/components/build-deploy-panel.tsx @@ -24,11 +24,11 @@ import { AuditType } from "@/data/audit"; import { Dialog, DialogContent, - DialogDescription, - DialogHeader, + DialogPortal } from "@/components/ui/dialog"; import { useWallet } from "@/data/wallet"; -import { getFaucetUrl, getGoogleCaptchaSitekey } from "@/lib/env"; +import { env } from 'next-runtime-env'; +import { DialogOverlay } from "@radix-ui/react-dialog"; export function BuildDeployPanel() { const commands = useCliCommands(); @@ -45,8 +45,8 @@ export function BuildDeployPanel() { const id = useWorkspaceId(); const recaptchaRef = useRef(null); const wallet = useWallet(); - const faucetUrl = getFaucetUrl(); - const captchaSitekey = getGoogleCaptchaSitekey(); + const faucetUrl = env('NEXT_PUBLIC_FAUCET_API_URL'); + const captchaSitekey = env('NEXT_PUBLIC_GOOGLE_CAPTCHA_SITEKEY'); const { data: isDeployable } = useSWR( id ? `deployable-${id}` : undefined, @@ -218,16 +218,29 @@ export function BuildDeployPanel() { }, ]; + const checkBalanceRecursive = async (type: "audit" | "deploy" | "") => { + if (type === "") return false; + let hasBalance = await isBalanceAvailable(type); + if (!hasBalance) { + // wait 1s before checking again + await new Promise((resolve) => setTimeout(resolve, 1000)); + return await checkBalanceRecursive(type); + } + return true; + } + const handleCaptchaSuccess = async (captchaToken:string) => { try { if (captchaType === "deploy") { setIsDeploying(true); const res = await getTokenBalance(captchaToken); + await checkBalanceRecursive(checkingBalanceType); setCheckingBalanceType(""); res && (await commands.deploy()); } else if (captchaType === "audit") { setIsAuditing(true); const res = await getTokenBalance(captchaToken); + await checkBalanceRecursive(checkingBalanceType); setCheckingBalanceType(""); res && (await commands.audit(AuditType.DEFAULT)); } @@ -235,6 +248,7 @@ export function BuildDeployPanel() { } finally { setIsDeploying(false); setIsAuditing(false); + closeRecaptcha(); } }; @@ -268,23 +282,22 @@ export function BuildDeployPanel() { ))} + - - - -
- -
-
-
-
+ + + +
+ +
+
+
diff --git a/lib/env.ts b/lib/env.ts index 5ad4ea8..cb53ad4 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -24,15 +24,4 @@ export function getGitHubToken() { export function getSolidityEnabled() { return getEnv("SOLIDITY_ENABLED") === "true"; -} - -export function getFaucetUrl() { - // https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser:~:text=Note%20that%20dynamic%20lookups%20will%20not%20be%20inlined%2C%20such%20as%3A - const varName = "NEXT_PUBLIC_FAUCET_API_URL"; - return process.env[varName]; -} - -export function getGoogleCaptchaSitekey() { - const varName = "NEXT_PUBLIC_GOOGLE_CAPTCHA_SITEKEY"; - return process.env[varName]; } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6725930..169d6a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,6 +59,7 @@ "lucide-react": "^0.408.0", "next": "15.0.3", "next-mdx-remote": "^5.0.0", + "next-runtime-env": "^3.2.2", "next-themes": "^0.3.0", "octokit": "^4.0.2", "parse-github-url": "^1.0.3", @@ -2085,6 +2086,22 @@ "node": ">= 10" } }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.18.tgz", + "integrity": "sha512-Ynxuk4ZgIpdcN7d16ivJdjsDG1+3hTvK24Pp8DiDmIa2+A4CfhJSEHHVndCHok6rnLUzAZD+/UOKESQgTsAZGg==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@next/swc-win32-x64-msvc": { "version": "15.0.3", "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.0.3.tgz", @@ -8771,7 +8788,6 @@ "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", - "dev": true, "license": "ISC" }, "node_modules/graphemer": { @@ -11105,6 +11121,265 @@ "react": ">=16" } }, + "node_modules/next-runtime-env": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/next-runtime-env/-/next-runtime-env-3.2.2.tgz", + "integrity": "sha512-S5S6NxIf3XeaVc9fLBN2L5Jzu+6dLYCXeOaPQa1RzKRYlG2BBayxXOj6A4VsciocyNkJMazW1VAibtbb1/ZjAw==", + "license": "MIT", + "dependencies": { + "next": "^14", + "react": "^18" + }, + "peerDependencies": { + "next": "^14", + "react": "^18" + } + }, + "node_modules/next-runtime-env/node_modules/@next/env": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.18.tgz", + "integrity": "sha512-2vWLOUwIPgoqMJKG6dt35fVXVhgM09tw4tK3/Q34GFXDrfiHlG7iS33VA4ggnjWxjiz9KV5xzfsQzJX6vGAekA==", + "license": "MIT" + }, + "node_modules/next-runtime-env/node_modules/@next/swc-darwin-arm64": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.18.tgz", + "integrity": "sha512-tOBlDHCjGdyLf0ube/rDUs6VtwNOajaWV+5FV/ajPgrvHeisllEdymY/oDgv2cx561+gJksfMUtqf8crug7sbA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-darwin-x64": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.18.tgz", + "integrity": "sha512-uJCEjutt5VeJ30jjrHV1VIHCsbMYnEqytQgvREx+DjURd/fmKy15NaVK4aR/u98S1LGTnjq35lRTnRyygglxoA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.18.tgz", + "integrity": "sha512-IL6rU8vnBB+BAm6YSWZewc+qvdL1EaA+VhLQ6tlUc0xp+kkdxQrVqAnh8Zek1ccKHlTDFRyAft0e60gteYmQ4A==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.18.tgz", + "integrity": "sha512-RCaENbIZqKKqTlL8KNd+AZV/yAdCsovblOpYFp0OJ7ZxgLNbV5w23CUU1G5On+0fgafrsGcW+GdMKdFjaRwyYA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.18.tgz", + "integrity": "sha512-3kmv8DlyhPRCEBM1Vavn8NjyXtMeQ49ID0Olr/Sut7pgzaQTo4h01S7Z8YNE0VtbowyuAL26ibcz0ka6xCTH5g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.18.tgz", + "integrity": "sha512-mliTfa8seVSpTbVEcKEXGjC18+TDII8ykW4a36au97spm9XMPqQTpdGPNBJ9RySSFw9/hLuaCMByluQIAnkzlw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.18.tgz", + "integrity": "sha512-J5g0UFPbAjKYmqS3Cy7l2fetFmWMY9Oao32eUsBPYohts26BdrMUyfCJnZFQkX9npYaHNDOWqZ6uV9hSDPw9NA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.18.tgz", + "integrity": "sha512-dtRGMhiU9TN5nyhwzce+7c/4CCeykYS+ipY/4mIrGzJ71+7zNo55ZxCB7cAVuNqdwtYniFNR2c9OFQ6UdFIMcg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/next-runtime-env/node_modules/@swc/helpers": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz", + "integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==", + "license": "Apache-2.0", + "dependencies": { + "@swc/counter": "^0.1.3", + "tslib": "^2.4.0" + } + }, + "node_modules/next-runtime-env/node_modules/next": { + "version": "14.2.18", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.18.tgz", + "integrity": "sha512-H9qbjDuGivUDEnK6wa+p2XKO+iMzgVgyr9Zp/4Iv29lKa+DYaxJGjOeEA+5VOvJh/M7HLiskehInSa0cWxVXUw==", + "license": "MIT", + "dependencies": { + "@next/env": "14.2.18", + "@swc/helpers": "0.5.5", + "busboy": "1.6.0", + "caniuse-lite": "^1.0.30001579", + "graceful-fs": "^4.2.11", + "postcss": "8.4.31", + "styled-jsx": "5.1.1" + }, + "bin": { + "next": "dist/bin/next" + }, + "engines": { + "node": ">=18.17.0" + }, + "optionalDependencies": { + "@next/swc-darwin-arm64": "14.2.18", + "@next/swc-darwin-x64": "14.2.18", + "@next/swc-linux-arm64-gnu": "14.2.18", + "@next/swc-linux-arm64-musl": "14.2.18", + "@next/swc-linux-x64-gnu": "14.2.18", + "@next/swc-linux-x64-musl": "14.2.18", + "@next/swc-win32-arm64-msvc": "14.2.18", + "@next/swc-win32-ia32-msvc": "14.2.18", + "@next/swc-win32-x64-msvc": "14.2.18" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.1.0", + "@playwright/test": "^1.41.2", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "sass": "^1.3.0" + }, + "peerDependenciesMeta": { + "@opentelemetry/api": { + "optional": true + }, + "@playwright/test": { + "optional": true + }, + "sass": { + "optional": true + } + } + }, + "node_modules/next-runtime-env/node_modules/postcss": { + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.6", + "picocolors": "^1.0.0", + "source-map-js": "^1.0.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/next-runtime-env/node_modules/styled-jsx": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/styled-jsx/-/styled-jsx-5.1.1.tgz", + "integrity": "sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==", + "license": "MIT", + "dependencies": { + "client-only": "0.0.1" + }, + "engines": { + "node": ">= 12.0.0" + }, + "peerDependencies": { + "react": ">= 16.8.0 || 17.x.x || ^18.0.0-0" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "babel-plugin-macros": { + "optional": true + } + } + }, "node_modules/next-themes": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.3.0.tgz", diff --git a/package.json b/package.json index a12f8dd..6187c45 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "lucide-react": "^0.408.0", "next": "15.0.3", "next-mdx-remote": "^5.0.0", + "next-runtime-env": "^3.2.2", "next-themes": "^0.3.0", "octokit": "^4.0.2", "parse-github-url": "^1.0.3",