Skip to content

Commit

Permalink
Merge pull request #11 from prototyp3-dev/refactor/cartesiClientEnvVar
Browse files Browse the repository at this point in the history
Refactor/cartesi client env var
  • Loading branch information
arthuravianna authored Jan 23, 2024
2 parents 98617b9 + 6ec0894 commit 77bf195
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NEXT_PUBLIC_DAPP_ADDR="0x70ac08179605AF2D9e75782b8DEcDD3c22aA4D0C"
NEXT_PUBLIC_CARTESI_NODE_URL="http://127.0.0.1:8080"
2 changes: 1 addition & 1 deletion frontend/app/components/CartridgeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function CartridgeInfo() {
in_card: selectedCartridge.inCard ? ethers.utils.hexlify(selectedCartridge.inCard) : "0x",
log: ethers.utils.hexlify(selectedCartridge.gameplayLog)
}
const replayRes = await replay(signer, envClient.DAPP_ADDR, inputData, {decode:true});
const replayRes = await replay(signer, envClient.DAPP_ADDR, inputData, {decode:true, cartesiNodeUrl: envClient.CARTESI_NODE_URL});
}

async function uploadLog() {
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/components/CartridgeScoreboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { cache } from 'react';
import { getOutputs } from '../backend-libs/app/lib';
import { ReplayScore } from '../backend-libs/app/ifaces';
import MilitaryTechIcon from '@mui/icons-material/MilitaryTech';
import { envClient } from '../utils/clientEnv';



const getGeneralScoreboard = cache(async (cartridge_id:string) => {
const scores:Array<ReplayScore> = await getOutputs({tags: ["score", cartridge_id]});
const scores:Array<ReplayScore> = await getOutputs({tags: ["score", cartridge_id]}, {cartesiNodeUrl: envClient.CARTESI_NODE_URL});
return scores;
})

Expand Down
3 changes: 2 additions & 1 deletion frontend/app/components/CartridgeSelectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { selectedCartridgeContext } from '../cartridges/selectedCartridgeProvide
import { CartridgeInfo as Cartridge } from "../backend-libs/app/ifaces"
import { cartridgeInfo } from '../backend-libs/app/lib';
import { fontPressStart2P } from '../utils/font';
import { envClient } from '../utils/clientEnv';

function CartridgeSelectButton({cartridge, index}:{cartridge:Cartridge, index:number}) {
const {selectedCartridge, changeCartridge} = useContext(selectedCartridgeContext);
Expand All @@ -18,7 +19,7 @@ function CartridgeSelectButton({cartridge, index}:{cartridge:Cartridge, index:nu

const handleCartridgeSelection = async (e:React.MouseEvent<HTMLElement>) => {

const cartridgeWithInfo = await cartridgeInfo({id:cartridge.id},{decode:true});
const cartridgeWithInfo = await cartridgeInfo({id:cartridge.id},{decode:true, cartesiNodeUrl: envClient.CARTESI_NODE_URL});

console.log('Select')

Expand Down
3 changes: 2 additions & 1 deletion frontend/app/components/CartridgesList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import CartridgeSelectButton from './CartridgeSelectButton';
import { cache } from 'react';
import { cartridges as cartridgerequest} from "../backend-libs/app/lib";
import { envClient } from '../utils/clientEnv';


const getCartridges = cache(async () => {
const cartridges: any[] = (await cartridgerequest({},{decode:true})).data;
const cartridges: any[] = (await cartridgerequest({},{decode:true, cartesiNodeUrl: envClient.CARTESI_NODE_URL})).data;

return cartridges;
})
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Navbar() {
<p>Cartridges</p>
</Link>

<Link href={"/upload-cartridge"} className={ pathname === "/upload-cartridge" ? "link-active" : "link-2step-hover" }>
<Link href={"/insert-cartridge"} className={ pathname === "/insert-cartridge" ? "link-active" : "link-2step-hover" }>
<p>Insert Cartridge</p>
</Link>
</nav>
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/components/Rivemu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import OndemandVideoIcon from '@mui/icons-material/OndemandVideo';
import { selectedCartridgeContext } from '../cartridges/selectedCartridgeProvider';
import { cartridge } from '../backend-libs/app/lib';
import { fontPressStart2P } from '../utils/font';
import { envClient } from '../utils/clientEnv';

// let rivlogData: Uint8Array | undefined = undefined;

Expand Down Expand Up @@ -51,7 +52,7 @@ function Rivemu() {

async function loadCartridge() {
if (!selectedCartridge || !selectedCartridge?.play || selectedCartridge.cartridgeData != undefined) return;
const data = await cartridge({id:selectedCartridge.id},{decode:true,decodeModel:"bytes"});
const data = await cartridge({id:selectedCartridge.id},{decode:true,decodeModel:"bytes", cartesiNodeUrl: envClient.CARTESI_NODE_URL});
setCartridgeData(data);
}

Expand Down
10 changes: 10 additions & 0 deletions frontend/app/insert-cartridge/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { fontPressStart2P } from "../utils/font"


export default function UploadCartridge() {
return (
<main className="flex items-center justify-center h-lvh">
<span className={`${fontPressStart2P.className} text-4xl` }>Coming Soon!</span>
</main>
)
}
7 changes: 0 additions & 7 deletions frontend/app/upload-cartridge/page.tsx

This file was deleted.

6 changes: 5 additions & 1 deletion frontend/app/utils/clientEnv.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { str, envsafe } from 'envsafe';
import { str, envsafe, url } from 'envsafe';


export const envClient = envsafe({
DAPP_ADDR: str({
input: process.env.NEXT_PUBLIC_DAPP_ADDR,
desc: "Cartesi DApp ETH address."
}),
CARTESI_NODE_URL: url({
input: process.env.NEXT_PUBLIC_CARTESI_NODE_URL,
desc: "Cartesi Node URL."
})
})

0 comments on commit 77bf195

Please sign in to comment.