Skip to content

Commit

Permalink
Prefix environment variables with PUBLIC_ and comment out DojoStore l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
Caspar Oostendorp committed Jun 24, 2024
1 parent f6bac43 commit cc7b8e8
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 78 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RPC_URL=http://localhost:5050
TORII_URL=http://localhost:8080
RELAY_URL=http://localhost:8080
SERVER_URL=http://localhost:3001
PUBLIC_RPC_URL=http://localhost:5050
PUBLIC_TORII_URL=http://localhost:8080
PUBLIC_RELAY_URL=http://localhost:8080
PUBLIC_SERVER_URL=http://localhost:3001
MASTER_ADDRESS=0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486
MASTER_PRIVATE_KEY=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a
WORLD_ADDRESS=0x60916a73fe631fcba3b2a930e21c6f7bb2533ea398c7bfa75c72f71a8709fc2
Expand Down
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RPC_URL=http://localhost:5050
TORII_URL=http://localhost:8080
RELAY_URL=http://localhost:8080
SERVER_URL=http://localhost:3000
PUBLIC_RPC_URL=http://localhost:5050
PUBLIC_TORII_URL=http://localhost:8080
PUBLIC_RELAY_URL=http://localhost:8080
PUBLIC_SERVER_URL=http://localhost:3000
MASTER_ADDRESS=0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486
MASTER_PRIVATE_KEY=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a
WORLD_ADDRESS=0x60916a73fe631fcba3b2a930e21c6f7bb2533ea398c7bfa75c72f71a8709fc2
Expand Down
124 changes: 62 additions & 62 deletions src/stores/DojoStore.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import {create} from 'zustand';
import {
DojoConfig, KATANA_CLASS_HASH, KATANA_ETH_CONTRACT_ADDRESS,
KATANA_PREFUNDED_ADDRESS, KATANA_PREFUNDED_PRIVATE_KEY,
LOCAL_KATANA, LOCAL_RELAY, LOCAL_TORII
} from "@dojoengine/core";
import manifest from "@/dojo/manifest.ts";

import * as torii from "@dojoengine/torii-client";

import {Client} from "@dojoengine/torii-wasm";

interface ClientState {
client?: Client;
createClient: () => Promise<void>;
}

const defaultDojoConfig: DojoConfig = {
relayUrl: import.meta.env.VITE_RELAY_URL || LOCAL_RELAY,
rpcUrl: import.meta.env.VITE_RPC_URL || LOCAL_KATANA,
toriiUrl: import.meta.env.VITE_TORII_URL || LOCAL_TORII,
manifest: manifest(import.meta.env.VITE_WORLD_ADDRESS),
masterAddress: import.meta.env.VITE_MASTER_ADDRESS || KATANA_PREFUNDED_ADDRESS,
masterPrivateKey: import.meta.env.VITE_MASTER_PRIVATE_KEY || KATANA_PREFUNDED_PRIVATE_KEY,
accountClassHash: import.meta.env.VITE_ACCOUNT_CLASS_HASH || KATANA_CLASS_HASH,
feeTokenAddress: import.meta.env.VITE_FEETOKEN_ADDRESS || KATANA_ETH_CONTRACT_ADDRESS
};

const useDojoStore = create<DojoConfig & ClientState & {
setUrls: (urls: Partial<Pick<DojoConfig, 'relayUrl' | 'rpcUrl' | 'toriiUrl'>>) => Promise<void>
}>((set, get) => ({
...defaultDojoConfig,
client: undefined,
setUrls: async (urls: Partial<Pick<DojoConfig, 'relayUrl' | 'rpcUrl' | 'toriiUrl'>>) => {
const checks = await Promise.all(
Object.entries(urls).map(async ([key, url]) => {
try {
const response = await fetch(url as string);
if (!response.ok) throw new Error('Response not ok');
return [key, url];
} catch {
console.warn(`URL for ${key} is not responding.`);
return [key, defaultDojoConfig[key as keyof DojoConfig]];
}
})
);
set(Object.fromEntries(checks));
},
createClient: async () => {
const {rpcUrl, toriiUrl, manifest} = get();
// Assuming async initialization logic for ToriiClient
const client = await torii.createClient([], {
rpcUrl,
toriiUrl,
worldAddress: manifest.world.address,
relayUrl: '', // Assuming this needs to be dynamically set or fetched
});
set({client});
},
}));

export default useDojoStore;
// import {create} from 'zustand';
// import {
// DojoConfig, KATANA_CLASS_HASH, KATANA_ETH_CONTRACT_ADDRESS,
// KATANA_PREFUNDED_ADDRESS, KATANA_PREFUNDED_PRIVATE_KEY,
// LOCAL_KATANA, LOCAL_RELAY, LOCAL_TORII
// } from "@dojoengine/core";
// import manifest from "@/dojo/manifest.ts";
//
// import * as torii from "@dojoengine/torii-client";
//
// import {Client} from "@dojoengine/torii-wasm";
//
// interface ClientState {
// client?: Client;
// createClient: () => Promise<void>;
// }
//
// const defaultDojoConfig: DojoConfig = {
// relayUrl: import.meta.env.VITE_RELAY_URL || LOCAL_RELAY,
// rpcUrl: import.meta.env.VITE_RPC_URL || LOCAL_KATANA,
// toriiUrl: import.meta.env.VITE_TORII_URL || LOCAL_TORII,
// manifest: manifest(import.meta.env.VITE_WORLD_ADDRESS),
// masterAddress: import.meta.env.VITE_MASTER_ADDRESS || KATANA_PREFUNDED_ADDRESS,
// masterPrivateKey: import.meta.env.VITE_MASTER_PRIVATE_KEY || KATANA_PREFUNDED_PRIVATE_KEY,
// accountClassHash: import.meta.env.VITE_ACCOUNT_CLASS_HASH || KATANA_CLASS_HASH,
// feeTokenAddress: import.meta.env.VITE_FEETOKEN_ADDRESS || KATANA_ETH_CONTRACT_ADDRESS
// };
//
// const useDojoStore = create<DojoConfig & ClientState & {
// setUrls: (urls: Partial<Pick<DojoConfig, 'relayUrl' | 'rpcUrl' | 'toriiUrl'>>) => Promise<void>
// }>((set, get) => ({
// ...defaultDojoConfig,
// client: undefined,
// setUrls: async (urls: Partial<Pick<DojoConfig, 'relayUrl' | 'rpcUrl' | 'toriiUrl'>>) => {
// const checks = await Promise.all(
// Object.entries(urls).map(async ([key, url]) => {
// try {
// const response = await fetch(url as string);
// if (!response.ok) throw new Error('Response not ok');
// return [key, url];
// } catch {
// console.warn(`URL for ${key} is not responding.`);
// return [key, defaultDojoConfig[key as keyof DojoConfig]];
// }
// })
// );
// set(Object.fromEntries(checks));
// },
// createClient: async () => {
// const {rpcUrl, toriiUrl, manifest} = get();
// // Assuming async initialization logic for ToriiClient
// const client = await torii.createClient([], {
// rpcUrl,
// toriiUrl,
// worldAddress: manifest.world.address,
// relayUrl: '', // Assuming this needs to be dynamically set or fetched
// });
// set({client});
// },
// }));
//
// export default useDojoStore;
8 changes: 4 additions & 4 deletions src/stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export interface ISettingsStore {
}

export const defaultDojoConfig: PixelawConfig = {
serverUrl: import.meta.env.SERVER_URL,
relayUrl: import.meta.env.RELAY_URL,
rpcUrl: import.meta.env.RPC_URL,
toriiUrl: import.meta.env.TORII_URL,
serverUrl: import.meta.env.PUBLIC_SERVER_URL,
relayUrl: import.meta.env.PUBLIC_RELAY_URL,
rpcUrl: import.meta.env.PUBLIC_RPC_URL,
toriiUrl: import.meta.env.PUBLIC_TORII_URL,
manifest: manifest(import.meta.env.WORLD_ADDRESS),
masterAddress: import.meta.env.MASTER_ADDRESS,
masterPrivateKey: import.meta.env.MASTER_PRIVATE_KEY,
Expand Down
8 changes: 4 additions & 4 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type ImportMetaEnv = {
MODE: string
DEV: boolean
PROD: boolean
RPC_URL: string
TORII_URL: string
RELAY_URL: string
SERVER_URL: string
PUBLIC_RPC_URL: string
PUBLIC_TORII_URL: string
PUBLIC_RELAY_URL: string
PUBLIC_SERVER_URL: string
MASTER_ADDRESS: string
MASTER_PRIVATE_KEY: string
WORLD_ADDRESS: string
Expand Down

0 comments on commit cc7b8e8

Please sign in to comment.