Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions functions/api/_shared.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const DEFAULT_CHAIN_ID = 13390;
export const DEFAULT_RPC_URL = 'https://rpc.meechain.live';

export const DEFAULT_CONTRACTS = {
token: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
nft: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
portal: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
};

export function resolveChainId(env) {
return Number.parseInt(env.CHAIN_ID || String(DEFAULT_CHAIN_ID), 10);
Comment thread
MEECHAIN1 marked this conversation as resolved.
}

export function resolveRpcUrl(env) {
return env.DRPC_RPC_URL || env.VITE_RPC_URL || DEFAULT_RPC_URL;
}

export function resolveContracts(env) {
return {
token: env.VITE_TOKEN_CONTRACT_ADDRESS || DEFAULT_CONTRACTS.token,
nft: env.VITE_NFT_CONTRACT_ADDRESS || DEFAULT_CONTRACTS.nft,
portal: env.VITE_STAKING_CONTRACT_ADDRESS || DEFAULT_CONTRACTS.portal,
};
}
9 changes: 9 additions & 0 deletions functions/api/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@
// ║ Cloudflare Pages Function: /api/health ║
// ╚══════════════════════════════════════════════════════╝

import { resolveChainId, resolveContracts, resolveRpcUrl } from './_shared.mjs';
import { getMeechainConfig } from './_shared/meechain-config.js';

export async function onRequestGet(ctx) {
const { env } = ctx;
const config = getMeechainConfig(env);

const contracts = resolveContracts(env);

const data = {
status: 'ok',
model: 'gpt-5-mini',
bot: 'MeeBot AI',
web3: false,
chainId: resolveChainId(env),
rpc: resolveRpcUrl(env),
contracts: {
token: contracts.token,
nft: contracts.nft,
staking: contracts.portal,
Comment on lines +21 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Close the health contracts object

The added contracts block is never closed before the old chainId/rpc fields continue, so the ES-module parser reaches the final }; while the outer data object is still open. Any deployment that loads /api/health will fail with a syntax error instead of returning the health JSON; close this block or remove the stale config fields.

Useful? React with 👍 / 👎.

chainId: config.chainId,
rpc: config.rpcPrimary,
contracts: {
Expand Down
6 changes: 4 additions & 2 deletions functions/api/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// ║ Cloudflare Pages Function: /api/network ║
// ╚══════════════════════════════════════════════════════╝

import { resolveChainId, resolveContracts, resolveRpcUrl } from './_shared.mjs';
function buildRpcGateway(env = {}) {
return {
primary: {
Expand Down Expand Up @@ -39,15 +40,16 @@ export async function onRequestGet(ctx) {
const { env } = ctx;
const config = getMeechainConfig(env);

const chainId = resolveChainId(env);
const data = {
chainId: `0x${chainId.toString(16)}`, // 0x344e
chainName: 'MeeChain Ritual Chain',
rpcUrls: [
env.DRPC_RPC_URL || 'https://rpc.meechain.live',
env.VITE_RPC_URL || 'https://rpc.meechain.live',
resolveRpcUrl(env),
],
nativeCurrency: { name: 'MEE Token', symbol: 'MEE', decimals: 18 },
blockExplorerUrls:['http://explorer.meechain.run.place'],
contracts: resolveContracts(env),
contracts: {
token: env.VITE_TOKEN_CONTRACT_ADDRESS || '0x5FbDB2315678afecb367f032d93F642f64180aa3',
nft: env.VITE_NFT_CONTRACT_ADDRESS || '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
Expand Down
8 changes: 8 additions & 0 deletions functions/api/web3/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
// ║ Cloudflare Pages Function: /api/web3/status ║
// ╚══════════════════════════════════════════════════════╝

import { resolveChainId, resolveContracts, resolveRpcUrl } from '../_shared.mjs';

export async function onRequestGet(ctx) {
const { env } = ctx;

const rpcUrl = resolveRpcUrl(env);
const chainId = resolveChainId(env);
const contracts = resolveContracts(env);
Comment on lines +7 to +12

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the nested duplicate status handler

The newly inserted onRequestGet starts here but is not closed before the existing import and handler below it, which makes the file invalid as an ES module because the later import is parsed inside a function body. In any Cloudflare Pages deployment that loads /api/web3/status, the route will fail to load; fold these resolver variables into the existing handler or remove this duplicate wrapper.

Useful? React with 👍 / 👎.

import { getMeechainConfig } from '../_shared/meechain-config.js';

export async function onRequestGet(ctx) {
Expand Down
Loading