Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export statement for personal wallet #737

Merged
merged 8 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,34 @@
"exportFormat": "Format",
"exportFrom": "From",
"exportInfoText": "Your wallet statement will be downloaded in CSV format.",
"exportInvalidDateInterval": "Invalid date interval",
"exportLoadingText": "This can take some minutes",
"exportHelper": "You can only export periods up to one year ago",
"exportHelper": "You can only export periods up to one year ago.",
"exportHintDate": "Invalid date",
"exportHintRange": "Invalid date",
"exportStatement": "Account statement",
"exportSuccessful": "<strong>Account statement</strong> successfully downloaded!",
"exportTimeSpan": "Time-span",
"exportTo": "To",
"exportWallet": "Wallet"
"exportWallet": "Wallet",
"fileUBIPaymentNote": "UBI payout",
"fileUBIName": "CirclesUBI",
"fileTitle": "Circles Wallet Statement",
"fileWalletName": "Wallet name",
"fileWalletSafeAddress": "Wallet safe address",
"filePeriodStartDate": "Period start date",
"filePeriodEndDate": "Period end date",
"fileBalanceOnEndDate": "Balance on end date",
"fileDemurrage": "Demurrage during selected period",
"fileSumTransactions": "Sum of transaction",
"fileBalanceOnStartDate": "Balance on start date",
"fileTransactionsTitle": "Transactions within period",
"fileTxDate": "Date",
"fileTxUsername": "To or from username",
"fileTxSafeAddress": "To or from safe address",
"fileTxPaymentNote": "Payment note",
"fileTxAmount": "Amount in circles",
"fileNamePrefix": "Circles_Statement"
},
"Finder": {
"bodyFilterDirect": "Directly trusted",
Expand Down
33 changes: 13 additions & 20 deletions src/components/ActivityStreamWithTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import DialogExportStatement from '~/components/DialogExportStatement';
import Popover from '~/components/Popover';
import TabNavigation from '~/components/TabNavigation';
import TabNavigationAction from '~/components/TabNavigationAction';
import { useIsOrganization } from '~/hooks/username';
import core from '~/services/core';
import translate from '~/services/locale';
import {
Expand Down Expand Up @@ -118,9 +117,7 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
const [filterTitle, setFilterTitle] = useState(filterItems[0].title);
const [anchorEl, setAnchorEl] = useState(null);
const { categories, lastSeenAt } = useSelector((state) => state.activity);
const safeAddress = useSelector((state) => state.safe.currentAccount);
const news = useSelector((state) => state.activity.news);
const { isOrganization } = useIsOrganization(safeAddress);

// Get only new Activities and segregate them by category
let newActivities = CATEGORIES.reduceRight((newActivities, category) => {
Expand Down Expand Up @@ -316,23 +313,19 @@ const ActivityStreamWithTabs = ({ basePath = ACTIVITIES_PATH }) => {
})}
</Popover>
</Box>
{selectedCategory === ActivityFilterTypes.TRANSFERS &&
isOrganization && (
<>
<Box className={classes.exportContainer}>
<ButtonIcon
icon="IconUnion"
onClick={exportStatementBtnHandler}
>
{translate('ExportStatement.exportBtnText')}
</ButtonIcon>
</Box>
<DialogExportStatement
dialogOpen={dialogOpen}
onCloseHandler={dialogCloseHandler}
/>
</>
)}
{selectedCategory === ActivityFilterTypes.TRANSFERS && (
<>
<Box className={classes.exportContainer}>
<ButtonIcon icon="IconUnion" onClick={exportStatementBtnHandler}>
{translate('ExportStatement.exportBtnText')}
</ButtonIcon>
</Box>
<DialogExportStatement
dialogOpen={dialogOpen}
onCloseHandler={dialogCloseHandler}
/>
</>
)}
</Box>
{activity && (
<ActivityStream
Expand Down
48 changes: 31 additions & 17 deletions src/utils/fileExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { from, lastValueFrom } from 'rxjs';
import { mergeMap, toArray } from 'rxjs/operators';

import core from '~/services/core';
import translate from '~/services/locale';
import resolveTxHash from '~/services/transfer';
import resolveUsernames from '~/services/username';
import web3 from '~/services/web3';
import { ZERO_ADDRESS } from '~/utils/constants';
import { formatCirclesValue } from '~/utils/format';

const NUMBER_OF_DECIMALS = 2;
Expand Down Expand Up @@ -55,20 +57,24 @@ const generateCsvContent = (
csvTransactions,
) => {
return [
'Circles Wallet Statement',
`${translate('ExportStatement.fileTitle')}`,
'',
`Wallet_name; ${walletName}`,
`Wallet_safe_address; ${safeAddress}`,
`Period_start_date; ${startDate}`,
`Period_end_date; ${endDate}`,
`${translate('ExportStatement.fileWalletName')}; ${walletName}`,
`${translate('ExportStatement.fileWalletSafeAddress')}; ${safeAddress}`,
`${translate('ExportStatement.filePeriodStartDate')}; ${startDate}`,
`${translate('ExportStatement.filePeriodEndDate')}; ${endDate}`,
'',
`Balance_on_end_date; ${endBalance}`,
`Demurrage_during_selected_period; ${demurrage}`,
`Sum_of_transaction; ${sumOfTransactions}`,
`Balance_on_start_date; ${startBalance}`,
`${translate('ExportStatement.fileBalanceOnEndDate')}; ${endBalance}`,
`${translate('ExportStatement.fileDemurrage')}; ${demurrage}`,
`${translate('ExportStatement.fileSumTransactions')}; ${sumOfTransactions}`,
`${translate('ExportStatement.fileBalanceOnStartDate')}; ${startBalance}`,
'',
'Transactions_within_period',
`Date; To_or_from_username; To_or_from_safe_address; Payment_note; Amount_in_circles`,
`${translate('ExportStatement.fileTransactionsTitle')}`,
`${translate('ExportStatement.fileTxDate')};${translate(
'ExportStatement.fileTxUsername',
)};${translate('ExportStatement.fileTxSafeAddress')};${translate(
'ExportStatement.fileTxPaymentNote',
)};${translate('ExportStatement.fileTxAmount')}`,
...csvTransactions,
].join('\n');
};
Expand Down Expand Up @@ -110,10 +116,16 @@ const formatTransactions = async (transactions, safeAddress) => {

// construct csv transaction
return transactionData.map((data, index) => {
data.name = namesBySafe[data.otherSafe]
? namesBySafe[data.otherSafe].username
: '-';
data.paymentNote = `"${notes[index].replaceAll('"', '""')}"`;
if (data.otherSafe === ZERO_ADDRESS) {
// UBI transaction
data.name = translate('ExportStatement.fileUBIName');
data.paymentNote = translate('ExportStatement.fileUBIPaymentNote');
} else {
data.name = namesBySafe[data.otherSafe]
? namesBySafe[data.otherSafe].username
: '-';
data.paymentNote = `"${notes[index].replaceAll('"', '""')}"`;
}

return `${data.date};${data.name};${data.otherSafe};${data.paymentNote};${data.amount}`;
});
Expand Down Expand Up @@ -196,7 +208,7 @@ export async function downloadCsvStatement(
) {
// Verify date order
if (startDate > endDate) {
throw new Error('Invalid date interval');
throw new Error(translate('ExportStatement.exportInvalidDateInterval'));
}

// Transactions
Expand Down Expand Up @@ -243,7 +255,9 @@ export async function downloadCsvStatement(
const dateString = [formatDate(startDate), formatDate(endDate)]
.join('_-_')
.replace('.', '-');
const filename = `Circles_Statement_${walletName}_${dateString}.csv`;
const filename = `${translate(
'ExportStatement.fileNamePrefix',
)}_${walletName}_${dateString}.csv`;

// Download
fileDownload(csvString, filename);
Expand Down