mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-24 23:38:57 +01:00
Merge branch 'master' into idle
This commit is contained in:
commit
4d5a729d9c
6 changed files with 46 additions and 14 deletions
|
@ -7,11 +7,13 @@ const BlueElectrum = require('./BlueElectrum');
|
||||||
|
|
||||||
const _lastTimeTriedToRefetchWallet = {}; // hashmap of timestamps we _started_ refetching some wallet
|
const _lastTimeTriedToRefetchWallet = {}; // hashmap of timestamps we _started_ refetching some wallet
|
||||||
|
|
||||||
|
export const WalletTransactionsStatus = { NONE: false, ALL: true };
|
||||||
export const BlueStorageContext = createContext();
|
export const BlueStorageContext = createContext();
|
||||||
export const BlueStorageProvider = ({ children }) => {
|
export const BlueStorageProvider = ({ children }) => {
|
||||||
const [wallets, setWallets] = useState([]);
|
const [wallets, setWallets] = useState([]);
|
||||||
const [pendingWallets, setPendingWallets] = useState([]);
|
const [pendingWallets, setPendingWallets] = useState([]);
|
||||||
const [selectedWallet, setSelectedWallet] = useState('');
|
const [selectedWallet, setSelectedWallet] = useState('');
|
||||||
|
const [walletTransactionUpdateStatus, setWalletTransactionUpdateStatus] = useState(WalletTransactionsStatus.NONE);
|
||||||
const [walletsInitialized, setWalletsInitialized] = useState(false);
|
const [walletsInitialized, setWalletsInitialized] = useState(false);
|
||||||
const [preferredFiatCurrency, _setPreferredFiatCurrency] = useState();
|
const [preferredFiatCurrency, _setPreferredFiatCurrency] = useState();
|
||||||
const [language, _setLanguage] = useState();
|
const [language, _setLanguage] = useState();
|
||||||
|
@ -80,9 +82,12 @@ export const BlueStorageProvider = ({ children }) => {
|
||||||
saveToDisk();
|
saveToDisk();
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshAllWalletTransactions = async lastSnappedTo => {
|
const refreshAllWalletTransactions = async (lastSnappedTo, showUpdateStatusIndicator = true) => {
|
||||||
let noErr = true;
|
let noErr = true;
|
||||||
try {
|
try {
|
||||||
|
if (showUpdateStatusIndicator) {
|
||||||
|
setWalletTransactionUpdateStatus(WalletTransactionsStatus.ALL);
|
||||||
|
}
|
||||||
await BlueElectrum.waitTillConnected();
|
await BlueElectrum.waitTillConnected();
|
||||||
const balanceStart = +new Date();
|
const balanceStart = +new Date();
|
||||||
await fetchWalletBalances(lastSnappedTo);
|
await fetchWalletBalances(lastSnappedTo);
|
||||||
|
@ -95,6 +100,8 @@ export const BlueStorageProvider = ({ children }) => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
noErr = false;
|
noErr = false;
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
|
} finally {
|
||||||
|
setWalletTransactionUpdateStatus(WalletTransactionsStatus.NONE);
|
||||||
}
|
}
|
||||||
if (noErr) await saveToDisk(); // caching
|
if (noErr) await saveToDisk(); // caching
|
||||||
};
|
};
|
||||||
|
@ -104,6 +111,7 @@ export const BlueStorageProvider = ({ children }) => {
|
||||||
let noErr = true;
|
let noErr = true;
|
||||||
try {
|
try {
|
||||||
// 5sec debounce:
|
// 5sec debounce:
|
||||||
|
setWalletTransactionUpdateStatus(walletID);
|
||||||
if (+new Date() - _lastTimeTriedToRefetchWallet[walletID] < 5000) {
|
if (+new Date() - _lastTimeTriedToRefetchWallet[walletID] < 5000) {
|
||||||
console.log('re-fetch wallet happens too fast; NOP');
|
console.log('re-fetch wallet happens too fast; NOP');
|
||||||
return;
|
return;
|
||||||
|
@ -122,6 +130,8 @@ export const BlueStorageProvider = ({ children }) => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
noErr = false;
|
noErr = false;
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
|
} finally {
|
||||||
|
setWalletTransactionUpdateStatus(WalletTransactionsStatus.NONE);
|
||||||
}
|
}
|
||||||
if (noErr) await saveToDisk(); // caching
|
if (noErr) await saveToDisk(); // caching
|
||||||
};
|
};
|
||||||
|
@ -207,6 +217,8 @@ export const BlueStorageProvider = ({ children }) => {
|
||||||
language,
|
language,
|
||||||
isHandOffUseEnabled,
|
isHandOffUseEnabled,
|
||||||
setIsHandOffUseEnabledAsyncStorage,
|
setIsHandOffUseEnabledAsyncStorage,
|
||||||
|
walletTransactionUpdateStatus,
|
||||||
|
setWalletTransactionUpdateStatus,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -127,6 +127,7 @@ const iStyles = StyleSheet.create({
|
||||||
const WalletCarouselItem = ({ item, index, onPress, handleLongPress, isSelectedWallet }) => {
|
const WalletCarouselItem = ({ item, index, onPress, handleLongPress, isSelectedWallet }) => {
|
||||||
const scaleValue = new Animated.Value(1.0);
|
const scaleValue = new Animated.Value(1.0);
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
|
const { walletTransactionUpdateStatus } = useContext(BlueStorageContext);
|
||||||
|
|
||||||
const onPressedIn = () => {
|
const onPressedIn = () => {
|
||||||
const props = { duration: 50 };
|
const props = { duration: 50 };
|
||||||
|
@ -203,6 +204,15 @@ const WalletCarouselItem = ({ item, index, onPress, handleLongPress, isSelectedW
|
||||||
image = require('../img/btc-shape.png');
|
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 (
|
return (
|
||||||
<Animated.View
|
<Animated.View
|
||||||
style={[iStyles.root, { opacity, transform: [{ scale: scaleValue }] }]}
|
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 }]}>
|
<Text numberOfLines={1} style={[iStyles.latestTx, { color: colors.inverseForegroundColor }]}>
|
||||||
{loc.wallets.list_latest_transaction}
|
{loc.wallets.list_latest_transaction}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Text numberOfLines={1} style={[iStyles.latestTxTime, { color: colors.inverseForegroundColor }]}>
|
<Text numberOfLines={1} style={[iStyles.latestTxTime, { color: colors.inverseForegroundColor }]}>
|
||||||
{item.getBalance() !== 0 && item.getLatestTransactionTime() === 0
|
{latestTransactionText}
|
||||||
? loc.wallets.pull_to_refresh
|
|
||||||
: item.getTransactions().find(tx => tx.confirmations === 0)
|
|
||||||
? loc.transactions.pending.toLowerCase()
|
|
||||||
: transactionTimeToReadable(item.getLatestTransactionTime())}
|
|
||||||
</Text>
|
</Text>
|
||||||
</LinearGradient>
|
</LinearGradient>
|
||||||
</TouchableWithoutFeedback>
|
</TouchableWithoutFeedback>
|
||||||
|
|
|
@ -87,7 +87,7 @@
|
||||||
"offer_promt_fiat": "How much {currency} do you want to buy?",
|
"offer_promt_fiat": "How much {currency} do you want to buy?",
|
||||||
"offer_promt_fiat_e": "For example, 100",
|
"offer_promt_fiat_e": "For example, 100",
|
||||||
"offer_window": "window",
|
"offer_window": "window",
|
||||||
"p2p": "A p2p exchange"
|
"p2p": "Buy Bitcoin on a p2p exchange"
|
||||||
},
|
},
|
||||||
"lnd": {
|
"lnd": {
|
||||||
"errorInvoiceExpired": "Invoice expired",
|
"errorInvoiceExpired": "Invoice expired",
|
||||||
|
@ -355,7 +355,8 @@
|
||||||
"status_bump": "Bump Fee",
|
"status_bump": "Bump Fee",
|
||||||
"status_cancel": "Cancel Transaction",
|
"status_cancel": "Cancel Transaction",
|
||||||
"transactions_count": "Transactions Count",
|
"transactions_count": "Transactions Count",
|
||||||
"txid": "Txid"
|
"txid": "Txid",
|
||||||
|
"updating": "Updating..."
|
||||||
},
|
},
|
||||||
"wallets": {
|
"wallets": {
|
||||||
"add_bitcoin": "Bitcoin",
|
"add_bitcoin": "Bitcoin",
|
||||||
|
|
|
@ -176,6 +176,7 @@
|
||||||
"details_adv_full_sure": "Haluatko varmasti käyttää lompakon koko saldon tähän siirtotapahtumaan?",
|
"details_adv_full_sure": "Haluatko varmasti käyttää lompakon koko saldon tähän siirtotapahtumaan?",
|
||||||
"details_adv_import": "Tuo Siirtotapahtuma",
|
"details_adv_import": "Tuo Siirtotapahtuma",
|
||||||
"details_amount_field_is_not_valid": "Määrä ei kelpaa",
|
"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_create": "Luo Lasku",
|
||||||
"details_error_decode": "Virhe: Bitcoin-osoitetta ei voida dekoodata",
|
"details_error_decode": "Virhe: Bitcoin-osoitetta ei voida dekoodata",
|
||||||
"details_fee_field_is_not_valid": "Siirtokulukenttä ei ole pätevä",
|
"details_fee_field_is_not_valid": "Siirtokulukenttä ei ole pätevä",
|
||||||
|
@ -444,10 +445,12 @@
|
||||||
"pull_to_refresh": "vedä päivittääksesi",
|
"pull_to_refresh": "vedä päivittääksesi",
|
||||||
"warning_do_not_disclose": "Varoitus! Älä paljasta",
|
"warning_do_not_disclose": "Varoitus! Älä paljasta",
|
||||||
"add_ln_wallet_first": "Sinun on ensin lisättävä Lightning-lompakko.",
|
"add_ln_wallet_first": "Sinun on ensin lisättävä Lightning-lompakko.",
|
||||||
|
"identity_pubkey": "Tunnus Pubkey",
|
||||||
"xpub_title": "lompakon XPUB"
|
"xpub_title": "lompakon XPUB"
|
||||||
},
|
},
|
||||||
"multisig": {
|
"multisig": {
|
||||||
"multisig_vault": "Holvi",
|
"multisig_vault": "Holvi",
|
||||||
|
"default_label": "Multisig Vault",
|
||||||
"multisig_vault_explain": "Paras turvallisuus suurille summille",
|
"multisig_vault_explain": "Paras turvallisuus suurille summille",
|
||||||
"provide_signature": "Toimita allekirjoitus",
|
"provide_signature": "Toimita allekirjoitus",
|
||||||
"vault_key": "Holvi avain {number}",
|
"vault_key": "Holvi avain {number}",
|
||||||
|
|
|
@ -139,13 +139,13 @@ const WalletsList = () => {
|
||||||
* Forcefully fetches TXs and balance for ALL wallets.
|
* Forcefully fetches TXs and balance for ALL wallets.
|
||||||
* Triggered manually by user on pull-to-refresh.
|
* Triggered manually by user on pull-to-refresh.
|
||||||
*/
|
*/
|
||||||
const refreshTransactions = (showLoadingIndicator = true) => {
|
const refreshTransactions = (showLoadingIndicator = true, showUpdateStatusIndicator = false) => {
|
||||||
setIsLoading(showLoadingIndicator);
|
setIsLoading(showLoadingIndicator);
|
||||||
refreshAllWalletTransactions().finally(() => setIsLoading(false));
|
refreshAllWalletTransactions(showLoadingIndicator, showUpdateStatusIndicator).finally(() => setIsLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshTransactions(false);
|
refreshTransactions(false, true);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []); // call refreshTransactions() only once, when screen mounts
|
}, []); // call refreshTransactions() only once, when screen mounts
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ const WalletsList = () => {
|
||||||
console.log('onSnapToItem', index);
|
console.log('onSnapToItem', index);
|
||||||
if (wallets[index] && (wallets[index].timeToRefreshBalance() || wallets[index].timeToRefreshTransaction())) {
|
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');
|
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);
|
setItemWidth(width * 0.82 > 375 ? 375 : width * 0.82);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onRefresh = () => {
|
||||||
|
refreshTransactions(true, false);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.root} onLayout={onLayout}>
|
<View style={styles.root} onLayout={onLayout}>
|
||||||
<StatusBar barStyle="default" />
|
<StatusBar barStyle="default" />
|
||||||
<View style={[styles.walletsListWrapper, stylesHook.walletsListWrapper]}>
|
<View style={[styles.walletsListWrapper, stylesHook.walletsListWrapper]}>
|
||||||
<SectionList
|
<SectionList
|
||||||
onRefresh={refreshTransactions}
|
onRefresh={onRefresh}
|
||||||
refreshing={isLoading}
|
refreshing={isLoading}
|
||||||
renderItem={renderSectionItem}
|
renderItem={renderSectionItem}
|
||||||
keyExtractor={sectionListKeyExtractor}
|
keyExtractor={sectionListKeyExtractor}
|
||||||
|
|
|
@ -48,7 +48,7 @@ const buttonFontSize =
|
||||||
: PixelRatio.roundToNearestPixel(Dimensions.get('window').width / 26);
|
: PixelRatio.roundToNearestPixel(Dimensions.get('window').width / 26);
|
||||||
|
|
||||||
const WalletTransactions = () => {
|
const WalletTransactions = () => {
|
||||||
const { wallets, saveToDisk, setSelectedWallet } = useContext(BlueStorageContext);
|
const { wallets, saveToDisk, setSelectedWallet, walletTransactionUpdateStatus } = useContext(BlueStorageContext);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isManageFundsModalVisible, setIsManageFundsModalVisible] = useState(false);
|
const [isManageFundsModalVisible, setIsManageFundsModalVisible] = useState(false);
|
||||||
const { walletID } = useRoute().params;
|
const { walletID } = useRoute().params;
|
||||||
|
@ -112,6 +112,11 @@ const WalletTransactions = () => {
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// 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(() => {
|
useEffect(() => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setLimit(15);
|
setLimit(15);
|
||||||
|
|
Loading…
Add table
Reference in a new issue