153 lines
8.5 KiB
JavaScript
153 lines
8.5 KiB
JavaScript
import { s as subscribe } from "./utils.js";
|
|
import { c as create_ssr_component, e as escape } from "./ssr.js";
|
|
import { p as page } from "./stores.js";
|
|
import { w as walletStore } from "./walletStore.js";
|
|
import { w as writable } from "./index2.js";
|
|
import { s as server } from "./horizonQueries.js";
|
|
const createAccountBalancesStore = () => {
|
|
const defaultState = {
|
|
balances: {},
|
|
lastUpdated: null
|
|
};
|
|
const initialState = defaultState;
|
|
const { subscribe: subscribe2, set, update } = writable(initialState);
|
|
return {
|
|
subscribe: subscribe2,
|
|
/**
|
|
* Load balances for an account
|
|
*/
|
|
loadBalances: async (publicKey) => {
|
|
if (!publicKey) {
|
|
return set(initialState);
|
|
}
|
|
update((state) => ({ ...state, isLoading: true, error: null }));
|
|
try {
|
|
const account = await server.loadAccount(publicKey);
|
|
const balances = {};
|
|
const assets = [];
|
|
account.balances.forEach((balance) => {
|
|
if (balance.asset_type === "native") {
|
|
balances.native = balance.balance;
|
|
} else if (balance.asset_type === "credit_alphanum4" || balance.asset_type === "credit_alphanum12") {
|
|
const assetCode = balance.asset_code;
|
|
const assetIssuer = balance.asset_issuer;
|
|
assets.push({
|
|
code: assetCode,
|
|
issuer: assetIssuer,
|
|
balance: balance.balance
|
|
});
|
|
} else if (balance.asset_type === "liquidity_pool_shares") {
|
|
assets.push({
|
|
code: "POOL",
|
|
issuer: balance.liquidity_pool_id || "unknown",
|
|
balance: balance.balance
|
|
});
|
|
}
|
|
});
|
|
set({
|
|
native: balances.native || "0",
|
|
assets,
|
|
isLoading: false,
|
|
error: null,
|
|
lastUpdated: /* @__PURE__ */ new Date()
|
|
});
|
|
return balances;
|
|
} catch (error) {
|
|
console.error("Failed to load account balances:", error);
|
|
update((state) => ({
|
|
...state,
|
|
isLoading: false,
|
|
error: error.message || "Failed to load account balances"
|
|
}));
|
|
return null;
|
|
}
|
|
},
|
|
/**
|
|
* Update balance for an account
|
|
* @param {string} accountId - The account ID
|
|
* @param {Object} balanceData - The balance data
|
|
*/
|
|
updateBalance: (accountId, balanceData) => update((state) => {
|
|
return {
|
|
...state,
|
|
balances: {
|
|
...state.balances,
|
|
[accountId]: {
|
|
...balanceData,
|
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
}
|
|
},
|
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
};
|
|
}),
|
|
/**
|
|
* Get balance for a specific account
|
|
* @param {string} accountId - The account ID
|
|
*/
|
|
getBalance: (accountId) => {
|
|
return new Promise((resolve) => {
|
|
const unsubscribe = subscribe2((state) => {
|
|
resolve(state.balances[accountId] || null);
|
|
unsubscribe();
|
|
});
|
|
});
|
|
},
|
|
/**
|
|
* Clear all balances
|
|
*/
|
|
clearBalances: () => set(defaultState),
|
|
/**
|
|
* Clear all balance data
|
|
*/
|
|
reset: () => {
|
|
set(initialState);
|
|
}
|
|
};
|
|
};
|
|
const accountBalancesStore = createAccountBalancesStore();
|
|
const css = {
|
|
code: ".nav-link.active.svelte-17gu044.svelte-17gu044{background-color:rgba(59, 130, 246, 0.1);font-weight:500}.nav-link.active.svelte-17gu044 span.svelte-17gu044{color:rgb(37, 99, 235)}",
|
|
map: null
|
|
};
|
|
const SidebarMenu = create_ssr_component(($$result, $$props, $$bindings, slots) => {
|
|
let $page, $$unsubscribe_page;
|
|
let $walletStore, $$unsubscribe_walletStore;
|
|
let $accountBalancesStore, $$unsubscribe_accountBalancesStore;
|
|
$$unsubscribe_page = subscribe(page, (value) => $page = value);
|
|
$$unsubscribe_walletStore = subscribe(walletStore, (value) => $walletStore = value);
|
|
$$unsubscribe_accountBalancesStore = subscribe(accountBalancesStore, (value) => $accountBalancesStore = value);
|
|
$$result.css.add(css);
|
|
$$unsubscribe_page();
|
|
$$unsubscribe_walletStore();
|
|
$$unsubscribe_accountBalancesStore();
|
|
return ` <div class="h-full min-h-screen flex flex-col bg-gray-100 border-r"> <div class="py-6 px-6 flex flex-col items-center" data-svelte-h="svelte-ziydui"><a href="/" class="flex items-center w-full"><div class="mr-3 text-2xl">馃捀</div> <div class="text-xl font-semibold">InstantSplit</div></a></div> <div class="flex flex-col gap-1 mt-3 flex-1 px-3"> <a href="/dashboard" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/dashboard" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-4vxixh"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃彔</span> <span class="font-medium svelte-17gu044">Home</span></a> <a href="/send" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/send" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-8igdwj"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃摛</span> <span class="font-medium svelte-17gu044">Send</span></a> <a href="/split" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/split" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-l8pu1u"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃捀</span> <span class="font-medium svelte-17gu044">Split Expense</span> <span class="ml-auto bg-green-100 text-green-700 text-xs px-2 py-1 rounded-full svelte-17gu044">New</span></a> <a href="/dashboard/expenses-dashboard" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/dashboard/expenses-dashboard" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-t6oqxe"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃搳</span> <span class="font-medium svelte-17gu044">Expenses Dashboard</span></a> <a href="/receive" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/receive" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-1e0s24n"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃摜</span> <span class="font-medium svelte-17gu044">Receive</span></a> <a href="/swap" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/swap" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-1tg7vl2"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃攧</span> <span class="font-medium svelte-17gu044">Swap</span></a> <a href="/deposit-withdraw" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group svelte-17gu044",
|
|
$page.url.pathname === "/deposit-withdraw" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-a4x8ro"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">馃彟</span> <span class="font-medium svelte-17gu044">Deposit & Withdraw</span></a> <a href="/settings" class="${[
|
|
"nav-link flex items-center space-x-3 px-4 py-3 rounded-lg hover:bg-gray-100 transition-colors group mt-auto svelte-17gu044",
|
|
$page.url.pathname === "/settings" ? "active" : ""
|
|
].join(" ").trim()}" data-svelte-h="svelte-1vr4jng"><span class="text-xl group-hover:scale-110 transition-transform svelte-17gu044">鈿欙笍</span> <span class="font-medium svelte-17gu044">Settings</span></a></div> <div class="mt-auto mb-4 mx-3">${$walletStore.publicKey ? `<div class="bg-green-50 border border-green-200 rounded-lg p-3"><div class="text-sm font-medium text-green-700 break-all">${escape($walletStore.publicKey.substring(0, 5))}...${escape($walletStore.publicKey.substring($walletStore.publicKey.length - 5))}</div> ${$accountBalancesStore.native ? `<div class="text-xs text-green-600 mt-1">${escape($accountBalancesStore.native)} XLM</div>` : ``}</div>` : `<a href="/auto-login" class="block text-center bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg transition-colors" data-svelte-h="svelte-1amoci2">Connect Wallet</a>`}</div> </div>`;
|
|
});
|
|
export {
|
|
SidebarMenu as S,
|
|
accountBalancesStore as a
|
|
};
|