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
27 changes: 26 additions & 1 deletion packages/relay/src/views/landing/page.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from 'bun:test'
import { afterAll, describe, expect, test } from 'bun:test'
import '@/shared/test-helpers'
import { LandingPage } from './page'

Expand Down Expand Up @@ -28,3 +28,28 @@ describe('LandingPage', () => {
expect(html).toContain('register-form')
})
})

describe('LandingPage env toggle', () => {
const originalEnv = process.env.NETWORK_ENV

afterAll(() => {
if (originalEnv === undefined) delete process.env.NETWORK_ENV
else process.env.NETWORK_ENV = originalEnv
})

test('on testnet: Mainnet radio is disabled, Testnet is checked', () => {
process.env.NETWORK_ENV = 'testnet'
const html = LandingPage()
expect(html).toMatch(/id="env-mainnet"[^>]*?disabled[^>]*?\/>/)
expect(html).toMatch(/id="env-testnet"[^>]*?checked[^>]*?\/>/)
expect(html).not.toMatch(/id="env-mainnet"[^>]*?checked[^>]*?\/>/)
})

test('on mainnet: Testnet radio is disabled, Mainnet is checked', () => {
process.env.NETWORK_ENV = 'mainnet'
const html = LandingPage()
expect(html).toMatch(/id="env-testnet"[^>]*?disabled[^>]*?\/>/)
expect(html).toMatch(/id="env-mainnet"[^>]*?checked[^>]*?\/>/)
expect(html).not.toMatch(/id="env-testnet"[^>]*?checked[^>]*?\/>/)
})
})
16 changes: 15 additions & 1 deletion packages/relay/src/views/landing/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { resolveNetworkEnv } from '@402md/shared/networks'
import { Layout } from '../layout'
import { Nav } from '../nav'
import landingContent from './content.html' with { type: 'text' }
import landingStyles from './styles.css' with { type: 'text' }
import landingScript from './script.txt' with { type: 'text' }

const lockEnvToggle = (html: string, env: 'mainnet' | 'testnet'): string => {
const disabledId = env === 'testnet' ? 'env-mainnet' : 'env-testnet'
const checkedId = env === 'testnet' ? 'env-testnet' : 'env-mainnet'
return html
.replace(new RegExp(`(id="${disabledId}"[^>]*?)\\s+checked`), '$1 disabled')
.replace(new RegExp(`(id="${disabledId}"[^>]*?)(\\s*/>)`), (match, prefix, suffix) =>
match.includes(' disabled') ? match : `${prefix} disabled${suffix}`,
)
.replace(new RegExp(`(id="${checkedId}"[^>]*?)(\\s*/>)`), (match, prefix, suffix) =>
match.includes(' checked') ? match : `${prefix} checked${suffix}`,
)
}

export const LandingPage = () => (
<Layout
title="402md Facilitator — Cross-chain USDC settlement for x402 and MPP"
description="Accept USDC payments from any chain. Buyer pays on Solana, seller receives on Stellar. One HTTP request, zero custom code, 0% fee."
extraStyles={landingStyles}
>
<Nav />
{landingContent}
{lockEnvToggle(landingContent, resolveNetworkEnv())}
<script>{landingScript}</script>
</Layout>
)
Loading