Skip to content

Commit 148eb0b

Browse files
[explorer/frontend] task: initial project (#974)
Problem: There is no frontend project for NEM Explorer. Solution: - Setup Next.js project. - Add Jenkinsfile and Dockerfile. - Add lint and test configuration. - Add styles. - Add pages: 1. Home 2. Account List. 3. Account Info. 4. Block List. 5. Block Info. 6. Mosaic List. 7. Mosaic Info. 8. Namespace List. 9. Namespace Info. 10. Transaction List. 11. Transaction Info. 12. Error 404. 13. Error 500. - Add services for API communication. - Add utils. - Add reusable UI components. - Add tests.
1 parent 73bbe33 commit 148eb0b

File tree

282 files changed

+30237
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

282 files changed

+30237
-0
lines changed

.github/buildConfiguration.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
builds:
2+
- name: Explorer Frontend
3+
path: explorer/frontend
4+
25
- name: Explorer Nodewatch
36
path: explorer/nodewatch
47

.github/codecov.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ coverage:
66
default:
77
target: 95% # overall project / repo coverage
88

9+
explorer-frontend:
10+
target: auto
11+
threshold: 1%
12+
flags:
13+
- explorer-frontend
14+
915
explorer-nodewatch:
1016
target: auto
1117
threshold: 1%
@@ -61,6 +67,11 @@ coverage:
6167
# monorepo. This allows code coverage per package.
6268

6369
flags:
70+
explorer-frontend:
71+
paths:
72+
- explorer/frontend
73+
carryforward: true
74+
6475
explorer-nodewatch:
6576
paths:
6677
- explorer/nodewatch

.github/dependabot.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ updates:
1717
- minor
1818
- patch
1919

20+
- package-ecosystem: npm
21+
directory: /explorer/frontend
22+
schedule:
23+
interval: weekly
24+
day: sunday
25+
target-branch: dev
26+
labels: [Explorer Frontend]
27+
versioning-strategy: increase-if-necessary
28+
commit-message:
29+
prefix: '[dependency]'
30+
groups:
31+
explorer-frontend-dependencies:
32+
patterns:
33+
- '*'
34+
update-types:
35+
- minor
36+
- patch
37+
2038
- package-ecosystem: pip
2139
directory: /explorer/nodewatch
2240
schedule:

explorer/frontend/.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
3+
/build

explorer/frontend/.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
build/
3+
coverage/
4+
setupTests.js

explorer/frontend/.eslintrc.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
extends:
2+
- ../../_symbol/linters/javascript/default.eslintrc
3+
- eslint-config-next
4+
- plugin:import/react
5+
6+
rules:
7+
import/extensions:
8+
- error
9+
- always
10+
- json: always
11+
js: never
12+
jsx: never
13+
yoda: off
14+
15+
settings:
16+
import/resolver:
17+
jsconfig:
18+
config: jsconfig.json
19+
20+
globals:
21+
$t: false

explorer/frontend/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
# dependencies
3+
node_modules/
4+
5+
# testing
6+
coverage/
7+
8+
# production
9+
build/
10+
.next/
11+
12+
# sqlite3 database
13+
data/
14+
15+
# misc
16+
.DS_Store
17+
.env
18+
.env.local
19+
.env.development.local
20+
.env.test.local
21+
.env.production.local
22+
23+
npm-debug.log*

explorer/frontend/.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
build/
3+
coverage/
4+
setupTests.js

explorer/frontend/.prettierrc.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
bracketSpacing: true
2+
jsxBracketSameLine: false
3+
singleQuote: true
4+
trailingComma: none
5+
tabWidth: 4
6+
useTabs: true
7+
arrowParens: avoid
8+
semi: true
9+
printWidth: 140

explorer/frontend/.stylelintrc.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extends:
2+
- stylelint-config-standard-scss
3+
- stylelint-config-rational-order
4+
5+
plugins:
6+
- stylelint-order
7+
8+
rules:
9+
font-family-no-missing-generic-family-keyword: null
10+
font-family-name-quotes: always-unless-keyword
11+
color-function-notation: legacy
12+
selector-class-pattern: '([a-z]+([A-Z][a-z0-9]+)*)'
13+
selector-id-pattern: '([a-z]+([A-Z][a-z0-9]+)*)'

explorer/frontend/Dockerfile

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM node:lts-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
# Install dependencies using npm
10+
COPY package.json package-lock.json* ./
11+
RUN npm install
12+
13+
# Rebuild the source code only when needed
14+
FROM base AS builder
15+
WORKDIR /app
16+
COPY --from=deps /app/node_modules ./node_modules
17+
COPY . .
18+
19+
ENV NEXT_TELEMETRY_DISABLED 1
20+
21+
RUN npm run build
22+
23+
# Production image, copy all the files and run next
24+
FROM base AS runner
25+
WORKDIR /app
26+
27+
ENV NODE_ENV production
28+
ENV NEXT_TELEMETRY_DISABLED 1
29+
30+
RUN addgroup --system --gid 1001 nodejs
31+
RUN adduser --system --uid 1001 nextjs
32+
33+
COPY --from=builder /app/public ./public
34+
35+
# Set the correct permission for prerender cache
36+
RUN mkdir .next
37+
RUN chown nextjs:nodejs .next
38+
39+
# Automatically leverage output traces to reduce image size
40+
# https://nextjs.org/docs/advanced-features/output-file-tracing
41+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
42+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
43+
44+
USER nextjs
45+
46+
EXPOSE 3000
47+
48+
ENV PORT 3000
49+
50+
# server.js is created by next build from the standalone output
51+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
52+
CMD HOSTNAME="0.0.0.0" node server.js

explorer/frontend/Jenkinsfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defaultCiPipeline {
2+
operatingSystem = ['ubuntu']
3+
instanceSize = 'medium'
4+
5+
environment = 'javascript'
6+
7+
packageId = 'explorer-frontend'
8+
9+
publisher = 'docker'
10+
dockerImageName = 'symbolplatform/explorer-frontend'
11+
12+
codeCoverageTool = 'c8'
13+
minimumCodeCoverage = 95
14+
}

explorer/frontend/README.md

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# NEM Block Explorer
2+
3+
This project is a NEM blockchain explorer built using the Next.js framework. It provides a user-friendly interface to explore and interact with the NEM blockchain, including features such as transaction searches, block exploration, and statistic data visualization.
4+
5+
## Folder Structure
6+
7+
- **api/**: Contains modules for making requests to APIs to fetch data.
8+
- **components/**: Contains reusable UI components.
9+
- **config/**: Contains app configuration and reexports environment variables.
10+
- **constants/**: Contains constants used across the app.
11+
- **pages/**: Contains the pages of the application.
12+
- **public/**: Contains static files.
13+
- **scripts/**: Contains CI scripts.
14+
- **styles/**: Contains stylesheets.
15+
- **utils/**: Contains commonly used functions.
16+
- **.env**: Contains environment variables.
17+
18+
## Environment Variables
19+
20+
- `NEXT_PUBLIC_NATIVE_MOSAIC_ID`: Native mosaic ID
21+
- `NEXT_PUBLIC_NATIVE_MOSAIC_TICKER`: Native mosaic ticker
22+
- `NEXT_PUBLIC_NATIVE_MOSAIC_DIVISIBILITY`: Native mosaic divisibility
23+
- `NEXT_PUBLIC_BLOCKCHAIN_UNWIND_LIMIT`: Blockchain unwind limit
24+
- `NEXT_PUBLIC_REQUEST_TIMEOUT`: Request timeout
25+
- `NEXT_PUBLIC_API_BASE_URL`: Explorer REST API endpoint
26+
- `NEXT_PUBLIC_SUPERNODE_STATS_URL`: Supernodes statistics endpoint
27+
- `NEXT_PUBLIC_NODELIST_URL`: Node list endpoint
28+
- `NEXT_PUBLIC_MARKET_DATA_URL`: Market data endpoint
29+
- `NEXT_PUBLIC_HISTORICAL_PRICE_URL`: Historical coin price endpoint
30+
31+
## Requirements
32+
33+
- Node.js v20.11.0
34+
35+
## Installation
36+
37+
This project is part of a Product monorepo. Follow the steps below to set up and run the project.
38+
39+
1. Clone the repository from GitHub:
40+
```bash
41+
git clone https://github.com/symbol/product.git
42+
```
43+
44+
2. Initialize:
45+
```bash
46+
bash init.sh
47+
```
48+
49+
3. Navigate to the project folder:
50+
```bash
51+
cd explorer/frontend
52+
```
53+
54+
4. Install Node.js dependencies:
55+
```bash
56+
npm install
57+
```
58+
59+
5. Setup environment variables (or create `.env` file in `frontend/` root directory).
60+
61+
## Building the Project
62+
63+
To build the project, run:
64+
```bash
65+
npm run build
66+
```
67+
68+
## Running the Project
69+
70+
To run the built project, use:
71+
```bash
72+
npm run start
73+
```
74+
75+
## Development Server
76+
77+
To run the development server, use:
78+
```bash
79+
npm run dev
80+
```
81+
82+
## Running Tests
83+
84+
To run tests, use:
85+
```bash
86+
npm run test
87+
```
88+
89+
## Linting
90+
91+
To run lint checks, use:
92+
```bash
93+
npm run lint
94+
```
95+
96+
To fix lint issues, use:
97+
```bash
98+
npm run lint:fix
99+
```
100+
101+
## Building the Docker Image
102+
103+
1. Make sure you are in the explorer/frontend directory.
104+
105+
2. Build the Docker image:
106+
```bash
107+
docker build -t symbolplatform/explorer-frontend .
108+
```
109+
110+
## Running the Docker Container
111+
112+
Run the Docker container:
113+
```bash
114+
docker run -p 3000:3000 symbolplatform/explorer-frontend
115+
```
116+
117+
This command will start the container and expose the application on port 3000.

explorer/frontend/__mocks__/axios.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import mockAxios from 'jest-mock-axios';
2+
export default mockAxios;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const makeBlockie = address => `image-${address}`;
2+
export default makeBlockie;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const useTranslation = () => ({
2+
t: key => key
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const useTranslation = () => ({
2+
t: key => key
3+
});
4+
5+
export const serverSideTranslations = () => Promise.resolve({});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const ReactApexChart = () => <div id="mocked-react-apexcharts">Mocked React ApexCharts</div>;
2+
export default ReactApexChart;

0 commit comments

Comments
 (0)