Skip to content

Commit

Permalink
[frenemies] Signup flow (MystenLabs#7622)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Mysten authored Jan 24, 2023
1 parent c2d5e2c commit 8c60703
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ yarn-error.log*

# misc
*.key
.env
14 changes: 14 additions & 0 deletions dapps/frenemies/public/capy_cowboy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions dapps/frenemies/public/capy_singing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions dapps/frenemies/src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const cardStyles = cva(["rounded-2xl", "shadow-notification"], {
sm: "p-6",
md: "p-8",
lg: "p-10",
xl: 'p-12'
},
},
defaultVariants: {
Expand Down
4 changes: 4 additions & 0 deletions dapps/frenemies/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
import { Root } from "./routes/Root";
import { Home } from "./routes/Home";
import { Connect } from "./routes/Connect";
import { Setup } from "./routes/Setup";

const plausible = Plausible({});
plausible.enableAutoPageviews();
Expand All @@ -30,6 +31,9 @@ const router = createBrowserRouter([
{
path: 'connect',
element: <Connect />
},{
path: 'setup',
element: <Setup />
}
],
},
Expand Down
13 changes: 10 additions & 3 deletions dapps/frenemies/src/network/queries/scorecard.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { getRawObjectParsedUnsafe, ObjectData } from "../rawObject";
import { getRawObjectParsedUnsafe } from "../rawObject";
import { useQuery } from "@tanstack/react-query";
import { Scorecard } from "../types";
import provider from "../provider";
Expand All @@ -18,7 +18,7 @@ const SCORECARD_TYPE = "frenemies::Scorecard";
* We do not guarantee correct behavior if people registered more than once,
* lookup is done with `Array.prototype.find` for the first occurrence.
*/
export function useScorecard(account: string | null) {
export function useScorecard(account?: string | null) {
return useQuery(
["scorecard", account],
async () => {
Expand All @@ -33,7 +33,14 @@ export function useScorecard(account: string | null) {
return null;
}

return getRawObjectParsedUnsafe<Scorecard>(provider, search.objectId, "frenemies::Scorecard");
return getRawObjectParsedUnsafe<Scorecard>(
provider,
search.objectId,
"frenemies::Scorecard"
);
},
{
enabled: !!account,
}
);
}
37 changes: 35 additions & 2 deletions dapps/frenemies/src/routes/Connect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { ConnectButton } from "@mysten/wallet-kit";
import { ConnectButton, useWalletKit } from "@mysten/wallet-kit";
import { useEffect } from "react";
import { useNavigate } from "react-router-dom";
import { Card } from "../components/Card";

export function Connect() {
return <ConnectButton />;
const navigate = useNavigate();
const { currentAccount } = useWalletKit();

useEffect(() => {
if (currentAccount) {
navigate("/setup", { replace: true });
}
}, [currentAccount]);

return (
<div className="max-w-4xl w-full mx-auto text-center">
<Card spacing="xl">
<h1 className="text-steel-darker text-2xl leading-tight font-semibold mb-5">
Welcome to Sui Frenemies game
</h1>
<img src="/capy_cowboy.svg" className="mb-5 h-64 w-64 mx-auto" />
<div className="text-steel-dark uppercase leading-tight mb-1">
Your Objective
</div>
<p className="text-steel-dark text-sm max-w-xs mb-12 mx-auto">
The goal of the game is to stake Sui tokens to move your assigned
Validator to one of three designated positions: Friend (top third),
Neutral (middle third), or Foe (bottom third).
</p>
<ConnectButton
connectText="Connect Wallet to participate"
className="!bg-frenemies !text-white !shadow-notification !leading-none !px-5 !py-3 "
/>
</Card>
</div>
);
}
15 changes: 13 additions & 2 deletions dapps/frenemies/src/routes/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ import { YourScore } from "../components/your-score/YourScore";
import { useScorecard } from "../network/queries/scorecard";
import { formatAddress, formatGoal } from "../utils/format";
import { useWalletKit } from "@mysten/wallet-kit";
import { useNavigate } from "react-router-dom";
import { useEffect } from "react";

/**
* The Home page.
*/
export function Home() {
const navigate = useNavigate();
const { currentAccount } = useWalletKit();
const { data: scorecard } = useScorecard(currentAccount || '');
const { data: scorecard } = useScorecard(currentAccount || "");

useEffect(() => {
if (!currentAccount) {
navigate("/connect");
}
}, [currentAccount]);

// TODO: Render login screen (not registered)
// TODO: Track wallet connection and make sure user is logged in
Expand All @@ -36,7 +45,9 @@ export function Home() {
<Stat label="Your Role">{formatGoal(assignment.goal)}</Stat>
</Card>
<Card spacing="sm">
<Stat label="Assigned Validator">{formatAddress(assignment.validator)}</Stat>
<Stat label="Assigned Validator">
{formatAddress(assignment.validator)}
</Stat>
</Card>
<Card spacing="sm">
<Stat label="Time Remaining">
Expand Down
Loading

0 comments on commit 8c60703

Please sign in to comment.