From b807fc1776e415db7e65755d4732655bb9fbd636 Mon Sep 17 00:00:00 2001 From: ultraviolet10 Date: Tue, 15 Apr 2025 13:41:44 +0530 Subject: [PATCH 1/6] add deployed indexer url --- packages/core/src/network/config/chainConfigs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/network/config/chainConfigs.ts b/packages/core/src/network/config/chainConfigs.ts index f19ee3927..9c2df767d 100644 --- a/packages/core/src/network/config/chainConfigs.ts +++ b/packages/core/src/network/config/chainConfigs.ts @@ -75,7 +75,7 @@ const baseSepolia: ChainConfig = { export const happyChainSepolia: ChainConfig = { ...happyChainDef, - indexerUrl: "http://localhost:3001", // ## [happyTODO :: deploy indexer and then add the URL here] ## + indexerUrl: "http://148.113.212.211:3001", // ## [happyTODO :: deploy indexer and then add the URL here] ## }; export type ChainConfig = MUDChain & { indexerUrl?: string }; From ee3f89c1e0af7c190f671b41e554181abb7dfbd0 Mon Sep 17 00:00:00 2001 From: ultraviolet10 Date: Tue, 15 Apr 2025 13:46:48 +0530 Subject: [PATCH 2/6] remove comment --- packages/core/src/network/config/chainConfigs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/network/config/chainConfigs.ts b/packages/core/src/network/config/chainConfigs.ts index 9c2df767d..30a44ef1e 100644 --- a/packages/core/src/network/config/chainConfigs.ts +++ b/packages/core/src/network/config/chainConfigs.ts @@ -75,7 +75,7 @@ const baseSepolia: ChainConfig = { export const happyChainSepolia: ChainConfig = { ...happyChainDef, - indexerUrl: "http://148.113.212.211:3001", // ## [happyTODO :: deploy indexer and then add the URL here] ## + indexerUrl: "http://148.113.212.211:3001", }; export type ChainConfig = MUDChain & { indexerUrl?: string }; From 508086775a3e901829cb993843b7eb3728db1c06 Mon Sep 17 00:00:00 2001 From: ultraviolet10 Date: Mon, 21 Apr 2025 23:11:57 +0530 Subject: [PATCH 3/6] happy primodium indexer url --- packages/core/src/network/config/chainConfigs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/network/config/chainConfigs.ts b/packages/core/src/network/config/chainConfigs.ts index 30a44ef1e..8f2178c4c 100644 --- a/packages/core/src/network/config/chainConfigs.ts +++ b/packages/core/src/network/config/chainConfigs.ts @@ -75,7 +75,7 @@ const baseSepolia: ChainConfig = { export const happyChainSepolia: ChainConfig = { ...happyChainDef, - indexerUrl: "http://148.113.212.211:3001", + indexerUrl: "https://primodium-indexer.happy.tech/", }; export type ChainConfig = MUDChain & { indexerUrl?: string }; From ab6f2df0fb5fca5c10eb24e6b14195fa8588b77f Mon Sep 17 00:00:00 2001 From: ultraviolet10 Date: Wed, 9 Apr 2025 14:29:59 +0530 Subject: [PATCH 4/6] feat: integrate happy session keys mvp --- .../src/components/transfer/Authorize.tsx | 62 +++++++++++-------- packages/client/src/screens/Enter.tsx | 31 ++++++---- 2 files changed, 53 insertions(+), 40 deletions(-) diff --git a/packages/client/src/components/transfer/Authorize.tsx b/packages/client/src/components/transfer/Authorize.tsx index 1707b943d..5058ba8e8 100644 --- a/packages/client/src/components/transfer/Authorize.tsx +++ b/packages/client/src/components/transfer/Authorize.tsx @@ -1,7 +1,7 @@ +import { requestSessionKey } from "@happy.tech/core"; import { useEffect, useState } from "react"; import { FaClipboard, FaExclamationCircle, FaEye, FaEyeSlash, FaInfoCircle, FaTimes, FaUnlink } from "react-icons/fa"; -import { Address, Hex } from "viem"; -import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; +import { Address } from "viem"; import { STORAGE_PREFIX } from "@primodiumxyz/core"; import { useAccountClient } from "@primodiumxyz/core/react"; @@ -11,14 +11,21 @@ import { SecondaryCard } from "@/components/core/Card"; import { TransactionQueueMask } from "@/components/shared/TransactionQueueMask"; import { useContractCalls } from "@/hooks/useContractCalls"; import { copyToClipboard } from "@/util/clipboard"; -import { findEntriesWithPrefix } from "@/util/localStorage"; -const sessionWalletTooltip = - "Bypass annoying confirmation popups by authorizing a session account. This allows you to securely perform certain actions without external confirmation."; +const sessionWalletTooltip = ( + <> + Bypass confirmation popups by authorizing a session key. Powered by{" "} + Happy Wallet, this lets you securely perform actions without repeated + approvals. + +); export function Authorize() { - const { sessionAccount } = useAccountClient(); - const { grantAccessWithSignature, revokeAccess } = useContractCalls(); + const { + playerAccount: { worldContract }, + sessionAccount, + } = useAccountClient(); + const { revokeAccess } = useContractCalls(); const [showDetails, setShowDetails] = useState(false); const [showHelp, setShowHelp] = useState(!localStorage.getItem("hideHelp")); @@ -29,26 +36,26 @@ export function Authorize() { // Function to handle private key validation and connection const sessionAddress = sessionAccount?.address; - const submitPrivateKey = async (privateKey: Hex) => { - // Validate the private key format here - // This is a basic example, adjust the validation according to your requirements - const isValid = /^0x[a-fA-F0-9]{64}$/.test(privateKey); - if (!isValid) return; - const account = privateKeyToAccount(privateKey as Hex); + // const _submitPrivateKey = async (privateKey: Hex) => { + // // Validate the private key format here + // // This is a basic example, adjust the validation according to your requirements + // const isValid = /^0x[a-fA-F0-9]{64}$/.test(privateKey); + // if (!isValid) return; + // const account = privateKeyToAccount(privateKey as Hex); - if (sessionAddress && sessionAddress === account.address) return; - else await grantAccessWithSignature(privateKey, { id: defaultEntity }); - }; + // if (sessionAddress && sessionAddress === account.address) return; + // else await grantAccessWithSignature(privateKey, { id: defaultEntity }); + // }; - const handleRandomPress = () => { - const storedKeys = findEntriesWithPrefix(); - const privateKey = storedKeys.length > 0 ? storedKeys[0].privateKey : generatePrivateKey(); + // const _handleRandomPress = () => { + // const storedKeys = findEntriesWithPrefix(); + // const privateKey = storedKeys.length > 0 ? storedKeys[0].privateKey : generatePrivateKey(); - const account = privateKeyToAccount(privateKey as Hex); - localStorage.setItem(STORAGE_PREFIX + account.address, privateKey); + // const account = privateKeyToAccount(privateKey as Hex); + // localStorage.setItem(STORAGE_PREFIX + account.address, privateKey); - return privateKey; - }; + // return privateKey; + // }; const removeSessionKey = async (publicKey: Address) => { await revokeAccess(publicKey); @@ -136,12 +143,13 @@ export function Authorize() { variant="primary" size="md" className="w-full" - onClick={() => { - const key = handleRandomPress(); - submitPrivateKey(key); + onClick={async () => { + // const key = handleRandomPress(); + // submitPrivateKey(key); + await requestSessionKey(worldContract.address); }} > - CLICK TO AUTHORIZE SESSION ACCOUNT + CLICK TO AUTHORIZE SESSION KEY )} diff --git a/packages/client/src/screens/Enter.tsx b/packages/client/src/screens/Enter.tsx index 0d1fb5ebb..fc8725741 100644 --- a/packages/client/src/screens/Enter.tsx +++ b/packages/client/src/screens/Enter.tsx @@ -1,27 +1,30 @@ +import { requestSessionKey } from "@happy.tech/core"; import { useEffect, useState } from "react"; import { FaExclamationTriangle, FaInfoCircle } from "react-icons/fa"; import { useLocation, useNavigate } from "react-router-dom"; import { toast } from "react-toastify"; -import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; -import { STORAGE_PREFIX } from "@primodiumxyz/core"; +// import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; + +// import { STORAGE_PREFIX } from "@primodiumxyz/core"; import { useAccountClient, useCore } from "@primodiumxyz/core/react"; import { defaultEntity } from "@primodiumxyz/reactive-tables"; import { Tooltip } from "@/components/core/Tooltip"; import { TransactionQueueMask } from "@/components/shared/TransactionQueueMask"; import { useContractCalls } from "@/hooks/useContractCalls"; -import { findEntriesWithPrefix } from "@/util/localStorage"; + +// import { findEntriesWithPrefix } from "@/util/localStorage"; import { Landing } from "./Landing"; export const Enter: React.FC = () => { const { tables } = useCore(); const { - playerAccount: { entity: playerEntity }, + playerAccount: { worldContract, entity: playerEntity }, sessionAccount, } = useAccountClient(); - const { grantAccessWithSignature, spawn } = useContractCalls(); + const { spawn } = useContractCalls(); const navigate = useNavigate(); const location = useLocation(); const [showingToast, setShowingToast] = useState(false); @@ -93,13 +96,15 @@ export const Enter: React.FC = () => { navigate("/game" + location.search); }; - const handleDelegate = async () => { - const storedKeys = findEntriesWithPrefix(); - const privateKey = storedKeys.length > 0 ? storedKeys[0].privateKey : generatePrivateKey(); - const account = privateKeyToAccount(privateKey); - localStorage.setItem(STORAGE_PREFIX + account.address, privateKey); + const handleRegisterHappySessionKey = async () => { + // const storedKeys = findEntriesWithPrefix(); + // const privateKey = storedKeys.length > 0 ? storedKeys[0].privateKey : generatePrivateKey(); + // const account = privateKeyToAccount(privateKey); + // localStorage.setItem(STORAGE_PREFIX + account.address, privateKey); + + // await grantAccessWithSignature(privateKey, { id: defaultEntity }); - await grantAccessWithSignature(privateKey, { id: defaultEntity }); + await requestSessionKey(worldContract.address); }; return ( @@ -108,7 +113,7 @@ export const Enter: React.FC = () => { {state === "delegate" && (
- Authorize Delegate + Register Session Key