forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[frenemies] Autoconnect and leaderboard (MystenLabs#7656)
- Loading branch information
1 parent
090252c
commit 68433cd
Showing
7 changed files
with
103 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Tab } from "@headlessui/react"; | ||
import { ReactNode, useState } from "react"; | ||
import { Card } from "../Card"; | ||
import { Leaderboard } from "../leaderboard/Leaderboard"; | ||
import { YourScore } from "../your-score/YourScore"; | ||
|
||
function TabItem({ children }: { children: ReactNode }) { | ||
return ( | ||
<Tab className="font-semibold leading-tight px-5 py-2 rounded-full ui-selected:bg-white ui-selected:text-steel-darker ui-not-selected:bg-transparent ui-not-selected:text-white"> | ||
{children} | ||
</Tab> | ||
); | ||
} | ||
|
||
export function Scoreboard() { | ||
const [selectedIndex, setSelectedIndex] = useState(0); | ||
|
||
return ( | ||
<Card variant={selectedIndex === 0 ? "score" : "leaderboard"}> | ||
<Tab.Group selectedIndex={selectedIndex} onChange={setSelectedIndex}> | ||
<Tab.List className="inline-flex space-x-1 rounded-full bg-white/[15%]"> | ||
<TabItem>You</TabItem> | ||
<TabItem>Leaderboard</TabItem> | ||
</Tab.List> | ||
<Tab.Panels> | ||
<Tab.Panel> | ||
<YourScore /> | ||
</Tab.Panel> | ||
<Tab.Panel> | ||
<Leaderboard /> | ||
</Tab.Panel> | ||
</Tab.Panels> | ||
</Tab.Group> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useWalletKit } from "@mysten/wallet-kit"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
const AUTOCONNECT_KEY = "frenemies:wallet"; | ||
|
||
export function useAutoconnect() { | ||
const { wallets, currentWallet, connect } = useWalletKit(); | ||
const previousWallet = useRef(currentWallet); | ||
|
||
useEffect(() => { | ||
const storedWallet = localStorage.getItem(AUTOCONNECT_KEY); | ||
// Initial load: | ||
if (!currentWallet && !previousWallet.current && storedWallet) { | ||
connect(storedWallet); | ||
} | ||
// Disconnect: | ||
if (!currentWallet && previousWallet.current) { | ||
localStorage.removeItem(AUTOCONNECT_KEY); | ||
} | ||
// Connect: | ||
if (currentWallet) { | ||
localStorage.setItem(AUTOCONNECT_KEY, currentWallet.name); | ||
} | ||
|
||
previousWallet.current = currentWallet; | ||
}, [wallets, currentWallet]); | ||
} |