Skip to content

Commit

Permalink
add menu page (#438)
Browse files Browse the repository at this point in the history
* add menu page

* setDelegate page

* rebase
  • Loading branch information
notV4l authored Aug 8, 2024
1 parent b18a085 commit 96a8cbd
Show file tree
Hide file tree
Showing 23 changed files with 1,861 additions and 1,418 deletions.
2 changes: 2 additions & 0 deletions examples/starknet-react-next/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SignMessage } from "components/SignMessage";
import { DojoSpawnAndMove } from "components/DojoSpawnAndMove";
import { DelegateAccount } from "components/DelegateAccount";
import { ColorModeToggle } from "components/ColorModeToggle";
import { Menu } from "components/Menu";

export default function Home() {
return (
Expand All @@ -16,6 +17,7 @@ export default function Home() {
<ColorModeToggle />
</div>
<ConnectWallet />
<Menu />
<DojoSpawnAndMove />
<TransferEth />
<DelegateAccount />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export const DelegateAccount = () => {
setDelegateAddress(delegate?.toString() || "");
setIsDelegateSupported(true);
} catch (e: any) {
console.log(e)
// controller doesnt support delegateAccount, ignore
}
}, [account, cartridgeConnector]);
}, [account, chainId, cartridgeConnector]);

const execute = useCallback(async () => {
if (!account) {
Expand Down Expand Up @@ -75,7 +76,7 @@ export const DelegateAccount = () => {
type="text"
min-width="420px"
value={delegateAddressInput}
onChange={(e) => setDelegateAddressInput(e.target.value)}
onChange={(e:any ) => setDelegateAddressInput(e.target.value)}
/>
<Button onClick={() => execute()} disabled={submitted}>
Set Delegate
Expand Down
30 changes: 30 additions & 0 deletions examples/starknet-react-next/src/components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";

import { useAccount, useDisconnect } from "@starknet-react/core";
import CartridgeConnector from "@cartridge/connector";
import { Button } from "@cartridge/ui-next";

export function Menu() {
const { account, connector } = useAccount();
const { disconnect } = useDisconnect();
const cartridgeConnector = connector as unknown as CartridgeConnector;

const onOpenMenu = async () => {
if (!account) return;
const isConnected = await cartridgeConnector.openMenu();
if (!isConnected) {
disconnect()
}
};

if (!account) {
return null;
}

return (
<div style={{ marginTop: "10px" }}>
<h2>Open Menu</h2>
<Button onClick={onOpenMenu}>Open Menu</Button>
</div>
);
}
Loading

0 comments on commit 96a8cbd

Please sign in to comment.