update
This commit is contained in:
parent
f8cb3764d9
commit
f1363a4f55
|
|
@ -17,6 +17,11 @@ function getXpub(coin: string): string {
|
|||
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 {
|
||||
const xpub = getXpub(coin === "xec" ? "xec" : coin);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Elysia, t } from "elysia";
|
||||
import sql from "./db";
|
||||
import { derive } from "./address";
|
||||
import { derive, hasXpub } from "./address";
|
||||
import { getExchangeRates, getAvailableCoins, fetchQrBase64 } from "./freedom";
|
||||
import { PLAN_PRICING as PLANS, COINS, planTier } from "../../shared/plans";
|
||||
import { generateReceipt } from "./receipt";
|
||||
|
|
@ -33,7 +33,7 @@ export const routes = new Elysia()
|
|||
.get("/coins", async () => {
|
||||
const [available, rates] = await Promise.all([getAvailableCoins(), getExchangeRates()]);
|
||||
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] }));
|
||||
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 (!hasXpub(coin)) { set.status = 400; return { error: `${coin} is not configured` }; }
|
||||
const available = await getAvailableCoins();
|
||||
if (!available.includes(coin)) { set.status = 400; return { error: `${coin} is temporarily unavailable` }; }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue