-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add payment status by hash query/subscription
- Loading branch information
Showing
19 changed files
with
398 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
subscription lnInvoicePaymentStatusByHashSubscription($input: LnInvoicePaymentStatusByHashInput!) { | ||
lnInvoicePaymentStatusByHash(input: $input) { | ||
errors { | ||
message | ||
} | ||
status | ||
paymentHash | ||
paymentRequest | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query LnInvoicePaymentStatusByHashQuery($input: LnInvoicePaymentStatusByHashInput!) { | ||
lnInvoicePaymentStatusByHash(input: $input) { | ||
status | ||
paymentHash | ||
paymentRequest | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
query LnInvoicePaymentStatusQuery($input: LnInvoicePaymentStatusInput!) { | ||
lnInvoicePaymentStatus(input: $input) { | ||
status | ||
paymentHash | ||
paymentRequest | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/api/src/graphql/public/root/query/ln-invoice-payment-status-by-hash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Lightning } from "@/app" | ||
import { WalletInvoiceStatus } from "@/domain/wallet-invoices" | ||
|
||
import { GT } from "@/graphql/index" | ||
import { mapAndParseErrorForGqlResponse } from "@/graphql/error-map" | ||
import LnInvoicePaymentStatusPayload from "@/graphql/public/types/payload/ln-invoice-payment-status" | ||
import LnInvoicePaymentStatusByHashInput from "@/graphql/public/types/object/ln-invoice-payment-status-by-hash-input" | ||
|
||
const LnInvoicePaymentStatusByHashQuery = GT.Field({ | ||
type: GT.NonNull(LnInvoicePaymentStatusPayload), | ||
args: { | ||
input: { type: GT.NonNull(LnInvoicePaymentStatusByHashInput) }, | ||
}, | ||
resolve: async (_, args) => { | ||
const { paymentHash } = args.input | ||
if (paymentHash instanceof Error) { | ||
return { errors: [{ message: paymentHash.message }] } | ||
} | ||
|
||
const paymentStatusChecker = await Lightning.PaymentStatusCheckerByHash({ | ||
paymentHash, | ||
}) | ||
if (paymentStatusChecker instanceof Error) { | ||
return { errors: [mapAndParseErrorForGqlResponse(paymentStatusChecker)] } | ||
} | ||
|
||
const paid = await paymentStatusChecker.invoiceIsPaid() | ||
if (paid instanceof Error) { | ||
return { errors: [mapAndParseErrorForGqlResponse(paid)] } | ||
} | ||
|
||
const { paymentRequest, isExpired } = paymentStatusChecker | ||
|
||
if (paid) { | ||
return { errors: [], paymentHash, paymentRequest, status: WalletInvoiceStatus.Paid } | ||
} | ||
|
||
const status = isExpired ? WalletInvoiceStatus.Expired : WalletInvoiceStatus.Pending | ||
return { errors: [], paymentHash, paymentRequest, status } | ||
}, | ||
}) | ||
|
||
export default LnInvoicePaymentStatusByHashQuery |
Oops, something went wrong.