refactor(market): reuse banking treasury account helper
Drops market's local treasury account lookup in favor of getTreasuryAccountId from the banking lib, re-exported for compatibility. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
80ec3a0386
commit
86464b528a
1 changed files with 8 additions and 17 deletions
|
|
@ -9,7 +9,14 @@ import {
|
||||||
resolveAssetId,
|
resolveAssetId,
|
||||||
toLockerGridItems,
|
toLockerGridItems,
|
||||||
} from "@/lib/locker";
|
} from "@/lib/locker";
|
||||||
import { applyTransaction, ensurePersonalAccount, getMainCurrencyId } from "@/lib/banking";
|
import {
|
||||||
|
applyTransaction,
|
||||||
|
ensurePersonalAccount,
|
||||||
|
getMainCurrencyId,
|
||||||
|
getTreasuryAccountId,
|
||||||
|
} from "@/lib/banking";
|
||||||
|
|
||||||
|
export { getTreasuryAccountId } from "@/lib/banking";
|
||||||
|
|
||||||
type PayloadType = Awaited<ReturnType<typeof import("payload").getPayload>>;
|
type PayloadType = Awaited<ReturnType<typeof import("payload").getPayload>>;
|
||||||
|
|
||||||
|
|
@ -218,22 +225,6 @@ export async function creditLockerQuantity(
|
||||||
})) as unknown as LockerStorage;
|
})) as unknown as LockerStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resolve the id of the open unit treasury account, if any. */
|
|
||||||
export async function getTreasuryAccountId(payload: PayloadType): Promise<number | null> {
|
|
||||||
try {
|
|
||||||
const result = (await payload.find({
|
|
||||||
collection: "bank-accounts",
|
|
||||||
where: { and: [{ accountType: { equals: "treasury" } }, { status: { equals: "open" } }] },
|
|
||||||
limit: 1,
|
|
||||||
depth: 0,
|
|
||||||
overrideAccess: true,
|
|
||||||
})) as unknown as { docs: { id: number }[] };
|
|
||||||
return result.docs[0]?.id ?? null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuyResult {
|
export interface BuyResult {
|
||||||
transactionId: number;
|
transactionId: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue