Skip to content

Commit

Permalink
Merge pull request #2494 from aura-nw/baseline/main_20231009
Browse files Browse the repository at this point in the history
Baseline/main 20231009
  • Loading branch information
nhphuc2411 authored Oct 10, 2023
2 parents 63a4c58 + 86d3ef7 commit 4b9dfc3
Show file tree
Hide file tree
Showing 157 changed files with 3,331 additions and 2,667 deletions.
4 changes: 2 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"production": {
"budgets": [{
"type": "initial",
"maximumWarning": "10mb",
"maximumError": "10mb"
"maximumWarning": "15mb",
"maximumError": "15mb"
},
{
"type": "anyComponentStyle",
Expand Down
65 changes: 59 additions & 6 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,40 @@ import { getInfo } from './core/utils/common/info-common';
import { Globals } from './global/global';
// import eruda from 'eruda';
import { EnvironmentService } from 'src/app/core/data-services/environment.service';
import { forkJoin } from 'rxjs';
import { NameTagService } from './core/services/name-tag.service';
import * as _ from 'lodash';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
// chainInfo = this.env.configValue.chain_info;
// TESTNET = ['aura-testnet-2', 'serenity-testnet-001'];
// isTestnet = this.TESTNET.includes(
// this.chainInfo?.chainId || ''
// );
constructor(
private commonService: CommonService,
private globals: Globals,
private tokenService: TokenService, // private env: EnvironmentService
private tokenService: TokenService,
private nameTagService: NameTagService,
) {}
ngOnInit(): void {
this.getListNameTag();
this.getInfoCommon();
this.getPriceToken();

setInterval(() => {
this.getListNameTag();
this.getInfoCommon();
this.getPriceToken();
}, 60000);

setInterval(() => {
this.getListNameTag();
}, 20000);

// if (this.isTestnet) {
// let el = document.createElement('div');
// document.body.appendChild(el);
Expand Down Expand Up @@ -61,13 +67,60 @@ export class AppComponent implements OnInit {
});
}

getListNameTag(): void {
async getListNameTag() {
const payload = {
limit: 500,
nextKey: 0,
};
this.commonService.getListNameTag(payload).subscribe((res) => {
this.globals.listNameTag = this.commonService.listNameTag = res.data?.nameTags;

const payloadPrivate = {
limit: 100,
offset: 0,
keyword: null,
};

// get list name tag if not login email
const userEmail = localStorage.getItem('userEmail');
if (!userEmail) {
await this.commonService.getListNameTag(payload).subscribe((res) => {
this.globals.listNameTag = this.commonService.listNameTag = res.data?.nameTags;
});
return;
}

// get list name tag if login email
forkJoin({
publicName: this.commonService.getListNameTag(payload),
privateName: this.nameTagService.getListPrivateNameTag(payloadPrivate),
}).subscribe(({ publicName, privateName }) => {
let listTemp = publicName.data?.nameTags?.map((element) => {
const address = _.get(element, 'address');
let name_tag = _.get(element, 'name_tag');
let isPrivate = false;
let name_tag_private = null;
let id;
const enterpriseUrl = _.get(element, 'enterpriseUrl');
let privateData = privateName?.data?.find((k) => k.address === address);
if (privateData) {
name_tag_private = privateData.nameTag;
isPrivate = true;
id = privateData.id;
}
return { address, name_tag, isPrivate, enterpriseUrl, name_tag_private, id};
});

// get other data of private list
const isSameUser = (listTemp, privateName) => listTemp?.address === privateName.address;
const onlyInLeft = (left, right, compareFunction) =>
left.filter((leftValue) => !right.some((rightValue) => compareFunction(leftValue, rightValue)));
const lstPrivate = onlyInLeft(privateName?.data, listTemp, isSameUser);
lstPrivate.forEach((element) => {
element['name_tag_private'] = element.nameTag;
element['nameTag'] = null;
element['isPrivate'] = true;
});
const result = [...listTemp, ...lstPrivate];
this.globals.listNameTag = this.commonService.listNameTag = result;
});
}
}
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import { Globals } from './global/global';
import { LayoutsModule } from './layouts/layouts.module';
import { SchemaViewerModule } from './pages/schema-viewer/schema-viewer.module';
import { MediaExpandModule } from './shared/components/media-expand/media-expand.module';
import { NameTagService } from './core/services/name-tag.service';
import { UserService } from './core/services/user.service';

export function createTranslateLoader(http: HttpClient): any {
return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
Expand Down Expand Up @@ -174,6 +176,8 @@ export class MaterialModule {}
FeeGrantService,
SoulboundService,
MappingErrorService,
NameTagService,
UserService,
{
provide: DateAdapter,
useClass: MomentDateAdapter,
Expand Down
9 changes: 6 additions & 3 deletions src/app/core/constants/common.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ export const CHART_RANGE = {
export const LENGTH_CHARACTER = {
ADDRESS: 43,
CONTRACT: 63,
TRANSACTION: 64
TRANSACTION: 64,
};

export const NULL_ADDRESS = 'Null address';

export const TOKEN_ID_GET_PRICE = {
AURA: 'aura-network',
BTC: 'bitcoin'
BTC: 'bitcoin',
};

export enum MEDIA_TYPE {
IMG = 'img',
VIDEO = 'video',
_3D = '3d',
AUDIO = 'audio',
}
}

export const CW20_TRACKING = ['mint', 'burn', 'transfer', 'send', 'transfer_from', 'burn_from', 'send_from'];
export const CW721_TRACKING = ['mint', 'burn', 'transfer_nft', 'send_nft'];
8 changes: 4 additions & 4 deletions src/app/core/constants/contract.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const CONTRACT_TABLE_TEMPLATES: Array<TableTemplate> = [
{ matColumnDef: 'txHash', headerCellDef: 'Txn Hash', type: 'hash-url', headerWidth: 12, isUrl: '/transaction' },
{ matColumnDef: 'method', headerCellDef: 'Method', type: 'status', headerWidth: 12 },
{ matColumnDef: 'status', headerCellDef: 'Result', type: 'result', headerWidth: 9 },
{ matColumnDef: 'blockHeight', headerCellDef: 'Block', type: 'hash-url', headerWidth: 6, isUrl: '/blocks' },
{ matColumnDef: 'time', headerCellDef: 'Time', type: 'time-distance', headerWidth: 8, suffix: 'ago' },
{ matColumnDef: 'from', headerCellDef: 'From', type: 'hash-url', headerWidth: 12, isUrl: '/account', isNameTag: true },
{ matColumnDef: 'label', headerCellDef: '', type: 'type', headerWidth: 6, justify: 'center' },
{ matColumnDef: 'to', headerCellDef: 'To', type: 'hash-url', headerWidth: 12, isUrl: '/contracts', isNameTag: true },
{ matColumnDef: 'blockHeight', headerCellDef: 'Block', type: 'hash-url', headerWidth: 6, isUrl: '/blocks' },
{ matColumnDef: 'from', headerCellDef: 'Message Sender', type: 'hash-url', headerWidth: 12, isUrl: '/account', isNameTag: true },
// { matColumnDef: 'label', headerCellDef: '', type: 'type', headerWidth: 6, justify: 'center' },
// { matColumnDef: 'to', headerCellDef: 'To', type: 'hash-url', headerWidth: 12, isUrl: '/contracts', isNameTag: true },
{ matColumnDef: 'fee', headerCellDef: 'Txn Fee', type: 'numb', headerWidth: 10 },
];

Expand Down
7 changes: 5 additions & 2 deletions src/app/core/data-services/environment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IConfiguration {
horoscopePathApi: string;
notice: { content: string; url: string };
googleClientId: string;
quotaSetPrivateName: number;
}

@Injectable()
Expand All @@ -50,7 +51,8 @@ export class EnvironmentService {
horoscopePathGraphql: '',
horoscopePathApi: '',
notice: { content: '', url: '' },
googleClientId: ''
googleClientId: '',
quotaSetPrivateName: null
});

get configValue(): IConfiguration {
Expand Down Expand Up @@ -88,7 +90,8 @@ export class EnvironmentService {
horoscopePathGraphql: config['horoscopePathGraphql'],
horoscopePathApi: config['horoscopePathApi'],
notice: config['notice'] || { content: '', url: '' },
googleClientId: config['googleClientId'] || '3465782004-hp7u6vlitgs109rl0emrsf1oc7bjvu08.apps.googleusercontent.com'
googleClientId: config['googleClientId'] || '3465782004-hp7u6vlitgs109rl0emrsf1oc7bjvu08.apps.googleusercontent.com',
quotaSetPrivateName: config['quotaSetPrivateName'] || 10
};

this.config.next(data);
Expand Down
60 changes: 46 additions & 14 deletions src/app/core/helpers/error.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { AuthenticationService } from '../services/auth.service';
import { UserService } from '../services/user.service';
import { Router } from '@angular/router';

@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
constructor(private userService: UserService, private router: Router) {}

constructor(private authenticationService: AuthenticationService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(
catchError((err) => {
// check status unauthorized, refresh token
if (err?.error?.statusCode === 401 && err?.error?.message == 'Unauthorized') {
const payload = {
refreshToken: localStorage.getItem('refreshToken').replace(/"/g, ''),
};
this.userService.refreshToken(payload).subscribe({
next: (res) => {
if (res.error?.statusCode === 400) {
// redirect to log out
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
localStorage.removeItem('userEmail');
this.router.navigate(['/login']);

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(request).pipe(catchError(err => {
if (err.status === 401) {
// auto logout if 401 response returned from api
// location.reload();
}
const error = err.error || err.statusText;
return throwError(error);
}))
}
}
setTimeout(() => {
location.reload();
}, 500);
}

localStorage.setItem('accessToken', JSON.stringify(res.accessToken));
localStorage.setItem('refreshToken', JSON.stringify(res.refreshToken));
},
error: () => {
localStorage.removeItem('accessToken');
localStorage.removeItem('refreshToken');
localStorage.removeItem('userEmail');
this.router.navigate(['/login']);

setTimeout(() => {
location.reload();
}, 500);
},
});
}
const error = err.error || err.statusText;
return throwError(error);
}),
);
}
}
Loading

0 comments on commit 4b9dfc3

Please sign in to comment.