@mx-cartographer/experiences 7.8.0-alpha.test2 → 7.8.0-alpha.test4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NetWorthStore-yV43kJro.mjs +168 -0
- package/dist/common/index.es.js +1 -1
- package/dist/networth/index.es.js +300 -303
- package/dist/networth/stores/NetWorthStore.d.ts +2 -0
- package/dist/settings/index.es.js +1 -1
- package/dist/spending/index.es.js +45 -45
- package/package.json +1 -1
- package/dist/NetWorthStore-xMX8Q30L.mjs +0 -163
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { makeAutoObservable as p } from "mobx";
|
|
2
|
+
import { A as m } from "./AccountApi-DgZ8ILj1.mjs";
|
|
3
|
+
import { format as B } from "date-fns/format";
|
|
4
|
+
import { fromUnixTime as W } from "date-fns/fromUnixTime";
|
|
5
|
+
import { startOfMonth as D } from "date-fns/startOfMonth";
|
|
6
|
+
import { subMonths as _ } from "date-fns/subMonths";
|
|
7
|
+
import { a as f } from "./Accounts-M-LTzStv.mjs";
|
|
8
|
+
import { e as L, a as M, f as v } from "./Account-BiB1F8lL.mjs";
|
|
9
|
+
const A = 13, I = (n, t) => n.filter((e) => {
|
|
10
|
+
const { is_closed: o, is_deleted: s, is_hidden: a, is_manual: c } = e;
|
|
11
|
+
return o || s || a ? !1 : c || !e.guid ? !0 : t.some((l) => n.some((u) => l.guid === u.member_guid));
|
|
12
|
+
}), N = (n, t) => [...n, ...t], g = (n) => {
|
|
13
|
+
if (n && n.length > 0)
|
|
14
|
+
return n[n.length - 1];
|
|
15
|
+
}, S = (n, t) => n.year_month - t.year_month, x = () => Array.from({ length: A }, (n, t) => Math.floor(D(_(/* @__PURE__ */ new Date(), t)).getTime() / 1e3)).sort(), T = (n, t, e) => !n.length || !t.length ? [] : x().reduceRight((s, a) => {
|
|
16
|
+
const c = t.filter(
|
|
17
|
+
({ year_month: r }) => r === parseInt(B(W(a), "yyyyMM"))
|
|
18
|
+
), l = n.map((r) => {
|
|
19
|
+
const i = c.find((h) => h.account_guid === r.guid), d = {
|
|
20
|
+
change: 0,
|
|
21
|
+
guid: r.guid,
|
|
22
|
+
name: r.name,
|
|
23
|
+
type: r.account_type,
|
|
24
|
+
balance: 0
|
|
25
|
+
};
|
|
26
|
+
if (!i && s.length === 0 && !r.balance) return d;
|
|
27
|
+
if (!i && s.length === 0)
|
|
28
|
+
return {
|
|
29
|
+
...d,
|
|
30
|
+
value: f(r) ? -(r.balance ?? 0) : r.balance ?? 0
|
|
31
|
+
};
|
|
32
|
+
if (!i) {
|
|
33
|
+
const h = s[0].accounts.find((b) => b.guid === r.guid);
|
|
34
|
+
return h || d;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
change: i.transaction_total,
|
|
38
|
+
guid: r.guid,
|
|
39
|
+
name: r.name,
|
|
40
|
+
type: r.account_type,
|
|
41
|
+
value: i.balance
|
|
42
|
+
};
|
|
43
|
+
}), { y: u, change: y } = l.reduce(
|
|
44
|
+
(r, i) => ({
|
|
45
|
+
y: r.y + (i.value || 0),
|
|
46
|
+
change: r.change + (i.change || 0)
|
|
47
|
+
}),
|
|
48
|
+
{ y: 0, change: 0 }
|
|
49
|
+
);
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
accounts: l,
|
|
53
|
+
x: a,
|
|
54
|
+
y: u,
|
|
55
|
+
change: y
|
|
56
|
+
},
|
|
57
|
+
...s
|
|
58
|
+
];
|
|
59
|
+
}, []).slice(A - e), C = (n) => {
|
|
60
|
+
const t = [], e = [];
|
|
61
|
+
let o = 0, s = 0;
|
|
62
|
+
return n?.accounts.forEach((a) => {
|
|
63
|
+
a.change > 0 && (t.push({ accountName: a.name, gain: a.change }), o += a.change), a.change < 0 && (e.push({ accountName: a.name, loss: a.change }), s += a.change);
|
|
64
|
+
}), { netWorth: n, gains: t, losses: e, totalGains: o, totalLosses: s };
|
|
65
|
+
}, w = (n) => {
|
|
66
|
+
const t = [], e = [];
|
|
67
|
+
let o = 0, s = 0;
|
|
68
|
+
return n.forEach((a) => {
|
|
69
|
+
if (f(a)) {
|
|
70
|
+
const c = a.balance ?? 0;
|
|
71
|
+
e.push({ accountName: a.name, accountType: a.account_type, balance: c }), s += c;
|
|
72
|
+
} else {
|
|
73
|
+
const c = a.balance ?? 0;
|
|
74
|
+
t.push({ accountName: a.name, accountType: a.account_type, balance: c }), o += c;
|
|
75
|
+
}
|
|
76
|
+
}), { assets: t, liabilities: e, totalAssets: o, totalLiabilities: s };
|
|
77
|
+
}, z = (n) => {
|
|
78
|
+
const t = n.reduce((e, o) => {
|
|
79
|
+
const s = o.accountType;
|
|
80
|
+
return e[s] || (e[s] = []), e[s].push(o), e;
|
|
81
|
+
}, {});
|
|
82
|
+
return Object.entries(t).map(([e, o]) => ({
|
|
83
|
+
icon: L[+e] || M[+e],
|
|
84
|
+
name: v[+e],
|
|
85
|
+
accounts: o
|
|
86
|
+
}));
|
|
87
|
+
};
|
|
88
|
+
class P {
|
|
89
|
+
globalStore;
|
|
90
|
+
accountsApi = new m("/", "");
|
|
91
|
+
monthlyAccountBalances = [];
|
|
92
|
+
monthlyAccountBalancesLoaded = !1;
|
|
93
|
+
hoveredIndex = -1;
|
|
94
|
+
selectedIndex = -1;
|
|
95
|
+
timeframe = 6;
|
|
96
|
+
// default timeframe is 6 months
|
|
97
|
+
constructor(t) {
|
|
98
|
+
this.globalStore = t, this.accountsApi = new m(
|
|
99
|
+
t.endpoint,
|
|
100
|
+
t.sessionToken,
|
|
101
|
+
t.onError
|
|
102
|
+
), p(this);
|
|
103
|
+
}
|
|
104
|
+
get isNetWorthDataLoaded() {
|
|
105
|
+
return this.globalStore.accountStore.isAccountDataLoaded && this.monthlyAccountBalancesLoaded;
|
|
106
|
+
}
|
|
107
|
+
get netWorthAccounts() {
|
|
108
|
+
return I(
|
|
109
|
+
this.globalStore.globalUiStore.selectedAccounts,
|
|
110
|
+
this.globalStore.accountStore.members
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
get netWorthData() {
|
|
114
|
+
return {
|
|
115
|
+
accounts: this.netWorthAccounts,
|
|
116
|
+
monthlyAccountBalances: this.monthlyAccountBalances
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
get netWorthChartData() {
|
|
120
|
+
return T(this.netWorthAccounts, this.monthlyAccountBalances, this.timeframe);
|
|
121
|
+
}
|
|
122
|
+
get selectedData() {
|
|
123
|
+
if (!(!this.netWorthChartData || this.netWorthChartData.length === 0))
|
|
124
|
+
return this.selectedIndex === -1 ? g(this.netWorthChartData) : this.netWorthChartData[this.selectedIndex];
|
|
125
|
+
}
|
|
126
|
+
get hoveredData() {
|
|
127
|
+
return this.hoveredIndex >= 0 ? this.netWorthChartData[this.hoveredIndex] : void 0;
|
|
128
|
+
}
|
|
129
|
+
get gainsLosses() {
|
|
130
|
+
return C(this.selectedData);
|
|
131
|
+
}
|
|
132
|
+
get assetsLiabilities() {
|
|
133
|
+
const { assets: t, liabilities: e, totalAssets: o, totalLiabilities: s } = w(
|
|
134
|
+
this.netWorthData.accounts
|
|
135
|
+
);
|
|
136
|
+
return {
|
|
137
|
+
netWorth: g(this.netWorthChartData),
|
|
138
|
+
assets: t,
|
|
139
|
+
liabilities: e,
|
|
140
|
+
totalAssets: o,
|
|
141
|
+
totalLiabilities: s
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
loadNetWorthData = async () => {
|
|
145
|
+
this.globalStore.accountStore.isAccountDataLoaded || await this.globalStore.accountStore.loadAccountData();
|
|
146
|
+
const e = (await Promise.all(
|
|
147
|
+
this.netWorthAccounts.map((o) => this.getMonthlyAccountBalances(o.guid))
|
|
148
|
+
)).reduce(N, []).sort(S);
|
|
149
|
+
this.setMonthlyAccountBalances(e);
|
|
150
|
+
};
|
|
151
|
+
getMonthlyAccountBalances = async (t) => {
|
|
152
|
+
try {
|
|
153
|
+
return await this.accountsApi.getMonthlyAccountBalances(t);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
return console.error(`Error occured while fetching monthly account balances: ${e}`), [];
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
setHoveredIndex = (t) => this.hoveredIndex = t;
|
|
159
|
+
setMonthlyAccountBalances = (t) => {
|
|
160
|
+
this.monthlyAccountBalances = t, this.monthlyAccountBalancesLoaded = !0;
|
|
161
|
+
};
|
|
162
|
+
setSelectedIndex = (t) => this.selectedIndex = t;
|
|
163
|
+
setTimeframe = (t) => this.timeframe = t;
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
P as N,
|
|
167
|
+
z as g
|
|
168
|
+
};
|
package/dist/common/index.es.js
CHANGED
|
@@ -66,7 +66,7 @@ import { a as xt } from "../DebtsStore-BIbOVCPe.mjs";
|
|
|
66
66
|
import { F as Dt } from "../FinstrongStore-bEn_im_e.mjs";
|
|
67
67
|
import { A as At, m as vt, a as Et, b as Tt } from "../InvestmentUtil-jOyOgzIB.mjs";
|
|
68
68
|
import { M as Bt } from "../MerchantStore-WvZ4gnQe.mjs";
|
|
69
|
-
import { N as It } from "../NetWorthStore-
|
|
69
|
+
import { N as It } from "../NetWorthStore-yV43kJro.mjs";
|
|
70
70
|
import { a as Nt } from "../SettingsStore-BHpuyujx.mjs";
|
|
71
71
|
import { addMonths as Mt } from "date-fns/addMonths";
|
|
72
72
|
import { getMonth as T } from "date-fns/getMonth";
|