mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-15 11:59:21 +01:00
REF: Implement Suggestions
This commit is contained in:
parent
841f49ceb9
commit
28d9fa1d53
1 changed files with 102 additions and 102 deletions
|
@ -18,6 +18,7 @@ import { useStorage } from '../../hooks/context/useStorage';
|
||||||
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import { LightningTransaction } from '../../class/wallets/types';
|
import { LightningTransaction } from '../../class/wallets/types';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
type LNDViewInvoiceRouteParams = {
|
type LNDViewInvoiceRouteParams = {
|
||||||
walletID: string;
|
walletID: string;
|
||||||
|
@ -69,88 +70,88 @@ const LNDViewInvoice = () => {
|
||||||
setOptions(
|
setOptions(
|
||||||
isModal
|
isModal
|
||||||
? {
|
? {
|
||||||
headerStyle: {
|
headerStyle: {
|
||||||
backgroundColor: colors.customHeader,
|
backgroundColor: colors.customHeader,
|
||||||
},
|
},
|
||||||
gestureEnabled: false,
|
gestureEnabled: false,
|
||||||
headerBackVisible: false,
|
headerBackVisible: false,
|
||||||
|
// eslint-disable-next-line react/no-unstable-nested-components
|
||||||
// eslint-disable-next-line react/no-unstable-nested-components
|
headerRight: () => (
|
||||||
headerRight: () => (
|
<TouchableOpacity
|
||||||
<TouchableOpacity
|
accessibilityRole="button"
|
||||||
accessibilityRole="button"
|
// @ts-ignore - button is not suppprted .
|
||||||
// @ts-ignore - button is not suppprted .
|
style={styles.button}
|
||||||
style={styles.button}
|
onPress={() => {
|
||||||
onPress={() => {
|
// @ts-ignore: navigation
|
||||||
// @ts-ignore: navigation
|
navigation?.getParent().pop();
|
||||||
navigation?.getParent().pop();
|
}}
|
||||||
}}
|
testID="NavigationCloseButton"
|
||||||
testID="NavigationCloseButton"
|
>
|
||||||
>
|
<Image source={closeImage} />
|
||||||
<Image source={closeImage} />
|
</TouchableOpacity>
|
||||||
</TouchableOpacity>
|
),
|
||||||
),
|
}
|
||||||
}
|
|
||||||
: {
|
: {
|
||||||
headerRight: () => { },
|
headerRight: () => {},
|
||||||
headerStyle: {
|
headerStyle: {
|
||||||
backgroundColor: colors.customHeader,
|
backgroundColor: colors.customHeader,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
);
|
);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [colors, isModal]);
|
}, [colors, isModal]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (wallet) {
|
if (!wallet) {
|
||||||
setSelectedWalletID(walletID);
|
return;
|
||||||
console.log('LNDViewInvoice - useEffect');
|
}
|
||||||
if (!invoice.ispaid) {
|
setSelectedWalletID(walletID);
|
||||||
fetchInvoiceInterval.current = setInterval(async () => {
|
console.log('LNDViewInvoice - useEffect');
|
||||||
if (isFetchingInvoices) {
|
if (!invoice.ispaid) {
|
||||||
try {
|
fetchInvoiceInterval.current = setInterval(async () => {
|
||||||
// @ts-ignore - getUserInvoices is not set on TWallet
|
if (isFetchingInvoices) {
|
||||||
const userInvoices = await wallet.getUserInvoices(20);
|
try {
|
||||||
// fetching only last 20 invoices
|
// @ts-ignore - getUserInvoices is not set on TWallet
|
||||||
// for invoice that was created just now - that should be enough (it is basically the last one, so limit=1 would be sufficient)
|
const userInvoices = await wallet.getUserInvoices(20);
|
||||||
// but that might not work as intended IF user creates 21 invoices, and then tries to check the status of invoice #0, it just wont be updated
|
// fetching only last 20 invoices
|
||||||
const updatedUserInvoice = userInvoices.filter((filteredInvoice: LightningTransaction) =>
|
// for invoice that was created just now - that should be enough (it is basically the last one, so limit=1 would be sufficient)
|
||||||
typeof invoice === 'object'
|
// but that might not work as intended IF user creates 21 invoices, and then tries to check the status of invoice #0, it just wont be updated
|
||||||
? filteredInvoice.payment_request === invoice.payment_request
|
const updatedUserInvoice = userInvoices.filter((filteredInvoice: LightningTransaction) =>
|
||||||
: filteredInvoice.payment_request === invoice,
|
typeof invoice === 'object'
|
||||||
)[0];
|
? filteredInvoice.payment_request === invoice.payment_request
|
||||||
if (typeof updatedUserInvoice !== 'undefined') {
|
: filteredInvoice.payment_request === invoice,
|
||||||
setInvoiceStatusChanged(true);
|
)[0];
|
||||||
setParams({ invoice: updatedUserInvoice });
|
if (typeof updatedUserInvoice !== 'undefined') {
|
||||||
setIsLoading(false);
|
setInvoiceStatusChanged(true);
|
||||||
if (updatedUserInvoice.ispaid) {
|
setParams({ invoice: updatedUserInvoice });
|
||||||
// we fetched the invoice, and it is paid :-)
|
setIsLoading(false);
|
||||||
setIsFetchingInvoices(false);
|
if (updatedUserInvoice.ispaid) {
|
||||||
|
// we fetched the invoice, and it is paid :-)
|
||||||
|
setIsFetchingInvoices(false);
|
||||||
|
fetchAndSaveWalletTransactions(walletID);
|
||||||
|
} else {
|
||||||
|
const currentDate = new Date();
|
||||||
|
const now = (currentDate.getTime() / 1000) | 0; // eslint-disable-line no-bitwise
|
||||||
|
const invoiceExpiration = updatedUserInvoice.timestamp + updatedUserInvoice.expire_time;
|
||||||
|
if (invoiceExpiration < now && !updatedUserInvoice.ispaid) {
|
||||||
|
// invoice expired :-(
|
||||||
fetchAndSaveWalletTransactions(walletID);
|
fetchAndSaveWalletTransactions(walletID);
|
||||||
} else {
|
setIsFetchingInvoices(false);
|
||||||
const currentDate = new Date();
|
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
||||||
const now = (currentDate.getTime() / 1000) | 0; // eslint-disable-line no-bitwise
|
clearInterval(fetchInvoiceInterval.current);
|
||||||
const invoiceExpiration = updatedUserInvoice.timestamp + updatedUserInvoice.expire_time;
|
fetchInvoiceInterval.current = undefined;
|
||||||
if (invoiceExpiration < now && !updatedUserInvoice.ispaid) {
|
|
||||||
// invoice expired :-(
|
|
||||||
fetchAndSaveWalletTransactions(walletID);
|
|
||||||
setIsFetchingInvoices(false);
|
|
||||||
triggerHapticFeedback(HapticFeedbackTypes.NotificationError);
|
|
||||||
clearInterval(fetchInvoiceInterval.current);
|
|
||||||
fetchInvoiceInterval.current = undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
}, 3000);
|
}
|
||||||
} else {
|
}, 3000);
|
||||||
setIsFetchingInvoices(false);
|
} else {
|
||||||
clearInterval(fetchInvoiceInterval.current);
|
setIsFetchingInvoices(false);
|
||||||
fetchInvoiceInterval.current = undefined;
|
clearInterval(fetchInvoiceInterval.current);
|
||||||
}
|
fetchInvoiceInterval.current = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
@ -207,8 +208,8 @@ const LNDViewInvoice = () => {
|
||||||
const invoiceExpiration = invoice?.timestamp && invoice?.expire_time ? invoice.timestamp + invoice.expire_time : undefined;
|
const invoiceExpiration = invoice?.timestamp && invoice?.expire_time ? invoice.timestamp + invoice.expire_time : undefined;
|
||||||
if (invoice.ispaid || invoice.type === 'paid_invoice') {
|
if (invoice.ispaid || invoice.type === 'paid_invoice') {
|
||||||
let amount = 0;
|
let amount = 0;
|
||||||
let transactionDate;
|
|
||||||
let description;
|
let description;
|
||||||
|
let invoiceDate;
|
||||||
if (invoice.type === 'paid_invoice' && invoice?.value) {
|
if (invoice.type === 'paid_invoice' && invoice?.value) {
|
||||||
amount = invoice.value;
|
amount = invoice.value;
|
||||||
} else if (invoice.type === 'user_invoice' && invoice.amt) {
|
} else if (invoice.type === 'user_invoice' && invoice.amt) {
|
||||||
|
@ -220,7 +221,7 @@ const LNDViewInvoice = () => {
|
||||||
description = invoice.memo;
|
description = invoice.memo;
|
||||||
}
|
}
|
||||||
if (invoice.timestamp) {
|
if (invoice.timestamp) {
|
||||||
transactionDate = new Date(invoice.timestamp * 1000).toLocaleString();
|
invoiceDate = dayjs(invoice.timestamp * (String(invoice.timestamp).length === 10 ? 1000 : 1)).format('LLL');
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<View style={styles.root}>
|
<View style={styles.root}>
|
||||||
|
@ -232,11 +233,9 @@ const LNDViewInvoice = () => {
|
||||||
shouldAnimate={false}
|
shouldAnimate={false}
|
||||||
/>
|
/>
|
||||||
<View style={styles.detailsRoot}>
|
<View style={styles.detailsRoot}>
|
||||||
{transactionDate && (
|
<Text style={[styles.detailsText, stylesHook.detailsText]}>
|
||||||
<Text style={[styles.detailsText, stylesHook.detailsText]}>
|
{loc.lndViewInvoice.date_time}: {invoiceDate}
|
||||||
{loc.lndViewInvoice.date_time}: {transactionDate}
|
</Text>
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
{invoice.payment_preimage && typeof invoice.payment_preimage === 'string' ? (
|
{invoice.payment_preimage && typeof invoice.payment_preimage === 'string' ? (
|
||||||
<TouchableOpacity accessibilityRole="button" style={styles.detailsTouch} onPress={navigateToPreImageScreen}>
|
<TouchableOpacity accessibilityRole="button" style={styles.detailsTouch} onPress={navigateToPreImageScreen}>
|
||||||
<Text style={[styles.detailsText, stylesHook.detailsText]}>{loc.send.create_details}</Text>
|
<Text style={[styles.detailsText, stylesHook.detailsText]}>{loc.send.create_details}</Text>
|
||||||
|
@ -263,33 +262,34 @@ const LNDViewInvoice = () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Invoice has not expired, nor has it been paid for.
|
// Invoice has not expired, nor has it been paid for.
|
||||||
return (
|
if (invoice.payment_request) {
|
||||||
<ScrollView>
|
return (
|
||||||
<View style={[styles.activeRoot, stylesHook.root]}>
|
<ScrollView>
|
||||||
<View style={styles.activeQrcode}>
|
<View style={[styles.activeRoot, stylesHook.root]}>
|
||||||
<QRCodeComponent value={invoice.payment_request ?? 'not found'} size={qrCodeSize} />
|
<View style={styles.activeQrcode}>
|
||||||
</View>
|
<QRCodeComponent value={invoice.payment_request} size={qrCodeSize} />
|
||||||
<BlueSpacing20 />
|
</View>
|
||||||
<BlueText>
|
<BlueSpacing20 />
|
||||||
{loc.lndViewInvoice.please_pay} {invoice.amt} {loc.lndViewInvoice.sats}
|
|
||||||
</BlueText>
|
|
||||||
{'description' in invoice && (invoice.description?.length ?? 0) > 0 && (
|
|
||||||
<BlueText>
|
<BlueText>
|
||||||
{loc.lndViewInvoice.for} {invoice.description ?? ''}
|
{loc.lndViewInvoice.please_pay} {invoice.amt} {loc.lndViewInvoice.sats}
|
||||||
</BlueText>
|
</BlueText>
|
||||||
)}
|
{'description' in invoice && (invoice.description?.length ?? 0) > 0 && (
|
||||||
<CopyTextToClipboard truncated text={invoice.payment_request ?? 'not found'} />
|
<BlueText>
|
||||||
<Button onPress={handleOnSharePressed} title={loc.receive.details_share} />
|
{loc.lndViewInvoice.for} {invoice.description ?? ''}
|
||||||
|
</BlueText>
|
||||||
<BlueSpacing20 />
|
)}
|
||||||
<Button
|
<CopyTextToClipboard truncated text={invoice.payment_request} />
|
||||||
style={stylesHook.additionalInfo}
|
<Button onPress={handleOnSharePressed} title={loc.receive.details_share} />
|
||||||
onPress={handleOnViewAdditionalInformationPressed}
|
<BlueSpacing20 />
|
||||||
title={loc.lndViewInvoice.additional_info}
|
<Button
|
||||||
/>
|
style={stylesHook.additionalInfo}
|
||||||
</View>
|
onPress={handleOnViewAdditionalInformationPressed}
|
||||||
</ScrollView>
|
title={loc.lndViewInvoice.additional_info}
|
||||||
);
|
/>
|
||||||
|
</View>
|
||||||
|
</ScrollView>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue