Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha #181

Merged
merged 7 commits into from
Mar 27, 2024
Merged

Alpha #181

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading