2020-10-24 19:20:59 +02:00
|
|
|
import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
2020-05-28 10:44:15 +02:00
|
|
|
import {
|
|
|
|
StatusBar,
|
|
|
|
View,
|
|
|
|
TouchableOpacity,
|
|
|
|
Text,
|
|
|
|
StyleSheet,
|
|
|
|
SectionList,
|
|
|
|
Platform,
|
2020-09-07 19:46:37 +02:00
|
|
|
Image,
|
2020-09-08 18:06:41 +02:00
|
|
|
Dimensions,
|
2020-10-08 22:03:57 +02:00
|
|
|
useWindowDimensions,
|
2021-02-27 01:23:59 +01:00
|
|
|
findNodeHandle,
|
2021-03-19 03:30:01 +01:00
|
|
|
I18nManager,
|
2020-05-28 10:44:15 +02:00
|
|
|
} from 'react-native';
|
2021-08-16 18:10:04 +02:00
|
|
|
import { BlueHeaderDefaultMain } from '../../BlueComponents';
|
2020-10-15 18:25:24 +02:00
|
|
|
import WalletsCarousel from '../../components/WalletsCarousel';
|
2018-09-01 01:28:19 +02:00
|
|
|
import { Icon } from 'react-native-elements';
|
2020-05-20 20:04:28 +02:00
|
|
|
import DeeplinkSchemaMatch from '../../class/deeplink-schema-match';
|
2018-12-18 07:05:03 +01:00
|
|
|
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
|
2020-05-28 10:44:15 +02:00
|
|
|
import ActionSheet from '../ActionSheet';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-09-07 19:46:37 +02:00
|
|
|
import { FContainer, FButton } from '../../components/FloatButtons';
|
2021-07-04 06:21:31 +02:00
|
|
|
import { useFocusEffect, useIsFocused, useNavigation, useRoute, useTheme } from '@react-navigation/native';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2021-05-29 07:57:40 +02:00
|
|
|
import { isDesktop, isMacCatalina, isTablet } from '../../blue_modules/environment';
|
2021-02-28 18:50:14 +01:00
|
|
|
import BlueClipboard from '../../blue_modules/clipboard';
|
2021-03-11 14:43:21 +01:00
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2021-08-16 18:10:04 +02:00
|
|
|
import { TransactionListItem } from '../../components/TransactionListItem';
|
2020-12-27 01:10:54 +01:00
|
|
|
|
2021-03-20 14:00:01 +01:00
|
|
|
const scanqrHelper = require('../../helpers/scan-qr');
|
2020-07-01 13:56:52 +02:00
|
|
|
const A = require('../../blue_modules/analytics');
|
2020-12-15 05:11:05 +01:00
|
|
|
const fs = require('../../blue_modules/fs');
|
2021-08-19 14:57:23 +02:00
|
|
|
const WalletsListSections = { CAROUSEL: 'CAROUSEL', TRANSACTIONS: 'TRANSACTIONS' };
|
2018-10-09 06:25:36 +02:00
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const WalletsList = () => {
|
|
|
|
const walletsCarousel = useRef();
|
2021-07-18 17:54:43 +02:00
|
|
|
const currentWalletIndex = useRef(0);
|
2022-01-26 18:50:41 +01:00
|
|
|
const { wallets, getTransactions, getBalance, refreshAllWalletTransactions, setSelectedWallet, isElectrumDisabled } =
|
|
|
|
useContext(BlueStorageContext);
|
2020-10-08 22:03:57 +02:00
|
|
|
const { width } = useWindowDimensions();
|
2021-09-27 18:40:58 +02:00
|
|
|
const { colors, scanImage, barStyle } = useTheme();
|
2020-10-11 09:07:22 +02:00
|
|
|
const { navigate, setOptions } = useNavigation();
|
2021-07-04 06:21:31 +02:00
|
|
|
const isFocused = useIsFocused();
|
2020-10-08 22:03:57 +02:00
|
|
|
const routeName = useRoute().name;
|
2020-10-24 19:20:59 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
2020-10-08 22:03:57 +02:00
|
|
|
const [isLargeScreen, setIsLargeScreen] = useState(
|
2021-09-17 05:49:33 +02:00
|
|
|
Platform.OS === 'android' ? isTablet() : (width >= Dimensions.get('screen').width / 2 && isTablet()) || isDesktop,
|
2020-10-08 22:03:57 +02:00
|
|
|
);
|
2020-10-24 19:20:59 +02:00
|
|
|
const dataSource = getTransactions(null, 10);
|
2021-02-08 04:34:19 +01:00
|
|
|
const walletsCount = useRef(wallets.length);
|
2021-02-27 01:23:59 +01:00
|
|
|
const walletActionButtonsRef = useRef();
|
2020-10-08 22:03:57 +02:00
|
|
|
|
|
|
|
const stylesHook = StyleSheet.create({
|
|
|
|
walletsListWrapper: {
|
|
|
|
backgroundColor: colors.brandingColor,
|
|
|
|
},
|
|
|
|
listHeaderBack: {
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
listHeaderText: {
|
|
|
|
color: colors.foregroundColor,
|
|
|
|
},
|
|
|
|
});
|
2020-10-06 12:28:06 +02:00
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
useFocusEffect(
|
|
|
|
useCallback(() => {
|
2020-10-24 19:20:59 +02:00
|
|
|
verifyBalance();
|
2020-11-15 19:19:55 +01:00
|
|
|
setSelectedWallet('');
|
2020-10-08 22:03:57 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, []),
|
|
|
|
);
|
2018-01-30 23:42:38 +01:00
|
|
|
|
2020-10-24 19:20:59 +02:00
|
|
|
useEffect(() => {
|
2021-09-23 15:05:10 +02:00
|
|
|
// new wallet added
|
|
|
|
if (wallets.length > walletsCount.current) {
|
2021-06-16 08:05:04 +02:00
|
|
|
walletsCarousel.current?.scrollToItem({ item: wallets[walletsCount.current] });
|
2021-02-08 04:54:04 +01:00
|
|
|
}
|
2021-09-23 15:05:10 +02:00
|
|
|
// wallet has been deleted
|
|
|
|
if (wallets.length < walletsCount.current) {
|
2021-07-18 17:54:43 +02:00
|
|
|
walletsCarousel.current?.scrollToItem({ item: false });
|
2020-10-24 19:20:59 +02:00
|
|
|
}
|
2021-09-23 15:05:10 +02:00
|
|
|
walletsCount.current = wallets.length;
|
|
|
|
}, [wallets]);
|
2020-10-24 19:20:59 +02:00
|
|
|
|
|
|
|
const verifyBalance = () => {
|
|
|
|
if (getBalance() !== 0) {
|
|
|
|
A(A.ENUM.GOT_NONZERO_BALANCE);
|
|
|
|
} else {
|
|
|
|
A(A.ENUM.GOT_ZERO_BALANCE);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-11 09:07:22 +02:00
|
|
|
useEffect(() => {
|
|
|
|
setOptions({
|
2021-05-29 07:57:40 +02:00
|
|
|
headerShown: !isDesktop,
|
2020-10-11 09:07:22 +02:00
|
|
|
headerStyle: {
|
2021-09-14 07:36:00 +02:00
|
|
|
backgroundColor: colors.customHeader,
|
2020-10-11 09:07:22 +02:00
|
|
|
borderBottomWidth: 0,
|
|
|
|
elevation: 0,
|
|
|
|
shadowOpacity: 0,
|
|
|
|
shadowOffset: { height: 0, width: 0 },
|
|
|
|
},
|
2021-03-19 03:30:01 +01:00
|
|
|
headerRight: () =>
|
|
|
|
I18nManager.isRTL ? null : (
|
2021-06-24 14:50:57 +02:00
|
|
|
<TouchableOpacity accessibilityRole="button" testID="SettingsButton" style={styles.headerTouch} onPress={navigateToSettings}>
|
2021-03-19 03:30:01 +01:00
|
|
|
<Icon size={22} name="kebab-horizontal" type="octicon" color={colors.foregroundColor} />
|
|
|
|
</TouchableOpacity>
|
|
|
|
),
|
|
|
|
headerLeft: () =>
|
|
|
|
I18nManager.isRTL ? (
|
2021-06-24 14:50:57 +02:00
|
|
|
<TouchableOpacity accessibilityRole="button" testID="SettingsButton" style={styles.headerTouch} onPress={navigateToSettings}>
|
2021-03-19 03:30:01 +01:00
|
|
|
<Icon size={22} name="kebab-horizontal" type="octicon" color={colors.foregroundColor} />
|
|
|
|
</TouchableOpacity>
|
|
|
|
) : null,
|
2020-10-11 09:07:22 +02:00
|
|
|
});
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [colors]);
|
|
|
|
|
|
|
|
const navigateToSettings = () => {
|
|
|
|
navigate('Settings');
|
|
|
|
};
|
|
|
|
|
2018-07-02 13:09:34 +02:00
|
|
|
/**
|
2020-11-13 16:14:49 +01:00
|
|
|
* Forcefully fetches TXs and balance for ALL wallets.
|
2018-12-25 20:07:43 +01:00
|
|
|
* Triggered manually by user on pull-to-refresh.
|
2018-07-02 13:09:34 +02:00
|
|
|
*/
|
2021-08-10 16:35:47 +02:00
|
|
|
const refreshTransactions = async (showLoadingIndicator = true, showUpdateStatusIndicator = false) => {
|
2021-08-24 06:33:32 +02:00
|
|
|
if (isElectrumDisabled) return setIsLoading(false);
|
2020-11-22 01:42:39 +01:00
|
|
|
setIsLoading(showLoadingIndicator);
|
2021-11-09 12:08:47 +01:00
|
|
|
refreshAllWalletTransactions(false, showUpdateStatusIndicator).finally(() => setIsLoading(false));
|
2020-10-08 22:03:57 +02:00
|
|
|
};
|
2018-06-25 00:22:46 +02:00
|
|
|
|
2020-11-22 01:42:39 +01:00
|
|
|
useEffect(() => {
|
2021-01-28 01:30:42 +01:00
|
|
|
refreshTransactions(false, true);
|
2020-11-13 16:14:49 +01:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-11-22 01:42:39 +01:00
|
|
|
}, []); // call refreshTransactions() only once, when screen mounts
|
2020-11-13 16:14:49 +01:00
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const handleClick = index => {
|
2018-10-09 06:25:36 +02:00
|
|
|
console.log('click', index);
|
2021-07-18 17:54:43 +02:00
|
|
|
if (index <= wallets.length - 1) {
|
|
|
|
const wallet = wallets[index];
|
|
|
|
const walletID = wallet.getID();
|
|
|
|
navigate('WalletTransactions', {
|
|
|
|
walletID,
|
|
|
|
walletType: wallet.type,
|
|
|
|
key: `WalletTransactions-${walletID}`,
|
|
|
|
});
|
2021-09-23 15:05:10 +02:00
|
|
|
} else if (index >= wallets.length) {
|
2020-10-24 19:20:59 +02:00
|
|
|
navigate('AddWalletRoot');
|
2018-06-25 00:22:46 +02:00
|
|
|
}
|
2020-05-17 14:17:08 +02:00
|
|
|
};
|
2018-06-25 00:22:46 +02:00
|
|
|
|
2021-06-16 08:05:04 +02:00
|
|
|
const onSnapToItem = e => {
|
2021-07-05 19:56:11 +02:00
|
|
|
if (!isFocused) return;
|
|
|
|
|
|
|
|
const contentOffset = e.nativeEvent.contentOffset;
|
|
|
|
const index = Math.ceil(contentOffset.x / width);
|
2021-07-18 17:54:43 +02:00
|
|
|
|
|
|
|
if (currentWalletIndex.current !== index) {
|
|
|
|
console.log('onSnapToItem', wallets.length === index ? 'NewWallet/Importing card' : index);
|
|
|
|
if (wallets[index] && (wallets[index].timeToRefreshBalance() || wallets[index].timeToRefreshTransaction())) {
|
|
|
|
console.log(wallets[index].getLabel(), 'thinks its time to refresh either balance or transactions. refetching both');
|
|
|
|
refreshAllWalletTransactions(index, false).finally(() => setIsLoading(false));
|
|
|
|
}
|
|
|
|
currentWalletIndex.current = index;
|
|
|
|
} else {
|
|
|
|
console.log('onSnapToItem did not change. Most likely momentum stopped at the same index it started.');
|
2020-11-13 16:14:49 +01:00
|
|
|
}
|
2020-10-08 22:03:57 +02:00
|
|
|
};
|
2018-09-18 09:24:42 +02:00
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderListHeaderComponent = () => {
|
|
|
|
const style = { opacity: isLoading ? 1.0 : 0.5 };
|
2018-10-09 06:25:36 +02:00
|
|
|
return (
|
2020-10-08 22:03:57 +02:00
|
|
|
<View style={[styles.listHeaderBack, stylesHook.listHeaderBack]}>
|
2020-11-11 04:59:24 +01:00
|
|
|
<Text textBreakStrategy="simple" style={[styles.listHeaderText, stylesHook.listHeaderText]}>
|
|
|
|
{`${loc.transactions.list_title}${' '}`}
|
|
|
|
</Text>
|
2021-05-29 07:57:40 +02:00
|
|
|
{isDesktop && (
|
2021-06-24 14:50:57 +02:00
|
|
|
<TouchableOpacity accessibilityRole="button" style={style} onPress={() => refreshTransactions(true)} disabled={isLoading}>
|
2020-10-08 22:03:57 +02:00
|
|
|
<Icon name="refresh" type="font-awesome" color={colors.feeText} />
|
2020-08-21 00:50:38 +02:00
|
|
|
</TouchableOpacity>
|
|
|
|
)}
|
2018-10-09 06:25:36 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const handleLongPress = () => {
|
2021-09-23 15:05:10 +02:00
|
|
|
if (wallets.length > 1) {
|
2020-10-08 22:03:57 +02:00
|
|
|
navigate('ReorderWallets');
|
2018-12-18 07:05:03 +01:00
|
|
|
} else {
|
2019-05-03 14:36:11 +02:00
|
|
|
ReactNativeHapticFeedback.trigger('notificationError', { ignoreAndroidSystemSettings: false });
|
2018-12-11 23:52:46 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderTransactionListsRow = data => {
|
2020-03-26 21:15:00 +01:00
|
|
|
return (
|
2020-05-24 11:17:26 +02:00
|
|
|
<View style={styles.transaction}>
|
2021-12-17 11:41:18 +01:00
|
|
|
<TransactionListItem item={data.item} itemPriceUnit={data.item.walletPreferredBalanceUnit} walletID={data.item.walletID} />
|
2020-03-26 21:15:00 +01:00
|
|
|
</View>
|
|
|
|
);
|
2019-02-17 02:22:14 +01:00
|
|
|
};
|
2019-12-28 01:53:34 +01:00
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderWalletsCarousel = () => {
|
2020-05-17 03:41:38 +02:00
|
|
|
return (
|
|
|
|
<WalletsCarousel
|
2021-07-18 17:54:43 +02:00
|
|
|
data={wallets.concat(false)}
|
2021-09-23 15:05:10 +02:00
|
|
|
extraData={[wallets]}
|
2020-10-08 22:03:57 +02:00
|
|
|
onPress={handleClick}
|
|
|
|
handleLongPress={handleLongPress}
|
2021-06-16 08:05:04 +02:00
|
|
|
onMomentumScrollEnd={onSnapToItem}
|
2020-10-08 22:03:57 +02:00
|
|
|
ref={walletsCarousel}
|
2020-05-21 17:36:46 +02:00
|
|
|
testID="WalletsList"
|
2021-06-16 05:21:28 +02:00
|
|
|
horizontal
|
2021-07-04 06:21:31 +02:00
|
|
|
scrollEnabled={isFocused}
|
2020-05-17 03:41:38 +02:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderSectionItem = item => {
|
2020-05-17 03:41:38 +02:00
|
|
|
switch (item.section.key) {
|
|
|
|
case WalletsListSections.CAROUSEL:
|
2020-10-08 22:03:57 +02:00
|
|
|
return isLargeScreen ? null : renderWalletsCarousel();
|
2020-05-17 03:41:38 +02:00
|
|
|
case WalletsListSections.TRANSACTIONS:
|
2020-10-08 22:03:57 +02:00
|
|
|
return renderTransactionListsRow(item);
|
2020-05-17 03:41:38 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderSectionHeader = section => {
|
|
|
|
switch (section.section.key) {
|
2020-05-17 03:41:38 +02:00
|
|
|
case WalletsListSections.CAROUSEL:
|
2020-10-08 22:03:57 +02:00
|
|
|
return isLargeScreen ? null : (
|
2021-07-18 17:54:43 +02:00
|
|
|
<BlueHeaderDefaultMain leftText={loc.wallets.list_title} onNewWalletPress={() => navigate('AddWalletRoot')} />
|
2020-05-17 03:41:38 +02:00
|
|
|
);
|
|
|
|
case WalletsListSections.TRANSACTIONS:
|
2020-10-08 22:03:57 +02:00
|
|
|
return renderListHeaderComponent();
|
2020-05-17 03:41:38 +02:00
|
|
|
default:
|
|
|
|
return null;
|
2018-01-30 23:42:38 +01:00
|
|
|
}
|
2020-05-17 03:41:38 +02:00
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderSectionFooter = section => {
|
|
|
|
switch (section.section.key) {
|
2020-05-17 14:17:08 +02:00
|
|
|
case WalletsListSections.TRANSACTIONS:
|
2020-10-08 22:03:57 +02:00
|
|
|
if (dataSource.length === 0 && !isLoading) {
|
2020-05-17 14:17:08 +02:00
|
|
|
return (
|
2021-03-02 14:38:02 +01:00
|
|
|
<View style={styles.footerRoot} testID="NoTransactionsMessage">
|
2020-07-20 15:38:46 +02:00
|
|
|
<Text style={styles.footerEmpty}>{loc.wallets.list_empty_txs1}</Text>
|
|
|
|
<Text style={styles.footerStart}>{loc.wallets.list_empty_txs2}</Text>
|
2020-05-17 14:17:08 +02:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const renderScanButton = () => {
|
2021-09-23 15:05:10 +02:00
|
|
|
if (wallets.length > 0) {
|
2020-05-22 02:21:08 +02:00
|
|
|
return (
|
2021-02-27 01:23:59 +01:00
|
|
|
<FContainer ref={walletActionButtonsRef}>
|
2020-09-07 19:46:37 +02:00
|
|
|
<FButton
|
2020-10-08 22:03:57 +02:00
|
|
|
onPress={onScanButtonPressed}
|
2021-01-02 20:53:02 +01:00
|
|
|
onLongPress={isMacCatalina ? undefined : sendButtonLongPress}
|
2020-10-08 22:03:57 +02:00
|
|
|
icon={<Image resizeMode="stretch" source={scanImage} />}
|
2020-09-07 19:46:37 +02:00
|
|
|
text={loc.send.details_scan}
|
|
|
|
/>
|
|
|
|
</FContainer>
|
2020-05-22 02:21:08 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2020-05-21 13:24:12 +02:00
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const sectionListKeyExtractor = (item, index) => {
|
2020-05-17 03:41:38 +02:00
|
|
|
return `${item}${index}}`;
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const onScanButtonPressed = () => {
|
2021-01-02 20:53:02 +01:00
|
|
|
if (isMacCatalina) {
|
2021-04-05 01:26:38 +02:00
|
|
|
fs.showActionSheet({ anchor: findNodeHandle(walletActionButtonsRef.current) }).then(onBarScanned);
|
2020-08-11 02:11:11 +02:00
|
|
|
} else {
|
2021-03-20 14:00:01 +01:00
|
|
|
scanqrHelper(navigate, routeName, false).then(onBarScanned);
|
2020-08-11 02:11:11 +02:00
|
|
|
}
|
2020-05-20 20:04:28 +02:00
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const onBarScanned = value => {
|
2021-03-20 14:00:01 +01:00
|
|
|
if (!value) return;
|
2020-05-20 20:04:28 +02:00
|
|
|
DeeplinkSchemaMatch.navigationRouteFor({ url: value }, completionValue => {
|
|
|
|
ReactNativeHapticFeedback.trigger('impactLight', { ignoreAndroidSystemSettings: false });
|
2020-10-08 22:03:57 +02:00
|
|
|
navigate(...completionValue);
|
2020-05-20 20:04:28 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-11-16 05:10:21 +01:00
|
|
|
const copyFromClipboard = async () => {
|
2021-02-28 18:50:14 +01:00
|
|
|
onBarScanned(await BlueClipboard.getClipboardContent());
|
2020-05-28 10:44:15 +02:00
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const sendButtonLongPress = async () => {
|
2021-02-28 18:50:14 +01:00
|
|
|
const isClipboardEmpty = (await BlueClipboard.getClipboardContent()).trim().length === 0;
|
2020-05-28 10:44:15 +02:00
|
|
|
if (Platform.OS === 'ios') {
|
2021-01-02 20:53:02 +01:00
|
|
|
if (isMacCatalina) {
|
2021-02-27 01:23:59 +01:00
|
|
|
fs.showActionSheet({ anchor: findNodeHandle(walletActionButtonsRef.current) }).then(onBarScanned);
|
2020-12-20 08:01:39 +01:00
|
|
|
} else {
|
2020-12-20 08:03:22 +01:00
|
|
|
const options = [loc._.cancel, loc.wallets.list_long_choose, loc.wallets.list_long_scan];
|
2020-12-20 08:01:39 +01:00
|
|
|
if (!isClipboardEmpty) {
|
|
|
|
options.push(loc.wallets.list_long_clipboard);
|
|
|
|
}
|
2021-02-27 01:23:59 +01:00
|
|
|
ActionSheet.showActionSheetWithOptions(
|
|
|
|
{ options, cancelButtonIndex: 0, anchor: findNodeHandle(walletActionButtonsRef.current) },
|
|
|
|
buttonIndex => {
|
|
|
|
if (buttonIndex === 1) {
|
|
|
|
fs.showImagePickerAndReadImage().then(onBarScanned);
|
|
|
|
} else if (buttonIndex === 2) {
|
2021-03-20 14:00:01 +01:00
|
|
|
scanqrHelper(navigate, routeName, false).then(onBarScanned);
|
2021-02-27 01:23:59 +01:00
|
|
|
} else if (buttonIndex === 3) {
|
|
|
|
copyFromClipboard();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2020-12-20 08:01:39 +01:00
|
|
|
}
|
2020-05-28 10:44:15 +02:00
|
|
|
} else if (Platform.OS === 'android') {
|
2020-06-01 14:54:23 +02:00
|
|
|
const buttons = [
|
2020-05-28 10:44:15 +02:00
|
|
|
{
|
2020-07-20 15:38:46 +02:00
|
|
|
text: loc._.cancel,
|
2020-05-28 10:44:15 +02:00
|
|
|
onPress: () => {},
|
|
|
|
style: 'cancel',
|
|
|
|
},
|
|
|
|
{
|
2020-07-20 15:38:46 +02:00
|
|
|
text: loc.wallets.list_long_choose,
|
2021-04-28 16:27:45 +02:00
|
|
|
onPress: () => fs.showImagePickerAndReadImage().then(onBarScanned),
|
2020-05-28 10:44:15 +02:00
|
|
|
},
|
|
|
|
{
|
2020-07-20 15:38:46 +02:00
|
|
|
text: loc.wallets.list_long_scan,
|
2021-03-20 14:00:01 +01:00
|
|
|
onPress: () => scanqrHelper(navigate, routeName, false).then(onBarScanned),
|
2020-05-28 10:44:15 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
if (!isClipboardEmpty) {
|
|
|
|
buttons.push({
|
2020-07-20 15:38:46 +02:00
|
|
|
text: loc.wallets.list_long_clipboard,
|
2020-11-16 05:10:21 +01:00
|
|
|
onPress: copyFromClipboard,
|
2020-05-28 10:44:15 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
ActionSheet.showActionSheetWithOptions({
|
|
|
|
title: '',
|
|
|
|
message: '',
|
|
|
|
buttons,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
const onLayout = _e => {
|
2021-09-17 05:49:33 +02:00
|
|
|
setIsLargeScreen(Platform.OS === 'android' ? isTablet() : (width >= Dimensions.get('screen').width / 2 && isTablet()) || isDesktop);
|
2020-09-08 18:06:41 +02:00
|
|
|
};
|
|
|
|
|
2021-01-28 01:30:42 +01:00
|
|
|
const onRefresh = () => {
|
|
|
|
refreshTransactions(true, false);
|
|
|
|
};
|
|
|
|
|
2020-10-08 22:03:57 +02:00
|
|
|
return (
|
2021-01-05 02:44:28 +01:00
|
|
|
<View style={styles.root} onLayout={onLayout}>
|
2021-09-27 18:40:58 +02:00
|
|
|
<StatusBar barStyle={barStyle} backgroundColor="transparent" translucent animated />
|
2021-01-05 02:44:28 +01:00
|
|
|
<View style={[styles.walletsListWrapper, stylesHook.walletsListWrapper]}>
|
|
|
|
<SectionList
|
2021-08-19 21:56:59 +02:00
|
|
|
contentInsetAdjustmentBehavior="automatic"
|
|
|
|
automaticallyAdjustContentInsets
|
2021-01-05 02:44:28 +01:00
|
|
|
refreshing={isLoading}
|
2021-08-24 06:33:32 +02:00
|
|
|
{...(isElectrumDisabled ? {} : { refreshing: isLoading, onRefresh: onRefresh })}
|
2021-01-05 02:44:28 +01:00
|
|
|
renderItem={renderSectionItem}
|
|
|
|
keyExtractor={sectionListKeyExtractor}
|
|
|
|
renderSectionHeader={renderSectionHeader}
|
|
|
|
initialNumToRender={20}
|
|
|
|
contentInset={styles.scrollContent}
|
|
|
|
renderSectionFooter={renderSectionFooter}
|
|
|
|
sections={[
|
|
|
|
{ key: WalletsListSections.CAROUSEL, data: [WalletsListSections.CAROUSEL] },
|
|
|
|
{ key: WalletsListSections.TRANSACTIONS, data: dataSource },
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
{renderScanButton()}
|
|
|
|
</View>
|
|
|
|
</View>
|
2020-10-08 22:03:57 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WalletsList;
|
2021-09-14 07:36:00 +02:00
|
|
|
WalletsList.navigationOptions = navigationStyle({}, opts => ({ ...opts, headerTitle: '', headerBackTitle: loc.wallets.list_title }));
|
2019-12-28 01:53:34 +01:00
|
|
|
|
2020-07-06 18:04:44 +02:00
|
|
|
const styles = StyleSheet.create({
|
2021-01-05 02:44:28 +01:00
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2020-07-06 18:04:44 +02:00
|
|
|
scrollContent: {
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
bottom: 60,
|
|
|
|
right: 0,
|
|
|
|
},
|
|
|
|
walletsListWrapper: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
headerTouch: {
|
|
|
|
height: 48,
|
|
|
|
paddingVertical: 10,
|
|
|
|
},
|
2020-07-16 19:41:20 +02:00
|
|
|
listHeaderBack: {
|
2020-08-21 00:50:38 +02:00
|
|
|
flexDirection: 'row',
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
alignItems: 'center',
|
|
|
|
marginHorizontal: 16,
|
2020-07-16 19:41:20 +02:00
|
|
|
},
|
2020-07-06 18:04:44 +02:00
|
|
|
listHeaderText: {
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: 24,
|
2021-08-19 15:27:57 +02:00
|
|
|
marginVertical: 16,
|
2020-07-06 18:04:44 +02:00
|
|
|
},
|
|
|
|
footerRoot: {
|
|
|
|
top: 80,
|
|
|
|
height: 160,
|
|
|
|
marginBottom: 80,
|
|
|
|
},
|
|
|
|
footerEmpty: {
|
|
|
|
fontSize: 18,
|
|
|
|
color: '#9aa0aa',
|
|
|
|
textAlign: 'center',
|
|
|
|
},
|
|
|
|
footerStart: {
|
|
|
|
fontSize: 18,
|
|
|
|
color: '#9aa0aa',
|
|
|
|
textAlign: 'center',
|
|
|
|
fontWeight: '600',
|
|
|
|
},
|
|
|
|
transaction: {
|
2020-10-13 17:37:58 +02:00
|
|
|
marginHorizontal: 0,
|
2020-07-06 18:04:44 +02:00
|
|
|
},
|
|
|
|
});
|