Compare commits

..

No commits in common. "84e6e81f04689a5b2e318252bfcf61357ab02af4" and "eb3f1cf0300b1939be88668c7bae630f73776dea" have entirely different histories.

12 changed files with 43 additions and 147 deletions

View file

@ -33,18 +33,7 @@ const Main = () => {
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [restrictionLevel, setRestrictionLevel] = useState(null) const [restrictionLevel, setRestrictionLevel] = useState(null)
// Skip auth queries on unauthenticated pages (like /register and /login)
const isPublicPage = location.startsWith('/register') || location.startsWith('/login')
// Set loading to false immediately for public pages
React.useEffect(() => {
if (isPublicPage) {
setLoading(false)
}
}, [isPublicPage])
useQuery(GET_USER_DATA, { useQuery(GET_USER_DATA, {
skip: isPublicPage,
onCompleted: userResponse => { onCompleted: userResponse => {
if (!userData && userResponse?.userData) { if (!userData && userResponse?.userData) {
setUserData(userResponse.userData) setUserData(userResponse.userData)
@ -54,10 +43,6 @@ const Main = () => {
} }
setLoading(false) setLoading(false)
}, },
onError: () => {
// If query fails, just mark as not loading
setLoading(false)
},
}) })
const sidebar = hasSidebar(location) const sidebar = hasSidebar(location)

View file

@ -83,11 +83,6 @@ const LoginState = ({ dispatch, strategy }) => {
if (!loginResponse.login) return if (!loginResponse.login) return
// Handle SKIP2FA case - directly get user data and navigate
if (loginResponse.login === 'SKIP2FA') {
return getUserData()
}
return dispatch({ return dispatch({
type: loginResponse.login, type: loginResponse.login,
payload: { payload: {

View file

@ -11,7 +11,6 @@ import inforu from './inforu'
import infura from './infura' import infura from './infura'
import _itbit from './itbit' import _itbit from './itbit'
import _kraken from './kraken' import _kraken from './kraken'
import lnbits from './lnbits'
import mailgun from './mailgun' import mailgun from './mailgun'
import scorechain from './scorechain' import scorechain from './scorechain'
import sumsub from './sumsub' import sumsub from './sumsub'
@ -32,7 +31,6 @@ const schemas = (markets = {}) => {
return { return {
[bitgo.code]: bitgo, [bitgo.code]: bitgo,
[galoy.code]: galoy, [galoy.code]: galoy,
[lnbits.code]: lnbits,
[bitstamp.code]: bitstamp, [bitstamp.code]: bitstamp,
[blockcypher.code]: blockcypher, [blockcypher.code]: blockcypher,
[elliptic.code]: elliptic, [elliptic.code]: elliptic,

View file

@ -1,36 +0,0 @@
import * as Yup from 'yup'
import {
SecretInput,
TextInput,
} from '../../../components/inputs/formik'
import { secretTest } from './helper'
export default {
code: 'lnbits',
name: 'LNBits',
title: 'LNBits (Wallet)',
elements: [
{
code: 'endpoint',
display: 'LNBits Server URL',
component: TextInput,
},
{
code: 'adminKey',
display: 'Admin Key',
component: SecretInput,
},
],
getValidationSchema: account => {
return Yup.object().shape({
endpoint: Yup.string('The endpoint must be a string')
.max(200, 'The endpoint is too long')
.required('The endpoint is required'),
adminKey: Yup.string('The Admin Key must be a string')
.max(200, 'The Admin Key is too long')
.test(secretTest(account?.adminKey)),
})
},
}

View file

@ -36,7 +36,7 @@ const SAVE_ACCOUNTS = gql`
` `
const isConfigurable = it => const isConfigurable = it =>
R.includes(it)(['infura', 'bitgo', 'trongrid', 'galoy', 'lnbits']) R.includes(it)(['infura', 'bitgo', 'trongrid', 'galoy'])
const isLocalHosted = it => const isLocalHosted = it =>
R.includes(it)([ R.includes(it)([
@ -178,19 +178,6 @@ const ChooseWallet = ({ data: currentData, addData }) => {
/> />
</> </>
)} )}
{selected === 'lnbits' && (
<>
<H4 noMargin>Enter wallet information</H4>
<FormRenderer
value={accounts.lnbits}
save={saveWallet(selected)}
elements={schema.lnbits.elements}
validationSchema={schema.lnbits.getValidationSchema(accounts.lnbits)}
buttonLabel={'Continue'}
buttonClass={classes.formButton}
/>
</>
)}
</div> </div>
) )
} }

View file

@ -103,7 +103,6 @@ const ALL_ACCOUNTS = [
cryptos: [BTC, ZEC, LTC, BCH, DASH], cryptos: [BTC, ZEC, LTC, BCH, DASH],
}, },
{ code: 'galoy', display: 'Galoy', class: WALLET, cryptos: [LN] }, { code: 'galoy', display: 'Galoy', class: WALLET, cryptos: [LN] },
{ code: 'lnbits', display: 'LNBits', class: WALLET, cryptos: [LN] },
{ {
code: 'bitstamp', code: 'bitstamp',
display: 'Bitstamp', display: 'Bitstamp',

View file

@ -10,7 +10,6 @@ const users = require('../../../users')
const sessionManager = require('../../../session-manager') const sessionManager = require('../../../session-manager')
const authErrors = require('../errors') const authErrors = require('../errors')
const credentials = require('../../../hardware-credentials') const credentials = require('../../../hardware-credentials')
const { skip2fa } = require('../../../environment-helper')
const REMEMBER_ME_AGE = 90 * T.day const REMEMBER_ME_AGE = 90 * T.day
@ -163,25 +162,15 @@ const deleteSession = (sessionID, context) => {
return sessionManager.deleteSessionById(sessionID) return sessionManager.deleteSessionById(sessionID)
} }
const login = (username, password, context) => { const login = (username, password) => {
return authenticateUser(username, password) return authenticateUser(username, password)
.then(user => { .then(user => {
// Skip 2FA if environment variable is set
if (skip2fa) {
initializeSession(context, user, false)
return 'SKIP2FA'
}
return Promise.all([ return Promise.all([
credentials.getHardwareCredentialsByUserId(user.id), credentials.getHardwareCredentialsByUserId(user.id),
user.twofa_code, user.twofa_code,
]) ])
}) })
.then(result => { .then(([devices, twoFASecret]) => {
// If we already handled skip2fa, return the result
if (result === 'SKIP2FA') return result
const [devices, twoFASecret] = result
if (!_.isEmpty(devices)) return 'FIDO' if (!_.isEmpty(devices)) return 'FIDO'
return twoFASecret ? 'INPUT2FA' : 'SETUP2FA' return twoFASecret ? 'INPUT2FA' : 'SETUP2FA'
}) })

View file

@ -124,8 +124,8 @@ const resolver = {
sessionManager.deleteSessionsByUsername(username), sessionManager.deleteSessionsByUsername(username),
changeUserRole: (...[, { confirmationCode, id, newRole }, context]) => changeUserRole: (...[, { confirmationCode, id, newRole }, context]) =>
userManagement.changeUserRole(confirmationCode, id, newRole, context), userManagement.changeUserRole(confirmationCode, id, newRole, context),
login: (...[, { username, password }, context]) => login: (...[, { username, password }]) =>
userManagement.login(username, password, context), userManagement.login(username, password),
input2FA: (...[, { username, password, rememberMe, code }, context]) => input2FA: (...[, { username, password, rememberMe, code }, context]) =>
userManagement.input2FA(username, password, rememberMe, code, context), userManagement.input2FA(username, password, rememberMe, code, context),
setup2FA: ( setup2FA: (

View file

@ -5,15 +5,7 @@ const { machines } = require('typesafe-db')
const CACHE_DURATION = 30 * 60 * 1000 const CACHE_DURATION = 30 * 60 * 1000
const _getHighestRestrictionLevel = async () => { const _getHighestRestrictionLevel = async () => {
try { return machines.getHighestRestrictionLevel()
const level = await machines.getHighestRestrictionLevel()
// Return 0 if null/undefined (no machines in database)
return level ?? 0
} catch (err) {
// Log error and return 0 for empty database or other errors
console.error('Error fetching restriction level:', err.message)
return 0
}
} }
const getCachedRestrictionLevel = mem(_getHighestRestrictionLevel, { const getCachedRestrictionLevel = mem(_getHighestRestrictionLevel, {

View file

@ -93,11 +93,11 @@ async function newAddress(account, info, tx) {
const endpoint = `${account.endpoint}/api/v1/payments` const endpoint = `${account.endpoint}/api/v1/payments`
const result = await request(endpoint, 'POST', invoiceData, account.adminKey) const result = await request(endpoint, 'POST', invoiceData, account.adminKey)
if (!result.bolt11) { if (!result.payment_request) {
throw new Error('LNBits did not return a bolt11 invoice') throw new Error('LNBits did not return a payment request')
} }
return result.bolt11 return result.payment_request
} }
async function getStatus(account, tx) { async function getStatus(account, tx) {
@ -131,44 +131,12 @@ async function getStatus(account, tx) {
} }
} }
async function sendLNURL(account, lnurl, cryptoAtoms) {
validateConfig(account)
const paymentData = {
lnurl: lnurl,
amount: parseInt(cryptoAtoms.toString()) * 1000, // Convert satoshis to millisatoshis
comment: `Lamassu ATM - ${new Date().toISOString()}`
}
const endpoint = `${account.endpoint}/api/v1/payments/lnurl`
const result = await request(endpoint, 'POST', paymentData, account.adminKey)
if (!result.payment_hash) {
throw new Error('LNBits LNURL payment failed: No payment hash returned')
}
return {
txid: result.payment_hash,
fee: result.fee_msat ? Math.ceil(result.fee_msat / 1000) : 0
}
}
async function sendCoins(account, tx) { async function sendCoins(account, tx) {
validateConfig(account) validateConfig(account)
const { toAddress, cryptoAtoms, cryptoCode } = tx const { toAddress, cryptoAtoms, cryptoCode } = tx
await checkCryptoCode(cryptoCode) await checkCryptoCode(cryptoCode)
// Handle LNURL addresses
if (isLnurl(toAddress)) {
return sendLNURL(account, toAddress, cryptoAtoms)
}
// Handle bolt11 invoices
if (!isLnInvoice(toAddress)) {
throw new Error('Invalid Lightning address: must be bolt11 invoice or LNURL')
}
const paymentData = { const paymentData = {
out: true, out: true,
bolt11: toAddress bolt11: toAddress
@ -221,9 +189,10 @@ async function newFunding(account, cryptoCode) {
const [walletBalance, fundingAddress] = await Promise.all(promises) const [walletBalance, fundingAddress] = await Promise.all(promises)
return { return {
fundingPendingBalance: new BN(0), fundingAddress,
fundingConfirmedBalance: walletBalance, fundingAddressQr: fundingAddress,
fundingAddress confirmed: walletBalance.gte(0),
confirmedBalance: walletBalance.toString()
} }
} }

View file

@ -1,17 +1,36 @@
const { saveConfig } = require('../lib/new-settings-loader') const db = require('./db')
exports.up = function (next) { exports.up = function (next) {
const config = { const sql = `
'lnbits_endpoint': '', INSERT INTO user_config (name, display_name, type, data_type, config_type, enabled, secret, options)
'lnbits_adminKey': '', VALUES
'LN_wallet': 'lnbits' ('lnbitsEndpoint', 'LNBits Server URL', 'text', 'string', 'wallets', false, false, null),
} ('lnbitsAdminKey', 'LNBits Admin Key', 'text', 'string', 'wallets', false, true, null)
ON CONFLICT (name) DO NOTHING;
saveConfig(config).then(next).catch(next) -- Add LNBits as a valid wallet option for Lightning Network
INSERT INTO user_config (name, display_name, type, data_type, config_type, enabled, secret, options)
VALUES
('LN_wallet', 'Lightning Network Wallet', 'text', 'string', 'wallets', true, false,
'[{"code": "lnbits", "display": "LNBits"}, {"code": "galoy", "display": "Galoy (Blink)"}, {"code": "bitcoind", "display": "Bitcoin Core"}]')
ON CONFLICT (name)
DO UPDATE SET options = EXCLUDED.options
WHERE user_config.options NOT LIKE '%lnbits%';
`
db.multi(sql, next)
} }
exports.down = function (next) { exports.down = function (next) {
// No-op - removing config entries is not typically done in down migrations const sql = `
// as it could break existing configurations DELETE FROM user_config
next() WHERE name IN ('lnbitsEndpoint', 'lnbitsAdminKey');
-- Remove LNBits from wallet options
UPDATE user_config
SET options = REPLACE(options, ', {"code": "lnbits", "display": "LNBits"}', '')
WHERE name = 'LN_wallet';
`
db.multi(sql, next)
} }

View file

@ -31,7 +31,6 @@
"bchaddrjs": "^0.3.0", "bchaddrjs": "^0.3.0",
"bignumber.js": "9.0.1", "bignumber.js": "9.0.1",
"bip39": "^2.3.1", "bip39": "^2.3.1",
"bolt11": "^1.4.1",
"ccxt": "2.9.16", "ccxt": "2.9.16",
"compression": "^1.7.4", "compression": "^1.7.4",
"connect-pg-simple": "^6.2.1", "connect-pg-simple": "^6.2.1",