This commit is contained in:
nate 2026-04-11 02:28:23 +04:00
parent f8cb3764d9
commit f1363a4f55
2 changed files with 8 additions and 2 deletions

View File

@ -17,6 +17,11 @@ function getXpub(coin: string): string {
return val; return val;
} }
export function hasXpub(coin: string): boolean {
const key = `XPUB_${coin.toUpperCase()}`;
return !!process.env[key];
}
export function derive(coin: string, index: number): string { export function derive(coin: string, index: number): string {
const xpub = getXpub(coin === "xec" ? "xec" : coin); const xpub = getXpub(coin === "xec" ? "xec" : coin);

View File

@ -1,6 +1,6 @@
import { Elysia, t } from "elysia"; import { Elysia, t } from "elysia";
import sql from "./db"; import sql from "./db";
import { derive } from "./address"; import { derive, hasXpub } from "./address";
import { getExchangeRates, getAvailableCoins, fetchQrBase64 } from "./freedom"; import { getExchangeRates, getAvailableCoins, fetchQrBase64 } from "./freedom";
import { PLAN_PRICING as PLANS, COINS, planTier } from "../../shared/plans"; import { PLAN_PRICING as PLANS, COINS, planTier } from "../../shared/plans";
import { generateReceipt } from "./receipt"; import { generateReceipt } from "./receipt";
@ -33,7 +33,7 @@ export const routes = new Elysia()
.get("/coins", async () => { .get("/coins", async () => {
const [available, rates] = await Promise.all([getAvailableCoins(), getExchangeRates()]); const [available, rates] = await Promise.all([getAvailableCoins(), getExchangeRates()]);
const coins = Object.entries(COINS) const coins = Object.entries(COINS)
.filter(([k]) => available.includes(k)) .filter(([k]) => available.includes(k) && hasXpub(k))
.map(([k, v]) => ({ id: k, ...v, rate: rates[k] })); .map(([k, v]) => ({ id: k, ...v, rate: rates[k] }));
return { coins, plans: PLANS }; return { coins, plans: PLANS };
}) })
@ -55,6 +55,7 @@ export const routes = new Elysia()
} }
if (!COINS[coin]) { set.status = 400; return { error: `Unknown coin: ${coin}` }; } if (!COINS[coin]) { set.status = 400; return { error: `Unknown coin: ${coin}` }; }
if (!hasXpub(coin)) { set.status = 400; return { error: `${coin} is not configured` }; }
const available = await getAvailableCoins(); const available = await getAvailableCoins();
if (!available.includes(coin)) { set.status = 400; return { error: `${coin} is temporarily unavailable` }; } if (!available.includes(coin)) { set.status = 400; return { error: `${coin} is temporarily unavailable` }; }