--- /dev/null
+//! SPDX-FileCopyrightText: 2026 Chris Duncan <chris@codecow.com>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+export type AccountBalance = {
+ balance: string
+ pending: string
+ receivable: string
+}
+
+export function account_balance (body: unknown): AccountBalance {
+ const response: AccountBalance = {
+ balance: '0',
+ pending: '0',
+ receivable: '0',
+ }
+ if (body == null || typeof body !== 'object') {
+ return response
+ }
+ if ('balance' in body && typeof body.balance === 'string') {
+ response.balance = body.balance
+ }
+ if ('pending' in body && typeof body.pending === 'string') {
+ response.pending = body.pending
+ }
+ if ('receivable' in body && typeof body.receivable === 'string') {
+ response.receivable = body.receivable
+ }
+ return response
+}
//! SPDX-License-Identifier: GPL-3.0-or-later
import { Account } from '../account'
+import { AccountBalance, account_balance } from './account_balance'
type AccountsBalances = {
balances?: {
- [address: string]: {
- balance: string,
- receivable: string
- }
- },
+ [address: string]: AccountBalance
+ }
errors?: {
[address: string]: string
}
if (data == null || typeof data !== 'object') {
throw new Error('Invalid account balance data')
}
- if ('balance' in data && typeof data.balance === 'string') {
- response.balances ??= {}
- response.balances[address].balance = data.balance
- }
- if ('receivable' in data && typeof data.receivable === 'string') {
- response.balances ??= {}
- response.balances[address].receivable = data.receivable
- }
+ response.balances ??= {}
+ response.balances[address] = account_balance(data)
} catch (err: any) {
response.errors ??= {}
response.errors[address] = err?.message