Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
chore: adding back the lninvoice and lnpayment even when a tx is asso…
Browse files Browse the repository at this point in the history
…ciated with the hash
  • Loading branch information
Nicolas Burtey committed Oct 8, 2023
1 parent e78d696 commit 37f327a
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 22 deletions.
6 changes: 5 additions & 1 deletion app/account/search-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AccountDetailsByEmailQuery,
AccountDetailsByUserPhoneDocument,
AccountDetailsByUserPhoneQuery,
AccountDetailsByUserPhoneQueryVariables,
AccountDetailsByUsernameDocument,
AccountDetailsByUsernameQuery,
} from "../../generated"
Expand All @@ -23,7 +24,10 @@ export const accountSearch = async (_prevState: unknown, formData: FormData) =>
let uuid: string | undefined

try {
const data = await getClient().query<AccountDetailsByUserPhoneQuery>({
const data = await getClient().query<
AccountDetailsByUserPhoneQuery,
AccountDetailsByUserPhoneQueryVariables
>({
query: AccountDetailsByUserPhoneDocument,
variables: { phone: search },
})
Expand Down
55 changes: 54 additions & 1 deletion app/transactions/hash/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import {
LightningInvoice,
LightningInvoiceDocument,
LightningInvoiceQuery,
LightningPayment,
LightningPaymentDocument,
LightningPaymentQuery,
TransactionsByHashDocument,
TransactionsByHashQuery,
} from "../../../../generated"

import TransactionList from "../../../../components/transactions/list"
import { getClient } from "../../../graphql-rsc"
import LnInvoice from "../../../../components/transactions/ln-invoice"
import LnPayment from "../../../../components/transactions/ln-payment"

export default async function TransactionDetails({ params }: { params: { id: string } }) {
const id = params.id
Expand All @@ -16,14 +24,59 @@ export default async function TransactionDetails({ params }: { params: { id: str

const txs = data.data.transactionsByHash

let invoice: LightningInvoice | undefined

try {
const data = await getClient().query<LightningInvoiceQuery>({
query: LightningInvoiceDocument,
variables: { hash: id },
})

invoice = data.data.lightningInvoice
} catch (err) {
// ignore
// no invoice attached to this hash
console.log(err)
}

let payment: LightningPayment

try {
const data = await getClient().query<LightningPaymentQuery>({
query: LightningPaymentDocument,
variables: { hash: id },
})

payment = data.data?.lightningPayment
} catch (err) {
const message = err instanceof Error ? err.message : "Unknown error"
return { message: `Failed to fetch: ${message}` }
}

return (
<>
<h1 className="mx-6 mt-6 text-2xl font-semibold text-gray-700">
Transaction details
</h1>
<div className="grid gap-6 mb-8 md:grid-cols-1 p-6">
{data && <TransactionList transactions={txs} />}
{txs && <TransactionList transactions={txs} />}
</div>
{invoice && (
<>
<h1 className="mx-6 mt-6 text-2xl font-semibold text-gray-700">Invoice</h1>
<div className="grid gap-6 mb-8 md:grid-cols-1 p-6">
{invoice && <LnInvoice invoice={invoice} />}
</div>
</>
)}
{payment && (
<>
<h1 className="mx-6 mt-6 text-2xl font-semibold text-gray-700">Invoice</h1>
<div className="grid gap-6 mb-8 md:grid-cols-1 p-6">
{payment && <LnPayment payment={payment} />}
</div>
</>
)}
</>
)
}
11 changes: 9 additions & 2 deletions app/transactions/id/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { TransactionByIdDocument, TransactionByIdQuery } from "../../../../generated"
import {
TransactionByIdDocument,
TransactionByIdQuery,
TransactionByIdQueryVariables,
} from "../../../../generated"

import TransactionList from "../../../../components/transactions/list"
import { getClient } from "../../../graphql-rsc"

export default async function TransactionDetails({ params }: { params: { id: string } }) {
const id = params.id

const data = await getClient().query<TransactionByIdQuery>({
const data = await getClient().query<
TransactionByIdQuery,
TransactionByIdQueryVariables
>({
query: TransactionByIdDocument,
variables: { id },
})
Expand Down
13 changes: 10 additions & 3 deletions app/transactions/invoice/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { LightningInvoiceDocument, LightningInvoiceQuery } from "../../../../generated"
import {
LightningInvoiceDocument,
LightningInvoiceQuery,
LightningInvoiceQueryVariables,
} from "../../../../generated"

import LnInvoice from "../../../../components/transactions/ln-invoice"
import { getClient } from "../../../graphql-rsc"

export default async function InvoiceDetails({ params }: { params: { id: string } }) {
const id = params.id

const data = await getClient().query<LightningInvoiceQuery>({
const data = await getClient().query<
LightningInvoiceQuery,
LightningInvoiceQueryVariables
>({
query: LightningInvoiceDocument,
variables: { id },
variables: { hash: id },
})

const invoice = data.data.lightningInvoice
Expand Down
13 changes: 10 additions & 3 deletions app/transactions/payment/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { LightningPaymentDocument, LightningPaymentQuery } from "../../../../generated"
import {
LightningPaymentDocument,
LightningPaymentQuery,
LightningPaymentQueryVariables,
} from "../../../../generated"

import LnPayment from "../../../../components/transactions/ln-payment"
import { getClient } from "../../../graphql-rsc"

export default async function InvoiceDetails({ params }: { params: { id: string } }) {
const id = params.id

const data = await getClient().query<LightningPaymentQuery>({
const data = await getClient().query<
LightningPaymentQuery,
LightningPaymentQueryVariables
>({
query: LightningPaymentDocument,
variables: { id },
variables: { hash: id },
})

const payment = data.data.lightningPayment
Expand Down
28 changes: 22 additions & 6 deletions app/transactions/search-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { redirect } from "next/navigation"
import {
LightningInvoiceDocument,
LightningInvoiceQuery,
LightningInvoiceQueryVariables,
LightningPaymentDocument,
LightningPaymentQuery,
Transaction,
LightningPaymentQueryVariables,
TransactionByIdDocument,
TransactionByIdQuery,
TransactionByIdQueryVariables,
TransactionsByHashDocument,
TransactionsByHashQuery,
TransactionsByHashQueryVariables,
} from "../../generated"
import { getClient } from "../graphql-rsc"

Expand All @@ -30,7 +33,10 @@ export const transactionSearch = async (_prevState: unknown, formData: FormData)
let tx: unknown | undefined

try {
const data = await getClient().query<TransactionsByHashQuery>({
const data = await getClient().query<
TransactionsByHashQuery,
TransactionsByHashQueryVariables
>({
query: TransactionsByHashDocument,
variables: { hash: search },
})
Expand All @@ -49,7 +55,10 @@ export const transactionSearch = async (_prevState: unknown, formData: FormData)
}

try {
const data = await getClient().query<LightningPaymentQuery>({
const data = await getClient().query<
LightningPaymentQuery,
LightningPaymentQueryVariables
>({
query: LightningPaymentDocument,
variables: { hash: search },
})
Expand All @@ -67,9 +76,12 @@ export const transactionSearch = async (_prevState: unknown, formData: FormData)
let invoice: unknown | undefined

try {
const data = await getClient().query<LightningInvoiceQuery>({
const data = await getClient().query<
LightningInvoiceQuery,
LightningInvoiceQueryVariables
>({
query: LightningInvoiceDocument,
variables: { id: search },
variables: { hash: search },
})

invoice = data.data.lightningInvoice
Expand All @@ -82,11 +94,15 @@ export const transactionSearch = async (_prevState: unknown, formData: FormData)
redirect(`/transactions/invoice/${search}`)
}
}

if (isValidTxId(search)) {
let txid: string | undefined

try {
const data = await getClient().query<TransactionByIdQuery>({
const data = await getClient().query<
TransactionByIdQuery,
TransactionByIdQueryVariables
>({
query: TransactionByIdDocument,
variables: { id: search },
})
Expand Down
12 changes: 10 additions & 2 deletions components/account/business-map-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
AuditedAccount,
BusinessDeleteMapInfoDocument,
BusinessDeleteMapInfoMutation,
BusinessDeleteMapInfoMutationVariables,
BusinessUpdateMapInfoDocument,
BusinessUpdateMapInfoMutation,
BusinessUpdateMapInfoMutationVariables,
} from "../../generated"
import ConfirmForm from "./confirm"
import { getClient } from "../../app/graphql-rsc"
Expand All @@ -20,7 +22,10 @@ const deleteBusiness = async (formData: FormData) => {

const username = formData.get("username") as string

await getClient().mutate<BusinessDeleteMapInfoMutation>({
await getClient().mutate<
BusinessDeleteMapInfoMutation,
BusinessDeleteMapInfoMutationVariables
>({
mutation: BusinessDeleteMapInfoDocument,
variables: { input: { username } },
})
Expand All @@ -45,7 +50,10 @@ const update = async (formData: FormData) => {
) {
const input = { username, title, latitude, longitude }

await getClient().mutate<BusinessUpdateMapInfoMutation>({
await getClient().mutate<
BusinessUpdateMapInfoMutation,
BusinessUpdateMapInfoMutationVariables
>({
mutation: BusinessUpdateMapInfoDocument,
variables: { input },
})
Expand Down
23 changes: 19 additions & 4 deletions components/account/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { getClient } from "../../app/graphql-rsc"
import {
AccountDetailsByAccountIdDocument,
AccountDetailsByAccountIdQuery,
AccountDetailsByAccountIdQueryVariables,
AccountLevel,
AccountStatus,
AccountUpdateLevelDocument,
AccountUpdateLevelMutation,
AccountUpdateLevelMutationVariables,
AccountUpdateStatusDocument,
AccountUpdateStatusMutation,
AccountUpdateStatusMutationVariables,
AuditedAccount,
} from "../../generated"
import ConfirmForm from "./confirm"
Expand All @@ -23,14 +26,20 @@ const updateLevel = async (formData: FormData) => {

const id = formData.get("id") as string

const { data } = await getClient().query<AccountDetailsByAccountIdQuery>({
const { data } = await getClient().query<
AccountDetailsByAccountIdQuery,
AccountDetailsByAccountIdQueryVariables
>({
query: AccountDetailsByAccountIdDocument,
variables: { accountId: id },
})

const auditedAccount = data?.accountDetailsByAccountId

await getClient().mutate<AccountUpdateLevelMutation>({
await getClient().mutate<
AccountUpdateLevelMutation,
AccountUpdateLevelMutationVariables
>({
mutation: AccountUpdateLevelDocument,
variables: { input: { uid: auditedAccount.id, level: AccountLevel.Two } },
})
Expand All @@ -42,7 +51,10 @@ const updateStatus = async (formData: FormData) => {
"use server"
const id = formData.get("id") as string

const { data } = await getClient().query<AccountDetailsByAccountIdQuery>({
const { data } = await getClient().query<
AccountDetailsByAccountIdQuery,
AccountDetailsByAccountIdQueryVariables
>({
query: AccountDetailsByAccountIdDocument,
variables: { accountId: id },
})
Expand All @@ -52,7 +64,10 @@ const updateStatus = async (formData: FormData) => {
const targetStatus =
auditedAccount.status === "ACTIVE" ? AccountStatus.Locked : AccountStatus.Active

await getClient().mutate<AccountUpdateStatusMutation>({
await getClient().mutate<
AccountUpdateStatusMutation,
AccountUpdateStatusMutationVariables
>({
mutation: AccountUpdateStatusDocument,
variables: { input: { uid: auditedAccount.id, status: targetStatus } },
})
Expand Down

0 comments on commit 37f327a

Please sign in to comment.