Skip to content

Commit

Permalink
chore: use const object instead of enums (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleSamtoshi authored Jan 18, 2023
1 parent fd7bf86 commit d9cdc72
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions src/parsing-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,82 +71,93 @@ export const getHashFromInvoice = (
}
}

export enum PaymentType {
Lightning = "lightning",
Intraledger = "intraledger",
Onchain = "onchain",
Lnurl = "lnurl",
Unified = "unified",
NullInput = "nullinput",
Unknown = "unknown",
}
export const PaymentType = {
Lightning: "lightning",
Intraledger: "intraledger",
Onchain: "onchain",
Lnurl: "lnurl",
NullInput: "nullInput",
Unified: "unified",
Unknown: "unknown",
} as const

export type PaymentType = typeof PaymentType[keyof typeof PaymentType]

export type UnknownPaymentDestination = {
paymentType: PaymentType.Unknown
paymentType: typeof PaymentType.Unknown
}

export type NullInputPaymentDestination = {
paymentType: PaymentType.NullInput
paymentType: typeof PaymentType.NullInput
}

export enum InvalidLnurlPaymentDestinationReason {
Unknown = "Unknown",
export const InvalidLnurlPaymentDestinationReason = {
Unknown: "unknown",
}

export type InvalidLnurlPaymentDestinationReason =
typeof InvalidLnurlPaymentDestinationReason[keyof typeof InvalidLnurlPaymentDestinationReason]

export type LnurlPaymentDestination =
| {
paymentType: PaymentType.Lnurl
paymentType: typeof PaymentType.Lnurl
valid: true
lnurl: string
}
| {
paymentType: PaymentType.Lnurl
paymentType: typeof PaymentType.Lnurl
valid: false
invalidReason: InvalidLnurlPaymentDestinationReason
}

export enum InvalidLightningDestinationReason {
InvoiceExpired = "InvoiceExpired",
WrongNetwork = "WrongNetwork",
Unknown = "Unknown",
}
export const InvalidLightningDestinationReason = {
InvoiceExpired: "InvoiceExpired",
WrongNetwork: "WrongNetwork",
Unknown: "Unknown",
} as const

export type InvalidLightningDestinationReason =
typeof InvalidLightningDestinationReason[keyof typeof InvalidLightningDestinationReason]

export type LightningPaymentDestination =
| {
paymentType: PaymentType.Lightning
paymentType: typeof PaymentType.Lightning
valid: true
paymentRequest: string
amount?: number | undefined
memo?: string | undefined
}
| {
paymentType: PaymentType.Lightning
paymentType: typeof PaymentType.Lightning
valid: false
invalidReason: InvalidLightningDestinationReason
}

export enum InvalidOnchainDestinationReason {
WrongNetwork = "WrongNetwork",
Unknown = "Unknown",
InvalidAmount = "InvalidAmount",
}
export const InvalidOnchainDestinationReason = {
WrongNetwork: "WrongNetwork",
Unknown: "Unknown",
InvalidAmount: "InvalidAmount",
} as const

export type InvalidOnchainDestinationReason =
typeof InvalidOnchainDestinationReason[keyof typeof InvalidOnchainDestinationReason]

export type OnchainPaymentDestination =
| {
paymentType: PaymentType.Onchain
paymentType: typeof PaymentType.Onchain
valid: true
address: string
amount?: number | undefined
memo?: string | undefined
}
| {
paymentType: PaymentType.Onchain
paymentType: typeof PaymentType.Onchain
valid: false
invalidReason: InvalidOnchainDestinationReason
}

export type IntraledgerPaymentDestination = {
paymentType: PaymentType.Intraledger
paymentType: typeof PaymentType.Intraledger
handle: string
}

Expand Down

0 comments on commit d9cdc72

Please sign in to comment.