Compare commits
No commits in common. "8438e9f26dd4133d3dce907a13e0bc8b4e58ac74" and "7308292642373d87514e9599de70729bdda5de62" have entirely different histories.
8438e9f26d
...
7308292642
1 changed files with 1 additions and 11 deletions
|
|
@ -4,9 +4,6 @@ import { injectService, SERVICE_TOKENS } from '@/core/di-container'
|
||||||
import { config } from '@/lib/config'
|
import { config } from '@/lib/config'
|
||||||
import { decode as decodeBolt11 } from 'light-bolt11-decoder'
|
import { decode as decodeBolt11 } from 'light-bolt11-decoder'
|
||||||
|
|
||||||
/** The `amount` member of light-bolt11-decoder's `Section` union. */
|
|
||||||
type AmountSection = { name: 'amount'; letters: string; value: string }
|
|
||||||
|
|
||||||
export interface PayLink {
|
export interface PayLink {
|
||||||
id: string
|
id: string
|
||||||
wallet: string
|
wallet: string
|
||||||
|
|
@ -347,14 +344,7 @@ export default class WalletService extends BaseService {
|
||||||
private getInvoiceAmountMsat(bolt11: string): number | null {
|
private getInvoiceAmountMsat(bolt11: string): number | null {
|
||||||
try {
|
try {
|
||||||
const decoded = decodeBolt11(bolt11)
|
const decoded = decodeBolt11(bolt11)
|
||||||
// `sections` is a discriminated union, and not every member carries a
|
const section = decoded.sections.find((s: any) => s.name === 'amount')
|
||||||
// `value` — the "checksum" member has only `letters`. Narrow with a
|
|
||||||
// type predicate so the compiler knows which member we are reading;
|
|
||||||
// an `(s: any)` callback is not a type guard, so `find` still returned
|
|
||||||
// the whole union and `.value` failed to resolve under `vue-tsc -b`.
|
|
||||||
const section = decoded.sections.find(
|
|
||||||
(s): s is AmountSection => s.name === 'amount'
|
|
||||||
)
|
|
||||||
if (!section || section.value === undefined || section.value === null) return 0
|
if (!section || section.value === undefined || section.value === null) return 0
|
||||||
return Number(section.value)
|
return Number(section.value)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue