Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(credits): show the $THREE holder tier the caller is actually charged at

nirholased5a3aef037e
diff --git a/api/_lib/pricing/catalog.js b/api/_lib/pricing/catalog.js
index 474cc6bcb..b8076f6d9 100644
--- a/api/_lib/pricing/catalog.js
+++ b/api/_lib/pricing/catalog.js
@@ -58,55 +58,55 @@ export const TTS_OPENAI_USD_PER_1K = 0.03;
export const CATALOG = Object.freeze({
// ── Generation & compute (real GPU / vendor cost) — POLICY.CONSUMPTION ──────
'forge.standard': {
- label: 'Forge — Standard generation',
+ label: 'Forge: Standard generation',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: FORGE_STANDARD_USD,
},
'forge.high': {
- label: 'Forge — High generation (PBR)',
+ label: 'Forge: High generation (PBR)',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: FORGE_HIGH_USD,
},
'forge.gameready': {
- label: 'Forge — Game-Ready export (Unity/Unreal)',
+ label: 'Forge: Game-Ready export (Unity/Unreal)',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: FORGE_GAMEREADY_USD,
},
'mcp3d.text_to_3d': {
- label: 'MCP-3D — text → 3D',
+ label: 'MCP-3D: text → 3D',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: FORGE_STANDARD_USD,
},
'mcp3d.image_to_3d': {
- label: 'MCP-3D — image → 3D',
+ label: 'MCP-3D: image → 3D',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: FORGE_STANDARD_USD,
},
'mcp3d.auto_rig': {
- label: 'MCP-3D — auto-rig',
+ label: 'MCP-3D: auto-rig',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: 0.1,
},
'mcp3d.stylize': {
- label: 'MCP-3D — stylize',
+ label: 'MCP-3D: stylize',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: 0.1,
},
'mcp3d.retexture': {
- label: 'MCP-3D — retexture',
+ label: 'MCP-3D: retexture',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: FORGE_STANDARD_USD,
},
'voice.clone': {
- label: 'Voice Lab — custom voice clone',
+ label: 'Voice Lab: custom voice clone',
category: 'generation',
policy: POLICY.CONSUMPTION,
usd: 0.5,
@@ -130,19 +130,19 @@ export const CATALOG = Object.freeze({
usd: 0.25,
},
'granite.forecast': {
- label: 'Granite Oracle — forecast',
+ label: 'Granite Oracle: forecast',
category: 'data',
policy: POLICY.CONSUMPTION,
usd: 0.05,
},
'granite.vision': {
- label: 'Granite Vision — image → identity',
+ label: 'Granite Vision: image → identity',
category: 'data',
policy: POLICY.CONSUMPTION,
usd: 0.05,
},
'granite.proof': {
- label: 'Granite Proof — notarized forecast',
+ label: 'Granite Proof: notarized forecast',
category: 'data',
policy: POLICY.CONSUMPTION,
usd: 0.1,
diff --git a/api/credits/index.js b/api/credits/index.js
index 1d151b573..2bc1ee284 100644
--- a/api/credits/index.js
+++ b/api/credits/index.js
@@ -15,6 +15,7 @@ import { getCreditAccount, listLedger } from '../_lib/credits.js';
import { depositWallet } from '../_lib/credit-deposit.js';
import { TOKEN_MINT, TOKEN_SYMBOL, TOKEN_DECIMALS } from '../_lib/token/config.js';
import { publicCatalog } from '../_lib/pricing/catalog.js';
+import { resolveUserTier, nextTier } from '../_lib/three-tier.js';
import { isUuid } from '../_lib/validate.js';
async function resolveUser(req, res) {
@@ -30,6 +31,29 @@ async function resolveUser(req, res) {
return null;
}
+async function resolveHolder(user) {
+ try {
+ const { tier, usd, next } = await resolveUserTier(user);
+ const nt = next ?? nextTier(tier);
+ return {
+ tier: {
+ level: tier.level,
+ id: tier.id,
+ label: tier.label,
+ discount_bps: tier.discountBps,
+ },
+ usd_held: Math.round((Number(usd) || 0) * 100) / 100,
+ discount_bps: tier.discountBps,
+ next_tier: nt ? { id: nt.id, label: nt.label, min_usd: nt.minUsd } : null,
+ usd_to_next: nt
+ ? Math.max(0, Math.round((nt.minUsd - (Number(usd) || 0)) * 100) / 100)
+ : 0,
+ };
+ } catch {
+ return null;
+ }
+}
+
export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,OPTIONS', credentials: true })) return;
if (!method(req, res, ['GET'])) return;
@@ -48,9 +72,16 @@ export default wrap(async (req, res) => {
if (cursor && !isUuid(cursor))
return error(res, 400, 'bad_request', 'cursor must be a ledger entry id');
- const [acct, ledger] = await Promise.all([
+ // The $THREE holder discount is the headline promise of this surface ("hold
+ // $THREE for up to 30% off every spend"), and every debit already applies it
+ // (api/_lib/credits.js). Report it here so the page can show the tier the
+ // caller is actually being charged at, in the same `holder` shape /api/pricing
+ // uses. It reads a Solana balance, so it resolves alongside the DB work and
+ // degrades to null rather than failing the balance read.
+ const [acct, ledger, holder] = await Promise.all([
getCreditAccount(user.id),
listLedger({ userId: user.id, limit, before: cursor }),
+ resolveHolder(user),
]);
// What credits buy: the fixed-price compute actions (variable / marketplace
@@ -59,6 +90,7 @@ export default wrap(async (req, res) => {
return json(res, 200, {
balance_usd: acct.balanceUsd,
+ holder,
lifetime_deposited_usd: acct.lifetimeDepositedUsd,
lifetime_spent_usd: acct.lifetimeSpentUsd,
deposit: {
diff --git a/pages/credits.html b/pages/credits.html
index 51b3837f7..c9285e6a6 100644
--- a/pages/credits.html
+++ b/pages/credits.html
@@ -23,14 +23,23 @@
<meta
name="description"
content="Top up your three.ws balance with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for a discount on every spend."
- data-i18n-attr="content:credits.meta_description"/>
- <meta property="og:title" content="Credits · three.ws" data-i18n-attr="content:credits.meta_og_title"/>
+ data-i18n-attr="content:credits.meta_description"
+ />
+ <meta
+ property="og:title"
+ content="Credits · three.ws"
+ data-i18n-attr="content:credits.meta_og_title"
+ />
<meta
property="og:description"
content="Deposit SOL or $THREE for credits. Spend on Forge, agents, and compute. Hold $THREE for up to 30% off."
- data-i18n-attr="content:credits.meta_og_description"/>
+ data-i18n-attr="content:credits.meta_og_description"
+ />
<meta property="og:url" content="https://three.ws/credits" />
- <meta property="og:image" content="https://three.ws/api/page-og?s=account&amp;t=Credits&amp;d=Top+up+with+SOL+or+%24THREE+and+spend+credits+on+3D+generation%2C+agents%2C+and+compute.+Hold+%24THREE+for+up+to+30%25+off+every+spend.&amp;p=%2Fcredits" />
+ <meta
+ property="og:image"
+ content="https://three.ws/api/page-og?s=account&amp;t=Credits&amp;d=Top+up+with+SOL+or+%24THREE+and+spend+credits+on+3D+generation%2C+agents%2C+and+compute.+Hold+%24THREE+for+up+to+30%25+off+every+spend.&amp;p=%2Fcredits"
+ />
<meta name="twitter:card" content="summary_large_image" />
<link rel="canonical" href="https://three.ws/credits" />
<link rel="icon" href="/favicon.ico" sizes="any" />
@@ -43,8 +52,16 @@
<link rel="stylesheet" href="/fonts/fonts.css" />
<link rel="stylesheet" href="/mobile.css" />
<style>
+ /* <body> is a column flexbox site-wide, so <main> is a flex item and
+ inherits min-width:auto. That floors it at its min-content width and
+ made the whole page 417px wide inside a 320px viewport, clipped
+ (not scrolled) by the global overflow-x:clip. min-width:0 lets it
+ shrink; the amount input below supplies the min-content that forced
+ it. Same reason for the grid/card rules that follow. */
.credits-wrap {
max-width: 1040px;
+ width: 100%;
+ min-width: 0;
margin: 0 auto;
padding: clamp(1.25rem, 4vw, 3rem) 1.25rem 4rem;
}
@@ -72,6 +89,10 @@
grid-template-columns: 1.1fr 0.9fr;
gap: 1.1rem;
align-items: start;
+ min-width: 0;
+ }
+ .credits-grid > * {
+ min-width: 0;
}
@media (max-width: 820px) {
.credits-grid {
@@ -83,6 +104,7 @@
border: 1px solid var(--border, #262a33);
border-radius: 16px;
padding: 1.25rem 1.35rem;
+ min-width: 0;
}
.card h2 {
font-size: 0.82rem;
@@ -175,6 +197,7 @@
}
.amt-row input {
flex: 1;
+ min-width: 0;
background: var(--surface-2, #1c1f27);
border: 1px solid var(--border, #262a33);
border-radius: 10px;
@@ -403,24 +426,159 @@
grid-template-columns: 1fr;
}
}
+ /* Wide content scrolls inside its own box so the page itself never
+ scrolls sideways on a phone. */
+ .ledger-scroll {
+ overflow-x: auto;
+ -webkit-overflow-scrolling: touch;
+ }
+ .ledger {
+ min-width: 22rem;
+ }
+ .addr-row {
+ display: flex;
+ align-items: stretch;
+ gap: 0.4rem;
+ margin: 0.6rem 0;
+ }
+ .addr-row .addr {
+ flex: 1;
+ min-width: 0;
+ margin: 0;
+ }
+ .copy-addr {
+ appearance: none;
+ flex: 0 0 auto;
+ border: 1px solid var(--border, #262a33);
+ background: var(--surface-2, #1c1f27);
+ color: var(--text-secondary, #9aa3b2);
+ border-radius: 8px;
+ padding: 0 0.7rem;
+ font: inherit;
+ font-size: 0.78rem;
+ font-weight: 600;
+ cursor: pointer;
+ transition:
+ color 0.15s,
+ border-color 0.15s;
+ }
+ .copy-addr:hover:not(:disabled) {
+ color: var(--text-primary, #e8ebf2);
+ border-color: var(--accent, #6c8cff);
+ }
+ .copy-addr:disabled {
+ opacity: var(--disabled-opacity, 0.4);
+ cursor: var(--disabled-cursor, not-allowed);
+ }
+ /* Error state: a designed, actionable card. Before this existed a failed
+ /api/credits hid every panel and left the page blank below the h1. */
+ .state-msg {
+ text-align: center;
+ padding: 2.25rem 1.25rem;
+ }
+ .state-msg h2 {
+ text-transform: none;
+ letter-spacing: -0.01em;
+ font-size: 1.05rem;
+ color: var(--text-primary, #e8ebf2);
+ margin: 0 0 0.4rem;
+ }
+ .state-msg p {
+ margin: 0 auto;
+ max-width: 44ch;
+ color: var(--text-secondary, #9aa3b2);
+ font-size: 0.9rem;
+ line-height: 1.5;
+ }
+ .state-msg .btn {
+ max-width: 16rem;
+ margin-left: auto;
+ margin-right: auto;
+ }
+ .state-links {
+ margin-top: 0.9rem;
+ font-size: 0.85rem;
+ }
+ .state-links a {
+ color: var(--accent, #6c8cff);
+ font-weight: 600;
+ }
+ /* Keyboard users get the same affordance as the pointer hover states
+ above; tokens are the site-wide focus ring. */
+ .seg button:focus-visible,
+ .quick button:focus-visible,
+ .btn:focus-visible,
+ .copy-addr:focus-visible,
+ .manual summary:focus-visible,
+ .amt-row input:focus-visible,
+ .manual input:focus-visible,
+ .ledger a:focus-visible,
+ .signin a:focus-visible,
+ .state-links a:focus-visible {
+ outline: var(--focus-ring-width, 2px) solid var(--focus-ring-color, #6c8cff);
+ outline-offset: var(--focus-ring-offset, 2px);
+ }
+ .amt-row input:focus,
+ .manual input:focus {
+ border-color: var(--accent, #6c8cff);
+ }
+ .is-busy::after {
+ content: '\2026';
+ }
+ @media (prefers-reduced-motion: reduce) {
+ .skel {
+ animation: none;
+ }
+ }
[hidden] {
display: none !important;
}
</style>
-
- <meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1">
- <meta property="og:type" content="website">
- <meta property="og:site_name" content="three.ws">
- <meta property="og:locale" content="en_US">
- <meta property="og:image:alt" content="Credits — three.ws">
- <meta name="twitter:site" content="@trythreews">
- <meta name="twitter:title" content="Credits · three.ws" data-i18n-attr="content:credits.meta_twitter_title">
- <meta name="twitter:description" content="Top up with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for up to 30% off every spend." data-i18n-attr="content:credits.meta_twitter_description">
- <meta name="twitter:image" content="https://three.ws/api/page-og?s=account&amp;t=Credits&amp;d=Top+up+with+SOL+or+%24THREE+and+spend+credits+on+3D+generation%2C+agents%2C+and+compute.+Hold+%24THREE+for+up+to+30%25+off+every+spend.&amp;p=%2Fcredits">
- <script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"Credits","description":"Top up with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for up to 30% off every spend.","url":"https://three.ws/credits","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"},"primaryImageOfPage":"https://three.ws/api/page-og?s=account&t=Credits&d=Top+up+with+SOL+or+%24THREE+and+spend+credits+on+3D+generation%2C+agents%2C+and+compute.+Hold+%24THREE+for+up+to+30%25+off+every+spend.&p=%2Fcredits"}]}</script>
-</head>
+
+ <meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1" />
+ <meta property="og:type" content="website" />
+ <meta property="og:site_name" content="three.ws" />
+ <meta property="og:locale" content="en_US" />
+ <meta property="og:image:alt" content="Credits — three.ws" />
+ <meta name="twitter:site" content="@trythreews" />
+ <meta
+ name="twitter:title"
+ content="Credits · three.ws"
+ data-i18n-attr="content:credits.meta_twitter_title"
+ />
+ <meta
+ name="twitter:description"
+ content="Top up with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for up to 30% off every spend."
+ data-i18n-attr="content:credits.meta_twitter_description"
+ />
+ <meta
+ name="twitter:image"
+ content="https://three.ws/api/page-og?s=account&amp;t=Credits&amp;d=Top+up+with+SOL+or+%24THREE+and+spend+credits+on+3D+generation%2C+agents%2C+and+compute.+Hold+%24THREE+for+up+to+30%25+off+every+spend.&amp;p=%2Fcredits"
+ />
+ <script type="application/ld+json">
+ {
+ "@context": "https://schema.org",
+ "@graph": [
+ {
+ "@type": "WebPage",
+ "name": "Credits",
+ "description": "Top up with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for up to 30% off every spend.",
+ "url": "https://three.ws/credits",
+ "isPartOf": {
+ "@type": "WebSite",
+ "name": "three.ws",
+ "url": "https://three.ws"
+ },
+ "primaryImageOfPage": "https://three.ws/api/page-og?s=account&t=Credits&d=Top+up+with+SOL+or+%24THREE+and+spend+credits+on+3D+generation%2C+agents%2C+and+compute.+Hold+%24THREE+for+up+to+30%25+off+every+spend.&p=%2Fcredits"
+ }
+ ]
+ }
+ </script>
+ </head>
<body>
- <a href="#main-content" class="h-skip-link" data-i18n="credits.skip_to_main_content">Skip to main content</a>
+ <a href="#main-content" class="h-skip-link" data-i18n="credits.skip_to_main_content"
+ >Skip to main content</a
+ >
<header><div id="nav-container"></div></header>
<script src="/nav.js"></script>
@@ -435,9 +593,30 @@
</div>
</div>
+ <!-- Load failure: designed + actionable, with a real retry -->
+ <section id="error-state" class="card state-msg" hidden>
+ <h2 data-i18n="credits.we_could_not_load_your_credits">
+ We could not load your credits
+ </h2>
+ <p id="error-msg" data-i18n="credits.the_credits_service_did_not_respond">
+ The credits service did not respond. Your balance and history are safe; this
+ page just could not read them.
+ </p>
+ <button class="btn" id="retry-btn" type="button" data-i18n="credits.try_again">
+ Try again
+ </button>
+ <p class="state-links">
+ <a href="/status" data-i18n="credits.check_platform_status"
+ >Check platform status</a
+ >
+ </p>
+ </section>
+
<!-- Signed-out -->
<section id="signin-state" class="card signin" hidden>
- <p data-i18n="credits.sign_in_to_view_your_balance_and">Sign in to view your balance and top up.</p>
+ <p data-i18n="credits.sign_in_to_view_your_balance_and">
+ Sign in to view your balance and top up.
+ </p>
<p data-i18n-html="credits.sign_in"><a href="/login?next=/credits">Sign in →</a></p>
</section>
@@ -463,6 +642,16 @@
<div>
<h2 data-i18n="credits.what_credits_buy">What credits buy</h2>
<div class="buys" id="buys"></div>
+ <div
+ class="muted"
+ id="buys-empty"
+ style="font-size: 0.85rem"
+ hidden
+ data-i18n="credits.pricing_is_unavailable_right_now"
+ >
+ Pricing is unavailable right now. Deposits still credit at the
+ live USD value.
+ </div>
</div>
</div>
</section>
@@ -471,13 +660,34 @@
<section class="card" aria-label="Add credits">
<h2 data-i18n="credits.add_credits">Add credits</h2>
<div class="seg" role="group" aria-label="Deposit asset">
- <button type="button" data-asset="SOL" aria-pressed="true" data-i18n="credits.sol">SOL</button>
- <button type="button" data-asset="THREE" aria-pressed="false" data-i18n="credits.three">
+ <button
+ type="button"
+ data-asset="SOL"
+ aria-pressed="true"
+ data-i18n="credits.sol"
+ >
+ SOL
+ </button>
+ <button
+ type="button"
+ data-asset="THREE"
+ aria-pressed="false"
+ data-i18n="credits.three"
+ >
$THREE
</button>
</div>
<div class="field">
- <label for="amount" id="amount-label" data-i18n="credits.amount_sol">Amount (SOL)</label>
+ <label for="amount" id="amount-label"
+ ><span data-asset-label="SOL" data-i18n="credits.amount_sol"
+ >Amount (SOL)</span
+ ><span
+ data-asset-label="THREE"
+ data-i18n="credits.amount_three"
+ hidden
+ >Amount ($THREE)</span
+ ></label
+ >
<div class="amt-row">
<input
id="amount"
@@ -486,27 +696,71 @@
step="0.001"
inputmode="decimal"
placeholder="0.0"
+ aria-describedby="estimate"
/>
- <span class="unit" id="amount-unit" data-i18n="credits.sol_2">SOL</span>
+ <span class="unit" id="amount-unit"
+ ><span data-asset-unit="SOL" data-i18n="credits.sol_2">SOL</span
+ ><span
+ data-asset-unit="THREE"
+ data-i18n="credits.three_2"
+ hidden
+ >$THREE</span
+ ></span
+ >
</div>
<div class="quick" id="quick"></div>
<div class="est" id="estimate"></div>
</div>
- <button class="btn" id="deposit-btn" type="button" data-i18n="credits.connect_wallet_deposit">
+ <button
+ class="btn"
+ id="deposit-btn"
+ type="button"
+ data-i18n="credits.connect_wallet_deposit"
+ >
Connect wallet &amp; deposit
</button>
<div class="status" id="status" role="status" aria-live="polite"></div>
<details class="manual">
- <summary data-i18n="credits.already_sent_it_yourself_verify_by_signature">Already sent it yourself? Verify by signature</summary>
- <p class="muted" style="font-size: 0.82rem; margin: 0.6rem 0 0.3rem" data-i18n="credits.send_from_a_wallet_linked_to_your">
- Send from a wallet linked to your account to this three.ws
- deposit address, then paste the signature:
+ <summary
+ data-i18n="credits.already_sent_it_yourself_verify_by_signature"
+ >
+ Already sent it yourself? Verify by signature
+ </summary>
+ <p
+ class="muted"
+ style="font-size: 0.82rem; margin: 0.6rem 0 0.3rem"
+ data-i18n="credits.send_from_a_wallet_linked_to_your"
+ >
+ Send from a wallet linked to your account to this three.ws deposit
+ address, then paste the signature:
</p>
- <div class="addr" id="deposit-addr">—</div>
+ <div class="addr-row">
+ <div
+ class="addr"
+ id="deposit-addr"
+ data-i18n="credits.loading_deposit_address"
+ >
+ Loading the deposit address
+ </div>
+ <button
+ class="copy-addr"
+ id="copy-addr"
+ type="button"
+ disabled
+ data-i18n="credits.copy"
+ >
+ Copy
+ </button>
+ </div>
+ <label for="manual-sig" data-i18n="credits.transaction_signature"
+ >Transaction signature</label
+ >
<input
id="manual-sig"
type="text"
+ autocomplete="off"
+ spellcheck="false"
placeholder="Paste transaction signature"
/>
<button
@@ -514,14 +768,19 @@
id="verify-btn"
type="button"
style="margin-top: 0.6rem"
- data-i18n="credits.verify_deposit">
+ data-i18n="credits.verify_deposit"
+ >
Verify deposit
</button>
- <p class="muted" style="font-size: 0.76rem; margin: 0.5rem 0 0" data-i18n="credits.we_verify_on_chain_that_the_transaction">
- We verify on-chain that the transaction was signed by your
- linked wallet, so only you can claim your deposit — pasting
- someone else's signature won't credit your balance. Sent from a
- wallet that isn't linked yet? Sign in with it or link it first.
+ <p
+ class="muted"
+ style="font-size: 0.76rem; margin: 0.5rem 0 0"
+ data-i18n="credits.we_verify_on_chain_that_the_transaction"
+ >
+ We verify on-chain that the transaction was signed by your linked
+ wallet, so only you can claim your deposit. Pasting someone else's
+ signature won't credit your balance. Sent from a wallet that isn't
+ linked yet? Sign in with it or link it first.
</p>
</details>
</section>
@@ -531,29 +790,45 @@
<section class="card" style="margin-top: 1.1rem" aria-label="History">
<h2 data-i18n="credits.history">History</h2>
<div id="ledger-host">
- <table class="ledger" id="ledger" hidden>
- <thead>
- <tr>
- <th data-i18n="credits.when">When</th>
- <th data-i18n="credits.activity">Activity</th>
- <th style="text-align: right" data-i18n="credits.amount">Amount</th>
- <th style="text-align: right" data-i18n="credits.balance_2">Balance</th>
- </tr>
- </thead>
- <tbody id="ledger-body"></tbody>
- </table>
- <div class="empty" id="ledger-empty" hidden>
- No activity yet. Add credits to get started.
+ <div class="ledger-scroll">
+ <table class="ledger" id="ledger" hidden>
+ <thead>
+ <tr>
+ <th data-i18n="credits.when">When</th>
+ <th data-i18n="credits.activity">Activity</th>
+ <th style="text-align: right" data-i18n="credits.amount">
+ Amount
+ </th>
+ <th style="text-align: right" data-i18n="credits.balance_2">
+ Balance
+ </th>
+ </tr>
+ </thead>
+ <tbody id="ledger-body"></tbody>
+ </table>
</div>
- <button
- class="btn secondary"
- id="ledger-more"
- type="button"
+ <div
+ class="empty"
+ id="ledger-empty"
hidden
- data-i18n="credits.load_older"
+ data-i18n="credits.no_activity_yet_add_credits_to_get"
>
- Load older activity
+ No activity yet. Add credits above and every deposit, spend, and refund
+ shows up here.
+ </div>
+ <button class="btn secondary" id="ledger-more" type="button" hidden>
+ <span data-i18n="credits.load_older">Load older activity</span>
</button>
+ <p
+ class="empty"
+ id="ledger-error"
+ role="alert"
+ hidden
+ style="padding-top: 0.6rem"
+ data-i18n="credits.older_activity_did_not_load_try_again"
+ >
+ Older activity did not load. Try the button again.
+ </p>
</div>
</section>
</div>
@@ -572,6 +847,6 @@
<script src="/footer.js"></script>
<script type="module" src="/src/credits.js"></script>
<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
- <script type="module" src="/i18n.js"></script>
-</body>
+ <script type="module" src="/i18n.js"></script>
+ </body>
</html>
diff --git a/public/locales/en.json b/public/locales/en.json
index 1e35edd2d..e95f7f9d3 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -3573,19 +3573,26 @@
"already_sent_it_yourself_verify_by_signature": "Already sent it yourself? Verify by signature",
"amount": "Amount",
"amount_sol": "Amount (SOL)",
+ "amount_three": "Amount ($THREE)",
"balance": "Balance",
"balance_2": "Balance",
+ "check_platform_status": "Check platform status",
"connect_wallet_deposit": "Connect wallet & deposit",
+ "copy": "Copy",
"credits": "Credits",
"deposited": "Deposited",
"history": "History",
"load_older": "Load older activity",
+ "loading_deposit_address": "Loading the deposit address",
"meta_description": "Top up your three.ws balance with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for a discount on every spend.",
"meta_og_description": "Deposit SOL or $THREE for credits. Spend on Forge, agents, and compute. Hold $THREE for up to 30% off.",
"meta_og_title": "Credits · three.ws",
"meta_title": "Credits · three.ws",
"meta_twitter_description": "Top up with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for up to 30% off every spend.",
"meta_twitter_title": "Credits · three.ws",
+ "no_activity_yet_add_credits_to_get": "No activity yet. Add credits above and every deposit, spend, and refund shows up here.",
+ "older_activity_did_not_load_try_again": "Older activity did not load. Try the button again.",
+ "pricing_is_unavailable_right_now": "Pricing is unavailable right now. Deposits still credit at the live USD value.",
"send_from_a_wallet_linked_to_your": "Send from a wallet linked to your account to this three.ws deposit address, then paste the signature:",
"sign_in": "<a href=\"/login?next=/credits\">Sign in →</a>",
"sign_in_to_view_your_balance_and": "Sign in to view your balance and top up.",
@@ -3593,10 +3600,15 @@
"sol": "SOL",
"sol_2": "SOL",
"spent": "Spent",
+ "the_credits_service_did_not_respond": "The credits service did not respond. Your balance and history are safe; this page just could not read them.",
"three": "$THREE",
+ "three_2": "$THREE",
"top_up_with_sol_or_three_and": "Top up with SOL or $THREE and spend credits on 3D generation, agents, and compute. Hold $THREE for up to 30% off every spend.",
+ "transaction_signature": "Transaction signature",
+ "try_again": "Try again",
"verify_deposit": "Verify deposit",
- "we_verify_on_chain_that_the_transaction": "We verify on-chain that the transaction was signed by your linked wallet, so only you can claim your deposit — pasting someone else's signature won't credit your balance. Sent from a wallet that isn't linked yet? Sign in with it or link it first.",
+ "we_could_not_load_your_credits": "We could not load your credits",
+ "we_verify_on_chain_that_the_transaction": "We verify on-chain that the transaction was signed by your linked wallet, so only you can claim your deposit. Pasting someone else's signature won't credit your balance. Sent from a wallet that isn't linked yet? Sign in with it or link it first.",
"what_credits_buy": "What credits buy",
"when": "When"
},
diff --git a/src/credits.js b/src/credits.js
index 5a598596e..ac3579940 100644
--- a/src/credits.js
+++ b/src/credits.js
@@ -1,4 +1,4 @@
-// /credits — prepaid balance, deposit (SOL or $THREE → credits), and ledger.
+// /credits: prepaid balance, deposit (SOL or $THREE into credits), and ledger.
//
// Deposit flow reuses the platform Solana adapter (src/onchain/adapters): connect
// + inline SIWS link (so the signing wallet is linked, which the deposit verifier
@@ -64,34 +64,54 @@ function setStatus(msg, kind = 'work') {
el.className = `status ${kind}`;
}
-function renderTier(discountBps) {
+// The page's headline promise is the $THREE holder discount, so the pill states
+// the tier the caller is actually charged at, and nudges toward the next one
+// when they are not yet at the top. Hidden only when the tier cannot be read.
+function renderTier(holder) {
const pill = $('tier-pill');
- if (discountBps > 0) {
- pill.hidden = false;
- pill.textContent = `Holder discount active · ${(discountBps / 100).toFixed(0)}% off every spend`;
- } else {
+ if (!holder) {
pill.hidden = true;
+ return;
+ }
+ const bps = Number(holder.discount_bps) || 0;
+ const label = holder.tier?.label || 'Member';
+ if (bps > 0) {
+ pill.textContent = `${label} · ${(bps / 100).toFixed(0)}% off every spend`;
+ } else if (holder.next_tier && holder.usd_to_next > 0) {
+ pill.textContent = `${label} · hold ${fmtUsd(holder.usd_to_next)} more $THREE for ${holder.next_tier.label}`;
+ } else {
+ pill.textContent = `${label} · no holder discount yet`;
}
+ pill.hidden = false;
}
function renderBuys(buys) {
const host = $('buys');
host.innerHTML = '';
- if (!buys?.length) {
- host.innerHTML =
- '<div class="muted" style="font-size:0.85rem">Pricing loads shortly.</div>';
- return;
- }
+ $('buys-empty').hidden = Boolean(buys?.length);
+ if (!buys?.length) return;
for (const b of buys.slice(0, 8)) {
const row = document.createElement('div');
row.className = 'buy-row';
- row.innerHTML = `<span class="label"></span><span class="price"></span>`;
- row.querySelector('.label').textContent = b.label;
- row.querySelector('.price').textContent = fmtUsd(b.usd);
+ const label = document.createElement('span');
+ label.className = 'label';
+ label.textContent = b.label;
+ const price = document.createElement('span');
+ price.className = 'price';
+ price.textContent = fmtUsd(b.usd);
+ row.append(label, price);
host.appendChild(row);
}
}
+function cell(tr, className, text) {
+ const td = document.createElement('td');
+ if (className) td.className = className;
+ if (text != null) td.textContent = text;
+ tr.appendChild(td);
+ return td;
+}
+
function renderLedger(items, { append = false } = {}) {
const table = $('ledger');
const empty = $('ledger-empty');
@@ -107,64 +127,81 @@ function renderLedger(items, { append = false } = {}) {
for (const r of items) {
const tr = document.createElement('tr');
const credit = r.amount_usd >= 0;
- const sig = r.tx_signature
- ? `<a href="https://solscan.io/tx/${r.tx_signature}" target="_blank" rel="noopener">view</a>`
- : '';
- tr.innerHTML = `
- <td class="muted">${fmtWhen(r.created_at)}</td>
- <td>${escapeHtml(ledgerActivity(r))} ${sig}</td>
- <td class="amt ${credit ? 'pos' : 'neg'}">${credit ? '+' : '−'}${fmtUsd(Math.abs(r.amount_usd))}</td>
- <td class="amt">${fmtUsd(r.balance_after)}</td>`;
+ cell(tr, 'muted', fmtWhen(r.created_at));
+ const activity = cell(tr, null, ledgerActivity(r));
+ // Built as a node with an encoded signature rather than interpolated
+ // markup, so a ledger row can never inject HTML into the page.
+ if (r.tx_signature) {
+ activity.append(' ');
+ const link = document.createElement('a');
+ link.href = `https://solscan.io/tx/${encodeURIComponent(r.tx_signature)}`;
+ link.target = '_blank';
+ link.rel = 'noopener';
+ link.textContent = 'view';
+ activity.appendChild(link);
+ }
+ cell(
+ tr,
+ `amt ${credit ? 'pos' : 'neg'}`,
+ `${credit ? '+' : '\u2212'}${fmtUsd(Math.abs(r.amount_usd))}`,
+ );
+ cell(tr, 'amt', fmtUsd(r.balance_after));
body.appendChild(tr);
}
}
// The ledger is keyset-paginated (25 per page). Show the button only while the
// API hands back a cursor, so the last page ends cleanly with no dead control.
-// The label is captured from the DOM rather than hardcoded so the i18n catalog
-// (data-i18n on the button) still owns the copy in every locale.
+// The label lives in a child <span data-i18n>, so the busy affordance is a class
+// (`.is-busy` appends an ellipsis in CSS) and the catalog keeps owning the copy
+// in every locale.
function renderLedgerMore() {
const btn = $('ledger-more');
if (!btn) return;
- if (!btn.dataset.label) btn.dataset.label = btn.textContent.trim();
btn.hidden = !state.ledgerCursor;
btn.disabled = state.loadingMore;
btn.setAttribute('aria-busy', state.loadingMore ? 'true' : 'false');
- btn.textContent = state.loadingMore ? `${btn.dataset.label}\u2026` : btn.dataset.label;
+ btn.classList.toggle('is-busy', state.loadingMore);
}
async function loadMoreLedger() {
if (!state.ledgerCursor || state.loadingMore) return;
state.loadingMore = true;
+ $('ledger-error').hidden = true;
renderLedgerMore();
try {
- const r = await fetch(`/api/credits?cursor=${encodeURIComponent(state.ledgerCursor)}`, {
- credentials: 'include',
- });
+ const r = await fetchCredits(
+ `/api/credits?cursor=${encodeURIComponent(state.ledgerCursor)}`,
+ );
if (!r.ok) throw new Error('Could not load older activity.');
const data = await r.json();
state.ledgerCursor = data.next_cursor || null;
renderLedger(data.ledger, { append: true });
- } catch (err) {
- setStatus(err.message || 'Could not load older activity.', 'err');
+ } catch {
+ // Reported next to the ledger, not in the deposit card's status line, so
+ // the message sits where the failed control is. The button stays enabled
+ // so the retry is one click.
+ $('ledger-error').hidden = false;
} finally {
state.loadingMore = false;
renderLedgerMore();
}
}
-function escapeHtml(s) {
- return String(s).replace(
- /[&<>"]/g,
- (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c],
- );
-}
-
function renderAll(data) {
$('balance').textContent = fmtUsd(data.balance_usd);
$('lifetime-dep').textContent = fmtUsd(data.lifetime_deposited_usd);
$('lifetime-spent').textContent = fmtUsd(data.lifetime_spent_usd);
- $('deposit-addr').textContent = data.deposit?.wallet || 'Not configured';
+ const addr = $('deposit-addr');
+ const wallet = data.deposit?.wallet || '';
+ addr.textContent = wallet || 'Deposits are not configured right now.';
+ // From here the script owns this element, so the catalog pass (which lands
+ // after an async locale fetch) cannot revert a real address to its
+ // placeholder copy.
+ addr.dataset.i18nOwned = '1';
+ $('copy-addr').disabled = !wallet;
+ $('copy-addr').hidden = !wallet;
+ renderTier(data.holder);
renderBuys(data.buys);
state.ledgerCursor = data.next_cursor || null;
renderLedger(data.ledger);
@@ -193,17 +230,20 @@ function updateEstimate() {
const mint = state.asset === 'SOL' ? SOL_MINT : state.deposit?.three_mint;
const price = state.prices[mint];
const el = $('estimate');
+ const unit = state.asset === 'SOL' ? 'SOL' : '$THREE';
+ const fallback = 'Credited at the live USD value when your deposit confirms.';
+ el.textContent = '';
if (!(amt > 0)) {
- el.innerHTML = price
- ? `1 ${state.asset === 'SOL' ? 'SOL' : '$THREE'} ≈ ${fmtUsd(price)}`
- : 'Credited at the live USD value when your deposit confirms.';
+ el.textContent = price > 0 ? `1 ${unit} \u2248 ${fmtUsd(price)}` : fallback;
return;
}
- if (price > 0) {
- el.innerHTML = `≈ <b>${fmtUsd(amt * price)}</b> in credits`;
- } else {
- el.innerHTML = 'Credited at the live USD value when your deposit confirms.';
+ if (!(price > 0)) {
+ el.textContent = fallback;
+ return;
}
+ const strong = document.createElement('b');
+ strong.textContent = fmtUsd(amt * price);
+ el.append('\u2248 ', strong, ' in credits');
}
function setAsset(asset) {
@@ -211,8 +251,11 @@ function setAsset(asset) {
for (const btn of document.querySelectorAll('.seg button')) {
btn.setAttribute('aria-pressed', String(btn.dataset.asset === asset));
}
- $('amount-label').textContent = `Amount (${asset === 'SOL' ? 'SOL' : '$THREE'})`;
- $('amount-unit').textContent = asset === 'SOL' ? 'SOL' : '$THREE';
+ // Both asset variants ship in the HTML with their own catalog keys, so the
+ // swap is a visibility toggle and the copy stays localized.
+ for (const el of document.querySelectorAll('[data-asset-label], [data-asset-unit]')) {
+ el.hidden = (el.dataset.assetLabel || el.dataset.assetUnit) !== asset;
+ }
$('amount').step = asset === 'SOL' ? '0.001' : '1';
const quick = $('quick');
quick.innerHTML = '';
@@ -230,24 +273,76 @@ function setAsset(asset) {
loadPrices();
}
+// Exactly one of loading / signed-out / error / app is visible at any moment.
+function showState(name) {
+ $('loading-state').hidden = name !== 'loading';
+ $('signin-state').hidden = name !== 'signin';
+ $('error-state').hidden = name !== 'error';
+ $('app-state').hidden = name !== 'app';
+}
+
+// A failed load used to hide every panel and leave the page blank below the
+// heading, because the only status line lives inside the (hidden) app panel.
+function showError(message) {
+ const el = $('error-msg');
+ el.textContent =
+ message ||
+ 'The credits service did not respond. Your balance and history are safe; this page just could not read them.';
+ el.dataset.i18nOwned = '1';
+ showState('error');
+}
+
+// A dropped connection rejects with the browser's own "Failed to fetch", which
+// is not a message anyone can act on. Every throw out of here is designed copy.
+async function fetchCredits(path) {
+ try {
+ return await fetch(path, { credentials: 'include' });
+ } catch {
+ throw new Error(
+ navigator.onLine === false
+ ? 'You appear to be offline. Reconnect, then try again.'
+ : 'We could not reach three.ws. Check your connection, then try again.',
+ );
+ }
+}
+
async function refresh() {
- const r = await fetch('/api/credits', { credentials: 'include' });
+ const r = await fetchCredits('/api/credits');
if (r.status === 401) {
- $('loading-state').hidden = true;
- $('app-state').hidden = true;
- $('signin-state').hidden = false;
+ showState('signin');
return null;
}
- if (!r.ok) throw new Error('Could not load your credits.');
+ if (!r.ok) {
+ const body = await r.json().catch(() => ({}));
+ throw new Error(
+ body.error_description ||
+ (r.status === 429
+ ? 'Too many requests. Wait a moment, then try again.'
+ : 'We could not read your balance and history. Try again in a moment.'),
+ );
+ }
const data = await r.json();
state.deposit = data.deposit;
- $('loading-state').hidden = true;
- $('signin-state').hidden = true;
- $('app-state').hidden = false;
+ showState('app');
renderAll(data);
return data;
}
+async function reload() {
+ const btn = $('retry-btn');
+ btn.disabled = true;
+ btn.classList.add('is-busy');
+ try {
+ showState('loading');
+ await refresh();
+ } catch (err) {
+ showError(err?.message);
+ } finally {
+ btn.disabled = false;
+ btn.classList.remove('is-busy');
+ }
+}
+
async function buildSolTransfer({ web3, conn, from, to, amountSol }) {
const lamports = BigInt(Math.round(amountSol * web3.LAMPORTS_PER_SOL));
if (lamports <= 0n) throw new Error('Enter an amount greater than zero.');
@@ -388,7 +483,7 @@ async function doDeposit() {
// then; we poll the same endpoint on a real interval (not a fake progress bar)
// so credits apply automatically without the user re-submitting.
const FINALIZE_POLL_MS = 3000;
-const FINALIZE_MAX_TRIES = 12; // ~36s — covers finalization with margin
+const FINALIZE_MAX_TRIES = 12; // ~36s, which covers finalization with margin
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function verifyAndApply(txSignature, asset, attempt = 0) {
@@ -407,17 +502,17 @@ async function verifyAndApply(txSignature, asset, attempt = 0) {
if (data.pending) {
if (attempt >= FINALIZE_MAX_TRIES) {
setStatus(
- 'Your deposit is confirmed and credits the moment it finalizes on-chain — leave this page open, it updates automatically.',
+ 'Your deposit is confirmed. It credits the moment it finalizes on-chain, so leave this page open and it updates automatically.',
'work',
);
return;
}
- setStatus('Confirmed — finalizing on-chain…');
+ setStatus('Confirmed. Finalizing on-chain…');
await sleep(FINALIZE_POLL_MS);
return verifyAndApply(txSignature, asset, attempt + 1);
}
if (data.replay) {
- setStatus(`Already credited — balance ${fmtUsd(data.balance_usd)}.`, 'ok');
+ setStatus(`Already credited. Balance ${fmtUsd(data.balance_usd)}.`, 'ok');
} else {
setStatus(
`Added ${fmtUsd(data.credited_usd)} (${fmtAmount(data.amount)} ${asset}). New balance ${fmtUsd(data.balance_usd)}.`,
@@ -445,6 +540,33 @@ async function doManualVerify() {
}
}
+// Deposit addresses are 44 characters of base58 that nobody should retype.
+// Restores its own label after a moment so the control never looks stuck.
+let copyResetTimer = 0;
+async function copyDepositAddress() {
+ const wallet = state.deposit?.wallet;
+ if (!wallet) return;
+ const btn = $('copy-addr');
+ try {
+ await navigator.clipboard.writeText(wallet);
+ btn.textContent = 'Copied';
+ } catch {
+ // Clipboard permission denied (or an insecure origin): select the address
+ // so the copy is still one keystroke away.
+ const range = document.createRange();
+ range.selectNodeContents($('deposit-addr'));
+ const sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ btn.textContent = 'Selected';
+ }
+ btn.dataset.i18nOwned = '1';
+ clearTimeout(copyResetTimer);
+ copyResetTimer = setTimeout(() => {
+ btn.textContent = 'Copy';
+ }, 1800);
+}
+
function wire() {
for (const btn of document.querySelectorAll('.seg button')) {
btn.addEventListener('click', () => setAsset(btn.dataset.asset));
@@ -453,6 +575,8 @@ function wire() {
$('deposit-btn').addEventListener('click', doDeposit);
$('verify-btn').addEventListener('click', doManualVerify);
$('ledger-more').addEventListener('click', loadMoreLedger);
+ $('copy-addr').addEventListener('click', copyDepositAddress);
+ $('retry-btn').addEventListener('click', reload);
}
async function main() {
@@ -461,8 +585,7 @@ async function main() {
try {
await refresh();
} catch (err) {
- $('loading-state').hidden = true;
- setStatus(err?.message || 'Something went wrong loading your credits.', 'err');
+ showError(err?.message);
}
}