Skip to content

Commit

Permalink
feat: display faucet error message
Browse files Browse the repository at this point in the history
  • Loading branch information
He1DAr committed Oct 21, 2023
1 parent 47e1fd0 commit aa37059
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/sandbox/faucet/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ import { useMutation } from '@tanstack/react-query';

import { useUser } from '../hooks/useUser';

function getErrorMessage(error: any) {
if (!error) return '';
const defaultErrorMessage = 'Something went wrong, please try again later.';
if (!!error?.message) {
return error.message;
}
if (!!error?.status) {
switch (error.status) {
case 429:
return 'Too many requests, please try again later.';
default:
return defaultErrorMessage;
}
} else {
return defaultErrorMessage;
}
}

const Faucet: NextPage = () => {
const { faucetsApi } = useApi();
const { stxAddress } = useUser();
Expand All @@ -24,7 +42,7 @@ const Faucet: NextPage = () => {
} = useMutation((staking?: boolean) =>
faucetsApi.runFaucetStx({ address: stxAddress, ...(staking ? { staking: true } : {}) })
);
const errorMessage = isError && error instanceof Error ? error.message : '';
const errorMessage = getErrorMessage(error);
const handleStackingRequest = () => {
if (stackingIndex <= 3) {
setIndex(i => ++i);
Expand Down

0 comments on commit aa37059

Please sign in to comment.