Skip to content

Commit

Permalink
more format stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 6, 2024
1 parent 57e0a85 commit 0dfbf74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"**/*.{test,spec}.ts": [
"node scripts/check-test-files.js"
],
"{src,frontend/src}/**/*.ts?(x)": [
"src/**/!(*d).ts": [
"prettier --write",
"eslint --fix",
"prettier --check",
Expand All @@ -42,6 +42,13 @@
"pnpm test:related",
"pnpm smoke-test:precommit"
],
"frontend/src/**/*.ts?(x)": [
"prettier --write",
"eslint --fix",
"prettier --check",
"eslint --max-warnings 0",
"tsc --noEmit --skipLibCheck"
],
"*.{json,md}": [
"prettier --write",
"prettier --check"
Expand Down
36 changes: 23 additions & 13 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ interface SerializedCompactRecord {
createdAt: string;
}

interface Balance {
chainId: string;
lockId: string;
allocatableBalance: string;
allocatedBalance: string;
balanceAvailableToAllocate: string;
withdrawalStatus: number;
}

// Authentication middleware
function createAuthMiddleware(server: FastifyInstance) {
return async function authenticateRequest(
Expand Down Expand Up @@ -147,7 +156,9 @@ export async function setupRoutes(server: FastifyInstance): Promise<void> {
normalizedAddress = getAddress(address);
} catch (error) {
return reply.code(400).send({
error: `Invalid Ethereum address format: ${error instanceof Error ? error.message : String(error)}`,
error: `Invalid Ethereum address format: ${
error instanceof Error ? error.message : String(error)
}`,
});
}

Expand Down Expand Up @@ -359,15 +370,16 @@ export async function setupRoutes(server: FastifyInstance): Promise<void> {
}

// Filter locks to only include those managed by this allocator
const ourLocks = response.account.resourceLocks.items.filter(
(item) => {
try {
return getAddress(item?.resourceLock?.allocatorAddress) === getAddress(process.env.ALLOCATOR_ADDRESS!);
} catch {
return false;
}
const ourLocks = response.account.resourceLocks.items.filter((item) => {
try {
return (
getAddress(item?.resourceLock?.allocatorAddress) ===
getAddress(process.env.ALLOCATOR_ADDRESS!)
);
} catch {
return false;
}
);
});

// Get balance details for each lock
const balances = (
Expand Down Expand Up @@ -427,12 +439,10 @@ export async function setupRoutes(server: FastifyInstance): Promise<void> {
balanceAvailableToAllocate:
balanceAvailableToAllocate.toString(),
withdrawalStatus: resourceLock.withdrawalStatus,
};
} as Balance;
})
)
).filter(
(balance): balance is NonNullable<typeof balance> => balance !== null
);
).filter((balance): balance is Balance => balance !== null);

// Filter out any null results and return
return {
Expand Down

0 comments on commit 0dfbf74

Please sign in to comment.