Skip to content

Commit adc401a

Browse files
authored
feat: add sepolia requests to Request Scan (#79)
1 parent 90b9360 commit adc401a

File tree

6 files changed

+200
-78
lines changed

6 files changed

+200
-78
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "request-scan",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/app/request/[id]/page.tsx

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/** @format */
2-
'use client';
2+
"use client";
33

4-
import { TransactionsAndPaymentsTable } from '@/components/transactions-and-payments-table';
5-
import { Button } from '@/components/ui/button';
4+
import { TransactionsAndPaymentsTable } from "@/components/transactions-and-payments-table";
5+
import { Button } from "@/components/ui/button";
66
import {
77
Card,
88
CardHeader,
99
CardTitle,
1010
CardContent,
1111
CardFooter,
12-
} from '@/components/ui/card';
13-
import { Skeleton } from '@/components/ui/skeleton';
14-
import { fetchRequest } from '@/lib/queries/channel';
15-
import { fetchRequestPayments } from '@/lib/queries/request-payments';
12+
} from "@/components/ui/card";
13+
import { Skeleton } from "@/components/ui/skeleton";
14+
import { fetchRequest } from "@/lib/queries/channel";
15+
import { fetchRequestPayments } from "@/lib/queries/request-payments";
1616
import {
1717
calculateLongPaymentReference,
1818
calculateShortPaymentReference,
@@ -25,31 +25,39 @@ import {
2525
getPaymentDataFromCreateTransaction,
2626
getTransactionCreateParameters,
2727
renderAddress,
28-
} from '@/lib/utils';
29-
import { ActorInfo } from '@requestnetwork/data-format';
30-
import { useQuery } from '@tanstack/react-query';
31-
import { Copy, File, Loader2 } from 'lucide-react';
32-
import Link from 'next/link';
33-
import { redirect } from 'next/navigation';
34-
import TimeAgo from 'timeago-react';
35-
import { JsonEditor } from 'json-edit-react';
36-
import useExportPDF from '@/lib/hooks/use-export-pdf';
37-
import { useState } from 'react';
28+
} from "@/lib/utils";
29+
import { ActorInfo } from "@requestnetwork/data-format";
30+
import { useQuery } from "@tanstack/react-query";
31+
import { Copy, File, Loader2 } from "lucide-react";
32+
import Link from "next/link";
33+
import { redirect } from "next/navigation";
34+
import TimeAgo from "timeago-react";
35+
import { JsonEditor } from "json-edit-react";
36+
import useExportPDF from "@/lib/hooks/use-export-pdf";
37+
import { useState } from "react";
38+
import { Channel } from "@/lib/types";
3839

3940
interface RequestPageProps {
4041
params: {
4142
id: string;
4243
};
4344
}
4445

46+
const getGateway = (request: Channel | null) => {
47+
if (request?.source === "storage_sepolia") {
48+
return "sepolia.gateway.request.network";
49+
}
50+
return "gnosis.gateway.request.network";
51+
};
52+
4553
const ActorInfoSection = ({ actorInfo }: { actorInfo?: ActorInfo }) => {
4654
if (
4755
!actorInfo ||
4856
Object.keys(actorInfo).every(
49-
(k) => !Object.keys((actorInfo as any)[k]).length,
57+
(k) => !Object.keys((actorInfo as any)[k]).length
5058
)
5159
) {
52-
return 'N/A';
60+
return "N/A";
5361
}
5462

5563
return (
@@ -113,7 +121,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
113121
const [isDownloading, setIsDownloading] = useState(false);
114122

115123
const { data: request, isLoading: isLoadingRequest } = useQuery({
116-
queryKey: ['request', id],
124+
queryKey: ["request", id],
117125
queryFn: () => fetchRequest({ id }),
118126
...commonQueryOptions,
119127
});
@@ -122,19 +130,19 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
122130
? calculateShortPaymentReference(
123131
id,
124132
request?.transactions[0].dataObject.data.parameters.extensionsData[0]
125-
.parameters.salt || '',
133+
.parameters.salt || "",
126134
request?.transactions[0].dataObject.data.parameters.extensionsData[0]
127-
.parameters.paymentAddress || '',
135+
.parameters.paymentAddress || ""
128136
)
129-
: '';
137+
: "";
130138

131139
const longPaymentReference = shortPaymentReference
132140
? calculateLongPaymentReference(shortPaymentReference)
133-
: '';
141+
: "";
134142

135143
const { data: requestPayments, isLoading: isLoadingRequestPayments } =
136144
useQuery({
137-
queryKey: ['request-payments', longPaymentReference],
145+
queryKey: ["request-payments", longPaymentReference],
138146
queryFn: () => fetchRequestPayments({ reference: longPaymentReference }),
139147
...commonQueryOptions,
140148
});
@@ -144,7 +152,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
144152
}
145153

146154
if (!request) {
147-
redirect('/not-found');
155+
redirect("/not-found");
148156
}
149157

150158
const firstTransaction = request?.transactions[0];
@@ -160,14 +168,14 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
160168
const balanceCurrency =
161169
paymentData?.acceptedTokens?.length > 0
162170
? paymentData.acceptedTokens[0]
163-
: '';
171+
: "";
164172

165173
const buyerData = contentData?.buyerInfo;
166174
const sellerData = contentData?.sellerInfo;
167175

168176
const status =
169177
balance >= BigInt(createParameters.expectedAmount)
170-
? 'Paid'
178+
? "Paid"
171179
: lastTransaction?.dataObject?.data?.name;
172180

173181
const modifiedTimestamp =
@@ -190,7 +198,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
190198
paymentData,
191199
});
192200
} catch (error) {
193-
console.error('Error exporting PDF:', error);
201+
console.error("Error exporting PDF:", error);
194202
} finally {
195203
setIsDownloading(false);
196204
}
@@ -240,6 +248,10 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
240248
<td className="text-muted-foreground">Status:</td>
241249
<td className="pl-16">{status}</td>
242250
</tr>
251+
<tr>
252+
<td className="text-muted-foreground">Gateway:</td>
253+
<td className="pl-16">{getGateway(request)}</td>
254+
</tr>
243255
<tr>
244256
<td className="text-muted-foreground">Payee:</td>
245257
<td className="pl-16">
@@ -277,7 +289,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
277289
<td className="pl-16">
278290
{getAmountWithCurrencySymbol(
279291
BigInt(createParameters.expectedAmount),
280-
createParameters.currency.value,
292+
createParameters.currency.value
281293
)}
282294
</td>
283295
</tr>
@@ -286,7 +298,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
286298
<td className="pl-16">
287299
{getAmountWithCurrencySymbol(
288300
BigInt(balance),
289-
balanceCurrency || '',
301+
balanceCurrency || ""
290302
)}
291303
</td>
292304
</tr>
@@ -296,7 +308,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
296308
<TimeAgo
297309
datetime={firstTransaction.blockTimestamp * 1000}
298310
locale="en_short"
299-
/>{' '}
311+
/>{" "}
300312
({formatTimestamp(firstTransaction.blockTimestamp)})
301313
</td>
302314
</tr>
@@ -306,7 +318,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
306318
<TimeAgo
307319
datetime={modifiedTimestamp * 1000}
308320
locale="en_short"
309-
/>{' '}
321+
/>{" "}
310322
({formatTimestamp(modifiedTimestamp)})
311323
</td>
312324
</tr>
@@ -319,7 +331,7 @@ export default function RequestPage({ params: { id } }: RequestPageProps) {
319331
<td className="pl-16">
320332
{paymentData?.network
321333
? capitalize(paymentData?.network)
322-
: ''}
334+
: ""}
323335
</td>
324336
</tr>
325337
<tr>

src/lib/queries/address-transactions.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/** @format */
22

3-
import { gql } from 'graphql-request';
4-
import { graphQLClient } from '../graphQlClient';
5-
import { Transaction } from '../types';
6-
import { groupBy } from '../utils';
7-
import { getAddress } from 'viem';
3+
import { gql } from "graphql-request";
4+
import { graphQLClient } from "../graphQlClient";
5+
import { Transaction } from "../types";
6+
import { groupBy } from "../utils";
7+
import { getAddress } from "viem";
88

99
export const ADDRESS_TRANSACTIONS_QUERY = gql`
1010
query AddressTransactionsQuery(
@@ -37,6 +37,30 @@ export const ADDRESS_TRANSACTIONS_QUERY = gql`
3737
smartContractAddress
3838
}
3939
}
40+
storage_sepolia {
41+
transactions(
42+
first: $first
43+
skip: $skip
44+
orderBy: blockNumber
45+
orderDirection: desc
46+
where: {
47+
or: [
48+
{ data_contains: $checksumAddress }
49+
{ data_contains: $lowercaseAddress }
50+
]
51+
}
52+
) {
53+
blockNumber
54+
blockTimestamp
55+
channelId
56+
data
57+
dataHash
58+
hash
59+
id
60+
size
61+
smartContractAddress
62+
}
63+
}
4064
}
4165
`;
4266

@@ -54,18 +78,29 @@ export const fetchAddressRequests = async (variables: {
5478
lowercaseAddress: variables.address.toLowerCase(),
5579
};
5680

57-
const data: { storage: { transactions: Transaction[] } } =
58-
await graphQLClient.request(ADDRESS_TRANSACTIONS_QUERY, formatedVariables);
81+
const data: {
82+
storage: { transactions: Transaction[] };
83+
storage_sepolia: { transactions: Transaction[] };
84+
} = await graphQLClient.request(
85+
ADDRESS_TRANSACTIONS_QUERY,
86+
formatedVariables
87+
);
88+
89+
// Combine transactions from both networks
90+
const allTransactions = [
91+
...(data?.storage?.transactions || []),
92+
...(data?.storage_sepolia?.transactions || []),
93+
];
5994

60-
return data?.storage.transactions
95+
return allTransactions.length
6196
? groupBy(
62-
data?.storage.transactions.map((transaction: Transaction) => {
97+
allTransactions.map((transaction: Transaction) => {
6398
return {
6499
...transaction,
65100
dataObject: JSON.parse(transaction.data),
66101
};
67102
}),
68-
'channelId',
103+
"channelId"
69104
)
70105
: [];
71106
};

0 commit comments

Comments
 (0)