Skip to content

Commit 8a4ea3e

Browse files
committed
Frontend - Firebase Caching
1 parent bc9b025 commit 8a4ea3e

24 files changed

+418
-117
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ nvm install 20.11.1
191191

192192
Download [Node.js v20.11.1](https://nodejs.org/) from the official website, open the installer and follow the prompts to complete the installation.
193193

194-
### 2. Angular CLI v16.2.0
194+
### 2. Angular CLI v17.3.0
195195

196196
```bash
197-
npm install -g @angular/cli@16.2.0
197+
npm install -g @angular/cli@17.3.0
198198
```
199199

200200
### 3. Installation

frontend/firebase.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
"value": "require-corp"
3535
}
3636
]
37+
},
38+
{
39+
"source": "**/*.@(js|wasm|html)",
40+
"headers": [
41+
{
42+
"key": "Cache-Control",
43+
"value": "no-cache, no-store, must-revalidate"
44+
}
45+
]
46+
},
47+
{
48+
"source": "/",
49+
"headers": [
50+
{
51+
"key": "Cache-Control",
52+
"value": "no-cache, no-store, must-revalidate"
53+
}
54+
]
3755
}
3856
]
3957
}

frontend/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "frontend",
3-
"version": "0.8.20",
3+
"version": "1.0.16",
44
"scripts": {
55
"install:deps": "npm install",
66
"start": "npm install && ng serve --configuration local --open",
@@ -12,14 +12,14 @@
1212
"tests:headless": "npx cypress run --headless --config baseUrl=http://localhost:4200",
1313
"docker": "npm run build:prod && docker buildx build --platform linux/amd64 -t openmina/frontend:latest . && docker push openmina/frontend:latest",
1414
"start:bundle": "npx http-server dist/frontend -p 4200",
15-
"prebuild": "node scripts/update-webnode-version.js",
15+
"prebuild": "node scripts/update-frontend-version.js",
1616
"dev:ssr": "ng run frontend:serve-ssr",
1717
"serve:ssr": "node dist/frontend/server/main.js",
1818
"build:ssr": "ng build && ng run frontend:server",
1919
"prerender": "ng run frontend:prerender",
2020
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org openmina-uv --project openmina ./dist/frontend/browser && sentry-cli sourcemaps upload --org openmina-uv --project openmina ./dist/frontend/browser",
2121
"copy-env": "cp dist/frontend/browser/assets/environments/webnode.js dist/frontend/browser/assets/environments/env.js",
22-
"deploy": "npm run build:prod && npm run copy-env && firebase deploy"
22+
"deploy": "npm run prebuild && npm run build:prod && npm run copy-env && firebase deploy"
2323
},
2424
"private": true,
2525
"dependencies": {
@@ -86,4 +86,4 @@
8686
"webpack": "^5.88.2",
8787
"webpack-bundle-analyzer": "^4.9.0"
8888
}
89-
}
89+
}

frontend/scripts/download-webnode.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ download_circuit_files() {
3636
"wrap-wrap-proving-key-transaction-snark-b9a01295c8cc9bda6d12142a581cd305_internal_vars.bin"
3737
"wrap-wrap-proving-key-transaction-snark-b9a01295c8cc9bda6d12142a581cd305_rows_rev.bin"
3838
)
39-
DOWNLOAD_DIR="/Users/teofil/teo/mina/openmina/frontend/dist/frontend/browser/assets/webnode/circuit-blobs/$CIRCUITS_VERSION"
39+
DOWNLOAD_DIR="../src/assets/webnode/circuit-blobs/$CIRCUITS_VERSION"
4040

4141
mkdir -p "$DOWNLOAD_DIR"
4242

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {readFileSync, writeFileSync} from 'fs';
2+
import {platform, release} from 'os';
3+
4+
console.log('⏳ Updating Deployment Info...');
5+
6+
const packageJsonPath = './package.json';
7+
const packageJson = readFileSync(packageJsonPath, 'utf8');
8+
const packageJsonObj = JSON.parse(packageJson);
9+
const version = packageJsonObj.version.split('.');
10+
const newVersion = `${version[0]}.${version[1]}.${parseInt(version[2]) + 1}`;
11+
packageJsonObj.version = newVersion;
12+
writeFileSync(packageJsonPath, JSON.stringify(packageJsonObj, null, 2));
13+
14+
const publicIp = await getPublicIpAddress();
15+
const deploymentInfo = {
16+
dateUTC: new Date().toISOString(),
17+
deviceIp: publicIp,
18+
deviceOS: formatOS(platform()),
19+
deviceOSVersion: release(),
20+
version: newVersion,
21+
};
22+
23+
const newDeploymentScript = `
24+
const deployment = {
25+
dateUTC: '${deploymentInfo.dateUTC}',
26+
deviceIp: '${deploymentInfo.deviceIp}',
27+
deviceOS: '${deploymentInfo.deviceOS}',
28+
deviceOSVersion: '${deploymentInfo.deviceOSVersion}',
29+
version: '${deploymentInfo.version}',
30+
};
31+
window.deployment = deployment;
32+
`;
33+
const deploymentScriptPattern = /const deployment = \{[\s\S]*?\};[\s\S]*?window\.deployment = deployment;/;
34+
35+
// Read and update index.html
36+
const indexPath = './src/index.html';
37+
let indexHtml = readFileSync(indexPath, 'utf8');
38+
indexHtml = indexHtml.replace(deploymentScriptPattern, newDeploymentScript.trim());
39+
40+
writeFileSync(indexPath, indexHtml);
41+
42+
console.log('✅ Updated Deployment Info!');
43+
44+
async function getPublicIpAddress() {
45+
const response = await fetch('https://api.ipify.org/');
46+
return await response.text();
47+
}
48+
49+
function formatOS(platform) {
50+
const osMap = {
51+
'darwin': 'macOS',
52+
'win32': 'Windows',
53+
'linux': 'Linux',
54+
};
55+
return osMap[platform] || platform;
56+
}

frontend/scripts/update-webnode-version.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

frontend/src/app/app.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
2-
import { any, getMergedRoute, getWindow, MAX_WIDTH_700, MergedRoute, safelyExecuteInBrowser } from '@openmina/shared';
2+
import { any, getMergedRoute, getWindow, isBrowser, MAX_WIDTH_700, MergedRoute, safelyExecuteInBrowser } from '@openmina/shared';
33
import { AppMenu } from '@shared/types/app/app-menu.type';
44
import { BreakpointObserver, BreakpointState } from '@angular/cdk/layout';
55
import { AppSelectors } from '@app/app.state';
@@ -38,14 +38,16 @@ export class AppComponent extends StoreDispatcher implements OnInit {
3838
any(window).config = CONFIG;
3939
any(window).store = this.store;
4040
}
41-
})
41+
});
4242
}
4343

4444
ngOnInit(): void {
45-
const args = new URLSearchParams(window.location.search).get("a");
46-
if (!!args) {
47-
window.localStorage.setItem("webnodeArgs", args);
48-
}
45+
if (isBrowser()) {
46+
const args = new URLSearchParams(window.location.search).get('a');
47+
if (!!args) {
48+
localStorage.setItem('webnodeArgs', args);
49+
}
50+
}
4951

5052
this.select(
5153
getMergedRoute,

frontend/src/app/app.effects.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export class AppEffects extends BaseEffect {
101101
upload: 0,
102102
transactions: 0,
103103
snarks: 0,
104+
producingBlockAt: null,
105+
producingBlockGlobalSlot: null,
106+
producingBlockStatus: null,
104107
},
105108
})),
106109
));

frontend/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { Router } from '@angular/router';
3939
import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
4040
import { getAnalytics, provideAnalytics, ScreenTrackingService } from '@angular/fire/analytics';
4141
import { getPerformance, providePerformance } from '@angular/fire/performance';
42+
import { BlockProductionPillComponent } from '@app/layout/block-production-pill/block-production-pill.component';
4243

4344
registerLocaleData(localeFr, 'fr');
4445
registerLocaleData(localeEn, 'en');
@@ -159,6 +160,7 @@ export class AppGlobalErrorhandler implements ErrorHandler {
159160
ReactiveFormsModule,
160161
CopyComponent,
161162
WebNodeLandingPageComponent,
163+
BlockProductionPillComponent,
162164
],
163165
providers: [
164166
THEME_PROVIDER,

frontend/src/app/app.reducer.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const initialState: AppState = {
2222
upload: 0,
2323
transactions: 0,
2424
snarks: 0,
25+
producingBlockAt: null,
26+
producingBlockGlobalSlot: null,
27+
producingBlockStatus: null,
2528
},
2629
};
2730

0 commit comments

Comments
 (0)