Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: various fixes #2515

Merged
merged 5 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/screens/Onboarding/Passphrase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const styles = StyleSheet.create({
flexGrow: 1,
},
scrollContent: {
flex: 1,
flexGrow: 1,
},
navigationContainer: {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Settings/ElectrumConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/screens/Wallets/LNURLPay/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -34,6 +33,7 @@ import {
getEstimatedRoutingFee,
sendMax,
} from '../../../utils/wallet/transactions';
import AssetButton from '../AssetButton';
import SendNumberPad from '../Send/SendNumberPad';
import UnitButton from '../UnitButton';

Expand Down Expand Up @@ -125,6 +125,9 @@ const LNURLAmount = ({
/>
</TouchableOpacity>
<View style={styles.actionButtons}>
<View style={styles.actionButtonContainer}>
<AssetButton style={styles.actionButton} spending={true} />
</View>
<View style={styles.actionButtonContainer}>
<UnitButton
style={styles.actionButton}
Expand Down
7 changes: 5 additions & 2 deletions src/screens/Wallets/LNURLWithdraw/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, {
useEffect,
} 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';
Expand All @@ -25,11 +25,11 @@ 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 { getNumberPadText } from '../../../utils/numberpad';
import { sendMax } from '../../../utils/wallet/transactions';
import AssetButton from '../AssetButton';
import SendNumberPad from '../Send/SendNumberPad';
import UnitButton from '../UnitButton';

Expand Down Expand Up @@ -103,6 +103,9 @@ const Amount = ({
/>
</TouchableOpacity>
<View style={styles.actionButtons}>
<View style={styles.actionButtonContainer}>
<AssetButton style={styles.actionButton} spending={true} />
</View>
<View style={styles.actionButtonContainer}>
<UnitButton
style={styles.actionButton}
Expand Down
5 changes: 2 additions & 3 deletions src/screens/Wallets/Send/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
useEffect,
} 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 ContactImage from '../../../components/ContactImage';
Expand Down Expand Up @@ -42,7 +42,6 @@ import {
utxosSelector,
} from '../../../store/reselect/wallet';
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';
Expand Down Expand Up @@ -257,7 +256,7 @@ const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {

<View style={styles.numberPad} testID="SendAmountNumberPad">
<View style={styles.actions}>
<TouchableOpacity color="transparent" onPress={onMaxAmount}>
<TouchableOpacity onPress={onMaxAmount}>
<Caption13Up style={styles.availableAmountText} color="secondary">
{t('send_available')}
</Caption13Up>
Expand Down
32 changes: 21 additions & 11 deletions src/utils/lightning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion src/utils/scanner/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export const processPaymentData = async ({
skipLightning?: boolean;
showErrors?: boolean;
}): Promise<Result<TPaymentUri>> => {
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;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,27 +1288,27 @@ 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
reserveBalance: number; // Share of lightning funds that are locked up in channels
// 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;
Expand Down
9 changes: 4 additions & 5 deletions src/utils/wallet/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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'));
Expand Down
Loading