Skip to content

Commit 46e6c60

Browse files
authored
Merge pull request #2485 from synonymdev/fix/various-fixes
fix: various fixes
2 parents 1b16aa8 + e6025af commit 46e6c60

File tree

8 files changed

+39
-78
lines changed

8 files changed

+39
-78
lines changed

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
allowUndefined: false,
1313
},
1414
],
15-
'react-native-reanimated/plugin',
15+
'react-native-reanimated/plugin', // NOTE: this plugin MUST be last
1616
],
1717
env: {
1818
production: {

src/components/widgets/BlocksWidget.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { memo, ReactElement } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
44

5-
import { __E2E__ } from '../../constants/env';
65
import useBlocksWidget from '../../hooks/useBlocksWidget';
76
import { TBlocksWidgetOptions } from '../../store/types/widgets';
87
import { BodyMSB, BodySSB, CaptionB } from '../../styles/text';

src/hooks/transfer.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { useEffect, useState } from 'react';
22

33
import { blocktankInfoSelector } from '../store/reselect/blocktank';
44
import { blocktankChannelsSizeSelector } from '../store/reselect/lightning';
5+
import { EConversionUnit } from '../store/types/wallet';
56
import { estimateOrderFee } from '../utils/blocktank';
6-
import { fiatToBitcoinUnit } from '../utils/conversion';
7+
import { convertToSats } from '../utils/conversion';
78
import { useAppSelector } from './redux';
89

910
type TTransferValues = {
@@ -17,9 +18,9 @@ const getDefaultLspBalance = (
1718
clientBalance: number,
1819
maxLspBalance: number,
1920
): number => {
20-
const threshold1 = fiatToBitcoinUnit({ amount: 225, currency: 'EUR' });
21-
const threshold2 = fiatToBitcoinUnit({ amount: 495, currency: 'EUR' });
22-
const defaultLspBalance = fiatToBitcoinUnit({ amount: 450, currency: 'EUR' });
21+
const threshold1 = convertToSats(225, EConversionUnit.fiat, 'EUR');
22+
const threshold2 = convertToSats(495, EConversionUnit.fiat, 'EUR');
23+
const defaultLspBalance = convertToSats(450, EConversionUnit.fiat, 'EUR');
2324

2425
let lspBalance = defaultLspBalance - clientBalance;
2526

src/screens/Profile/ProfileEdit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const ProfileEdit = ({
109109
if (!onboardedProfile) {
110110
dispatch(setOnboardingProfileStep('OfflinePayments'));
111111
} else {
112-
navigation.navigate('Profile');
112+
navigation.popTo('Profile');
113113
}
114114
};
115115

src/utils/blocktank/index.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -387,59 +387,3 @@ export const logToBlocktank = async (
387387
): Promise<void> => {
388388
return bt.bitkitLog(nodeId, message);
389389
};
390-
391-
/**
392-
* Returns Blocktank spending limits in sats, USD & the user's selectedCurrency.
393-
* CURRENTLY UNUSED
394-
* @param selectedCurrency
395-
*/
396-
// export const getSpendingLimits = ({
397-
// selectedCurrency,
398-
// }: {
399-
// selectedCurrency?: string;
400-
// }): {
401-
// currentBalance: IDisplayValues;
402-
// spendableBalanceSats: number;
403-
// spendableBalanceFiat: number;
404-
// usdSpendingLimitFiat: number;
405-
// spendingLimitSats: number;
406-
// selectedCurrencySpendingLimitFiat: number;
407-
// } => {
408-
// if (!selectedCurrency) {
409-
// selectedCurrency = getSettingsStore().selectedCurrency;
410-
// }
411-
// const usdMax = 1000;
412-
// const denominator = 1.2;
413-
414-
// const currentBalance = getBalance({ onchain: true });
415-
// const spendableBalanceSats = Math.round(
416-
// currentBalance.satoshis / denominator,
417-
// );
418-
// const spendableBalanceFiat = Math.round(
419-
// currentBalance.fiatValue / denominator,
420-
// );
421-
// const usdSpendingLimitFiat =
422-
// spendableBalanceFiat < usdMax ? spendableBalanceFiat : usdMax;
423-
// const spendingLimitSats = fiatToBitcoinUnit({
424-
// fiatValue: usdSpendingLimitFiat,
425-
// bitcoinUnit: EBitcoinUnit.satoshi,
426-
// currency: 'USD',
427-
// });
428-
// const selectedCurrencySpendingLimitFiat = getFiatDisplayValues({
429-
// satoshis:
430-
// spendableBalanceSats < spendingLimitSats
431-
// ? spendableBalanceSats
432-
// : spendingLimitSats,
433-
// bitcoinUnit: EBitcoinUnit.satoshi,
434-
// currency: selectedCurrency,
435-
// });
436-
// return {
437-
// currentBalance,
438-
// spendableBalanceSats,
439-
// spendableBalanceFiat,
440-
// usdSpendingLimitFiat,
441-
// spendingLimitSats,
442-
// selectedCurrencySpendingLimitFiat:
443-
// selectedCurrencySpendingLimitFiat.fiatValue,
444-
// };
445-
// };

src/utils/conversion.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const satsToBtc = (balance: number): number => {
2828
export const convertToSats = (
2929
value: number | string,
3030
unit: EConversionUnit,
31+
currency?: string,
3132
): number => {
3233
const amount = Number(value);
3334

@@ -37,7 +38,7 @@ export const convertToSats = (
3738

3839
if (unit === EConversionUnit.fiat) {
3940
const denomination = getSettingsStore().denomination;
40-
const btcUnit = fiatToBitcoinUnit({ amount });
41+
const btcUnit = fiatToBitcoinUnit({ amount, currency });
4142
return denomination === EDenomination.modern ? btcUnit : btcToSats(btcUnit);
4243
}
4344

src/utils/scanner/scanner.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
lnurlAddress as processLnurlAddress,
44
} from '@synonymdev/react-native-lnurl';
55
import { Result, err, ok } from '@synonymdev/result';
6+
import { parse } from '@synonymdev/slashtags-url';
67
import {
78
EAddressType,
89
EAvailableNetworks,
@@ -25,7 +26,11 @@ import {
2526
setupOnChainTransaction,
2627
updateBeignetSendTransaction,
2728
} from '../../store/actions/wallet';
28-
import { dispatch, getSettingsStore } from '../../store/helpers';
29+
import {
30+
dispatch,
31+
getSettingsStore,
32+
getSlashtagsStore,
33+
} from '../../store/helpers';
2934
import { closeSheet, updateSendTransaction } from '../../store/slices/ui';
3035
import { EDenomination } from '../../store/types/wallet';
3136
import { showBottomSheet } from '../../store/utils/ui';
@@ -106,21 +111,28 @@ export const processUri = async ({
106111
paymentData = data;
107112
}
108113

109-
// If we're in the send flow and the data is a slashtag, process for slashpay.
110-
if (source === 'send' && data.type === EQRDataType.slashtag) {
111-
const slashPayResult = await processSlashPayUrl(data.url);
112-
if (slashPayResult.isErr()) {
113-
if (showErrors) {
114-
showToast({
115-
type: 'warning',
116-
title: i18n.t('slashtags:error_pay_title'),
117-
description: slashPayResult.error.message,
118-
});
114+
if (data.type === EQRDataType.slashtag) {
115+
const isSend = source === 'send';
116+
const { contacts } = getSlashtagsStore();
117+
const parsed = parse(data.url);
118+
const hasAddedContact = contacts[parsed.id];
119+
120+
// If we're in the send flow or the contact has already been added, process for slashpay.
121+
if (isSend || hasAddedContact) {
122+
const slashPayResult = await processSlashPayUrl(data.url);
123+
if (slashPayResult.isErr()) {
124+
if (showErrors) {
125+
showToast({
126+
type: 'warning',
127+
title: i18n.t('slashtags:error_pay_title'),
128+
description: slashPayResult.error.message,
129+
});
130+
}
131+
return err(slashPayResult.error.message);
119132
}
120-
return err(slashPayResult.error.message);
121-
}
122133

123-
paymentData = slashPayResult.value;
134+
paymentData = slashPayResult.value;
135+
}
124136
}
125137

126138
// Validate and process payment data.

src/utils/startup/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ export const startWalletServices = async ({
152152
if (setupResponse.isOk()) {
153153
keepLdkSynced({ selectedNetwork }).then();
154154
} else {
155+
if (setupResponse.error.message.includes('already_init')) {
156+
return ok('');
157+
}
158+
155159
showToast({
156160
type: 'error',
157161
title: i18n.t('wallet:ldk_start_error_title'),

0 commit comments

Comments
 (0)