diff --git a/src/routes/[network]/api/account/[[name]]/+server.ts b/src/routes/[network]/api/account/[[name]]/+server.ts index d62b48bb..e61e6e8f 100644 --- a/src/routes/[network]/api/account/[[name]]/+server.ts +++ b/src/routes/[network]/api/account/[[name]]/+server.ts @@ -1,15 +1,11 @@ import { json } from '@sveltejs/kit'; - import { getChainDefinitionFromParams, getNetwork, NetworkState } from '$lib/state/network.svelte'; -import { type API, type NameType } from '@wharfkit/antelope'; -import type { TokenBalance } from '@wharfkit/common'; -import type { ChainDefinition } from '@wharfkit/session'; -import { chainMapper } from '$lib/wharf/chains.js'; import { getCacheHeaders } from '$lib/utils'; -import { SystemContract } from '@wharfkit/account'; import type { LightAPIBalanceResponse, LightAPIBalanceRow } from '$lib/types.js'; +import type { RequestHandler } from './$types'; +import { Asset, type NameType } from '@wharfkit/antelope'; -export async function GET({ fetch, params }) { +export const GET: RequestHandler = async ({ fetch, params }) => { const chain = getChainDefinitionFromParams(params.network); if (!chain) { return json({ error: 'Invalid chain specified' }, { status: 400 }); @@ -22,31 +18,24 @@ export async function GET({ fetch, params }) { const network = getNetwork(chain, fetch); const { system: systemContract } = network.contracts; - const requests: [ - Promise, - Promise, - Promise, - Promise, - Promise - ] = [ - network.client.v1.chain.get_account(params.name), - systemContract.table('delband').all({ scope: params.name }), - systemContract.table('rexbal').get(params.name), - systemContract.table('rexfund').get(params.name), - loadBalances(network, params.name, fetch) - ]; - try { const headers = getCacheHeaders(5); - const [account_data, delegated, rexbal, rexfund, balances] = await Promise.all(requests); + const [account_data, delegated, rexbal, rexfund, balances] = await Promise.all([ + network.client.v1.chain.get_account(params.name), + systemContract.table('delband').all({ scope: params.name }), + systemContract.table('rexbal').get(params.name), + systemContract.table('rexfund').get(params.name), + loadBalances(network, params.name, fetch) + ]); - // If no response from the light API, add the core liquid balance as a default + // If no response from the light API, add a default balance of zero if (!balances.length && chain.systemToken) { + const symbol = Asset.Symbol.from(network.config.symbol); balances.push({ - contract: chain.systemToken.contract, - amount: account_data.core_liquid_balance.quantity, - decimals: account_data.core_liquid_balance.symbol.precision, - currency: account_data.core_liquid_balance.symbol.code + contract: String(chain.systemToken.contract), + amount: '0', + decimals: String(symbol.precision), + currency: String(symbol.code) }); } @@ -65,7 +54,7 @@ export async function GET({ fetch, params }) { console.error(error); return json({ error: 'Unable to load account.' }, { status: 500 }); } -} +}; async function loadBalances( network: NetworkState,