Skip to content

Commit

Permalink
chore: make image work locally or live
Browse files Browse the repository at this point in the history
  • Loading branch information
mariz-ov committed Nov 22, 2023
1 parent 0c4f515 commit fb58de8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ VITE_ACCOUNT_CLASS_HASH=0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27

VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_NODE_URL=http://localhost:5050
VITE_PUBLIC_TORII=http://localhost:8080/graphql
VITE_PUBLIC_TORII=http://localhost:8080
2 changes: 0 additions & 2 deletions web/.env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_NODE_URL=https://katana.demo.pixelaw.xyz/
VITE_PUBLIC_TORII=https://torii.demo.pixelaw.xyz/graphql
7 changes: 3 additions & 4 deletions web/src/dojo/setupNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { GraphQLClient } from 'graphql-request';
import { getSdk } from '@/generated/graphql';
import { Manifest } from '@/global/types'
import { streamToString } from '@/global/utils'
import { PUBLIC_NODE_URL, PUBLIC_TORII } from '@/global/constants'

export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
const MANIFEST_URL = '/manifests/core'

export async function setupNetwork() {
// Extract environment variables for better readability.
const { VITE_PUBLIC_NODE_URL, VITE_PUBLIC_TORII } = import.meta.env;

const manifest: Manifest = await (async () => {
const result = await fetch(MANIFEST_URL)
Expand All @@ -24,12 +23,12 @@ export async function setupNetwork() {
const worldAddress = manifest.world.address ?? ''

// Create a new RPCProvider instance.
const provider = new RPCProvider(worldAddress, manifest, VITE_PUBLIC_NODE_URL);
const provider = new RPCProvider(worldAddress, manifest, PUBLIC_NODE_URL);

// Utility function to get the SDK.
// Add in new queries or subscriptions in src/graphql/schema.graphql
// then generate them using the codegen and fix-codegen commands in package.json
const createGraphSdk = () => getSdk(new GraphQLClient(VITE_PUBLIC_TORII));
const createGraphSdk = () => getSdk(new GraphQLClient(`${PUBLIC_TORII}/graphql`));

// Return the setup object.
return {
Expand Down
6 changes: 5 additions & 1 deletion web/src/global/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export const PUBLIC_NODE_URL: string = import.meta.env.VITE_PUBLIC_NODE_URL ?? 'http://localhost:5050'
import { getProductionUrl } from '@/global/utils'

export const PUBLIC_TORII: string = import.meta.env.VITE_PUBLIC_TORII ?? getProductionUrl('torii')

export const PUBLIC_NODE_URL: string = import.meta.env.VITE_PUBLIC_NODE_URL ?? getProductionUrl('katana')

export const BLOCK_TIME = 1_000

Expand Down
12 changes: 12 additions & 0 deletions web/src/global/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ export const argbToHex = (argb: number) => {
const hexCode = convertToHexadecimalAndLeadWithOx(argb)
return hexCode.replace("0xff", "#")
}

export const getProductionUrl = (type: 'katana' | 'torii') => {
const protocol = window.location.protocol
const hostname = window.location.hostname.replace('www.', '')

if (hostname === 'localhost') {
if (type === 'katana') return 'http://localhost:5050'
else return 'http://localhost:8080'
}

return`${protocol}//${type}.${hostname}`
}

0 comments on commit fb58de8

Please sign in to comment.