• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cameri / nostream / 24342667594

13 Apr 2026 12:12PM UTC coverage: 42.555% (-13.0%) from 55.529%
24342667594

Pull #468

github

web-flow
Merge 4fd541f37 into 1410824d2
Pull Request #468: Phase3: UI Implementation for Dashboard

424 of 1204 branches covered (35.22%)

Branch coverage included in aggregate %.

164 of 540 new or added lines in 14 files covered. (30.37%)

373 existing lines in 23 files now uncovered.

1385 of 3047 relevant lines covered (45.45%)

7.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.0
/src/utils/transform.ts
1
import { always, applySpec, cond, equals, ifElse, is, isNil, multiply, path, pathSatisfies, pipe, prop, propSatisfies, T } from 'ramda'
2✔
2
import { bech32 } from 'bech32'
2✔
3

4
import { Invoice, InvoiceStatus, InvoiceUnit } from '../@types/invoice'
2✔
5
import { User } from '../@types/user'
6

7
export const toJSON = (input: any) => JSON.stringify(input)
27✔
8

9
export const toBuffer = (input: any) => Buffer.from(input, 'hex')
275✔
10

11
export const fromBuffer = (input: Buffer) => input.toString('hex')
94✔
12

13
export const toBigInt = (input: string | number): bigint => BigInt(input)
2✔
14

15
export const fromBigInt = (input: bigint) => input.toString()
2✔
16

17
const addTime = (ms: number) => (input: Date) => new Date(input.getTime() + ms)
2✔
18

19
export const fromDBInvoice = applySpec<Invoice>({
2✔
20
  id: prop('id') as () => string,
21
  pubkey: pipe(prop('pubkey') as () => Buffer, fromBuffer),
22
  bolt11: prop('bolt11'),
23
  amountRequested: pipe(prop('amount_requested') as () => string, toBigInt),
24
  amountPaid: ifElse(
25
    propSatisfies(isNil, 'amount_paid'),
26
    always(undefined),
27
    pipe(prop('amount_paid') as () => string, toBigInt),
28
  ),
29
  unit: prop('unit'),
30
  status: prop('status'),
31
  description: prop('description'),
32
  confirmedAt: prop('confirmed_at'),
33
  expiresAt: prop('expires_at'),
34
  updatedAt: prop('updated_at'),
35
  createdAt: prop('created_at'),
36
  verifyURL: prop('verify_url'),
37
})
38

39
export const fromDBUser = applySpec<User>({
2✔
40
  pubkey: pipe(prop('pubkey') as () => Buffer, fromBuffer),
41
  isAdmitted: prop('is_admitted'),
42
  balance: prop('balance'),
43
  createdAt: prop('created_at'),
44
  updatedAt: prop('updated_at'),
45
})
46

47
export const fromBech32 = (input: string) => {
2✔
UNCOV
48
  const { prefix, words } = bech32.decode(input)
×
UNCOV
49
  if (!input.startsWith(prefix)) {
×
50
    throw new Error(`Bech32 invalid prefix: ${prefix}`)
×
51
  }
52

UNCOV
53
  return Buffer.from(
×
54
    bech32.fromWords(words).slice(0, 32)
55
  ).toString('hex')
56
}
57

58
export const toBech32 = (prefix: string) => (input: string): string => {
2✔
UNCOV
59
  return bech32.encode(prefix, bech32.toWords(Buffer.from(input, 'hex')))
×
60
}
61

62
export const toDate = (input: string | number) => new Date(input)
2✔
63

64
export const fromZebedeeInvoice = applySpec<Invoice>({
2✔
65
  id: prop('id'),
66
  pubkey: prop('internalId'),
67
  bolt11: path(['invoice', 'request']),
68
  amountRequested: pipe(prop('amount') as () => string, toBigInt),
69
  description: prop('description'),
70
  unit: prop('unit'),
71
  status: prop('status'),
72
  expiresAt: ifElse(
73
    propSatisfies(is(String), 'expiresAt'),
74
    pipe(prop('expiresAt'), toDate),
75
    always(null),
76
  ),
77
  confirmedAt: ifElse(
78
    propSatisfies(is(String), 'confirmedAt'),
79
    pipe(prop('confirmedAt'), toDate),
80
    always(null),
81
  ),
82
  createdAt: ifElse(
83
    propSatisfies(is(String), 'createdAt'),
84
    pipe(prop('createdAt'), toDate),
85
    always(null),
86
  ),
87
  rawResponse: toJSON,
88
})
89

90
export const fromNodelessInvoice = applySpec<Invoice>({
2✔
91
  id: prop('id'),
92
  pubkey: path(['metadata', 'requestId']),
93
  bolt11: prop('lightningInvoice'),
94
  amountRequested: pipe(prop('satsAmount') as () => number, toBigInt),
95
  description: path(['metadata', 'description']),
96
  unit: path(['metadata', 'unit']),
97
  status: pipe(
98
    prop('status'),
99
    cond([
100
      [equals('new'), always(InvoiceStatus.PENDING)],
101
      [equals('pending_confirmation'), always(InvoiceStatus.PENDING)],
102
      [equals('underpaid'), always(InvoiceStatus.PENDING)],
103
      [equals('in_flight'), always(InvoiceStatus.PENDING)],
104
      [equals('paid'), always(InvoiceStatus.COMPLETED)],
105
      [equals('overpaid'), always(InvoiceStatus.COMPLETED)],
106
      [equals('expired'), always(InvoiceStatus.EXPIRED)],
107
    ]),
108
  ),
109
  expiresAt: ifElse(
110
    propSatisfies(is(String), 'expiresAt'),
111
    pipe(prop('expiresAt'), toDate),
112
    ifElse(
113
      propSatisfies(is(String), 'createdAt'),
114
      pipe(prop('createdAt'), toDate, addTime(15 * 60000)),
115
      always(null),
116
    ),
117
  ),
118
  confirmedAt: cond([
119
    [propSatisfies(is(String), 'paidAt'), pipe(prop('paidAt'), toDate)],
120
    [T, always(null)],
121
  ]),
122
  createdAt: ifElse(
123
    propSatisfies(is(String), 'createdAt'),
124
    pipe(prop('createdAt'), toDate),
125
    always(null),
126
  ),
127
  // rawResponse: toJSON,
128
})
129

130
export const fromOpenNodeInvoice = applySpec<Invoice>({
2✔
131
  id: prop('id'),
132
  pubkey: prop('order_id'),
133
  bolt11: ifElse(
134
    pathSatisfies(is(String), ['lightning_invoice', 'payreq']),
135
    path(['lightning_invoice', 'payreq']),
136
    path(['lightning', 'payreq'])
137
  ),
138
  amountRequested: pipe(
139
    ifElse(
140
      propSatisfies(is(Number), 'amount'),
141
      prop('amount'),
142
      prop('price'),
143
    ) as () => number,
144
    toBigInt,
145
  ),
146
  description: prop('description'),
147
  unit: always(InvoiceUnit.SATS),
148
  status: pipe(
149
    prop('status'),
150
    cond([
151
      [equals('expired'), always(InvoiceStatus.EXPIRED)],
152
      [equals('refunded'), always(InvoiceStatus.EXPIRED)],
153
      [equals('unpaid'), always(InvoiceStatus.PENDING)],
154
      [equals('processing'), always(InvoiceStatus.PENDING)],
155
      [equals('underpaid'), always(InvoiceStatus.PENDING)],
156
      [equals('paid'), always(InvoiceStatus.COMPLETED)],
157
    ]),
158
  ),
159
  expiresAt: pipe(
160
    cond([
161
      [pathSatisfies(is(String), ['lightning', 'expires_at']), path(['lightning', 'expires_at'])],
162
      [pathSatisfies(is(Number), ['lightning_invoice', 'expires_at']), pipe(path(['lightning_invoice', 'expires_at']), multiply(1000))],
163
    ]),
164
    toDate,
165
  ),
166
  confirmedAt: cond([
UNCOV
167
    [propSatisfies(equals('paid'), 'status'), () => new Date()],
×
168
    [T, always(null)],
169
  ]),
170
  createdAt: pipe(
171
    ifElse(
172
      propSatisfies(is(Number), 'created_at'),
173
      pipe(prop('created_at'), multiply(1000)),
174
      prop('created_at'),
175
    ),
176
    toDate,
177
  ),
178
  rawResponse: toJSON,
179
})
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc