Commit 4f963f7 1 parent 2bc3ba4 commit 4f963f7 Copy full SHA for 4f963f7
File tree 10 files changed +57
-13
lines changed
Transaction/component/TxScripts
Transactions/components/TxCard
10 files changed +57
-13
lines changed Original file line number Diff line number Diff line change 1
1
FUEL_PROVIDER = https://beta-5.fuel.network/graphql
2
+ # Explorer API URL
3
+ FUEL_EXPLORER_API =
4
+ FUEL_EXPLORER_API_KEY =
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import { createExecutor , createSchema } from '@fuel-explorer/graphql' ;
2
2
import { ContextDomain } from '@fuel-explorer/graphql/src/domains/Context' ;
3
3
import { createYoga } from 'graphql-yoga' ;
4
+ import { NextResponse } from 'next/server' ;
4
5
import { requireEnv } from '~/systems/utils/requireEnv' ;
5
6
6
7
const { FUEL_PROVIDER : url } = requireEnv ( [ 'FUEL_PROVIDER' ] ) ;
@@ -29,8 +30,17 @@ const { handleRequest } = createYoga({
29
30
} ,
30
31
} ) ;
31
32
33
+ const authenticatiohMiddleware = async ( request : Request , ctx : Object ) => {
34
+ if ( process . env . FUEL_EXPLORER_API ) {
35
+ return new NextResponse ( 'Unauthorized' , {
36
+ status : 401 ,
37
+ } ) ;
38
+ }
39
+ return handleRequest ( request , ctx ) ;
40
+ } ;
41
+
32
42
export {
33
- handleRequest as GET ,
34
- handleRequest as POST ,
35
- handleRequest as OPTIONS ,
43
+ authenticatiohMiddleware as GET ,
44
+ authenticatiohMiddleware as POST ,
45
+ authenticatiohMiddleware as OPTIONS ,
36
46
} ;
Original file line number Diff line number Diff line change 1
1
import { resolve } from 'url' ;
2
- import { getSdk } from '@fuel-explorer/graphql' ;
2
+ import { getSdk } from '@fuel-explorer/graphql/src/sdk ' ;
3
3
import { GraphQLClient } from 'graphql-request' ;
4
4
5
+ const { FUEL_EXPLORER_API , FUEL_EXPLORER_API_KEY } = process . env ;
5
6
const VERCEL_URL = process . env . VERCEL_URL || process . env . NEXT_PUBLIC_VERCEL_URL ;
6
7
const VERCEL_ENV =
7
8
process . env . VERCEL_ENV || process . env . NEXT_PUBLIC_VERCEL_ENV || 'development' ;
8
9
9
10
const getBaseUrl = ( ) => {
10
- if ( VERCEL_ENV !== 'development' ) return `https://${ VERCEL_URL } ` ;
11
- return 'http://localhost:3000' ;
11
+ if ( FUEL_EXPLORER_API && FUEL_EXPLORER_API_KEY ) return FUEL_EXPLORER_API ;
12
+ if ( VERCEL_ENV !== 'development' )
13
+ return resolve ( `https://${ VERCEL_URL } ` , '/api/graphql' ) ;
14
+ return 'http://localhost:3000/api/graphql' ;
15
+ } ;
16
+ const getHeaders = ( ) => {
17
+ if ( FUEL_EXPLORER_API_KEY ) {
18
+ return { Authorization : `Bearer ${ FUEL_EXPLORER_API_KEY } ` } ;
19
+ }
20
+ return undefined ;
12
21
} ;
13
22
14
- const API_URL = resolve ( getBaseUrl ( ) , '/api/graphql' ) ;
15
- const client = new GraphQLClient ( API_URL , { fetch } ) ;
23
+ const client = new GraphQLClient ( getBaseUrl ( ) , {
24
+ fetch,
25
+ headers : getHeaders ( ) ,
26
+ } ) ;
16
27
export const sdk = getSdk ( client ) ;
Original file line number Diff line number Diff line change 1
- import { ReceiptType } from '@fuel-explorer/graphql' ;
1
+ import { ReceiptType } from '@fuel-explorer/graphql/src/sdk ' ;
2
2
import type {
3
3
Maybe ,
4
4
OperationReceipt ,
5
5
TransactionReceiptFragment ,
6
- } from '@fuel-explorer/graphql' ;
6
+ } from '@fuel-explorer/graphql/src/sdk ' ;
7
7
import type { BaseProps } from '@fuels/ui' ;
8
8
import {
9
9
Address ,
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { IconGasStation } from '@tabler/icons-react';
14
14
import Link from 'next/link' ;
15
15
import { Routes } from '~/routes' ;
16
16
17
+ import { isValidAddress } from '~/systems/Core/utils/address' ;
17
18
import { TX_INTENT_MAP } from '../../../Transaction/component/TxIcon/TxIcon' ;
18
19
import type { TransactionNode } from '../../../Transaction/types' ;
19
20
@@ -29,9 +30,10 @@ export function TxCard({
29
30
...props
30
31
} : TxCardProps ) {
31
32
const fee = bn ( tx . fee ) ;
33
+ const isValidTxID = isValidAddress ( tx . id ) ;
32
34
33
35
return (
34
- < Link scroll = { true } href = { Routes . txSimple ( tx . id ) } >
36
+ < Link scroll = { true } href = { Routes . txSimple ( tx . id ) } prefetch = { isValidTxID } >
35
37
< Card { ...props } className = { cx ( className ) } >
36
38
< Card . Body className = "flex flex-col gap-4 laptop:flex-row laptop:justify-between" >
37
39
< Box className = "flex gap-3 h-[26px]" >
Original file line number Diff line number Diff line change 1
1
node_moduels
2
2
.turbo
3
3
dist
4
+ .env
Original file line number Diff line number Diff line change @@ -3,7 +3,13 @@ import type { CodegenConfig } from '@graphql-codegen/cli';
3
3
const config : CodegenConfig = {
4
4
overwrite : true ,
5
5
documents : [ './src/queries/**.graphql' ] ,
6
- schema : `http://localhost:${ process . env . SERVER_PORT } /graphql` ,
6
+ schema : {
7
+ [ `http://localhost:${ process . env . SERVER_PORT } /graphql` ] : {
8
+ headers : {
9
+ Authorization : `Bearer ${ process . env . FUEL_EXPLORER_API_KEY } ` ,
10
+ } ,
11
+ } ,
12
+ } ,
7
13
generates : {
8
14
'src/generated/types.ts' : {
9
15
plugins : [
Original file line number Diff line number Diff line change
1
+ export * from './generated/types' ;
Original file line number Diff line number Diff line change @@ -11,13 +11,24 @@ import { requireEnv } from './utils/requireEnv';
11
11
const { FUEL_PROVIDER } = requireEnv ( [
12
12
[ 'FUEL_PROVIDER' , 'https://beta-5.fuel.network/graphql' ] ,
13
13
] ) ;
14
+ const { FUEL_EXPLORER_API_KEY } = process . env ;
14
15
15
16
// Create a server:
16
17
const app = express ( ) ;
17
18
18
19
app . use ( cors < cors . CorsRequest > ( ) ) ;
19
20
app . use ( express . json ( ) ) ;
20
21
22
+ if ( FUEL_EXPLORER_API_KEY ) {
23
+ app . use ( ( req , res , next ) => {
24
+ if ( req . headers . authorization !== `Bearer ${ FUEL_EXPLORER_API_KEY } ` ) {
25
+ res . status ( 401 ) . send ( 'Unauthorized' ) ;
26
+ return ;
27
+ }
28
+ next ( ) ;
29
+ } ) ;
30
+ }
31
+
21
32
app . get (
22
33
'/graphql' ,
23
34
expressPlayground ( {
You can’t perform that action at this time.
0 commit comments