mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-18 21:35:21 +01:00
FIX: Small ui fixs
This commit is contained in:
parent
b2daa7cf20
commit
2bdd65ffd1
@ -172,13 +172,6 @@ function Notifications(props) {
|
||||
});
|
||||
};
|
||||
|
||||
function _getHeaders() {
|
||||
return {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
}
|
||||
|
||||
async function _sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
@ -243,38 +236,6 @@ function Notifications(props) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The opposite of `majorTomToGroundControl` call.
|
||||
*
|
||||
* @param addresses {string[]}
|
||||
* @param hashes {string[]}
|
||||
* @param txids {string[]}
|
||||
* @returns {Promise<object>} Response object from API rest call
|
||||
*/
|
||||
Notifications.unsubscribe = async function (addresses, hashes, txids) {
|
||||
if (!Array.isArray(addresses) || !Array.isArray(hashes) || !Array.isArray(txids))
|
||||
throw new Error('no addresses or hashes or txids provided');
|
||||
const pushToken = await Notifications.getPushToken();
|
||||
if (!pushToken || !pushToken.token || !pushToken.os) return;
|
||||
|
||||
const response = await fetch(`${baseURI}/unsubscribe`, {
|
||||
method: 'POST',
|
||||
headers: _getHeaders(),
|
||||
body: JSON.stringify({
|
||||
addresses,
|
||||
hashes,
|
||||
txids,
|
||||
token: pushToken.token,
|
||||
os: pushToken.os,
|
||||
}),
|
||||
});
|
||||
|
||||
console.debug('Abandoning notifications Permissions...');
|
||||
PushNotification.abandonPermissions();
|
||||
console.debug('Abandoned notifications Permissions...');
|
||||
return response.json();
|
||||
};
|
||||
|
||||
Notifications.isNotificationsEnabled = async function () {
|
||||
const levels = await getLevels();
|
||||
return !!(await Notifications.getPushToken()) && !!levels.level_all;
|
||||
@ -511,4 +472,42 @@ function Notifications(props) {
|
||||
|
||||
export const isNotificationsCapable = hasGmsSync() || hasHmsSync() || Platform.OS !== 'android';
|
||||
|
||||
/**
|
||||
* The opposite of `majorTomToGroundControl` call.
|
||||
*
|
||||
* @param addresses {string[]}
|
||||
* @param hashes {string[]}
|
||||
* @param txids {string[]}
|
||||
* @returns {Promise<object>} Response object from API rest call
|
||||
*/
|
||||
export const unsubscribe = async (addresses, hashes, txids) => {
|
||||
if (!Array.isArray(addresses) || !Array.isArray(hashes) || !Array.isArray(txids))
|
||||
throw new Error('no addresses or hashes or txids provided');
|
||||
const pushToken = await Notifications.getPushToken();
|
||||
if (!pushToken || !pushToken.token || !pushToken.os) return;
|
||||
|
||||
const response = await fetch(`${baseURI}/unsubscribe`, {
|
||||
method: 'POST',
|
||||
headers: _getHeaders(),
|
||||
body: JSON.stringify({
|
||||
addresses,
|
||||
hashes,
|
||||
txids,
|
||||
token: pushToken.token,
|
||||
os: pushToken.os,
|
||||
}),
|
||||
});
|
||||
|
||||
console.debug('Abandoning notifications Permissions...');
|
||||
PushNotification.abandonPermissions();
|
||||
console.debug('Abandoned notifications Permissions...');
|
||||
return response.json();
|
||||
};
|
||||
|
||||
function _getHeaders() {
|
||||
return {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
}
|
||||
export default Notifications;
|
||||
|
@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { RouteProp, useRoute } from '@react-navigation/native';
|
||||
import { ActivityIndicator, FlatList, LayoutAnimation, StyleSheet, View } from 'react-native';
|
||||
import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback';
|
||||
import { BlueButtonLink, BlueFormLabel, BlueSpacing10, BlueSpacing20, BlueText } from '../../BlueComponents';
|
||||
import { BlueButtonLink, BlueFormLabel, BlueSpacing10, BlueSpacing20, BlueSpacing40, BlueText } from '../../BlueComponents';
|
||||
import { HDSegwitBech32Wallet, WatchOnlyWallet } from '../../class';
|
||||
import startImport, { TImport } from '../../class/wallet-import';
|
||||
import presentAlert from '../../components/Alert';
|
||||
@ -172,11 +172,23 @@ const ImportWalletDiscovery: React.FC = () => {
|
||||
const ListEmptyComponent = useMemo(
|
||||
() => (
|
||||
<View style={styles.noWallets}>
|
||||
<BlueText style={styles.center}>{loc.wallets.import_discovery_no_wallets}</BlueText>
|
||||
<BlueSpacing20 />
|
||||
{loading ? (
|
||||
<>
|
||||
<BlueSpacing40 />
|
||||
<ActivityIndicator testID="Loading" />
|
||||
<BlueSpacing20 />
|
||||
<BlueFormLabel>{progress}</BlueFormLabel>
|
||||
<BlueSpacing40 />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<BlueText style={styles.center}>{loc.wallets.import_discovery_no_wallets}</BlueText>
|
||||
<BlueSpacing20 />{' '}
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
),
|
||||
[],
|
||||
[loading, progress],
|
||||
);
|
||||
|
||||
return (
|
||||
@ -192,15 +204,6 @@ const ImportWalletDiscovery: React.FC = () => {
|
||||
contentInsetAdjustmentBehavior="always"
|
||||
/>
|
||||
<View style={[styles.center, stylesHook.center]}>
|
||||
{loading && (
|
||||
<>
|
||||
<BlueSpacing10 />
|
||||
<ActivityIndicator testID="Loading" />
|
||||
<BlueSpacing10 />
|
||||
<BlueFormLabel>{progress}</BlueFormLabel>
|
||||
<BlueSpacing10 />
|
||||
</>
|
||||
)}
|
||||
{bip39 && (
|
||||
<BlueButtonLink
|
||||
title={loc.wallets.import_discovery_derivation}
|
||||
@ -232,7 +235,7 @@ const styles = StyleSheet.create({
|
||||
marginHorizontal: 16,
|
||||
},
|
||||
center: {
|
||||
marginHorizontal: 16,
|
||||
margin: 16,
|
||||
alignItems: 'center',
|
||||
},
|
||||
buttonContainer: {
|
||||
|
@ -15,7 +15,6 @@ import {
|
||||
} from 'react-native';
|
||||
import { writeFileAndExport } from '../../blue_modules/fs';
|
||||
import triggerHapticFeedback, { HapticFeedbackTypes } from '../../blue_modules/hapticFeedback';
|
||||
import Notifications from '../../blue_modules/notifications';
|
||||
import { BlueCard, BlueLoading, BlueSpacing10, BlueSpacing20, BlueText } from '../../BlueComponents';
|
||||
import {
|
||||
HDAezeedWallet,
|
||||
@ -44,6 +43,7 @@ import { popToTop } from '../../NavigationService';
|
||||
import { useFocusEffect, useRoute, RouteProp } from '@react-navigation/native';
|
||||
import { LightningTransaction, Transaction, TWallet } from '../../class/wallets/types';
|
||||
import { DetailViewStackParamList } from '../../navigation/DetailViewStackParamList';
|
||||
import { unsubscribe } from '../../blue_modules/notifications';
|
||||
|
||||
type RouteProps = RouteProp<DetailViewStackParamList, 'WalletDetails'>;
|
||||
const WalletDetails: React.FC = () => {
|
||||
@ -146,44 +146,51 @@ const WalletDetails: React.FC = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [walletID]);
|
||||
|
||||
const navigateToOverviewAndDeleteWallet = () => {
|
||||
const navigateToOverviewAndDeleteWallet = useCallback(async () => {
|
||||
setIsLoading(true);
|
||||
let externalAddresses: string[] = [];
|
||||
try {
|
||||
if (wallet.getAllExternalAddresses) {
|
||||
externalAddresses = wallet.getAllExternalAddresses();
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
// @ts-ignore: ts-ify later
|
||||
Notifications.unsubscribe(externalAddresses, [], []);
|
||||
deleteWallet(wallet);
|
||||
saveToDisk(true);
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
|
||||
popToTop();
|
||||
};
|
||||
try {
|
||||
const externalAddresses = wallet.getAllExternalAddresses();
|
||||
if (externalAddresses.length > 0) {
|
||||
await unsubscribe(externalAddresses, [], []);
|
||||
}
|
||||
deleteWallet(wallet);
|
||||
saveToDisk(true);
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
|
||||
popToTop();
|
||||
} catch (e: unknown) {
|
||||
console.error(e);
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||
presentAlert({ message: (e as Error).message });
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [deleteWallet, saveToDisk, wallet]);
|
||||
|
||||
const presentWalletHasBalanceAlert = useCallback(async () => {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationWarning);
|
||||
try {
|
||||
const balance = formatBalanceWithoutSuffix(wallet.getBalance(), BitcoinUnit.SATS, true);
|
||||
const walletBalanceConfirmation = await prompt(
|
||||
loc.wallets.details_delete_wallet,
|
||||
loc.formatString(loc.wallets.details_del_wb_q, { balance: wallet.getBalance() }),
|
||||
loc.formatString(loc.wallets.details_del_wb_q, { balance }),
|
||||
true,
|
||||
'plain-text',
|
||||
'numeric',
|
||||
true,
|
||||
loc.wallets.details_delete,
|
||||
);
|
||||
if (Number(walletBalanceConfirmation) === wallet.getBalance()) {
|
||||
navigateToOverviewAndDeleteWallet();
|
||||
// Remove any non-numeric characters before comparison
|
||||
const cleanedConfirmation = (walletBalanceConfirmation || '').replace(/[^0-9]/g, '');
|
||||
|
||||
if (Number(cleanedConfirmation) === wallet.getBalance()) {
|
||||
await navigateToOverviewAndDeleteWallet();
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationSuccess);
|
||||
} else {
|
||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||
setIsLoading(false);
|
||||
presentAlert({ message: loc.wallets.details_del_wb_err });
|
||||
}
|
||||
} catch (_) {}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
}, [navigateToOverviewAndDeleteWallet, wallet]);
|
||||
|
||||
const navigateToWalletExport = () => {
|
||||
navigate('WalletExportRoot', {
|
||||
@ -300,11 +307,11 @@ const WalletDetails: React.FC = () => {
|
||||
}, [wallet, walletName, saveToDisk]);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = addListener('beforeRemove', () => {
|
||||
const subscribe = addListener('beforeRemove', () => {
|
||||
walletNameTextInputOnBlur();
|
||||
});
|
||||
|
||||
return unsubscribe;
|
||||
return subscribe;
|
||||
}, [addListener, walletName, walletNameTextInputOnBlur]);
|
||||
|
||||
const exportHistoryContent = useCallback(() => {
|
||||
|
@ -173,7 +173,7 @@ const WalletsList: React.FC = () => {
|
||||
useEffect(() => {
|
||||
// new wallet added
|
||||
if (wallets.length > walletsCount.current) {
|
||||
walletsCarousel.current?.scrollToItem({ item: wallets[walletsCount.current] });
|
||||
walletsCarousel.current?.scrollToItem({ item: wallets[walletsCount.current], viewPosition: 0.3 });
|
||||
}
|
||||
|
||||
walletsCount.current = wallets.length;
|
||||
|
Loading…
Reference in New Issue
Block a user