Skip to content

Commit

Permalink
with predeployed connector
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Mar 26, 2024
1 parent f01a6b7 commit 4e13166
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 43 deletions.
2 changes: 1 addition & 1 deletion scripts/default_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export GAME_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | sel

export PAPER_MOCK_ADDRESS=$(cat ./target/dev/manifest.json | jq -r '.contracts[] | select(.name == "rollyourown::_mocks::paper_mock::paper_mock" ).address')

export TREASURY_ADDRESS=$PAPER_MOCK_ADDRESS;
export TREASURY_ADDRESS="0xe29882a1fcba1e7e10cad46212257fea5c752a4f9b1b1ec683c503a2cf5c8a";

echo "---------------------------------------------------------------------------"
echo profile : $PROFILE
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ProfileLink } from "../pages/profile/Profile";
import { CashIndicator, DayIndicator, HealthIndicator } from "../player";
import { Burners } from "../wallet/Burners";
import { ChainSelector } from "../wallet/ChainSelector";
import { Predeployed } from "../wallet/Predeployed";

interface HeaderProps {
back?: boolean;
Expand Down Expand Up @@ -48,6 +49,7 @@ export const Header = observer(({ back }: HeaderProps) => {
<HStack gap={3} flex="1" /*justify={["left", "right"]}*/>
<Connect />
<Burners />
<Predeployed />
<ChainSelector canChange={!gameId} />
{/* {!game && (
<>
Expand Down
7 changes: 7 additions & 0 deletions web/src/components/wallet/Burners.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { useDojoContext } from "@/dojo/hooks";
import { Button, Menu, MenuButton, MenuList } from "@chakra-ui/react";
import { useAccount, useConnect } from "@starknet-react/core";
import { Wallet } from "../icons/archive";
import { BurnerManagerUi } from "./ui/BurnerManagerUi";

export const Burners = () => {
const { burnerManager } = useDojoContext();
const { connector } = useConnect();
const { account } = useAccount();


if (!burnerManager) return null;
if (!account) return null;
if (!connector) return null;
if (connector?.id !== "dojoburner") return null;
return (
<Menu>
<MenuButton as={Button} variant="pixelated" h="48px" /*rightIcon={<Arrow direction='down' />}*/>
Expand Down
11 changes: 6 additions & 5 deletions web/src/components/wallet/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const frenlyAddress = (address: string) => {

export const Connect = ({ ...props }) => {
const { account, address, status } = useAccount();

const { connect, connectors, connector } = useConnect();
const { disconnect } = useDisconnect();

Expand Down Expand Up @@ -196,13 +195,15 @@ const ConnectModal = ({
<VStack w="full">
{connectors.map((connector) => {
const isBurner = connector.id === "dojoburner";
if (isBurner && !isKatana) {
// burner not on katana
const isPredeployed = connector.id === "dojopredeployed";

if (!isKatana && (isBurner || isPredeployed)) {
// burner or predeployed not on katana
return null;
}

if (!isBurner && isKatana) {
// not burner on katana
if (isKatana && !(isBurner || isPredeployed )) {
// not burner or predeployed on katana
return null;
}

Expand Down
26 changes: 26 additions & 0 deletions web/src/components/wallet/Predeployed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useDojoContext } from "@/dojo/hooks";
import { Button, Menu, MenuButton, MenuList } from "@chakra-ui/react";
import { useAccount, useConnect } from "@starknet-react/core";
import { Wallet } from "../icons/archive";
import { PredeployedManagerUi } from "./ui/PredeployedManagerUi";

export const Predeployed = () => {
const { predeployedManager } = useDojoContext();
const { connector, isConnected } = useConnect();
const { account } = useAccount();

if (!predeployedManager) return null;
if (!account) return null;
if (!connector) return null;
if (connector?.id !== "dojopredeployed") return null;
return (
<Menu>
<MenuButton as={Button} variant="pixelated" h="48px" /*rightIcon={<Arrow direction='down' />}*/>
<Wallet />
</MenuButton>
<MenuList>
<PredeployedManagerUi predeployedManager={predeployedManager} />
</MenuList>
</Menu>
);
};
10 changes: 6 additions & 4 deletions web/src/components/wallet/ui/BurnerManagerUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ export const BurnerManagerUi = observer(({ burnerManager }: { burnerManager?: Bu
burnerManager.delete(burner.address);
setRefresher(!refresher);

playSound(Sounds.Magnum357)
playSound(Sounds.Magnum357);

// force connect active wallet
disconnect();
connect({ connector });
// force connect active wallet
disconnect();
connect({ connector });
};

if (!burnerManager) return null;
if (!connector) return null;
if (connector?.id !== "dojoburner") return null;

return (
<VStack w="full" p={3}>
Expand Down
70 changes: 70 additions & 0 deletions web/src/components/wallet/ui/PredeployedManagerUi.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { HStack, List, ListItem, Text, VStack } from "@chakra-ui/react";
import { Predeployed, PredeployedManager } from "@dojoengine/create-burner";
import { useConnect, useDisconnect } from "@starknet-react/core";
import { observer } from "mobx-react-lite";
import { useEffect, useState } from "react";
import { frenlyAddress } from "../Connect";

export const PredeployedManagerUi = observer(({ predeployedManager }: { predeployedManager?: PredeployedManager }) => {
const { connect, connector } = useConnect();
const { disconnect } = useDisconnect();

const [isDeploying, setIsDeploying] = useState(false);
const [refresher, setRefresher] = useState(false);
const [predeployed, setPredeployed] = useState<Predeployed[]>([]);

useEffect(() => {
if (!predeployedManager) return;
const predeployed = predeployedManager.list();
setPredeployed(predeployed);
}, [predeployedManager, predeployedManager?.chainId, refresher]);

const onSelect = (burner: Predeployed) => {
if (!predeployedManager) return;
predeployedManager.select(burner.address);
setRefresher(!refresher);

// force connect active wallet
disconnect();
connect({ connector });
};


if (!predeployedManager) return null;
if( !connector ) return null;
if( connector && connector?.id !== "dojopredeployed") return null;

return (
<VStack w="full" p={3}>
<>
{predeployed.length === 0 && <Text>No predeployed!</Text>}
{predeployed.length > 0 && (
<>
<List w="full">
{predeployed.map((predeployed: Predeployed, idx: number) => {
return (
<ListItem
key={idx}
w="full"
borderBottom="solid 2px"
borderBottomColor="neon.700"
py={1}
mb={1}
_last={{ borderBottom: 0 }}
>
<HStack w="full" color={predeployed.active ? "yellow.400" : "neon.400"} justifyContent="space-between">
<Text textTransform="uppercase" cursor="pointer" onClick={() => onSelect(predeployed)}>
{frenlyAddress(predeployed.address)} ({predeployed.name})
</Text>
</HStack>
</ListItem>
);
})}
</List>
</>
)}

</>
</VStack>
);
});
43 changes: 23 additions & 20 deletions web/src/dojo/context/DojoContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { BurnerManager, DojoBurnerStarknetWindowObject } from "@dojoengine/create-burner";
import { ReactNode, createContext, useContext, useEffect, useMemo, useState } from "react";
import {
BurnerManager,
PredeployedManager,
useBurnerWindowObject,
usePredeployedWindowObject
} from "@dojoengine/create-burner";
import { ReactNode, createContext, useContext, useEffect, useMemo } from "react";
import { QueryClientProvider } from "react-query";
import { Account, AccountInterface } from "starknet";
import { DojoChainsResult, useDojoChains } from "../hooks/useDojoChains";
Expand All @@ -13,6 +18,7 @@ interface DojoContextType {
clients: DojoClientsResult;
masterAccount?: AccountInterface;
burnerManager?: BurnerManager;
predeployedManager?: PredeployedManager;
configStore: ConfigStoreClass;
gameStore: GameStoreClass;
}
Expand All @@ -29,7 +35,6 @@ export const DojoContextProvider = ({
const currentValue = useContext(DojoContext);
if (currentValue) throw new Error("DojoProvider can only be used once");

const [snWindowObjectInitialized, setSnWindowObjectInitialized] = useState(false);

const defaultChain =
process.env.NODE_ENV === "production" ? dojoContextConfig.KATANA_SLOT_420 : dojoContextConfig.KATANA;
Expand All @@ -56,22 +61,18 @@ export const DojoContextProvider = ({
});
}, [masterAccount, selectedChain.accountClassHash, rpcProvider]);

useEffect(() => {
const init_async = async () => {
if (window.starknet_dojoburner && burnerManager) {
try {
// initialize burnerManager
await burnerManager.init();
// setBurnerManager
(window.starknet_dojoburner as DojoBurnerStarknetWindowObject).setBurnerManager(burnerManager);
} catch (e: any) {
console.log(e);
}
}
setSnWindowObjectInitialized(true);
};
init_async();
}, [burnerManager]);
const predeployedManager = useMemo(() => {
if (!selectedChain.predeployedAccounts || selectedChain.predeployedAccounts.length === 0) return undefined;
// console.log("new BurnerManager");

return new PredeployedManager({
rpcProvider: rpcProvider,
predeployedAccounts: selectedChain.predeployedAccounts,
});
}, [rpcProvider, selectedChain.predeployedAccounts]);

const { isInitialized: burnerSWOInitialized} = useBurnerWindowObject(burnerManager);
const { isInitialized: predeployedSWOInitialized} = usePredeployedWindowObject(predeployedManager);

const configStore = useMemo(() => {
return new ConfigStoreClass({
Expand All @@ -93,7 +94,8 @@ export const DojoContextProvider = ({
configStore.init();
}, [configStore]);

if (!snWindowObjectInitialized) return null;

if (!(burnerSWOInitialized && predeployedSWOInitialized)) return null;

return (
<DojoContext.Provider
Expand All @@ -113,6 +115,7 @@ export const DojoContextProvider = ({
rpcProvider,
},
burnerManager,
predeployedManager,
masterAccount,
configStore,
gameStore,
Expand Down
10 changes: 5 additions & 5 deletions web/src/dojo/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export type encountersActionNameKeys = keyof typeof encountersActionName;

export const randomGreetings = {
0: "Welcome to",
1: "GM",
2: "Yo",
3: "Sup",
4: "Here we go again",
5: "Ohayo",
// 1: "GM",
// 2: "Yo",
// 3: "Sup",
// 4: "Here we go again",
// 5: "Ohayo",
}
export type randomGreetingsKeys = keyof typeof randomGreetings;

Expand Down
26 changes: 26 additions & 0 deletions web/src/dojo/setup/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// TODO import manifest by chain
import { PredeployedAccount } from "@dojoengine/create-burner";
import { Chain, mainnet, sepolia } from "@starknet-react/chains";
import manifest from "../../../manifest.json";
import { katanaLocalChain, katanaSlot420Chain, katanaSlot421Chain } from "./chains";
Expand All @@ -18,6 +19,7 @@ export type DojoChainConfig = {
masterPrivateKey?: string,
accountClassHash?: string,
manifest: any,
predeployedAccounts: PredeployedAccount[]
}

const katanaLocal: DojoChainConfig = {
Expand All @@ -36,6 +38,26 @@ const katanaLocal: DojoChainConfig = {
process.env.NEXT_PUBLIC_ACCOUNT_CLASS_HASH ||
"0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c",
manifest,
predeployedAccounts: [
{
name: "Deployer",
address: "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03",
privateKey: "0x1800000000300000180000000000030000000000003006001800006600",
active: false
},
{
name: "Treasury",
address: "0xe29882a1fcba1e7e10cad46212257fea5c752a4f9b1b1ec683c503a2cf5c8a",
privateKey: "0x14d6672dcb4b77ca36a887e9a11cd9d637d5012468175829e9c6e770c61642",
active: false
},
{
name: "Acc 3",
address: "0x29873c310fbefde666dc32a1554fea6bb45eecc84f680f8a2b0a8fbb8cb89af",
privateKey: "0xc5b2fcab997346f3ea1c00b002ecf6f382c5f9c9659a3894eb783c5320f912",
active: false
},
]
}

const katanaSlot420: DojoChainConfig = {
Expand All @@ -48,6 +70,7 @@ const katanaSlot420: DojoChainConfig = {
masterPrivateKey: "0x2e8ac99614186737cefc47effe03134f5a19c6dc2443c16510d3384769f9c78",
accountClassHash: "0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c",
manifest,
predeployedAccounts: []
}

const katanaSlot421: DojoChainConfig = {
Expand All @@ -60,6 +83,7 @@ const katanaSlot421: DojoChainConfig = {
masterPrivateKey: "0x784b1dd14d761c414c6394fccca3ca1d1b0cac187e88122e4b06378f9e8c515",
accountClassHash: "0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c",
manifest,
predeployedAccounts: []
}

const snSepolia: DojoChainConfig = {
Expand All @@ -72,6 +96,7 @@ const snSepolia: DojoChainConfig = {
masterPrivateKey: undefined,
accountClassHash: undefined,
manifest,
predeployedAccounts: []
}

const snMainnet: DojoChainConfig = {
Expand All @@ -84,6 +109,7 @@ const snMainnet: DojoChainConfig = {
masterPrivateKey: undefined,
accountClassHash: undefined,
manifest,
predeployedAccounts: []
}


Expand Down
7 changes: 0 additions & 7 deletions web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import useKonamiCode, { starkpimpSequence } from "@/hooks/useKonamiCode";
import Fonts from "@/theme/fonts";
import GlobalStyles from "@/theme/global";
import { ChakraProvider } from "@chakra-ui/react";
import { useBurnerWindowObject } from "@dojoengine/create-burner";
import { Analytics } from "@vercel/analytics/react";
import type { AppProps } from "next/app";
import NextHead from "next/head";
Expand All @@ -27,12 +26,6 @@ export default function App({ Component, pageProps }: AppProps) {
}
}, [isRightSequence, setIsRightSequence, setSequence]);

// useEffect(() => {
// initializeInPage();
// }, []);

useBurnerWindowObject();

return (
<>
<DojoContextProvider dojoContextConfig={dojoContextConfig}>
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const TreasuryClaimCard = observer(() => {
<VStack alignItems="flex-start">
<HStack>
<Text w="180px">PAPER BALANCE</Text>
<TokenBalance address={config?.ryoAddress.paper} token={config?.ryoAddress.paper} />
<TokenBalance address={config?.ryoAddress.treasury} token={config?.ryoAddress.paper} />
</HStack>
<HStack>
<Text w="180px">PAPER CLAIMABLE</Text>
Expand Down

0 comments on commit 4e13166

Please sign in to comment.