-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathPaymentsStore.ts
50 lines (45 loc) · 1.45 KB
/
PaymentsStore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { action, observable } from 'mobx';
import Payment from './../models/Payment';
import SettingsStore from './SettingsStore';
import ChannelsStore from './ChannelsStore';
import BackendUtils from './../utils/BackendUtils';
export default class PaymentsStore {
@observable loading = false;
@observable error = false;
@observable error_msg: string;
@observable payments: Array<Payment | any> = [];
settingsStore: SettingsStore;
channelsStore: ChannelsStore;
constructor(settingsStore: SettingsStore, channelsStore: ChannelsStore) {
this.settingsStore = settingsStore;
this.channelsStore = channelsStore;
}
reset = () => {
this.resetPayments();
this.error = false;
this.error_msg = '';
};
resetPayments = () => {
this.payments = [];
this.loading = false;
};
@action
public getPayments = async () => {
this.loading = true;
await BackendUtils.getPayments()
.then((data: any) => {
const payments = data.payments;
this.payments = payments
.slice()
.reverse()
.map(
(payment: any) =>
new Payment(payment, this.channelsStore.nodes)
);
this.loading = false;
})
.catch(() => {
this.resetPayments();
});
};
}