My line: show payouts from an email-only session and across all owned positions
refreshMemberId falls back to the account's on-chain id when the session has no wallet address (phone sign-in by email code), without caching it into the session. /api/my/line now sums TierPaid events to every position the account owns (main id + linked positions), so each direct's 'paid you so far' is right from any device. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -1177,11 +1177,14 @@ const server = http.createServer(async (req, res) => {
|
||||
const levels = await accounts.downline(s.email, 3);
|
||||
// what each person has paid THIS member so far: sum of TierPaid events where
|
||||
// this member is the recipient and that person is the buyer (all indexed events)
|
||||
// ...counting payouts to every position this account owns (main id + linked positions)
|
||||
const myId = await auth.refreshMemberId(s);
|
||||
const own = (await accounts.positions(s.email)).filter(p => p.memberId);
|
||||
const myIds = new Set([myId, ...own.map(p => p.memberId)].filter(Boolean));
|
||||
const earnedBy = {};
|
||||
if (myId) {
|
||||
if (myIds.size) {
|
||||
for (const ev of chain.recentEvents(1e9)) {
|
||||
if (ev.type === 'TierPaid' && ev.recipientId === myId && ev.buyerId)
|
||||
if (ev.type === 'TierPaid' && myIds.has(ev.recipientId) && ev.buyerId)
|
||||
earnedBy[ev.buyerId] = (BigInt(earnedBy[ev.buyerId] || '0') + BigInt(ev.amountWei)).toString();
|
||||
}
|
||||
}
|
||||
@@ -1192,7 +1195,6 @@ const server = http.createServer(async (req, res) => {
|
||||
joined: m.created,
|
||||
earnedWei: (m.memberId && earnedBy[m.memberId]) || '0' })) }));
|
||||
// the member's own linked positions sit on level 1 too, labelled as theirs
|
||||
const own = (await accounts.positions(s.email)).filter(p => p.memberId);
|
||||
if (own.length) {
|
||||
if (!out.find(L => L.level === 1)) out.unshift({ level: 1, members: [] });
|
||||
const L1 = out.find(L => L.level === 1);
|
||||
|
||||
Reference in New Issue
Block a user