Skip to content

Commit 27e15f7

Browse files
authored
Merge pull request #2515 from synonymdev/fix/various-fixes
fix: various fixes
2 parents 9272e1e + 0c00646 commit 27e15f7

File tree

9 files changed

+43
-30
lines changed

9 files changed

+43
-30
lines changed

src/screens/Onboarding/Passphrase.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const styles = StyleSheet.create({
105105
flexGrow: 1,
106106
},
107107
scrollContent: {
108-
flex: 1,
109108
flexGrow: 1,
110109
},
111110
navigationContainer: {

src/screens/Settings/ElectrumConfig/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const isValidURL = (data: string): boolean => {
5353

5454
// Allow standard domains, custom TLDs like .local, and IPv4 addresses
5555
const isValidDomainOrIP = !!url.hostname.match(
56-
/^([a-z\d]([a-z\d-]*[a-z\d])*\.[a-z\d-]+|(\d{1,3}\.){3}\d{1,3})$/i,
56+
/^([a-z\d]([a-z\d-]*[a-z\d])*\.)+[a-z\d-]+|(\d{1,3}\.){3}\d{1,3}$/i,
5757
);
5858

5959
// Always allow .local domains

src/screens/Wallets/LNURLPay/Amount.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React, {
66
useState,
77
} from 'react';
88
import { useTranslation } from 'react-i18next';
9-
import { StyleSheet, View } from 'react-native';
9+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
1010

1111
import BottomSheetNavigationHeader from '../../../components/BottomSheetNavigationHeader';
1212
import GradientView from '../../../components/GradientView';
@@ -25,7 +25,6 @@ import {
2525
unitSelector,
2626
} from '../../../store/reselect/settings';
2727
import { IColors } from '../../../styles/colors';
28-
import { TouchableOpacity } from '../../../styles/components';
2928
import { Caption13Up } from '../../../styles/text';
3029
import { convertToSats } from '../../../utils/conversion';
3130
import { showToast } from '../../../utils/notifications';
@@ -34,6 +33,7 @@ import {
3433
getEstimatedRoutingFee,
3534
sendMax,
3635
} from '../../../utils/wallet/transactions';
36+
import AssetButton from '../AssetButton';
3737
import SendNumberPad from '../Send/SendNumberPad';
3838
import UnitButton from '../UnitButton';
3939

@@ -125,6 +125,9 @@ const LNURLAmount = ({
125125
/>
126126
</TouchableOpacity>
127127
<View style={styles.actionButtons}>
128+
<View style={styles.actionButtonContainer}>
129+
<AssetButton style={styles.actionButton} spending={true} />
130+
</View>
128131
<View style={styles.actionButtonContainer}>
129132
<UnitButton
130133
style={styles.actionButton}

src/screens/Wallets/LNURLWithdraw/Amount.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React, {
77
useEffect,
88
} from 'react';
99
import { useTranslation } from 'react-i18next';
10-
import { StyleSheet, View } from 'react-native';
10+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
1111

1212
import BottomSheetNavigationHeader from '../../../components/BottomSheetNavigationHeader';
1313
import GradientView from '../../../components/GradientView';
@@ -25,11 +25,11 @@ import {
2525
unitSelector,
2626
} from '../../../store/reselect/settings';
2727
import { IColors } from '../../../styles/colors';
28-
import { TouchableOpacity } from '../../../styles/components';
2928
import { Caption13Up } from '../../../styles/text';
3029
import { convertToSats } from '../../../utils/conversion';
3130
import { getNumberPadText } from '../../../utils/numberpad';
3231
import { sendMax } from '../../../utils/wallet/transactions';
32+
import AssetButton from '../AssetButton';
3333
import SendNumberPad from '../Send/SendNumberPad';
3434
import UnitButton from '../UnitButton';
3535

@@ -103,6 +103,9 @@ const Amount = ({
103103
/>
104104
</TouchableOpacity>
105105
<View style={styles.actionButtons}>
106+
<View style={styles.actionButtonContainer}>
107+
<AssetButton style={styles.actionButton} spending={true} />
108+
</View>
106109
<View style={styles.actionButtonContainer}>
107110
<UnitButton
108111
style={styles.actionButton}

src/screens/Wallets/Send/Amount.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React, {
88
useEffect,
99
} from 'react';
1010
import { useTranslation } from 'react-i18next';
11-
import { StyleSheet, View } from 'react-native';
11+
import { StyleSheet, TouchableOpacity, View } from 'react-native';
1212

1313
import BottomSheetNavigationHeader from '../../../components/BottomSheetNavigationHeader';
1414
import ContactImage from '../../../components/ContactImage';
@@ -42,7 +42,6 @@ import {
4242
utxosSelector,
4343
} from '../../../store/reselect/wallet';
4444
import { IColors } from '../../../styles/colors';
45-
import { TouchableOpacity } from '../../../styles/components';
4645
import { Caption13Up } from '../../../styles/text';
4746
import { convertToSats } from '../../../utils/conversion';
4847
import { showToast } from '../../../utils/notifications';
@@ -257,7 +256,7 @@ const Amount = ({ navigation }: SendScreenProps<'Amount'>): ReactElement => {
257256

258257
<View style={styles.numberPad} testID="SendAmountNumberPad">
259258
<View style={styles.actions}>
260-
<TouchableOpacity color="transparent" onPress={onMaxAmount}>
259+
<TouchableOpacity onPress={onMaxAmount}>
261260
<Caption13Up style={styles.availableAmountText} color="secondary">
262261
{t('send_available')}
263262
</Caption13Up>

src/utils/lightning/index.ts

+21-11
Original file line numberDiff line numberDiff line change
@@ -1664,17 +1664,6 @@ export const recoverOutputsFromForceClose = async (): Promise<
16641664
return await lm.recoverOutputsFromForceClose();
16651665
};
16661666

1667-
/**
1668-
* Returns total reserve balance for all open lightning channels.
1669-
* @returns {number}
1670-
*/
1671-
export const getLightningReserveBalance = (): number => {
1672-
const openChannels = getOpenChannels();
1673-
const result = reduceValue(openChannels, 'unspendable_punishment_reserve');
1674-
const reserveBalance = result.isOk() ? result.value : 0;
1675-
return reserveBalance;
1676-
};
1677-
16781667
/**
16791668
* Returns the claimable balance for all lightning channels.
16801669
* @param {boolean} [ignoreOpenChannels]
@@ -1798,3 +1787,24 @@ export const getLightningBalance = ({
17981787

17991788
return { localBalance, remoteBalance };
18001789
};
1790+
1791+
/**
1792+
* Returns total reserve balance for all open lightning channels.
1793+
* @returns {number}
1794+
*/
1795+
export const getLightningReserveBalance = (): number => {
1796+
const openChannels = getOpenChannels();
1797+
const result = reduceValue(openChannels, 'unspendable_punishment_reserve');
1798+
const reserveBalance = result.isOk() ? result.value : 0;
1799+
return reserveBalance;
1800+
};
1801+
1802+
/**
1803+
* Returns total spending balance for all open lightning channels.
1804+
* @returns {number}
1805+
*/
1806+
export const getSpendingBalance = (): number => {
1807+
const { localBalance } = getLightningBalance();
1808+
const reserveBalance = getLightningReserveBalance();
1809+
return localBalance - reserveBalance;
1810+
};

src/utils/scanner/scanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export const processPaymentData = async ({
386386
skipLightning?: boolean;
387387
showErrors?: boolean;
388388
}): Promise<Result<TPaymentUri>> => {
389-
let { onchainBalance, spendingBalance } = getBalance();
389+
let { onchainBalance, spendingBalance } = await getBalance();
390390
const isUnified = data.type === EQRDataType.unified;
391391
const isOnchain = data.type === EQRDataType.onchain;
392392
const isLightning = data.type === EQRDataType.lightning;

src/utils/wallet/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1288,27 +1288,27 @@ export const getCurrentAddressIndex = async ({
12881288
* @param {TWalletName} [selectedWallet]
12891289
* @param {EAvailableNetwork} [selectedNetwork]
12901290
*/
1291-
export const getBalance = ({
1291+
export const getBalance = async ({
12921292
selectedWallet = getSelectedWallet(),
12931293
selectedNetwork = getSelectedNetwork(),
12941294
}: {
12951295
selectedWallet?: TWalletName;
12961296
selectedNetwork?: EAvailableNetwork;
1297-
} = {}): {
1297+
} = {}): Promise<{
12981298
onchainBalance: number; // Total onchain funds
12991299
// lightningBalance: number; // Total lightning funds (spendable + reserved + claimable)
13001300
spendingBalance: number; // Share of lightning funds that are spendable
13011301
reserveBalance: number; // Share of lightning funds that are locked up in channels
13021302
// claimableBalance: number; // Funds that will be available after a channel opens/closes
13031303
spendableBalance: number; // Total spendable funds (onchain + spendable lightning)
13041304
// totalBalance: number; // Total funds (all of the above)
1305-
} => {
1305+
}> => {
13061306
const { currentWallet } = getCurrentWallet({
13071307
selectedWallet,
13081308
selectedNetwork,
13091309
});
13101310

1311-
const wallet = getOnChainWallet();
1311+
const wallet = await getOnChainWalletAsync();
13121312
const { localBalance } = getLightningBalance();
13131313
const reserveBalance = getLightningReserveBalance();
13141314
const spendingBalance = localBalance - reserveBalance;

src/utils/wallet/transactions.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import { EBackupCategory } from '../../store/types/backup';
2626
import { ETransactionSpeed } from '../../store/types/settings';
2727
import { reduceValue } from '../helpers';
2828
import i18n from '../i18n';
29+
import { getSpendingBalance } from '../lightning';
2930
import { EAvailableNetwork } from '../networks';
3031
import { showToast } from '../notifications';
3132
import { TRANSACTION_DEFAULTS } from './constants';
3233
import {
33-
getBalance,
3434
getOnChainWallet,
3535
getOnChainWalletElectrum,
3636
getOnChainWalletTransaction,
@@ -294,7 +294,7 @@ export const getMaxSendAmount = ({
294294

295295
if (method === 'lightning') {
296296
// lightning transaction
297-
const { spendingBalance } = getBalance();
297+
const spendingBalance = getSpendingBalance();
298298
const fee = getEstimatedRoutingFee(spendingBalance);
299299
const amount = spendingBalance - fee;
300300
const maxAmount = { amount, fee };
@@ -351,8 +351,7 @@ export const sendMax = async ({
351351
// TODO: Re-work lightning transaction invoices once beignet migration is complete.
352352
// Handle max toggle for lightning invoice
353353
if (paymentMethod === 'lightning') {
354-
const { spendingBalance } = getBalance();
355-
354+
const spendingBalance = getSpendingBalance();
356355
const fee = getEstimatedRoutingFee(spendingBalance);
357356
const amount = spendingBalance - fee;
358357

@@ -457,7 +456,7 @@ export const updateSendAmount = ({
457456

458457
if (paymentMethod === 'lightning') {
459458
// lightning transaction
460-
const { spendingBalance } = getBalance();
459+
const spendingBalance = getSpendingBalance();
461460

462461
if (amount > spendingBalance) {
463462
return err(i18n.t('wallet:send_amount_error_balance'));

0 commit comments

Comments
 (0)