Merge branch 'master' into idle

This commit is contained in:
marcosrdz 2021-01-29 15:20:51 -05:00
commit 4d5a729d9c
6 changed files with 46 additions and 14 deletions

View file

@ -7,11 +7,13 @@ const BlueElectrum = require('./BlueElectrum');
const _lastTimeTriedToRefetchWallet = {}; // hashmap of timestamps we _started_ refetching some wallet
export const WalletTransactionsStatus = { NONE: false, ALL: true };
export const BlueStorageContext = createContext();
export const BlueStorageProvider = ({ children }) => {
const [wallets, setWallets] = useState([]);
const [pendingWallets, setPendingWallets] = useState([]);
const [selectedWallet, setSelectedWallet] = useState('');
const [walletTransactionUpdateStatus, setWalletTransactionUpdateStatus] = useState(WalletTransactionsStatus.NONE);
const [walletsInitialized, setWalletsInitialized] = useState(false);
const [preferredFiatCurrency, _setPreferredFiatCurrency] = useState();
const [language, _setLanguage] = useState();
@ -80,9 +82,12 @@ export const BlueStorageProvider = ({ children }) => {
saveToDisk();
};
const refreshAllWalletTransactions = async lastSnappedTo => {
const refreshAllWalletTransactions = async (lastSnappedTo, showUpdateStatusIndicator = true) => {
let noErr = true;
try {
if (showUpdateStatusIndicator) {
setWalletTransactionUpdateStatus(WalletTransactionsStatus.ALL);
}
await BlueElectrum.waitTillConnected();
const balanceStart = +new Date();
await fetchWalletBalances(lastSnappedTo);
@ -95,6 +100,8 @@ export const BlueStorageProvider = ({ children }) => {
} catch (err) {
noErr = false;
console.warn(err);
} finally {
setWalletTransactionUpdateStatus(WalletTransactionsStatus.NONE);
}
if (noErr) await saveToDisk(); // caching
};
@ -104,6 +111,7 @@ export const BlueStorageProvider = ({ children }) => {
let noErr = true;
try {
// 5sec debounce:
setWalletTransactionUpdateStatus(walletID);
if (+new Date() - _lastTimeTriedToRefetchWallet[walletID] < 5000) {
console.log('re-fetch wallet happens too fast; NOP');
return;
@ -122,6 +130,8 @@ export const BlueStorageProvider = ({ children }) => {
} catch (err) {
noErr = false;
console.warn(err);
} finally {
setWalletTransactionUpdateStatus(WalletTransactionsStatus.NONE);
}
if (noErr) await saveToDisk(); // caching
};
@ -207,6 +217,8 @@ export const BlueStorageProvider = ({ children }) => {
language,
isHandOffUseEnabled,
setIsHandOffUseEnabledAsyncStorage,
walletTransactionUpdateStatus,
setWalletTransactionUpdateStatus,
}}
>
{children}

View file

@ -127,6 +127,7 @@ const iStyles = StyleSheet.create({
const WalletCarouselItem = ({ item, index, onPress, handleLongPress, isSelectedWallet }) => {
const scaleValue = new Animated.Value(1.0);
const { colors } = useTheme();
const { walletTransactionUpdateStatus } = useContext(BlueStorageContext);
const onPressedIn = () => {
const props = { duration: 50 };
@ -203,6 +204,15 @@ const WalletCarouselItem = ({ item, index, onPress, handleLongPress, isSelectedW
image = require('../img/btc-shape.png');
}
const latestTransactionText =
walletTransactionUpdateStatus === true || walletTransactionUpdateStatus === item.getID()
? loc.transactions.updating
: item.getBalance() !== 0 && item.getLatestTransactionTime() === 0
? loc.wallets.pull_to_refresh
: item.getTransactions().find(tx => tx.confirmations === 0)
? loc.transactions.pending
: transactionTimeToReadable(item.getLatestTransactionTime());
return (
<Animated.View
style={[iStyles.root, { opacity, transform: [{ scale: scaleValue }] }]}
@ -238,12 +248,9 @@ const WalletCarouselItem = ({ item, index, onPress, handleLongPress, isSelectedW
<Text numberOfLines={1} style={[iStyles.latestTx, { color: colors.inverseForegroundColor }]}>
{loc.wallets.list_latest_transaction}
</Text>
<Text numberOfLines={1} style={[iStyles.latestTxTime, { color: colors.inverseForegroundColor }]}>
{item.getBalance() !== 0 && item.getLatestTransactionTime() === 0
? loc.wallets.pull_to_refresh
: item.getTransactions().find(tx => tx.confirmations === 0)
? loc.transactions.pending.toLowerCase()
: transactionTimeToReadable(item.getLatestTransactionTime())}
{latestTransactionText}
</Text>
</LinearGradient>
</TouchableWithoutFeedback>

View file

@ -87,7 +87,7 @@
"offer_promt_fiat": "How much {currency} do you want to buy?",
"offer_promt_fiat_e": "For example, 100",
"offer_window": "window",
"p2p": "A p2p exchange"
"p2p": "Buy Bitcoin on a p2p exchange"
},
"lnd": {
"errorInvoiceExpired": "Invoice expired",
@ -355,7 +355,8 @@
"status_bump": "Bump Fee",
"status_cancel": "Cancel Transaction",
"transactions_count": "Transactions Count",
"txid": "Txid"
"txid": "Txid",
"updating": "Updating..."
},
"wallets": {
"add_bitcoin": "Bitcoin",

View file

@ -176,6 +176,7 @@
"details_adv_full_sure": "Haluatko varmasti käyttää lompakon koko saldon tähän siirtotapahtumaan?",
"details_adv_import": "Tuo Siirtotapahtuma",
"details_amount_field_is_not_valid": "Määrä ei kelpaa",
"details_amount_field_is_less_than_minimum_amount_sat": "Määritetty määrä on liian pieni. Anna summa, joka on yli 500 sats. ",
"details_create": "Luo Lasku",
"details_error_decode": "Virhe: Bitcoin-osoitetta ei voida dekoodata",
"details_fee_field_is_not_valid": "Siirtokulukenttä ei ole pätevä",
@ -444,10 +445,12 @@
"pull_to_refresh": "vedä päivittääksesi",
"warning_do_not_disclose": "Varoitus! Älä paljasta",
"add_ln_wallet_first": "Sinun on ensin lisättävä Lightning-lompakko.",
"identity_pubkey": "Tunnus Pubkey",
"xpub_title": "lompakon XPUB"
},
"multisig": {
"multisig_vault": "Holvi",
"default_label": "Multisig Vault",
"multisig_vault_explain": "Paras turvallisuus suurille summille",
"provide_signature": "Toimita allekirjoitus",
"vault_key": "Holvi avain {number}",

View file

@ -139,13 +139,13 @@ const WalletsList = () => {
* Forcefully fetches TXs and balance for ALL wallets.
* Triggered manually by user on pull-to-refresh.
*/
const refreshTransactions = (showLoadingIndicator = true) => {
const refreshTransactions = (showLoadingIndicator = true, showUpdateStatusIndicator = false) => {
setIsLoading(showLoadingIndicator);
refreshAllWalletTransactions().finally(() => setIsLoading(false));
refreshAllWalletTransactions(showLoadingIndicator, showUpdateStatusIndicator).finally(() => setIsLoading(false));
};
useEffect(() => {
refreshTransactions(false);
refreshTransactions(false, true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // call refreshTransactions() only once, when screen mounts
@ -194,7 +194,7 @@ const WalletsList = () => {
console.log('onSnapToItem', 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).finally(() => setIsLoading(false));
refreshAllWalletTransactions(index, false).finally(() => setIsLoading(false));
}
};
@ -432,12 +432,16 @@ const WalletsList = () => {
setItemWidth(width * 0.82 > 375 ? 375 : width * 0.82);
};
const onRefresh = () => {
refreshTransactions(true, false);
};
return (
<View style={styles.root} onLayout={onLayout}>
<StatusBar barStyle="default" />
<View style={[styles.walletsListWrapper, stylesHook.walletsListWrapper]}>
<SectionList
onRefresh={refreshTransactions}
onRefresh={onRefresh}
refreshing={isLoading}
renderItem={renderSectionItem}
keyExtractor={sectionListKeyExtractor}

View file

@ -48,7 +48,7 @@ const buttonFontSize =
: PixelRatio.roundToNearestPixel(Dimensions.get('window').width / 26);
const WalletTransactions = () => {
const { wallets, saveToDisk, setSelectedWallet } = useContext(BlueStorageContext);
const { wallets, saveToDisk, setSelectedWallet, walletTransactionUpdateStatus } = useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(false);
const [isManageFundsModalVisible, setIsManageFundsModalVisible] = useState(false);
const { walletID } = useRoute().params;
@ -112,6 +112,11 @@ const WalletTransactions = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
setOptions({ headerTitle: walletTransactionUpdateStatus === walletID ? loc.transactions.updating : '' });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [walletTransactionUpdateStatus]);
useEffect(() => {
setIsLoading(true);
setLimit(15);