Skip to content

Commit

Permalink
Merge pull request #2488 from ZeusLN/activity-csv
Browse files Browse the repository at this point in the history
[feature] Activity: CSV Export
  • Loading branch information
kaloudis authored Nov 1, 2024
2 parents 6aaa6c1 + 0e00001 commit e18da24
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 76 deletions.
4 changes: 4 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@
"views.ActivityFilter.isFailed": "Failed payments",
"views.ActivityFilter.standardInvoices": "Standard invoices",
"views.ActivityFilter.ampInvoices": "AMP invoices",
"views.ActivityToCsv.title": "Download Activity",
"views.ActivityToCsv.csvDownloaded": "CSV file has been downloaded",
"views.ActivityToCsv.textInputPlaceholder": "File name (optional)",
"views.ActivityToCsv.downloadButton": "Download CSV",
"views.Routing.RoutingEvent.sourceChannel": "Source Channel",
"views.Routing.RoutingEvent.destinationChannel": "Destination Channel",
"views.Olympians.title": "Olympians",
Expand Down
17 changes: 13 additions & 4 deletions models/Invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { observable, computed } from 'mobx';
import humanizeDuration from 'humanize-duration';

import BaseModel from './BaseModel';
import Base64Utils from './../utils/Base64Utils';
import DateTimeUtils from './../utils/DateTimeUtils';
import Bolt11Utils from './../utils/Bolt11Utils';
import { localeString } from './../utils/LocaleUtils';
import Base64Utils from '../utils/Base64Utils';
import DateTimeUtils from '../utils/DateTimeUtils';
import Bolt11Utils from '../utils/Bolt11Utils';
import { localeString } from '../utils/LocaleUtils';
import stores from '../stores/Stores';

interface HopHint {
fee_proportional_millionths: number;
Expand Down Expand Up @@ -243,6 +244,10 @@ export default class Invoice extends BaseModel {
);
}

@computed public get getCreationDate(): Date {
return DateTimeUtils.listDate(this.creation_date);
}

@computed public get formattedCreationDate(): string {
return DateTimeUtils.listFormattedDate(this.creation_date);
}
Expand Down Expand Up @@ -387,4 +392,8 @@ export default class Invoice extends BaseModel {
@computed public get getNoteKey(): string {
return `note-${this.payment_hash || this.getRPreimage}`;
}

@computed public get getNote(): string {
return stores.notesStore.notes[this.getNoteKey] || '';
}
}
5 changes: 5 additions & 0 deletions models/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { localeString } from '../utils/LocaleUtils';
import Bolt11Utils from '../utils/Bolt11Utils';
import Base64Utils from '../utils/Base64Utils';
import { lnrpc } from '../proto/lightning';
import stores from '../stores/Stores';

interface preimageBuffer {
data: Array<number>;
Expand Down Expand Up @@ -312,4 +313,8 @@ export default class Payment extends BaseModel {
@computed public get getNoteKey(): string {
return `note-${this.paymentHash || this.getPreimage}`;
}

@computed public get getNote(): string {
return stores.notesStore.notes[this.getNoteKey] || '';
}
}
9 changes: 7 additions & 2 deletions models/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { computed } from 'mobx';
import BigNumber from 'bignumber.js';

import BaseModel from './BaseModel';
import DateTimeUtils from './../utils/DateTimeUtils';
import { localeString } from './../utils/LocaleUtils';
import DateTimeUtils from '../utils/DateTimeUtils';
import { localeString } from '../utils/LocaleUtils';
import stores from '../stores/Stores';

interface OutputDetail {
address: string;
Expand Down Expand Up @@ -133,4 +134,8 @@ export default class Transaction extends BaseModel {
@computed public get getNoteKey(): string {
return `note-${this.tx}`;
}

@computed public get getNote(): string {
return stores.notesStore.notes[this.getNoteKey] || '';
}
}
5 changes: 5 additions & 0 deletions utils/ActivityFilterUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ jest.mock('dateformat', () => ({}));
jest.mock('./LocaleUtils', () => ({
localeString: (s: string) => s
}));
jest.mock('../stores/Stores', () => ({
NotesStore: {
notes: []
}
}));

import Payment from '../models/Payment';
import Invoice from '../models/Invoice';
Expand Down
75 changes: 51 additions & 24 deletions views/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Amount from '../../components/Amount';
import Header from '../../components/Header';
import LoadingIndicator from '../../components/LoadingIndicator';
import Screen from '../../components/Screen';
import { Row } from '../../components/layout/Row';

import { localeString } from '../../utils/LocaleUtils';
import BackendUtils from '../../utils/BackendUtils';
Expand All @@ -32,6 +33,7 @@ import { SATS_PER_BTC } from '../../stores/UnitsStore';

import Filter from '../../assets/images/SVG/Filter On.svg';
import Invoice from '../../models/Invoice';
import ActivityToCsv from './ActivityToCsv';

interface ActivityProps {
navigation: StackNavigationProp<any, any>;
Expand All @@ -45,6 +47,7 @@ interface ActivityProps {

interface ActivityState {
selectedPaymentForOrder: any;
isCsvModalVisible: boolean;
}

@inject('ActivityStore', 'FiatStore', 'PosStore', 'SettingsStore', 'NotesStore')
Expand All @@ -57,7 +60,8 @@ export default class Activity extends React.PureComponent<
invoicesListener: any;

state = {
selectedPaymentForOrder: null
selectedPaymentForOrder: null,
isCsvModalVisible: false
};

async UNSAFE_componentWillMount() {
Expand Down Expand Up @@ -143,7 +147,7 @@ export default class Activity extends React.PureComponent<
SettingsStore,
route
} = this.props;
const { selectedPaymentForOrder } = this.state;
const { selectedPaymentForOrder, isCsvModalVisible } = this.state;

const { loading, filteredActivity, getActivityAndFilter } =
ActivityStore;
Expand Down Expand Up @@ -233,23 +237,32 @@ export default class Activity extends React.PureComponent<
}
accessibilityLabel={localeString('views.ActivityFilter.title')}
>
<Filter fill={themeColor('text')} />
<Filter fill={themeColor('text')} size={35} />
</TouchableOpacity>
);

const getMatchingNote = (item: any) => {
const { NotesStore } = this.props;
const notes = NotesStore.notes;

// Use the getNoteKey from the model
const noteKey = item.getNoteKey;

if (noteKey && notes[noteKey]) {
return notes[noteKey];
}

return null;
};
const DownloadButton = () => (
<View style={{ marginRight: 15 }}>
<TouchableOpacity
onPress={() =>
this.setState({
isCsvModalVisible: true
})
}
accessibilityLabel={localeString(
'views.ActivityToCsv.title'
)}
>
<Icon
name="download"
type="feather"
color={themeColor('text')}
underlayColor="transparent"
size={35}
/>
</TouchableOpacity>
</View>
);

return (
<Screen>
Expand All @@ -263,16 +276,30 @@ export default class Activity extends React.PureComponent<
}
}}
rightComponent={
order ? (
selectedPaymentForOrder ? (
<MarkPaymentButton />
) : undefined
) : (
<FilterButton />
)
!loading ? (
<Row>
<DownloadButton />
{order ? (
selectedPaymentForOrder ? (
<MarkPaymentButton />
) : undefined
) : (
<FilterButton />
)}
</Row>
) : undefined
}
navigation={navigation}
/>

<ActivityToCsv
filteredActivity={filteredActivity}
closeModal={() =>
this.setState({ isCsvModalVisible: false })
}
isVisible={isCsvModalVisible}
/>

{loading ? (
<View style={{ padding: 50 }}>
<LoadingIndicator />
Expand All @@ -281,7 +308,7 @@ export default class Activity extends React.PureComponent<
<FlatList
data={filteredActivity}
renderItem={({ item }: { item: any }) => {
const note = getMatchingNote(item);
const note = item.getNote;

let displayName = item.model;
let subTitle = item.model;
Expand Down
2 changes: 1 addition & 1 deletion views/Activity/ActivityFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export default class ActivityFilter extends React.Component<
color={themeColor('text')}
underlayColor="transparent"
accessibilityLabel={localeString('general.clearChanges')}
size={30}
size={35}
/>
);

Expand Down
Loading

0 comments on commit e18da24

Please sign in to comment.