From 21889d02aa09c775bac3a494beb847ae8df2967a Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Wed, 3 Feb 2021 23:50:38 -0500 Subject: [PATCH 1/3] REF: Remove useRef for transactions list --- ios/Podfile.lock | 10 +-- package-lock.json | 4 + screen/wallets/details.js | 6 +- screen/wallets/transactions.js | 145 ++++++++++++++++----------------- 4 files changed, 83 insertions(+), 82 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 2c74670de..0efcdd346 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -379,14 +379,14 @@ PODS: - React-Core - RNReanimated (1.13.1): - React - - RNScreens (2.11.0): - - React + - RNScreens (2.16.1): + - React-Core - RNSecureKeyStore (1.0.0): - React - RNSentry (1.9.0): - React-Core - Sentry (~> 5.2.0) - - RNShare (4.0.2): + - RNShare (5.1.0): - React-Core - RNSVG (12.1.0): - React @@ -739,10 +739,10 @@ SPEC CHECKSUMS: RNRate: 2b31dad120cd1b78e33c6034808561c386a3dddf RNReactNativeHapticFeedback: 653a8c126a0f5e88ce15ffe280b3ff37e1fbb285 RNReanimated: dd8c286ab5dd4ba36d3a7fef8bff7e08711b5476 - RNScreens: 0e91da98ab26d5d04c7b59a9b6bd694124caf88c + RNScreens: 45c457af3d2ee9e08fc01e70da87e653d46b1198 RNSecureKeyStore: f1ad870e53806453039f650720d2845c678d89c8 RNSentry: 1adaa43b01c6a3ab5091d4d1add66b7c58558898 - RNShare: 7a7277f3c313652422d9de072ac50714dff5e8a4 + RNShare: fed99fd743f80ca255903c1da46fc9a6430efab6 RNSVG: ce9d996113475209013317e48b05c21ee988d42e RNVectorIcons: bc69e6a278b14842063605de32bec61f0b251a59 RNWatch: e4c5d19506c94506860032fb68aedd5991beb985 diff --git a/package-lock.json b/package-lock.json index 55bc2e2f8..2dc0669c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20149,6 +20149,10 @@ "object-assign": "^4.1.1" } }, + "scryptsy": { + "version": "file:blue_modules/scryptsy", + "integrity": "sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w==" + }, "secp256k1": { "version": "3.8.0", "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.8.0.tgz", diff --git a/screen/wallets/details.js b/screen/wallets/details.js index 2d842ff4d..93fe81821 100644 --- a/screen/wallets/details.js +++ b/screen/wallets/details.js @@ -376,10 +376,10 @@ const WalletDetails = () => { } else { setIsLoading(true); Notifications.unsubscribe(wallet.getAllExternalAddresses(), [], []); - deleteWallet(wallet); - ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false }); - await saveToDisk(); popToTop(); + ReactNativeHapticFeedback.trigger('notificationSuccess', { ignoreAndroidSystemSettings: false }); + deleteWallet(wallet); + saveToDisk(); } }, style: 'destructive', diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index c02915019..00cdaddad 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -1,5 +1,5 @@ /* global alert */ -import React, { useEffect, useState, useCallback, useContext, useRef } from 'react'; +import React, { useEffect, useState, useCallback, useContext } from 'react'; import { ActivityIndicator, Alert, @@ -24,7 +24,7 @@ import { Icon } from 'react-native-elements'; import { useRoute, useNavigation, useTheme, useFocusEffect } from '@react-navigation/native'; import isCatalyst from 'react-native-is-catalyst'; -import { Chain } from '../../models/bitcoinUnits'; +import { BitcoinUnit, Chain } from '../../models/bitcoinUnits'; import { BlueTransactionListItem, BlueWalletNavigationHeader, BlueAlertWalletExportReminder, BlueListItem } from '../../BlueComponents'; import WalletGradient from '../../class/wallet-gradient'; import navigationStyle from '../../components/navigationStyle'; @@ -51,11 +51,10 @@ const WalletTransactions = () => { const { wallets, saveToDisk, setSelectedWallet, walletTransactionUpdateStatus } = useContext(BlueStorageContext); const [isLoading, setIsLoading] = useState(false); const [isManageFundsModalVisible, setIsManageFundsModalVisible] = useState(false); - const { walletID } = useRoute().params; - const wallet = useRef(wallets.find(w => w.getID() === walletID)); - const name = useRoute().name; - const [itemPriceUnit, setItemPriceUnit] = useState(wallet.current.getPreferredBalanceUnit()); - const [dataSource, setDataSource] = useState(wallet.current.getTransactions(15)); + const { walletID, name } = useRoute().params; + const wallet = wallets.find(w => w.getID() === walletID); + const [itemPriceUnit, setItemPriceUnit] = useState(wallet?.getPreferredBalanceUnit() ?? BitcoinUnit.BTC); + const [dataSource, setDataSource] = useState(wallet?.getTransactions(15) ?? []); const [timeElapsed, setTimeElapsed] = useState(0); const [limit, setLimit] = useState(15); const [pageSize, setPageSize] = useState(20); @@ -87,14 +86,14 @@ const WalletTransactions = () => { }); /** - * Simple wrapper for `wallet.current.getTransactions()`, where `wallet` is current wallet.current. + * Simple wrapper for `wallet.getTransactions()`, where `wallet` is current wallet. * Sorts. Provides limiting. * * @param limit {Integer} How many txs return, starting from the earliest. Default: all of them. * @returns {Array} */ const getTransactionsSliced = (limit = Infinity) => { - let txs = wallet.current.getTransactions(); + let txs = wallet.getTransactions(); for (const tx of txs) { tx.sort_ts = +new Date(tx.received); } @@ -122,13 +121,13 @@ const WalletTransactions = () => { setLimit(15); setPageSize(20); setTimeElapsed(0); - setItemPriceUnit(wallet.current.getPreferredBalanceUnit()); + setItemPriceUnit(wallet.getPreferredBalanceUnit()); setIsLoading(false); - setSelectedWallet(wallet.current.getID()); - setDataSource(wallet.current.getTransactions(15)); + setSelectedWallet(wallet.getID()); + setDataSource(wallet.getTransactions(15)); setOptions({ headerStyle: { - backgroundColor: WalletGradient.headerColorFor(wallet.current.type), + backgroundColor: WalletGradient.headerColorFor(wallet.type), borderBottomWidth: 0, elevation: 0, // shadowRadius: 0, @@ -136,12 +135,11 @@ const WalletTransactions = () => { }, }); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [wallets, wallet.current, walletID]); + }, [wallets, wallet, walletID]); useEffect(() => { - const newwallet = wallets.find(w => w.getID() === walletID); - if (newwallet) { - wallet.current = newwallet; + const newWallet = wallets.find(w => w.getID() === walletID); + if (newWallet) { setParams({ walletID, isLoading: false }); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -150,7 +148,7 @@ const WalletTransactions = () => { // if balance of the wallet positive and there are no transactions, then // it'a freshly impoted wallet and we need to refresh transactions useEffect(() => { - if (dataSource.length === 0 && wallet.current.getBalance() > 0) { + if (dataSource.length === 0 && wallet.getBalance() > 0) { refreshTransactions(); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -164,7 +162,7 @@ const WalletTransactions = () => { ); const isLightning = () => { - const w = wallet.current; + const w = wallet; if (w && w.chain === Chain.OFFCHAIN) { return true; } @@ -185,23 +183,23 @@ const WalletTransactions = () => { await BlueElectrum.waitTillConnected(); /** @type {LegacyWallet} */ const balanceStart = +new Date(); - const oldBalance = wallet.current.getBalance(); - await wallet.current.fetchBalance(); - if (oldBalance !== wallet.current.getBalance()) smthChanged = true; + const oldBalance = wallet.getBalance(); + await wallet.fetchBalance(); + if (oldBalance !== wallet.getBalance()) smthChanged = true; const balanceEnd = +new Date(); - console.log(wallet.current.getLabel(), 'fetch balance took', (balanceEnd - balanceStart) / 1000, 'sec'); + console.log(wallet.getLabel(), 'fetch balance took', (balanceEnd - balanceStart) / 1000, 'sec'); const start = +new Date(); - const oldTxLen = wallet.current.getTransactions().length; - await wallet.current.fetchTransactions(); - if (wallet.current.fetchPendingTransactions) { - await wallet.current.fetchPendingTransactions(); + const oldTxLen = wallet.getTransactions().length; + await wallet.fetchTransactions(); + if (wallet.fetchPendingTransactions) { + await wallet.fetchPendingTransactions(); } - if (wallet.current.fetchUserInvoices) { - await wallet.current.fetchUserInvoices(); + if (wallet.fetchUserInvoices) { + await wallet.fetchUserInvoices(); } - if (oldTxLen !== wallet.current.getTransactions().length) smthChanged = true; + if (oldTxLen !== wallet.getTransactions().length) smthChanged = true; const end = +new Date(); - console.log(wallet.current.getLabel(), 'fetch tx took', (end - start) / 1000, 'sec'); + console.log(wallet.getLabel(), 'fetch tx took', (end - start) / 1000, 'sec'); } catch (err) { noErr = false; alert(err.message); @@ -254,9 +252,9 @@ const WalletTransactions = () => { The idea is to avoid showing on iOS an appstore/market style app that goes against the TOS. */} - {wallet.current.getTransactions().length > 0 && wallet.current.type !== LightningCustodianWallet.type && renderSellFiat()} - {wallet.current.type === LightningCustodianWallet.type && renderMarketplaceButton()} - {wallet.current.type === LightningCustodianWallet.type && Platform.OS === 'ios' && renderLappBrowserButton()} + {wallet.getTransactions().length > 0 && wallet.type !== LightningCustodianWallet.type && renderSellFiat()} + {wallet.type === LightningCustodianWallet.type && renderMarketplaceButton()} + {wallet.type === LightningCustodianWallet.type && Platform.OS === 'ios' && renderLappBrowserButton()} {loc.transactions.list_title} @@ -301,7 +299,7 @@ const WalletTransactions = () => { navigate('ReceiveDetailsRoot', { screen: 'ReceiveDetails', params: { - walletID: wallet.current.getID(), + walletID: wallet.getID(), }, }); }} @@ -334,7 +332,7 @@ const WalletTransactions = () => { }; const navigateToBuyBitcoin = () => { - BuyBitcoin.navigate(wallet.current); + BuyBitcoin.navigate(wallet); }; const renderMarketplaceButton = () => { @@ -342,13 +340,13 @@ const WalletTransactions = () => { android: ( { - if (wallet.current.type === LightningCustodianWallet.type) { + if (wallet.type === LightningCustodianWallet.type) { navigate('LappBrowserRoot', { screen: 'LappBrowser', - params: { fromSecret: wallet.current.getSecret(), fromWallet: wallet.current }, + params: { fromSecret: wallet.getSecret(), fromWallet: wallet }, }); } else { - navigate('Marketplace', { fromWallet: wallet.current }); + navigate('Marketplace', { fromWallet: wallet }); } }} style={[styles.marketplaceButton1, stylesHook.marketplaceButton1]} @@ -357,7 +355,7 @@ const WalletTransactions = () => { ), ios: - wallet.current.getBalance() > 0 ? ( + wallet.getBalance() > 0 ? ( { Linking.openURL('https://bluewallet.io/marketplace/'); @@ -378,7 +376,7 @@ const WalletTransactions = () => { navigate('LappBrowserRoot', { screen: 'LappBrowser', params: { - fromSecret: wallet.current.getSecret(), + fromSecret: wallet.getSecret(), fromWallet: wallet, url: 'https://duckduckgo.com', }, @@ -402,18 +400,18 @@ const WalletTransactions = () => { const onWalletSelect = async selectedWallet => { if (selectedWallet) { navigate('WalletTransactions', { - walletType: wallet.current.type, - walletID: wallet.current.getID(), - key: `WalletTransactions-${wallet.current.getID()}`, + walletType: wallet.type, + walletID: wallet.getID(), + key: `WalletTransactions-${wallet.getID()}`, }); /** @type {LightningCustodianWallet} */ let toAddress = false; - if (wallet.current.refill_addressess.length > 0) { - toAddress = wallet.current.refill_addressess[0]; + if (wallet.refill_addressess.length > 0) { + toAddress = wallet.refill_addressess[0]; } else { try { - await wallet.current.fetchBtcAddress(); - toAddress = wallet.current.refill_addressess[0]; + await wallet.fetchBtcAddress(); + toAddress = wallet.refill_addressess[0]; } catch (Err) { return alert(Err.message); } @@ -432,7 +430,7 @@ const WalletTransactions = () => { navigate('SendDetailsRoot', { screen: 'SendDetails', params: { - fromWallet: wallet.current, + fromWallet: wallet, }, }); }; @@ -443,11 +441,11 @@ const WalletTransactions = () => { if (!isLoading) { setIsLoading(true); const params = { - walletID: wallet.current.getID(), + walletID: wallet.getID(), uri: ret.data ? ret.data : ret, - fromWallet: wallet.current, + fromWallet: wallet, }; - if (wallet.current.chain === Chain.ONCHAIN) { + if (wallet.chain === Chain.ONCHAIN) { navigate('SendDetailsRoot', { screen: 'SendDetails', params }); } else { navigate('ScanLndInvoiceRoot', { screen: 'ScanLndInvoice', params }); @@ -483,11 +481,11 @@ const WalletTransactions = () => { }; const sendButtonPress = () => { - if (wallet.current.chain === Chain.OFFCHAIN) { - navigate('ScanLndInvoiceRoot', { screen: 'ScanLndInvoice', params: { walletID: wallet.current.getID() } }); + if (wallet.chain === Chain.OFFCHAIN) { + navigate('ScanLndInvoiceRoot', { screen: 'ScanLndInvoice', params: { walletID: wallet.getID() } }); } else { - if (wallet.current.type === WatchOnlyWallet.type && wallet.current.isHd() && wallet.current.getSecret().startsWith('zpub')) { - if (wallet.current.useWithHardwareWalletEnabled()) { + if (wallet.type === WatchOnlyWallet.type && wallet.isHd() && wallet.getSecret().startsWith('zpub')) { + if (wallet.useWithHardwareWalletEnabled()) { navigateToSendScreen(); } else { Alert.alert( @@ -497,7 +495,7 @@ const WalletTransactions = () => { { text: loc._.ok, onPress: async () => { - wallet.current.setUseWithHardwareWalletEnabled(true); + wallet.setUseWithHardwareWalletEnabled(true); await saveToDisk(); navigateToSendScreen(); }, @@ -584,23 +582,23 @@ const WalletTransactions = () => { navigate('ViewEditMultisigCosignersRoot', { screen: 'ViewEditMultisigCosigners', params: { - walletId: wallet.current.getID(), + walletId: wallet.getID(), }, }); }; return ( - - {wallet.current.chain === Chain.ONCHAIN && wallet.current.type !== MultisigHDWallet.type && ( + + {wallet.chain === Chain.ONCHAIN && wallet.type !== MultisigHDWallet.type && ( )} InteractionManager.runAfterInteractions(async () => { setItemPriceUnit(passedWallet.getPreferredBalanceUnit()); @@ -608,15 +606,15 @@ const WalletTransactions = () => { }) } onManageFundsPressed={() => { - if (wallet.current.type === MultisigHDWallet.type) { + if (wallet.type === MultisigHDWallet.type) { navigateToViewEditCosigners(); - } else if (wallet.current.type === LightningCustodianWallet.type) { - if (wallet.current.getUserHasSavedExport()) { + } else if (wallet.type === LightningCustodianWallet.type) { + if (wallet.getUserHasSavedExport()) { setIsManageFundsModalVisible(true); } else { BlueAlertWalletExportReminder({ onSuccess: async () => { - wallet.current.setUserHasSavedExport(true); + wallet.setUserHasSavedExport(true); await saveToDisk(); setIsManageFundsModalVisible(true); }, @@ -624,7 +622,7 @@ const WalletTransactions = () => { navigate('WalletExportRoot', { screen: 'WalletExport', params: { - walletID: wallet.current.getID(), + walletID: wallet.getID(), }, }), }); @@ -678,15 +676,15 @@ const WalletTransactions = () => { - {wallet.current.allowReceive() && ( + {wallet.allowReceive() && ( { - if (wallet.current.chain === Chain.OFFCHAIN) { - navigate('LNDCreateInvoiceRoot', { screen: 'LNDCreateInvoice', params: { walletID: wallet.current.getID() } }); + if (wallet.chain === Chain.OFFCHAIN) { + navigate('LNDCreateInvoiceRoot', { screen: 'LNDCreateInvoice', params: { walletID: wallet.getID() } }); } else { - navigate('ReceiveDetailsRoot', { screen: 'ReceiveDetails', params: { walletID: wallet.current.getID() } }); + navigate('ReceiveDetailsRoot', { screen: 'ReceiveDetails', params: { walletID: wallet.getID() } }); } }} icon={ @@ -696,8 +694,7 @@ const WalletTransactions = () => { } /> )} - {(wallet.current.allowSend() || - (wallet.current.type === WatchOnlyWallet.type && wallet.current.isHd() && wallet.current.getSecret().startsWith('zpub'))) && ( + {(wallet.allowSend() || (wallet.type === WatchOnlyWallet.type && wallet.isHd() && wallet.getSecret().startsWith('zpub'))) && ( Date: Wed, 3 Feb 2021 23:54:24 -0500 Subject: [PATCH 2/3] Update transactions.js --- screen/wallets/transactions.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index 00cdaddad..a80fb4abd 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -22,9 +22,7 @@ import { launchImageLibrary } from 'react-native-image-picker'; import Clipboard from '@react-native-community/clipboard'; import { Icon } from 'react-native-elements'; import { useRoute, useNavigation, useTheme, useFocusEffect } from '@react-navigation/native'; -import isCatalyst from 'react-native-is-catalyst'; - -import { BitcoinUnit, Chain } from '../../models/bitcoinUnits'; +import { Chain } from '../../models/bitcoinUnits'; import { BlueTransactionListItem, BlueWalletNavigationHeader, BlueAlertWalletExportReminder, BlueListItem } from '../../BlueComponents'; import WalletGradient from '../../class/wallet-gradient'; import navigationStyle from '../../components/navigationStyle'; @@ -36,11 +34,11 @@ import { FContainer, FButton } from '../../components/FloatButtons'; import BottomModal from '../../components/BottomModal'; import BuyBitcoin from './buyBitcoin'; import { BlueStorageContext } from '../../blue_modules/storage-context'; -import { getSystemName } from 'react-native-device-info'; +import { isCatalyst, isMacCatalina } from '../../blue_modules/environment'; + const fs = require('../../blue_modules/fs'); const BlueElectrum = require('../../blue_modules/BlueElectrum'); const LocalQRCode = require('@remobile/react-native-qrcode-local-image'); -const isDesktop = getSystemName() === 'Mac OS X'; const buttonFontSize = PixelRatio.roundToNearestPixel(Dimensions.get('window').width / 26) > 22 @@ -53,8 +51,8 @@ const WalletTransactions = () => { const [isManageFundsModalVisible, setIsManageFundsModalVisible] = useState(false); const { walletID, name } = useRoute().params; const wallet = wallets.find(w => w.getID() === walletID); - const [itemPriceUnit, setItemPriceUnit] = useState(wallet?.getPreferredBalanceUnit() ?? BitcoinUnit.BTC); - const [dataSource, setDataSource] = useState(wallet?.getTransactions(15) ?? []); + const [itemPriceUnit, setItemPriceUnit] = useState(wallet.getPreferredBalanceUnit()); + const [dataSource, setDataSource] = useState(wallet.getTransactions(15)); const [timeElapsed, setTimeElapsed] = useState(0); const [limit, setLimit] = useState(15); const [pageSize, setPageSize] = useState(20); @@ -514,7 +512,7 @@ const WalletTransactions = () => { }; const sendButtonLongPress = async () => { - if (isDesktop) { + if (isMacCatalina) { fs.showActionSheet().then(onBarCodeRead); } else { const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0; From 29581f80812c203f053f48e40c02ab1ae45e6bdf Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Fri, 5 Feb 2021 17:12:06 -0500 Subject: [PATCH 3/3] Update transactions.js --- screen/wallets/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screen/wallets/transactions.js b/screen/wallets/transactions.js index a80fb4abd..a073bb1eb 100644 --- a/screen/wallets/transactions.js +++ b/screen/wallets/transactions.js @@ -665,7 +665,7 @@ const WalletTransactions = () => { onRefresh={refreshTransactions} refreshing={isLoading} data={dataSource} - extraData={[timeElapsed, dataSource]} + extraData={[timeElapsed, dataSource, wallets]} keyExtractor={_keyExtractor} renderItem={renderItem} contentInset={{ top: 0, left: 0, bottom: 90, right: 0 }}