From 5c93f29209547c6ab6d6e59c00556c59bdd20ea2 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Fri, 19 Dec 2025 15:25:39 +0000 Subject: [PATCH] cleanup --- src/services/main/settings.ts | 40 +++++++++++++++-------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/services/main/settings.ts b/src/services/main/settings.ts index e852de16..3ee4126e 100644 --- a/src/services/main/settings.ts +++ b/src/services/main/settings.ts @@ -171,34 +171,28 @@ export type LiquiditySettings = { } export const LoadLiquiditySettingsFromEnv = (dbEnv: Record, addToDb?: EnvCacher): LiquiditySettings => { const providerNprofile = chooseEnv("PROVIDER_NPROFILE", dbEnv, "nprofile1qyd8wumn8ghj7um5wfn8y7fwwd5x7cmt9ehx2arhdaexkqpqwmk5tuqvafa6ckwc6zmaypyy3af3n4aeds2ql7m0ew42kzsn638q9s9z8p", addToDb) - - // Decode nprofile to extract pubkey and relay URL - let liquidityProviderPub = "" - let providerRelayUrl = "" - if (providerNprofile) { - try { - const decoded = nip19.decode(providerNprofile) - if (decoded.type === 'nprofile') { - liquidityProviderPub = decoded.data.pubkey - if (decoded.data.relays && decoded.data.relays.length > 0) { - providerRelayUrl = decoded.data.relays[0] - } else { - throw new Error("PROVIDER_NPROFILE must contain at least one relay") - } - } else { - throw new Error("PROVIDER_NPROFILE must be a valid nprofile") - } - } catch (e) { - throw new Error(`Failed to decode PROVIDER_NPROFILE as nprofile: ${e}`) - } - } - + const { liquidityProviderPub, providerRelayUrl } = decodeNprofile(providerNprofile) + const disableLiquidityProvider = chooseEnvBool("DISABLE_LIQUIDITY_PROVIDER", dbEnv, false, addToDb) || liquidityProviderPub === "null" const useOnlyLiquidityProvider = chooseEnvBool("USE_ONLY_LIQUIDITY_PROVIDER", dbEnv, false, addToDb) - + return { liquidityProviderPub, useOnlyLiquidityProvider, disableLiquidityProvider, providerRelayUrl } } +const decodeNprofile = (nprofile: string) => { + const decoded = nip19.decode(nprofile) + if (decoded.type !== 'nprofile') { + throw new Error("PROVIDER_NPROFILE must be a valid nprofile") + } + if (!decoded.data.pubkey) { + throw new Error("PROVIDER_NPROFILE must contain a pubkey") + } + if (!decoded.data.relays || decoded.data.relays.length === 0) { + throw new Error("PROVIDER_NPROFILE must contain at least one relay") + } + return { liquidityProviderPub: decoded.data.pubkey, providerRelayUrl: decoded.data.relays[0] } +} + export type SwapsSettings = { boltzHttpUrl: string boltzWebSocketUrl: string