Merge pull request #2587 from BlueWallet/2544

FIX: During long menmonics import, wallet panels are not scrolled to …
This commit is contained in:
GLaDOS 2021-02-09 14:29:21 +00:00 committed by GitHub
commit d398934deb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 31 deletions

View file

@ -21,7 +21,6 @@ export const BlueStorageProvider = ({ children }) => {
const [language, _setLanguage] = useState();
const getPreferredCurrencyAsyncStorage = useAsyncStorage(AppStorage.PREFERRED_CURRENCY).getItem;
const getLanguageAsyncStorage = useAsyncStorage(AppStorage.LANG).getItem;
const [newWalletAdded, setNewWalletAdded] = useState(false);
const [isHandOffUseEnabled, setIsHandOffUseEnabled] = useState(false);
const [isDrawerListBlurred, _setIsDrawerListBlurred] = useState(false);
@ -213,8 +212,6 @@ export const BlueStorageProvider = ({ children }) => {
sleep,
setHodlHodlApiKey,
createFakeStorage,
newWalletAdded,
setNewWalletAdded,
resetWallets,
getHodlHodlApiKey,
decryptStorage,

View file

@ -27,7 +27,7 @@ const wif = require('wif');
const prompt = require('../blue_modules/prompt');
function WalletImport() {
const { wallets, pendingWallets, setPendingWallets, saveToDisk, addWallet, setNewWalletAdded } = useContext(BlueStorageContext);
const { wallets, pendingWallets, setPendingWallets, saveToDisk, addWallet } = useContext(BlueStorageContext);
/**
*
@ -53,7 +53,6 @@ function WalletImport() {
}
addWallet(w);
await saveToDisk();
setNewWalletAdded(true);
A(A.ENUM.CREATED_WALLET);
alert(loc.wallets.import_success);
Notifications.majorTomToGroundControl(w.getAllExternalAddresses(), [], []);

View file

@ -41,7 +41,7 @@ const ButtonSelected = Object.freeze({
const WalletsAdd = () => {
const { colors } = useTheme();
const { addWallet, saveToDisk, setNewWalletAdded, isAdancedModeEnabled } = useContext(BlueStorageContext);
const { addWallet, saveToDisk, isAdancedModeEnabled } = useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(true);
const [walletBaseURI, setWalletBaseURI] = useState();
const [selectedIndex, setSelectedIndex] = useState(0);
@ -139,7 +139,6 @@ const WalletsAdd = () => {
}
addWallet(w);
await saveToDisk();
setNewWalletAdded(true);
A(A.ENUM.CREATED_WALLET);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
if (w.type === HDSegwitP2SHWallet.type || w.type === HDSegwitBech32Wallet.type) {
@ -184,7 +183,6 @@ const WalletsAdd = () => {
addWallet(wallet);
await saveToDisk();
setNewWalletAdded(true);
A(A.ENUM.CREATED_WALLET);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
navigate('PleaseBackupLNDHub', {

View file

@ -50,7 +50,7 @@ const isDesktop = getSystemName() === 'Mac OS X';
const staticCache = {};
const WalletsAddMultisigStep2 = () => {
const { addWallet, saveToDisk, setNewWalletAdded } = useContext(BlueStorageContext);
const { addWallet, saveToDisk } = useContext(BlueStorageContext);
const { colors } = useTheme();
const navigation = useNavigation();
@ -195,7 +195,6 @@ const WalletsAddMultisigStep2 = () => {
addWallet(w);
await saveToDisk();
setNewWalletAdded(true);
A(A.ENUM.CREATED_WALLET);
ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false });
navigation.dangerouslyGetParent().goBack();

View file

@ -17,12 +17,11 @@ import { BlurView } from '@react-native-community/blur';
const DrawerList = props => {
console.log('drawerList rendering...');
const walletsCarousel = useRef();
const { wallets, selectedWallet, pendingWallets, newWalletAdded, setNewWalletAdded, isDrawerListBlurred } = useContext(
BlueStorageContext,
);
const { wallets, selectedWallet, pendingWallets, isDrawerListBlurred } = useContext(BlueStorageContext);
const [carouselData, setCarouselData] = useState([]);
const height = useWindowDimensions().height;
const { colors } = useTheme();
const walletsCount = useRef(wallets.length);
const stylesHook = StyleSheet.create({
root: {
backgroundColor: colors.brandingColor,
@ -38,12 +37,18 @@ const DrawerList = props => {
}, [wallets, pendingWallets]);
useEffect(() => {
if (newWalletAdded) {
walletsCarousel.current?.snapToItem(carouselData.length - pendingWallets.length - 2);
setNewWalletAdded(false);
if (walletsCount.current < wallets.length) {
walletsCarousel.current?.snapToItem(walletsCount.current);
}
walletsCount.current = wallets.length;
}, [wallets]);
useEffect(() => {
if (pendingWallets.length > 0) {
walletsCarousel.current?.snapToItem(carouselData.length - pendingWallets.length);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [newWalletAdded]);
}, [pendingWallets]);
const handleClick = index => {
console.log('click', index);

View file

@ -35,16 +35,9 @@ const WalletsListSections = { CAROUSEL: 'CAROUSEL', LOCALTRADER: 'LOCALTRADER',
const WalletsList = () => {
const walletsCarousel = useRef();
const {
wallets,
pendingWallets,
getTransactions,
getBalance,
refreshAllWalletTransactions,
newWalletAdded,
setNewWalletAdded,
setSelectedWallet,
} = useContext(BlueStorageContext);
const { wallets, pendingWallets, getTransactions, getBalance, refreshAllWalletTransactions, setSelectedWallet } = useContext(
BlueStorageContext,
);
const { width } = useWindowDimensions();
const { colors, scanImage } = useTheme();
const { navigate, setOptions } = useNavigation();
@ -56,6 +49,7 @@ const WalletsList = () => {
);
const [carouselData, setCarouselData] = useState([]);
const dataSource = getTransactions(null, 10);
const walletsCount = useRef(wallets.length);
const stylesHook = StyleSheet.create({
walletsListWrapper: {
@ -96,12 +90,18 @@ const WalletsList = () => {
}, [wallets, pendingWallets]);
useEffect(() => {
if (newWalletAdded) {
walletsCarousel.current?.snapToItem(carouselData.length - pendingWallets.length - 2);
setNewWalletAdded(false);
if (walletsCount.current < wallets.length) {
walletsCarousel.current?.snapToItem(walletsCount.current);
}
walletsCount.current = wallets.length;
}, [wallets]);
useEffect(() => {
if (pendingWallets.length > 0) {
walletsCarousel.current?.snapToItem(carouselData.length - pendingWallets.length);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [newWalletAdded]);
}, [pendingWallets]);
const verifyBalance = () => {
if (getBalance() !== 0) {