diff --git a/components/SaveFileButton.tsx b/components/SaveFileButton.tsx index c49fd4adc..54c089c53 100644 --- a/components/SaveFileButton.tsx +++ b/components/SaveFileButton.tsx @@ -7,7 +7,7 @@ const fs = require('../blue_modules/fs'); interface SaveFileButtonProps { fileName: string; - fileContent: string | (() => string); + fileContent: string; children: ReactNode; style?: StyleProp; afterOnPress?: () => void; @@ -25,14 +25,13 @@ const SaveFileButton: React.FC = ({ 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 }); } diff --git a/screen/wallets/details.js b/screen/wallets/details.js index 908c7ebac..223923786 100644 --- a/screen/wallets/details.js +++ b/screen/wallets/details.js @@ -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 && ( <> - +