Skip to content

Commit

Permalink
show a warning on the wallet page if something is not loading (#99)
Browse files Browse the repository at this point in the history
* show a warning on the wallet page if something is not loading

Signed-off-by: Mirko Mollik <[email protected]>

* provide all errors in one file

Signed-off-by: Mirko Mollik <[email protected]>

---------

Signed-off-by: Mirko Mollik <[email protected]>
  • Loading branch information
cre8 authored Oct 7, 2024
1 parent 2a301f6 commit b7d9946
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
21 changes: 19 additions & 2 deletions viewer/scripts/link-checker.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// this script checks if all the links in the json files are still reachable
import { readdirSync, readFileSync, writeFileSync, mkdirSync, existsSync, rmSync } from 'fs';
import axios from 'axios';
import { join, dirname } from 'path';
import { join, dirname, basename, extname } from 'path';

let counter = 0;
let validFiles = 0;
let invalidFiles = 0;
const errorLog = {};
const consolidatedErrors = {};

async function isLinkReachable(url, filePath, jsonPath) {
try {
Expand All @@ -27,6 +28,18 @@ async function isLinkReachable(url, filePath, jsonPath) {
errorLog[filePath] = {};
}
errorLog[filePath][jsonPath] = url;

// Add to consolidated errors
const folderName = filePath.split('/')[1];
const fileNameWithoutExt = basename(filePath, extname(filePath));
if (!consolidatedErrors[folderName]) {
consolidatedErrors[folderName] = {};
}
if (!consolidatedErrors[folderName][fileNameWithoutExt]) {
consolidatedErrors[folderName][fileNameWithoutExt] = {};
}
consolidatedErrors[folderName][fileNameWithoutExt][jsonPath] = url;

return false;
}
}
Expand Down Expand Up @@ -60,7 +73,7 @@ async function checkLinksInObject(obj, filePath, currentPath = '') {
}

async function validateFolder(folder) {
if(!existsSync(folder)) {
if (!existsSync(folder)) {
return;
}
const files = readdirSync(folder);
Expand Down Expand Up @@ -104,6 +117,7 @@ const folders = ['case-studies', 'wallets', 'dependencies'];
}

console.log('\nError Log:');
console.log(errorLog);
for (const [filePath, errors] of Object.entries(errorLog)) {
const relativePath = filePath.replace('../', '');
const errorFilePath = join(errorsDir, relativePath);
Expand All @@ -114,4 +128,7 @@ const folders = ['case-studies', 'wallets', 'dependencies'];
}
writeFileSync(errorFilePath, JSON.stringify(errors, null, 2));
}

// Write all errors to a single errors.json file
writeFileSync(join(errorsDir, 'errors.json'), JSON.stringify(consolidatedErrors, null, 2));
})();
10 changes: 8 additions & 2 deletions viewer/src/app/wallets/wallets-show/wallets-show.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ <h1>{{ wallet.name }}</h1>
Share
</button>
</div>
@if(invalid) {
<div fxLayout="row" fxLayoutGap="16px" fxLayoutAlign="start center">
<mat-icon>warning</mat-icon>
<p>Entry is not valid: {{ invalid }}</p>
</div>
}
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="16px">
<a
*ngIf="wallet.urlGooglePlayStore"
Expand Down Expand Up @@ -69,7 +75,7 @@ <h1>{{ wallet.name }}</h1>
<mat-list>
<mat-list-item [matTooltip]="walletsService.getTooltip('type')">
<div matListItemTitle><b>Type</b></div>
<span matListItemLine>{{ wallet.type }}</span>
<span matListItemLine>{{ wallet.type ?? 'unknown' }}</span>
</mat-list-item>
<mat-list-item [matTooltip]="walletsService.getTooltip('capability')">
<div matListItemTitle><b>Capabilities</b></div>
Expand All @@ -84,7 +90,7 @@ <h1>{{ wallet.name }}</h1>
<mat-list-item [matTooltip]="walletsService.getTooltip('openSource')">
<div matListItemTitle><b>Open Source</b></div>
@if(!wallet.downloadSource) {
<span matListItemLine>{{ wallet.openSource }} </span>
<span matListItemLine>{{ wallet.openSource ?? 'unknown' }} </span>
} @else {
<a matListItemLine [href]="wallet.downloadSource">{{
wallet.downloadSource
Expand Down
2 changes: 2 additions & 0 deletions viewer/src/app/wallets/wallets-show/wallets-show.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class WalletsShowComponent implements OnInit, OnDestroy {
wallet?: Wallet;
logoError = true;
private routerSubscription?: Subscription;
invalid?: string;

constructor(
public walletsService: WalletsService,
Expand Down Expand Up @@ -76,6 +77,7 @@ export class WalletsShowComponent implements OnInit, OnDestroy {
.navigate(['/'])
.then(() => this.snachBar.open(`${id} not found`));
}
this.invalid = await this.walletsService.validEntry(id);
}

getSupport(value?: string) {
Expand Down
18 changes: 18 additions & 0 deletions viewer/src/app/wallets/wallets.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,22 @@ export class WalletsService {
if (url.startsWith('http')) return url;
return `assets/${url}`;
}

/**
* It will check the error branch of the repo where the error messages are located.
* @param id name of the wallet
*/
validEntry(id: string) {
return firstValueFrom(
this.httpClient.get<Record<string, string>>(
`https://raw.githubusercontent.com/openwallet-foundation/digital-wallet-and-agent-overviews-sig/refs/heads/errors/wallets/${id}.json`
)
)
.then((res) =>
Object.keys(res)
.map((key) => `${key}: ${res[key]}`)
.join(', ')
)
.catch(() => undefined);
}
}

0 comments on commit b7d9946

Please sign in to comment.