FIX: useMemo

This commit is contained in:
Marcos Rodriguez Velez 2024-03-29 15:07:14 -04:00
parent 377b4a913a
commit b7f9bbe212
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7
2 changed files with 15 additions and 22 deletions

View File

@ -7,7 +7,7 @@ const fs = require('../blue_modules/fs');
interface SaveFileButtonProps {
fileName: string;
fileContent: string | (() => string);
fileContent: string;
children: ReactNode;
style?: StyleProp<ViewStyle>;
afterOnPress?: () => void;
@ -25,14 +25,13 @@ const SaveFileButton: React.FC<SaveFileButtonProps> = ({ fileName, fileContent,
await beforeOnPress(); // Now properly awaiting a function that returns a promise
}
const action = actions.find(a => a.id === actionId);
const content = typeof fileContent === 'function' ? fileContent() : fileContent; // Simplified this line
if (action?.id === 'save') {
await fs.writeFileAndExport(fileName, content, false, Platform.OS !== 'android').finally(() => {
await fs.writeFileAndExport(fileName, fileContent, false, Platform.OS !== 'android').finally(() => {
afterOnPress?.(); // Safely call afterOnPress if it exists
});
} else if (action?.id === 'share') {
await fs.writeFileAndExport(fileName, content, true).finally(() => {
await fs.writeFileAndExport(fileName, fileContent, true).finally(() => {
afterOnPress?.(); // Safely call afterOnPress if it exists
});
}

View File

@ -420,23 +420,17 @@ const WalletDetails = () => {
}
};
const exportHistoryContent = () => {
const csvFileArray = [
loc.transactions.date,
loc.transactions.txid,
`${loc.send.create_amount} (${BitcoinUnit.BTC})`,
loc.send.create_memo,
];
const exportHistoryContent = useCallback(() => {
const headers = [loc.transactions.date, loc.transactions.txid, `${loc.send.create_amount} (${BitcoinUnit.BTC})`, loc.send.create_memo];
if (wallet.chain === Chain.OFFCHAIN) {
csvFileArray.push(loc.lnd.payment);
headers.push(loc.lnd.payment);
}
let csvFile = csvFileArray.join(','); // CSV header
const rows = [headers.join(',')];
const transactions = wallet.getTransactions();
for (const transaction of transactions) {
transactions.forEach(transaction => {
const value = formatBalanceWithoutSuffix(transaction.value, BitcoinUnit.BTC, true);
let hash = transaction.hash;
let memo = txMetadata[transaction.hash]?.memo?.trim() ?? '';
let status;
@ -446,8 +440,7 @@ const WalletDetails = () => {
memo = transaction.description;
status = transaction.ispaid ? loc._.success : loc.lnd.expired;
if (hash?.type === 'Buffer' && hash?.data) {
const bb = Buffer.from(hash);
hash = bb.toString('hex');
hash = Buffer.from(hash.data).toString('hex');
}
}
@ -457,10 +450,11 @@ const WalletDetails = () => {
data.push(status);
}
csvFile += '\n' + data.join(','); // CSV line
}
return csvFile;
};
rows.push(data.join(','));
});
return rows.join('\n');
}, [wallet, txMetadata]);
const handleDeleteButtonTapped = () => {
triggerHapticFeedback(HapticFeedbackTypes.NotificationWarning);
@ -664,7 +658,7 @@ const WalletDetails = () => {
{walletTransactionsLength > 0 && (
<>
<BlueSpacing20 />
<SaveFileButton fileName={fileName} fileContent={exportHistoryContent}>
<SaveFileButton fileName={fileName} fileContent={exportHistoryContent()}>
<SecondButton title={loc.wallets.details_export_history} />
</SaveFileButton>
</>