Skip to content

Commit 36c6ada

Browse files
committed
fix(ui): fix deep linking if app is closed
1 parent 1183e42 commit 36c6ada

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

src/utils/lightning/index.ts

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

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

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

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)