Skip to content

Commit

Permalink
Merge pull request #181 from moonstream-to/alpha
Browse files Browse the repository at this point in the history
Alpha
  • Loading branch information
Anton-Mushnin authored Mar 27, 2024
2 parents 76a6ae2 + 98909db commit 3169b9d
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 36 deletions.
1 change: 1 addition & 0 deletions web/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_HUMBUG_TOKEN=<HUMBUG_TOKEN>;
24 changes: 23 additions & 1 deletion web/src/components/playing/BatterViewMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,25 @@ const BatterViewMobile = ({
if (!commit) {
return Promise.reject(new Error("FulcountPlayerAPI commit doesn't have commit data"));
}
return commitOrRevealSwingFullcountPlayer({ token, commit, isCommit: true });
return commitOrRevealSwingFullcountPlayer({
token,
commit,
isCommit: true,
sessionID: sessionStatus.sessionID,
});
default:
return Promise.reject(new Error(`Unknown or unsupported token source: ${token.source}`));
}
},
{
retryDelay: (attemptIndex) => (attemptIndex < 1 ? 5000 : 10000),
retry: (failureCount, error) => {
console.log(error);
if (failureCount < 6) {
console.log("Will retry in 5, maybe 10 seconds");
}
return failureCount < 6;
},
onSuccess: () => {
setIsCommitted(true);
queryClient.refetchQueries("atBat");
Expand Down Expand Up @@ -95,12 +108,21 @@ const BatterViewMobile = ({
commit: { nonce, vertical, horizontal, actionChoice },
isCommit: false,
token,
sessionID: sessionStatus.sessionID,
});
default:
return Promise.reject(new Error(`Unknown or unsupported token source: ${token.source}`));
}
},
{
retryDelay: (attemptIndex) => (attemptIndex < 1 ? 5000 : 10000),
retry: (failureCount, error) => {
console.log(error);
if (failureCount < 6) {
console.log("Will retry in 5, maybe 10 seconds");
}
return failureCount < 6;
},
onSuccess: () => {
setIsRevealed(true);
queryClient.refetchQueries("atBat");
Expand Down
24 changes: 23 additions & 1 deletion web/src/components/playing/PitcherViewMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,25 @@ const PitcherViewMobile = ({
if (!commit) {
return Promise.reject(new Error("FulcountPlayerAPI commit doesn't have commit data"));
}
return commitOrRevealPitchFullcountPlayer({ token, commit, isCommit: true });
return commitOrRevealPitchFullcountPlayer({
token,
commit,
isCommit: true,
sessionID: sessionStatus.sessionID,
});
default:
return Promise.reject(new Error(`Unknown or unsupported token source: ${token.source}`));
}
},
{
retryDelay: (attemptIndex) => (attemptIndex < 1 ? 5000 : 10000),
retry: (failureCount, error) => {
console.log(error);
if (failureCount < 6) {
console.log("Will retry in 5, maybe 10 seconds");
}
return failureCount < 6;
},
onSuccess: () => {
setIsCommitted(true);
queryClient.refetchQueries("atBat");
Expand Down Expand Up @@ -94,12 +107,21 @@ const PitcherViewMobile = ({
commit: { nonce, vertical, horizontal, actionChoice },
isCommit: false,
token,
sessionID: sessionStatus.sessionID,
});
default:
return Promise.reject(new Error(`Unknown or unsupported token source: ${token.source}`));
}
},
{
retryDelay: (attemptIndex) => (attemptIndex < 1 ? 5000 : 10000),
retry: (failureCount, error) => {
console.log(error);
if (failureCount < 6) {
console.log("Will retry in 5, maybe 10 seconds");
}
return failureCount < 6;
},
onSuccess: () => {
setIsRevealed(true);
queryClient.refetchQueries("atBat");
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/playing/PlayerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ const PlayerView = ({
const handleReveal = async () => {
const localStorageKey = `fullcount.xyz-${contractAddress}-${sessionStatus.sessionID}-${selectedToken?.id}`;
const reveal = getLocalStorageItem(localStorageKey);
revealMutation.mutate(reveal);
if (!revealMutation.isLoading) {
revealMutation.mutate(reveal);
}
};

const handleCommit = async () => {
Expand Down Expand Up @@ -213,7 +215,7 @@ const PlayerView = ({
)}
</button>
)}
{(token.source === "BLBContract" || isRevealFailed) &&
{token.source === "BLBContract" &&
sessionStatus.didBatterCommit &&
sessionStatus.didPitcherCommit &&
!isRevealed && (
Expand Down
1 change: 1 addition & 0 deletions web/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ export const CHAIN_ID = 42170;
export const RPC = "https://nova.arbitrum.io/rpc";
export const blbImage = (idx: number) =>
`https://static.fullcount.xyz/Beer_League_Ballers/p${idx}.png`;
export const HUMBUG_REPORT_VERSION = "0.0.1";
7 changes: 5 additions & 2 deletions web/src/hooks/useLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMutation } from "react-query";
import useUser from "../contexts/UserContext";
import { loginService } from "../services/auth.service";
import useMoonToast from "./useMoonToast";
import { sendReport } from "../utils/humbug";

const useLogin = () => {
const { getUser } = useUser();
Expand All @@ -13,16 +14,18 @@ const useLogin = () => {
error,
data,
} = useMutation(loginService, {
onSuccess: (data: any) => {
onSuccess: (data: any, variables) => {
if (!data) {
return;
}
localStorage.setItem("FULLCOUNT_ACCESS_TOKEN", data.data.id);
sendReport("logged in", variables.username, [`user_token: ${data.data.id}`]);
getUser(data.data.user_id);
},
onError: (error: any) => {
onError: (error: any, variables) => {
console.log(error);
const message = error.response?.data?.detail ?? error.message;
sendReport("Error logging in", `${variables.username} - ${message}`, []);
toast(message, "error");
},
});
Expand Down
11 changes: 9 additions & 2 deletions web/src/hooks/useSignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMutation } from "react-query";
import useMoonToast from "./useMoonToast";
import useUser from "../contexts/UserContext";
import { registerService } from "../services/auth.service";
import { sendReport } from "../utils/humbug";

const useSignUp = () => {
const { getUser } = useUser();
Expand All @@ -14,13 +15,19 @@ const useSignUp = () => {
data,
isSuccess,
} = useMutation(registerService(), {
onSuccess: (response) => {
onSuccess: (response, variables) => {
localStorage.setItem("FULLCOUNT_ACCESS_TOKEN", response.data.id);
sendReport("signed up", `${variables.username} - ${variables.email}`, [
`user_token: ${response.data.id}`,
]);

getUser();
},
onError: (error: any) => {
onError: (error: any, variables) => {
console.log(error);
let message = error.response?.data?.detail ?? error.message;
sendReport("Error signing up", `${variables.username} - ${variables.email} - ${message}`, []);

if (error.response?.status === 409) {
message = "username or email already exists";
}
Expand Down
Loading

0 comments on commit 3169b9d

Please sign in to comment.