-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(api): centralize network and contract config for API handlers #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
| } | ||
|
|
||
| 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, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The added Useful? React with 👍 / 👎. |
||
| chainId: config.chainId, | ||
| rpc: config.rpcPrimary, | ||
| contracts: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The newly inserted Useful? React with 👍 / 👎. |
||
| import { getMeechainConfig } from '../_shared/meechain-config.js'; | ||
|
|
||
| export async function onRequestGet(ctx) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.