From eee96093bc8bf054dfa9b59ac1a1e35e37b65481 Mon Sep 17 00:00:00 2001 From: GlacierLuo <1090490148@qq.com> Date: Thu, 25 Jul 2024 20:43:26 +0800 Subject: [PATCH] fix: Optimized the process of sign query failure. --- package.json | 1 - pnpm-lock.yaml | 21 --------------- src/pages/certificate/_StepMint.tsx | 42 ++++++++++++++++------------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index cb68d44f..cea53afd 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "monaco-editor": "^0.44.0", "monaco-markdown": "^0.0.12", "monaco-themes": "^0.4.4", - "p-retry": "^6.2.0", "prism-react-renderer": "^1.3.5", "querystring": "^0.2.1", "react": "^17.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d72f7a21..76162d90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -137,9 +137,6 @@ dependencies: monaco-themes: specifier: ^0.4.4 version: 0.4.4 - p-retry: - specifier: ^6.2.0 - version: 6.2.0 prism-react-renderer: specifier: ^1.3.5 version: 1.3.5(react@17.0.2) @@ -6568,10 +6565,6 @@ packages: resolution: {integrity: sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==} dev: false - /@types/retry@0.12.2: - resolution: {integrity: sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow==} - dev: false - /@types/sax@1.2.7: resolution: {integrity: sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==} dependencies: @@ -11998,11 +11991,6 @@ packages: engines: {node: '>= 0.4'} dev: true - /is-network-error@1.1.0: - resolution: {integrity: sha512-tUdRRAnhT+OtCZR/LxZelH/C7QtjtFrTu5tXCA8pl55eTUElUHT+GPYV8MBMBvea/j+NxQqVt3LbWMRir7Gx9g==} - engines: {node: '>=16'} - dev: false - /is-npm@5.0.0: resolution: {integrity: sha512-WW/rQLOazUq+ST/bCAVBp/2oMERWLsR7OrKyt052dNDk4DHcDE0/7QSXITlmi+VBcV13DfIbysG3tZJm5RfdBA==} engines: {node: '>=10'} @@ -13958,15 +13946,6 @@ packages: retry: 0.13.1 dev: false - /p-retry@6.2.0: - resolution: {integrity: sha512-JA6nkq6hKyWLLasXQXUrO4z8BUZGUt/LjlJxx8Gb2+2ntodU/SS63YZ8b0LUTbQ8ZB9iwOfhEPhg4ykKnn2KsA==} - engines: {node: '>=16.17'} - dependencies: - '@types/retry': 0.12.2 - is-network-error: 1.1.0 - retry: 0.13.1 - dev: false - /p-try@2.2.0: resolution: {integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==} engines: {node: '>=6'} diff --git a/src/pages/certificate/_StepMint.tsx b/src/pages/certificate/_StepMint.tsx index 0a96d361..daa6ad5b 100644 --- a/src/pages/certificate/_StepMint.tsx +++ b/src/pages/certificate/_StepMint.tsx @@ -8,7 +8,6 @@ import StepCard from "@site/src/components/StepCard"; import { ArrowRightCircleIcon, RefreshCwIcon, Loader } from "lucide-react"; import { Input } from "@site/src/components/ui/Input"; import Spinner from "@site/src/components/ui/Spinner"; -import pRetry from "p-retry"; const StepMint = props => { const { next, info } = props; @@ -57,6 +56,27 @@ const StepMint = props => { } }; + const querySign = async () => { + setError(false); + try { + const nonce = await getNonce(); + const mintInfoRes = await getMintInfoByCourse( + info.courseId, + nonce.toNumber(), + ); + if (mintInfoRes?.code !== 0) { + setError(true); + setErrorMessage("获取mint签名失败,请重试!"); + return; + } + console.log(mintInfoRes.data); + setMintInfo(mintInfoRes.data); + } catch (e) { + setError(true); + setErrorMessage("获取mint签名失败,请重试!"); + } + }; + useEffect(() => { // TODO: SET MINIMUM DONATION AMOUNT if (mintInfo && donationAmount >= mintInfo.mint_price) return; @@ -70,23 +90,7 @@ const StepMint = props => { useEffect(() => { if (active) { - pRetry( - async () => { - const nonce = await getNonce(); - const mintInfoRes = await getMintInfoByCourse( - info.courseId, - nonce.toNumber(), - ); - if (mintInfoRes?.code !== 0) { - setError(true); - setErrorMessage("获取mint签名失败"); - return; - } - console.log(mintInfoRes.data); - setMintInfo(mintInfoRes.data); - }, - { retries: 5 }, - ); + querySign(); } }, [active]); @@ -109,7 +113,7 @@ const StepMint = props => { {active && loading && } {active && error && !loading && ( )}