-
Notifications
You must be signed in to change notification settings - Fork 13
[TASK-15250] feat(manteca): add receipts to all manteca transactions #1257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,42 @@ | ||
| 'use server' | ||
|
|
||
| import { EHistoryEntryType, completeHistoryEntry } from '@/utils/history.utils' | ||
| import type { HistoryEntry } from '@/utils/history.utils' | ||
| import { PEANUT_API_URL } from '@/constants' | ||
| import { fetchWithSentry } from '@/utils' | ||
|
|
||
| /** | ||
| * Fetches a single history entry from the API. This is used for receipts | ||
| * | ||
| * We want to cache the response for final states, that way we have less | ||
| * calls to the backend when sharing the receipt. | ||
| * For intermediate states, we want to avoid caching, so we can show the | ||
| * latest state whenever called. | ||
| * | ||
| * @param entryId The id of the entry to fetch | ||
| * @param entryType The type of the entry to fetch | ||
| * @returns The fetched history entry | ||
| */ | ||
| export async function getHistoryEntry(entryId: string, entryType: EHistoryEntryType): Promise<HistoryEntry | null> { | ||
| let response: Awaited<ReturnType<typeof fetchWithSentry>> | ||
| try { | ||
| response = await fetchWithSentry(`${PEANUT_API_URL}/history/${entryId}?entryType=${entryType}`) | ||
| } catch (error) { | ||
| throw new Error(`Unexpected error fetching history entry: ${error}`) | ||
| } | ||
|
|
||
| if (!response.ok) { | ||
| if (response.status === 404) { | ||
| return null | ||
| } | ||
| if (response.status === 400) { | ||
| const errorData = await response.json() | ||
| throw new Error(`Sent invalid params when fetching history entry: ${errorData.message ?? errorData.error}`) | ||
| } | ||
| throw new Error(`Failed to fetch history entry: ${response.statusText}`) | ||
| } | ||
|
|
||
| const data = await response.json() | ||
| const entry = completeHistoryEntry(data) | ||
| return entry | ||
| } |
This file contains hidden or 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,21 @@ | ||
| import Link from 'next/link' | ||
| import PageContainer from '@/components/0_Bruddle/PageContainer' | ||
| import PEANUTMAN_CRY from '@/animations/GIF_ALPHA_BACKGORUND/512X512_ALPHA_GIF_konradurban_05.gif' | ||
| import Image from 'next/image' | ||
|
|
||
| export default function NotFound() { | ||
| return ( | ||
| <PageContainer className="min-h-[100dvh]"> | ||
| <div className="my-auto flex h-full flex-col justify-center space-y-4"> | ||
| <div className="shadow-4 flex w-full flex-col items-center space-y-2 bg-white px-4 py-2"> | ||
| <h1 className="text-3xl font-extrabold">Not found</h1> | ||
| <Image src={PEANUTMAN_CRY.src} className="" alt="Peanutman crying 😭" width={96} height={96} /> | ||
| <p>Woah there buddy, you're not supposed to be here.</p> | ||
| <Link href="/" className="btn btn-purple"> | ||
| Take me home, I'm scared | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| </PageContainer> | ||
| ) | ||
| } |
This file contains hidden or 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,34 @@ | ||
| import { connection } from 'next/server' | ||
| import { notFound } from 'next/navigation' | ||
| import { EHistoryEntryType, isFinalState, historyTypeFromNumber } from '@/utils/history.utils' | ||
| import { getHistoryEntry } from '@/app/actions/history' | ||
| import { mapTransactionDataForDrawer } from '@/components/TransactionDetails/transactionTransformer' | ||
| import { TransactionDetailsReceipt } from '@/components/TransactionDetails/TransactionDetailsReceipt' | ||
|
|
||
| export default async function ReceiptPage({ | ||
| params, | ||
| searchParams, | ||
| }: { | ||
| params: Promise<{ entryId: string }> | ||
| searchParams: Promise<Record<string, string | string[] | undefined>> | ||
| }) { | ||
| const { entryId } = await params | ||
| let entryTypeId = (await searchParams).t | ||
| if (!entryId || !entryTypeId || typeof entryTypeId !== 'string' || !historyTypeFromNumber(Number(entryTypeId))) { | ||
| notFound() | ||
| } | ||
| const entryType = historyTypeFromNumber(Number(entryTypeId)) | ||
| const entry = await getHistoryEntry(entryId, entryType) | ||
| if (!entry) { | ||
| notFound() | ||
| } | ||
| if (!isFinalState(entry)) { | ||
| await connection() | ||
| } | ||
| const { transactionDetails } = mapTransactionDataForDrawer(entry) | ||
| return ( | ||
| <div className="flex min-h-[100dvh] flex-col items-center justify-center"> | ||
| <TransactionDetailsReceipt className="w-full px-5" transaction={transactionDetails!} /> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.