diff --git a/src/screens/Onboarding/Passphrase.tsx b/src/screens/Onboarding/Passphrase.tsx index 4c2f89056..627aea379 100644 --- a/src/screens/Onboarding/Passphrase.tsx +++ b/src/screens/Onboarding/Passphrase.tsx @@ -105,7 +105,6 @@ const styles = StyleSheet.create({ flexGrow: 1, }, scrollContent: { - flex: 1, flexGrow: 1, }, navigationContainer: { diff --git a/src/screens/Settings/ElectrumConfig/index.tsx b/src/screens/Settings/ElectrumConfig/index.tsx index d3ae31fe9..de284365f 100644 --- a/src/screens/Settings/ElectrumConfig/index.tsx +++ b/src/screens/Settings/ElectrumConfig/index.tsx @@ -53,7 +53,7 @@ const isValidURL = (data: string): boolean => { // Allow standard domains, custom TLDs like .local, and IPv4 addresses const isValidDomainOrIP = !!url.hostname.match( - /^([a-z\d]([a-z\d-]*[a-z\d])*\.[a-z\d-]+|(\d{1,3}\.){3}\d{1,3})$/i, + /^([a-z\d]([a-z\d-]*[a-z\d])*\.)+[a-z\d-]+|(\d{1,3}\.){3}\d{1,3}$/i, ); // Always allow .local domains diff --git a/src/screens/Wallets/LNURLPay/Amount.tsx b/src/screens/Wallets/LNURLPay/Amount.tsx index 9cb7300f5..f0d3f091a 100644 --- a/src/screens/Wallets/LNURLPay/Amount.tsx +++ b/src/screens/Wallets/LNURLPay/Amount.tsx @@ -6,7 +6,7 @@ import React, { useState, } from 'react'; import { useTranslation } from 'react-i18next'; -import { StyleSheet, View } from 'react-native'; +import { StyleSheet, TouchableOpacity, View } from 'react-native'; import BottomSheetNavigationHeader from '../../../components/BottomSheetNavigationHeader'; import GradientView from '../../../components/GradientView'; @@ -25,7 +25,6 @@ import { unitSelector, } from '../../../store/reselect/settings'; import { IColors } from '../../../styles/colors'; -import { TouchableOpacity } from '../../../styles/components'; import { Caption13Up } from '../../../styles/text'; import { convertToSats } from '../../../utils/conversion'; import { showToast } from '../../../utils/notifications'; @@ -34,6 +33,7 @@ import { getEstimatedRoutingFee, sendMax, } from '../../../utils/wallet/transactions'; +import AssetButton from '../AssetButton'; import SendNumberPad from '../Send/SendNumberPad'; import UnitButton from '../UnitButton'; @@ -125,6 +125,9 @@ const LNURLAmount = ({ /> + + + + + + ): ReactElement => { - + {t('send_available')} diff --git a/src/utils/lightning/index.ts b/src/utils/lightning/index.ts index 9357cd8e9..fb86756a8 100644 --- a/src/utils/lightning/index.ts +++ b/src/utils/lightning/index.ts @@ -1663,17 +1663,6 @@ export const recoverOutputsFromForceClose = async (): Promise< return await lm.recoverOutputsFromForceClose(); }; -/** - * Returns total reserve balance for all open lightning channels. - * @returns {number} - */ -export const getLightningReserveBalance = (): number => { - const openChannels = getOpenChannels(); - const result = reduceValue(openChannels, 'unspendable_punishment_reserve'); - const reserveBalance = result.isOk() ? result.value : 0; - return reserveBalance; -}; - /** * Returns the claimable balance for all lightning channels. * @param {boolean} [ignoreOpenChannels] @@ -1797,3 +1786,24 @@ export const getLightningBalance = ({ return { localBalance, remoteBalance }; }; + +/** + * Returns total reserve balance for all open lightning channels. + * @returns {number} + */ +export const getLightningReserveBalance = (): number => { + const openChannels = getOpenChannels(); + const result = reduceValue(openChannels, 'unspendable_punishment_reserve'); + const reserveBalance = result.isOk() ? result.value : 0; + return reserveBalance; +}; + +/** + * Returns total spending balance for all open lightning channels. + * @returns {number} + */ +export const getSpendingBalance = (): number => { + const { localBalance } = getLightningBalance(); + const reserveBalance = getLightningReserveBalance(); + return localBalance - reserveBalance; +}; diff --git a/src/utils/scanner/scanner.ts b/src/utils/scanner/scanner.ts index 0114ca728..064c4f895 100644 --- a/src/utils/scanner/scanner.ts +++ b/src/utils/scanner/scanner.ts @@ -386,7 +386,7 @@ export const processPaymentData = async ({ skipLightning?: boolean; showErrors?: boolean; }): Promise> => { - let { onchainBalance, spendingBalance } = getBalance(); + let { onchainBalance, spendingBalance } = await getBalance(); const isUnified = data.type === EQRDataType.unified; const isOnchain = data.type === EQRDataType.onchain; const isLightning = data.type === EQRDataType.lightning; diff --git a/src/utils/wallet/index.ts b/src/utils/wallet/index.ts index 6df9654ff..bab7ff832 100644 --- a/src/utils/wallet/index.ts +++ b/src/utils/wallet/index.ts @@ -1288,13 +1288,13 @@ export const getCurrentAddressIndex = async ({ * @param {TWalletName} [selectedWallet] * @param {EAvailableNetwork} [selectedNetwork] */ -export const getBalance = ({ +export const getBalance = async ({ selectedWallet = getSelectedWallet(), selectedNetwork = getSelectedNetwork(), }: { selectedWallet?: TWalletName; selectedNetwork?: EAvailableNetwork; -} = {}): { +} = {}): Promise<{ onchainBalance: number; // Total onchain funds // lightningBalance: number; // Total lightning funds (spendable + reserved + claimable) spendingBalance: number; // Share of lightning funds that are spendable @@ -1302,13 +1302,13 @@ export const getBalance = ({ // claimableBalance: number; // Funds that will be available after a channel opens/closes spendableBalance: number; // Total spendable funds (onchain + spendable lightning) // totalBalance: number; // Total funds (all of the above) -} => { +}> => { const { currentWallet } = getCurrentWallet({ selectedWallet, selectedNetwork, }); - const wallet = getOnChainWallet(); + const wallet = await getOnChainWalletAsync(); const { localBalance } = getLightningBalance(); const reserveBalance = getLightningReserveBalance(); const spendingBalance = localBalance - reserveBalance; diff --git a/src/utils/wallet/transactions.ts b/src/utils/wallet/transactions.ts index 7c50f774e..d3f754379 100644 --- a/src/utils/wallet/transactions.ts +++ b/src/utils/wallet/transactions.ts @@ -26,11 +26,11 @@ import { EBackupCategory } from '../../store/types/backup'; import { ETransactionSpeed } from '../../store/types/settings'; import { reduceValue } from '../helpers'; import i18n from '../i18n'; +import { getSpendingBalance } from '../lightning'; import { EAvailableNetwork } from '../networks'; import { showToast } from '../notifications'; import { TRANSACTION_DEFAULTS } from './constants'; import { - getBalance, getOnChainWallet, getOnChainWalletElectrum, getOnChainWalletTransaction, @@ -294,7 +294,7 @@ export const getMaxSendAmount = ({ if (method === 'lightning') { // lightning transaction - const { spendingBalance } = getBalance(); + const spendingBalance = getSpendingBalance(); const fee = getEstimatedRoutingFee(spendingBalance); const amount = spendingBalance - fee; const maxAmount = { amount, fee }; @@ -351,8 +351,7 @@ export const sendMax = async ({ // TODO: Re-work lightning transaction invoices once beignet migration is complete. // Handle max toggle for lightning invoice if (paymentMethod === 'lightning') { - const { spendingBalance } = getBalance(); - + const spendingBalance = getSpendingBalance(); const fee = getEstimatedRoutingFee(spendingBalance); const amount = spendingBalance - fee; @@ -457,7 +456,7 @@ export const updateSendAmount = ({ if (paymentMethod === 'lightning') { // lightning transaction - const { spendingBalance } = getBalance(); + const spendingBalance = getSpendingBalance(); if (amount > spendingBalance) { return err(i18n.t('wallet:send_amount_error_balance'));