From b7b4e4688d4fef9387f7f273e83a29325380b376 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Sat, 10 Aug 2024 09:00:56 +0200 Subject: [PATCH] support staging --- lib/validate.js | 26 ++++++++++++++++++++++++++ wallets/blink/index.js | 7 ++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/validate.js b/lib/validate.js index 559e69f9d..f1165ff00 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -694,6 +694,32 @@ export const blinkSchema = object({ }) }) +export const blinkStagingSchema = object({ + apiKey: string() + .required('required') + .test(async (nwcUrl, context) => { + try { + await string().required('required').validate(nwcUrl) + await string().matches(/^galoy_staging_[A-Za-z0-9]+$/, { message: 'must match pattern galoy_staging_A-Za-z0-9' }).validate(nwcUrl) + } catch (err) { + return context.createError({ message: err.message }) + } + return true + }), + currency: string() + .transform(value => value.toUpperCase()) + .default('BTC') + .test(async (currency, context) => { + try { + const supportedCurrencies = ['USD', 'BTC'] + await string().required('required').oneOf(supportedCurrencies, 'must be one of ' + supportedCurrencies.join(', ')).validate(currency) + } catch (err) { + return context.createError({ message: err.message }) + } + return true + }) +}) + export const lncSchema = object({ pairingPhrase: array() .transform(function (value, originalValue) { diff --git a/wallets/blink/index.js b/wallets/blink/index.js index 554748d6b..01c1840b0 100644 --- a/wallets/blink/index.js +++ b/wallets/blink/index.js @@ -1,6 +1,7 @@ -import { blinkSchema } from '@/lib/validate' +import { blinkSchema, blinkStagingSchema } from '@/lib/validate' -export const galoyBlinkUrl = '' +export const galoyStaging = false +export const galoyBlinkUrl = galoyStaging ? 'https://api.staging.galoy.io/graphql' : 'https://api.blink.sv/graphql' export const galoyBlinkDashboardUrl = 'https://dashboard.blink.sv/' export const name = 'blink' @@ -30,4 +31,4 @@ export const card = { badges: ['send only'] } -export const fieldValidation = blinkSchema +export const fieldValidation = galoyStaging ? blinkStagingSchema : blinkSchema