183 lines
16 KiB
JavaScript
183 lines
16 KiB
JavaScript
import { s as subscribe, i as is_promise, a as noop } from "../../../chunks/utils.js";
|
|
import { c as create_ssr_component, b as each, e as escape, v as validate_component, a as add_attribute, o as onDestroy, m as missing_component } from "../../../chunks/ssr.js";
|
|
import { p as page } from "../../../chunks/stores.js";
|
|
import { T as TruncatedKey } from "../../../chunks/TruncatedKey.js";
|
|
import { c as contactsStore } from "../../../chunks/contactsStore.js";
|
|
import { t as transfers, w as webAuthStore, q as queryTransfers6, a as queryTransfers24 } from "../../../chunks/sep6.js";
|
|
import { w as walletStore } from "../../../chunks/walletStoreFix.js";
|
|
import "../../../chunks/horizonQueries.js";
|
|
import { s as splitExpenseStore } from "../../../chunks/splitExpenseStore.js";
|
|
import { f as formatXLM } from "../../../chunks/splitExpenseUtils.js";
|
|
const AssetStats = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $page, $$unsubscribe_page;
|
|
$$unsubscribe_page = subscribe(page, (value) => $page = value);
|
|
$$unsubscribe_page();
|
|
return ` <h3 data-svelte-h="svelte-p5ngm6">Assets Overview</h3> <div class="stats stats-vertical w-full bg-primary text-primary-content shadow lg:stats-horizontal">${each($page.data.balances, (balance) => {
|
|
return `<div class="stat"><div class="stat-title">${escape(balance.asset_code ?? "XLM")} Balance</div> <div class="stat-value">${escape(parseFloat(balance.balance).toFixed(2))} ${escape(balance.asset_code ?? "XLM")}</div> </div>`;
|
|
})}</div>`;
|
|
});
|
|
const RecentPayments = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $page, $$unsubscribe_page;
|
|
$$unsubscribe_page = subscribe(page, (value) => $page = value);
|
|
$$unsubscribe_page();
|
|
return ` <h3 data-svelte-h="svelte-1c0ng58">Recent Payments</h3> <table class="table"><thead data-svelte-h="svelte-26m3cw"><tr><th>Amount</th> <th>Asset</th> <th>Direction</th> <th>Address</th></tr></thead> <tbody>${each($page.data.payments, (payment) => {
|
|
return `<tr><th>${payment.amount ? `${escape(parseFloat(payment.amount).toFixed(2))}` : `${payment.starting_balance ? `${escape(parseFloat(payment.starting_balance).toFixed(2))}` : `${payment.type === "account_merge" ? `${function(__value) {
|
|
if (is_promise(__value)) {
|
|
__value.then(null, noop);
|
|
return ``;
|
|
}
|
|
return function(effects) {
|
|
return ` ${each(effects.records.filter(
|
|
/** @type {EffectRecord} */
|
|
(e) => e.type === "account_credited"
|
|
), (effect) => {
|
|
return `${escape(parseFloat(effect.amount).toFixed(2))}`;
|
|
})} `;
|
|
}(__value);
|
|
}(payment.effects())}` : ``}`}`}</th> <td>${payment.type === "create_account" || payment.asset_type === "native" || payment.type === "account_merge" ? `XLM` : `${escape(payment.asset_code)}`}</td> <td>${payment.to === $page.data.publicKey || "funder" in payment && payment.funder !== $page.data.publicKey || "into" in payment && payment.into === $page.data.publicKey ? `Received` : `Sent`}</td> <td>${"to" in payment ? `${payment.to === $page.data.publicKey ? `${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: payment.from }, {}, {})}` : `${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: payment.to }, {}, {})}`}` : `${"funder" in payment ? `${payment.funder === $page.data.publicKey ? `${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: payment.account }, {}, {})}` : `${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: payment.funder }, {}, {})}`}` : `${"into" in payment ? `${payment.into === $page.data.publicKey ? `${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: payment.account }, {}, {})}` : `${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: payment.into }, {}, {})}`}` : ``}`}`}</td> </tr>`;
|
|
})}</tbody></table>`;
|
|
});
|
|
const FavoriteContacts = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let favoriteContacts;
|
|
let $contactsStore, $$unsubscribe_contactsStore;
|
|
$$unsubscribe_contactsStore = subscribe(contactsStore, (value) => $contactsStore = value);
|
|
favoriteContacts = $contactsStore?.contacts?.filter((contact) => contact.favorite);
|
|
$$unsubscribe_contactsStore();
|
|
return ` <h3 data-svelte-h="svelte-1k5sfut">Favorite Contacts</h3> <table class="table w-full"><thead data-svelte-h="svelte-ui8o41"><tr><th>Favorite</th> <th>Name</th> <th>Address</th></tr></thead> ${favoriteContacts ? `<tbody>${each(favoriteContacts, (contact) => {
|
|
return `<tr><th><input type="checkbox" class="checkbox-accent checkbox checkbox-sm" ${contact.favorite ? "checked" : ""}></th> <td><div class="flex items-center space-x-3"><div class="avatar"><div class="not-prose w-10 rounded-full"><img src="${"https://id.lobstr.co/" + escape(contact.address, true) + ".png"}" alt="Avatar Tailwind CSS Component"> </div></div> <div><div class="font-bold">${escape(contact.name)}</div></div> </div></td> <td>${validate_component(TruncatedKey, "TruncatedKey").$$render($$result, { keyText: contact.address }, {}, {})}</td> <th data-svelte-h="svelte-1mhspmj"><button class="btn-ghost btn-xs btn">Stellar.Expert</button></th> </tr>`;
|
|
})}</tbody>` : ``}</table>`;
|
|
});
|
|
const TransferHistory = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $transfers, $$unsubscribe_transfers;
|
|
let $webAuthStore, $$unsubscribe_webAuthStore;
|
|
let $page, $$unsubscribe_page;
|
|
$$unsubscribe_transfers = subscribe(transfers, (value) => $transfers = value);
|
|
$$unsubscribe_webAuthStore = subscribe(webAuthStore, (value) => $webAuthStore = value);
|
|
$$unsubscribe_page = subscribe(page, (value) => $page = value);
|
|
let expiredToken = false;
|
|
const protocolBadgeClasses = {
|
|
sep6: "badge badge-secondary",
|
|
sep24: "badge badge-accent"
|
|
};
|
|
const query = (protocol, assetCode, homeDomain) => new Promise((resolve) => {
|
|
protocol === "sep6" ? queryTransfers6({
|
|
authToken: $webAuthStore[homeDomain],
|
|
assetCode,
|
|
publicKey: $page.data.publicKey,
|
|
homeDomain
|
|
}).then(({ transactions }) => resolve(transactions.map((item) => {
|
|
return { ...item, asset_code: assetCode, protocol };
|
|
}))) : queryTransfers24({
|
|
authToken: $webAuthStore[homeDomain],
|
|
assetCode,
|
|
homeDomain
|
|
}).then(({ transactions }) => resolve(transactions.map((item) => {
|
|
return { ...item, asset_code: assetCode, protocol };
|
|
})));
|
|
});
|
|
const transfersPromise = async () => {
|
|
let transfersPromises = [];
|
|
if ($transfers) {
|
|
for (let homeDomain in $transfers) {
|
|
if ($webAuthStore[homeDomain] && !webAuthStore.isTokenExpired(homeDomain)) {
|
|
for (let protocol in $transfers[homeDomain]) {
|
|
let uniqueAssets = [
|
|
...new Set($transfers[homeDomain][protocol].map((item) => item.asset_code))
|
|
];
|
|
uniqueAssets.forEach(async (assetcode) => {
|
|
transfersPromises.push(query(protocol, assetcode, homeDomain));
|
|
});
|
|
}
|
|
} else {
|
|
expiredToken = true;
|
|
}
|
|
}
|
|
}
|
|
let allTransfers = await Promise.all(transfersPromises);
|
|
return allTransfers.flat().sort((a, b) => {
|
|
return new Date(b.started_at) - new Date(a.started_at);
|
|
});
|
|
};
|
|
$$unsubscribe_transfers();
|
|
$$unsubscribe_webAuthStore();
|
|
$$unsubscribe_page();
|
|
return ` ${$transfers ? `<h3 data-svelte-h="svelte-19jepzn">Transfer History</h3> ${function(__value) {
|
|
if (is_promise(__value)) {
|
|
__value.then(null, noop);
|
|
return ``;
|
|
}
|
|
return function(allTransfers) {
|
|
return ` <table class="table-compact table"><thead data-svelte-h="svelte-ekf24u"><tr><th>Amount</th> <th>Asset</th> <th>Direction</th> <th>Protocol</th> <th>Status</th> <th>Date</th> <th>More Info</th> <th>Actions</th></tr></thead> <tbody>${each(allTransfers, (transfer) => {
|
|
return `<tr><th>${escape(transfer.amount_in)}</th> <td>${escape(transfer.asset_code)}</td> <td>${escape(transfer.kind)}</td> <td><div${add_attribute("class", `${protocolBadgeClasses[transfer.protocol]}`, 0)}>${escape(transfer.protocol)} </div></td> <td>${escape(transfer.status)}</td> <td>${escape(new Date(Date.parse(transfer.started_at)).toLocaleString())}</td> <td>${transfer.status === "completed" ? `<a target="_blank"${add_attribute("href", `https://stellar.expert/explorer/testnet/tx/${transfer.stellar_transaction_id}`, 0)}>View Stellar transaction</a>` : `${"more_info_url" in transfer ? `<a target="_blank"${add_attribute("href", transfer.more_info_url, 0)}>View more info</a>` : ``}`}</td> <td>${transfer.kind === "withdrawal" && transfer.status === "pending_user_transfer_start" ? `Start a Payment` : `Nevermind`}</td> </tr>`;
|
|
})}</tbody></table> ${expiredToken ? `<p data-svelte-h="svelte-8rqe6n">It looks like there may be a problem with some of your anchor authentication. Head over
|
|
to the <a href="/dashboard/transfers">Transfers Page</a> to check that out.</p>` : ``} `;
|
|
}(__value);
|
|
}(transfersPromise())}` : ``}`;
|
|
});
|
|
const SplitExpenseHistory = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $$unsubscribe_walletStore;
|
|
$$unsubscribe_walletStore = subscribe(walletStore, (value) => value);
|
|
let { limit = 5 } = $$props;
|
|
onDestroy(() => {
|
|
});
|
|
if ($$props.limit === void 0 && $$bindings.limit && limit !== void 0) $$bindings.limit(limit);
|
|
$$unsubscribe_walletStore();
|
|
return `<div class="flex flex-col gap-2">${`<div class="flex justify-center p-4" data-svelte-h="svelte-1wa7lrt"><span class="loading loading-spinner loading-md"></span></div>`}</div>`;
|
|
});
|
|
const SplitExpenseStats = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $splitExpenseStore, $$unsubscribe_splitExpenseStore;
|
|
let $walletStore, $$unsubscribe_walletStore;
|
|
$$unsubscribe_splitExpenseStore = subscribe(splitExpenseStore, (value) => $splitExpenseStore = value);
|
|
$$unsubscribe_walletStore = subscribe(walletStore, (value) => $walletStore = value);
|
|
let totalCreated = 0;
|
|
let totalParticipating = 0;
|
|
let totalAmountCreated = 0;
|
|
let totalAmountOwed = 0;
|
|
let pendingPayments = 0;
|
|
function calculateStats() {
|
|
const userPublicKey = $walletStore.publicKey;
|
|
if (!userPublicKey) return;
|
|
const allExpenses = $splitExpenseStore.expenses;
|
|
totalCreated = 0;
|
|
totalParticipating = 0;
|
|
totalAmountCreated = 0;
|
|
totalAmountOwed = 0;
|
|
pendingPayments = 0;
|
|
for (const expense of allExpenses) {
|
|
if (expense.creator === userPublicKey) {
|
|
totalCreated++;
|
|
totalAmountCreated += parseFloat(expense.amount);
|
|
const unpaidParticipants = expense.participants.filter((p) => !p.paid && p.address !== expense.creator);
|
|
pendingPayments += unpaidParticipants.length;
|
|
} else {
|
|
const userParticipation = expense.participants.find((p) => p.address === userPublicKey);
|
|
if (userParticipation) {
|
|
totalParticipating++;
|
|
if (!userParticipation.paid) {
|
|
totalAmountOwed += parseFloat(userParticipation.amountDue || 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
{
|
|
if ($walletStore.publicKey && $splitExpenseStore.expenses) {
|
|
calculateStats();
|
|
}
|
|
}
|
|
$$unsubscribe_splitExpenseStore();
|
|
$$unsubscribe_walletStore();
|
|
return `<div class="stats stats-vertical lg:stats-horizontal shadow"><div class="stat"><div class="stat-figure text-primary" data-svelte-h="svelte-1soelez"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-8 h-8 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 100 4m0-4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 100 4m0-4v2m0-6V4"></path></svg></div> <div class="stat-title" data-svelte-h="svelte-hun2oo">Created</div> <div class="stat-value text-primary">${escape(totalCreated)}</div> <div class="stat-desc">${escape(formatXLM(totalAmountCreated))} XLM total</div></div> <div class="stat"><div class="stat-figure text-secondary" data-svelte-h="svelte-1idrw7t"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-8 h-8 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg></div> <div class="stat-title" data-svelte-h="svelte-rhu63p">Participating</div> <div class="stat-value text-secondary">${escape(totalParticipating)}</div> <div class="stat-desc">${escape(formatXLM(totalAmountOwed))} XLM owed</div></div> <div class="stat"><div class="stat-figure text-warning" data-svelte-h="svelte-njdx3b"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="inline-block w-8 h-8 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg></div> <div class="stat-title" data-svelte-h="svelte-1ax0u7p">Pending</div> <div class="stat-value text-warning">${escape(pendingPayments)}</div> <div class="stat-desc" data-svelte-h="svelte-15engh2">Awaiting payments</div></div></div>`;
|
|
});
|
|
const Page = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $splitExpenseStore, $$unsubscribe_splitExpenseStore;
|
|
$$unsubscribe_splitExpenseStore = subscribe(splitExpenseStore, (value) => $splitExpenseStore = value);
|
|
$$unsubscribe_splitExpenseStore();
|
|
return ` ${validate_component(AssetStats, "AssetStats").$$render($$result, {}, {}, {})} <div class="grid grid-cols-1 gap-10 lg:grid-cols-2"><div class="overflow-x-auto">${validate_component(RecentPayments, "RecentPayments").$$render($$result, {}, {}, {})}</div> <div class="overflow-x-auto">${validate_component(FavoriteContacts, "FavoriteContacts").$$render($$result, {}, {}, {})}</div></div> <div class="my-6"><h2 class="text-xl font-bold mb-4" data-svelte-h="svelte-15zgq2t">Split Expenses</h2> <div class="mb-6">${validate_component(SplitExpenseStats, "SplitExpenseStats").$$render($$result, {}, {}, {})}</div> <div class="card bg-base-100 shadow-xl"><div class="card-body"><div class="flex justify-between mb-4" data-svelte-h="svelte-14z3ml7"><h3 class="card-title">Recent Split Activity</h3> <a href="/dashboard/expenses-dashboard" class="text-blue-600 hover:underline">View All</a></div> ${$splitExpenseStore.expenses && $splitExpenseStore.expenses.length > 0 ? `<div class="flex flex-col space-y-3">${each($splitExpenseStore.expenses.slice(0, 3), (expense) => {
|
|
return `<div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg"><div><div class="font-medium">${escape(expense.title)}</div> <div class="text-sm text-gray-600">${escape(new Date(expense.createdAt).toLocaleDateString())} </div></div> <div class="text-right"><div class="font-bold">${escape(parseFloat(expense.amount).toFixed(2))} XLM</div> <div class="text-sm">${expense.status === "completed" ? `<span class="badge badge-success" data-svelte-h="svelte-ratymw">Completed</span>` : `<span class="badge badge-warning" data-svelte-h="svelte-h1hxtp">Pending</span>`} </div></div> </div>`;
|
|
})}</div>` : `<div class="text-center p-4 text-gray-500" data-svelte-h="svelte-vb5dh"><p>No split expenses yet</p> <a href="/split-expense" class="btn btn-sm btn-primary mt-2">Create Split Expense</a></div>`} <div class="divider" data-svelte-h="svelte-95jkk0">Recent Transactions</div> ${validate_component(SplitExpenseHistory || missing_component, "svelte:component").$$render($$result, { limit: 3 }, {}, {})}</div></div></div> <div class="overflow-x-auto">${validate_component(TransferHistory, "TransferHistory").$$render($$result, {}, {}, {})}</div>`;
|
|
});
|
|
export {
|
|
Page as default
|
|
};
|