Skip to content

Commit

Permalink
Merge pull request #219 from WTFAcademy/dev
Browse files Browse the repository at this point in the history
fix: Optimized the process of sign query failure.
  • Loading branch information
AmazingAng authored Jul 26, 2024
2 parents 6509174 + eee9609 commit 40efd86
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 41 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 0 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 23 additions & 19 deletions src/pages/certificate/_StepMint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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]);

Expand All @@ -109,7 +113,7 @@ const StepMint = props => {
{active && loading && <Spinner loading className="w-4 h-4" />}
{active && error && !loading && (
<RefreshCwIcon
onClick={startMint}
onClick={querySign}
className="w-4 h-4 cursor-pointer hover:rotate-[90deg] transition-transform duration-300"
/>
)}
Expand Down

0 comments on commit 40efd86

Please sign in to comment.