From 6e03d62856729796101667949ed417cfe2778bbb Mon Sep 17 00:00:00 2001 From: starknetdev Date: Tue, 3 Oct 2023 11:15:16 +0100 Subject: [PATCH] - seperate arcade and wallet connector detection - detect when player has no arcade accounts, provide dialog - improve arcade account deployment UX --- ui/src/app/components/ArcadeDialog.tsx | 45 +++------ ui/src/app/components/TopUpDialog.tsx | 23 ++--- .../app/components/adventurer/DeathDialog.tsx | 1 + .../components/animations/PixelatedImage.tsx | 98 ++++++++++--------- ui/src/app/components/intro/ArcadeIntro.tsx | 67 +++++++++++-- ui/src/app/lib/connectors.ts | 16 ++- ui/src/app/page.tsx | 17 +++- 7 files changed, 165 insertions(+), 102 deletions(-) diff --git a/ui/src/app/components/ArcadeDialog.tsx b/ui/src/app/components/ArcadeDialog.tsx index da604a7ed..62b5e2c69 100644 --- a/ui/src/app/components/ArcadeDialog.tsx +++ b/ui/src/app/components/ArcadeDialog.tsx @@ -2,26 +2,15 @@ import React, { useEffect } from "react"; import { useState } from "react"; import useUIStore from "@/app/hooks/useUIStore"; import { Button } from "./buttons/Button"; -import { PREFUND_AMOUNT, useBurner } from "../lib/burner"; -import { - Connector, - useAccount, - useBalance, - useConnectors, -} from "@starknet-react/core"; -import { - AccountInterface, - CallData, - TransactionFinalityStatus, - uint256, - Call, - Account, - Provider, -} from "starknet"; +import { useBurner } from "../lib/burner"; +import { Connector, useAccount, useConnectors } from "@starknet-react/core"; +import { AccountInterface, CallData, uint256 } from "starknet"; import { useCallback } from "react"; import { useContracts } from "../hooks/useContracts"; import { balanceSchema } from "../lib/utils"; import { MIN_BALANCE } from "../lib/constants"; +import PixelatedImage from "./animations/PixelatedImage"; +import { getArcadeConnectors } from "../lib/connectors"; const MAX_RETRIES = 10; const RETRY_DELAY = 2000; // 2 seconds @@ -45,12 +34,7 @@ export const ArcadeDialog = () => { const { ethContract } = useContracts(); const [balances, setBalances] = useState>({}); - const arcadeConnectors = useCallback(() => { - return available.filter( - (connector) => - typeof connector.id === "string" && connector.id.includes("0x") - ); - }, [available]); + const arcadeConnectors = getArcadeConnectors(available); const fetchBalanceWithRetry = async ( accountName: string, @@ -76,13 +60,12 @@ export const ArcadeDialog = () => { const getBalances = async () => { const localBalances: Record = {}; - const balancePromises = arcadeConnectors().map((account) => { + const balancePromises = arcadeConnectors.map((account) => { return fetchBalanceWithRetry(account.name).then((balance) => { localBalances[account.name] = balance; return balance; }); }); - console.log(balancePromises); await Promise.all(balancePromises); setBalances(localBalances); }; @@ -124,7 +107,7 @@ export const ArcadeDialog = () => { )}
- {arcadeConnectors().map((account, index) => { + {arcadeConnectors.map((account, index) => { const masterAccount = getMasterAccount(account.name); return ( { address={address!} walletAccount={walletAccount!} masterAccountAddress={masterAccount} - arcadeConnectors={arcadeConnectors()} + arcadeConnectors={arcadeConnectors} genNewKey={genNewKey} balance={balances[account.name]} getBalance={getBalance} @@ -149,13 +132,17 @@ export const ArcadeDialog = () => {
{(isDeploying || isGeneratingNewKey) && ( -
-

+
+ +

{isSettingPermissions ? "Setting Permissions" : isGeneratingNewKey ? "Generating New Key" - : "Deploying Account"} + : "Deploying Arcade Account"}

)} diff --git a/ui/src/app/components/TopUpDialog.tsx b/ui/src/app/components/TopUpDialog.tsx index 0b2cedf0d..713a0fdd3 100644 --- a/ui/src/app/components/TopUpDialog.tsx +++ b/ui/src/app/components/TopUpDialog.tsx @@ -5,37 +5,26 @@ import { useConnectors } from "@starknet-react/core"; import Storage from "../lib/storage"; import { BurnerStorage } from "../types"; import { useBurner } from "../lib/burner"; +import { getArcadeConnectors, getWalletConnectors } from "../lib/connectors"; export const TopUpDialog = () => { const { account: walletAccount, address, connector } = useAccount(); - const { connect, connectors } = useConnectors(); + const { connect, available } = useConnectors(); const showTopUpDialog = useUIStore((state) => state.showTopUpDialog); const topUpAccount = useUIStore((state) => state.topUpAccount); const setTopUpAccount = useUIStore((state) => state.setTopUpAccount); const { topUp, isToppingUp } = useBurner(); - const arcadeConnectors = () => - connectors.filter( - (connector) => - typeof connector.id === "string" && connector.id.includes("0x") - ); - - const walletConnectors = () => - connectors.filter( - (connector) => - typeof connector.id !== "string" || !connector.id.includes("0x") - ); + const arcadeConnectors = getArcadeConnectors(available); + const walletConnectors = getWalletConnectors(available); let storage: BurnerStorage = Storage.get("burners") || {}; const masterConnected = address === storage[topUpAccount]?.masterAccount; - const arcadeConnector = arcadeConnectors().find( + const arcadeConnector = arcadeConnectors.find( (connector) => connector.name === topUpAccount ); - console.log(arcadeConnector); - console.log(masterConnected); - return ( <>
@@ -47,7 +36,7 @@ export const TopUpDialog = () => {

Connect Master

- {walletConnectors().map((connector, index) => ( + {walletConnectors.map((connector, index) => ( +
+

+ Greetings! Behold, the revelation of Arcade Accounts, the key to + supercharging onchain games! These promise swift transactions, + unleashing a 10x surge in your gameplay speed. +

+

+ Fear not, for they're guarded by a labyrinth of security features, + fit for even the wiliest of adventurers! +

+

+ Connect using a wallet provider. +

+
+ {walletConnectors.map((connector, index) => ( + + ))} +
+

+ Create Arcade Account (Fund, deploy & initiate security permissions) +

+ + {isDeploying && ( +
+ +

+ {isSettingPermissions + ? "Setting Permissions" + : "Deploying Arcade Account"} +

+
+ )} +
); diff --git a/ui/src/app/lib/connectors.ts b/ui/src/app/lib/connectors.ts index d65de8a0b..51fc097be 100644 --- a/ui/src/app/lib/connectors.ts +++ b/ui/src/app/lib/connectors.ts @@ -1,4 +1,5 @@ -import { InjectedConnector } from "@starknet-react/core"; +import { useCallback } from "react"; +import { InjectedConnector, Connector } from "@starknet-react/core"; // import { WebWalletConnector } from "@argent/starknet-react-webwallet-connector"; export const argentConnector = new InjectedConnector({ @@ -13,6 +14,19 @@ export const braavosConnector = new InjectedConnector({ }, }); +export const getArcadeConnectors = (available: Connector[]) => { + return available.filter( + (connector) => + typeof connector.id === "string" && connector.id.includes("0x") + ); +}; + +export const getWalletConnectors = (available: Connector[]) => + available.filter( + (connector) => + typeof connector.id !== "string" || !connector.id.includes("0x") + ); + function argentWebWalletUrl() { switch (process.env.NEXT_PUBLIC_NETWORK) { case "dev": diff --git a/ui/src/app/page.tsx b/ui/src/app/page.tsx index ccc8a5030..ee2ba2296 100644 --- a/ui/src/app/page.tsx +++ b/ui/src/app/page.tsx @@ -68,6 +68,7 @@ import { useBalance } from "@starknet-react/core"; import { ArcadeIntro } from "./components/intro/ArcadeIntro"; import Logo from "../../public/icons/logo.svg"; import ScreenMenu from "./components/menu/ScreenMenu"; +import { getArcadeConnectors } from "./lib/connectors"; const allMenuItems: Menu[] = [ { id: 1, label: "Start", screen: "start", disabled: false }, @@ -89,7 +90,7 @@ const mobileMenuItems: Menu[] = [ ]; export default function Home() { - const { disconnect } = useConnectors(); + const { disconnect, available } = useConnectors(); const { chain } = useNetwork(); const { provider } = useProvider(); const disconnected = useUIStore((state) => state.disconnected); @@ -146,6 +147,8 @@ export default function Home() { const resetNotification = useLoadingStore((state) => state.resetNotification); const setStartOption = useUIStore((state) => state.setStartOption); + const arcadeConnectors = getArcadeConnectors(available); + const lordsBalance = useBalance({ token: lordsContract?.address, address, @@ -356,6 +359,14 @@ export default function Home() { } }, [isConnected]); + useEffect(() => { + if (arcadeConnectors.length === 0) { + showArcadeIntro(true); + } else { + showArcadeIntro(false); + } + }, [arcadeConnectors]); + if (!isConnected && introComplete && disconnected) { return ; } @@ -406,7 +417,7 @@ export default function Home() {