Skip to content

Commit

Permalink
Merge pull request #3073 from aura-nw/baseline/main_20240305
Browse files Browse the repository at this point in the history
Baseline/main 20240305
  • Loading branch information
nhphuc2411 authored Mar 6, 2024
2 parents c89962a + 1fb5bcc commit 1e7d423
Show file tree
Hide file tree
Showing 222 changed files with 8,249 additions and 3,566 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine as build-stage
FROM node:18-alpine as build-stage
RUN mkdir -p /data/app
WORKDIR /data/app
COPY . /data/app
Expand Down
3,377 changes: 3,040 additions & 337 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@
"@angular/platform-browser": "^16.2.8",
"@angular/platform-browser-dynamic": "^16.2.8",
"@angular/router": "^16.2.8",
"@coin98-com/connect-sdk": "^1.1.0",
"@cosmjs/cosmwasm-stargate": "^0.31.1",
"@cosmjs/stargate": "^0.31.1",
"@cosmjs/cosmwasm-stargate": "^0.31.2",
"@cosmjs/math": "^0.32.2",
"@cosmjs/stargate": "^0.31.2",
"@cosmos-kit/coin98": "^2.6.6",
"@cosmos-kit/core": "^2.8.6",
"@cosmos-kit/keplr": "^2.6.6",
"@cosmos-kit/leap": "^2.6.6",
"@cosmos-kit/leap-metamask-cosmos-snap": "^0.5.7",
"@cosmos-kit/walletconnect": "^2.5.6",
"@google/model-viewer": "^1.12.0",
"@ng-bootstrap/ng-bootstrap": "^15.1.1",
"@ngx-translate/core": "^15.0.0",
Expand All @@ -39,8 +45,12 @@
"bech32": "^2.0.0",
"bignumber.js": "^9.0.2",
"bootstrap": "~5.1.1",
"buffer": "^6.0.3",
"chain-registry": "^1.25.4",
"cosmjs-types": "^0.9.0",
"crypto-browserify": "^3.12.0",
"date-fns": "^2.28.0",
"eruda": "^3.0.1",
"export-xlsx": "^0.1.4",
"file-saver": "^2.0.5",
"firebase": "^10.5.2",
Expand All @@ -63,25 +73,30 @@
"ngx-toastr": "^17.0.2",
"path": "^0.12.7",
"phosphor-icons": "^1.4.2",
"process": "^0.11.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "~7.8.1",
"socket.io-client": "^4.5.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tslib": "^2.1.0",
"url": "^0.11.3",
"util": "^0.12.4",
"uuid": "^9.0.1",
"zone.js": "~0.13.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.2.5",
"@angular/cli": "^16.2.5",
"@angular/compiler-cli": "^16.2.8",
"@angular/localize": "^16.2.8",
"@keplr-wallet/types": "^0.12.29",
"@types/google-one-tap": "^1.2.3",
"@types/google.accounts": "0.0.7",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.20.55",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"jasmine-core": "^3.8.0",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
Expand Down
42 changes: 15 additions & 27 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { STORAGE_KEYS, TOKEN_ID_GET_PRICE } from './core/constants/common.constant';
import { STORAGE_KEYS } from './core/constants/common.constant';
import { CommonService } from './core/services/common.service';
import { TokenService } from './core/services/token.service';
import { getInfo } from './core/utils/common/info-common';
import { Globals } from './global/global';
// import eruda from 'eruda';
import eruda from 'eruda';
import * as _ from 'lodash';
import { forkJoin, map, Subject, takeUntil } from 'rxjs';
import { NameTagService } from './core/services/name-tag.service';
Expand All @@ -24,10 +24,8 @@ import BigNumber from 'bignumber.js';
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit, OnDestroy {
// TESTNET = ['aura-testnet-2', 'serenity-testnet-001'];
// isTestnet = this.TESTNET.includes(
// this.chainInfo?.chainId || ''
// );
TESTNET = ['aura-testnet-2', 'serenity-testnet-001'];
isTestnet = this.TESTNET.includes(this.environmentService.chainInfo?.chainId || '');
isFirstLoad = true;
user: IUser;

Expand Down Expand Up @@ -84,15 +82,15 @@ export class AppComponent implements OnInit, OnDestroy {
this.tokenService.getCoinData();
}, 600000);

// if (this.isTestnet) {
// let el = document.createElement('div');
// document.body.appendChild(el);
//
// eruda.init({
// container: el,
// tool: ['console', 'elements', 'resources', 'network'],
// });
// }
if (this.isTestnet) {
let el = document.createElement('div');
document.body.appendChild(el);

eruda.init({
container: el,
tool: ['console', 'elements', 'resources', 'network'],
});
}
}

getInfoCommon(): void {
Expand Down Expand Up @@ -228,17 +226,7 @@ export class AppComponent implements OnInit, OnDestroy {

async getDataNative(nativeData) {
const tempTotal = await this.ibcService.getTotalSupplyLCD(this.coinMinimalDenom).catch(() => '0');
let totalSupply = BigNumber(_.get(tempTotal, 'data.amount.amount') || '0');

this.tokenService
.getListAmountNative(this.excludedAddresses)
.pipe(takeUntil(this.destroyed$))
.subscribe((res) => {
res?.data?.forEach((item) => {
totalSupply = totalSupply.minus(BigNumber(_.get(item, 'amount')));
});
nativeData['totalSupply'] = totalSupply.toFixed();
local.setItem(STORAGE_KEYS.DATA_NATIVE, nativeData);
});
nativeData['totalSupply'] = BigNumber(_.get(tempTotal, 'data.amount.amount') || '0').toFixed();
local.setItem(STORAGE_KEYS.DATA_NATIVE, nativeData);
}
}
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ 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 { NgHttpCachingLocalStorage, NgHttpCachingModule, NgHttpCachingStrategy } from 'ng-http-caching';
import { CommonDirectiveModule } from './core/directives/common-directive.module';
import { ChainInfoInterceptor } from './core/helpers/chain-info.interceptor';
initializeApp(environment.firebaseConfig);

Expand All @@ -48,6 +49,7 @@ initializeApp(environment.firebaseConfig);
FormsModule,
MediaExpandModule,
SchemaViewerModule,
CommonDirectiveModule,
NgHttpCachingModule.forRoot({
cacheStrategy: NgHttpCachingStrategy.DISALLOW_ALL,
lifetime: 1000 * 60 * 5, // 5 minutes,
Expand Down
11 changes: 9 additions & 2 deletions src/app/core/constants/contract.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ export const MAX_LENGTH_SEARCH_CONTRACT = 200;

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: 'method', headerCellDef: 'Method', type: 'status', headerWidth: 15 },
{ matColumnDef: 'status', headerCellDef: 'Result', type: 'result', headerWidth: 9 },
{ matColumnDef: 'time', headerCellDef: 'Time', type: 'time-distance', headerWidth: 8, suffix: 'ago' },
{ 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: 'from',
headerCellDef: 'Message Sender',
type: 'hash-url',
headerWidth: 12,
isUrl: '/account',
isNameTag: true,
},
{ matColumnDef: 'fee', headerCellDef: 'Txn Fee', type: 'numb', headerWidth: 10 },
];

Expand Down
25 changes: 10 additions & 15 deletions src/app/core/data-services/api-account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,27 @@ export class ApiAccountService {

// https://github.com/aura-nw/aura-explorer-api/blob/main/src/components/account/services/account.service.ts#L117
parseBalance(account, isGetAlBalances = false) {
const defaultBalance = { amount: '0', denom: this.currencies.coinDecimals };
const lengthBalance = _.get(account, '[0].balances.length');
const balances = lengthBalance > 0 ? account[0]?.balances : [defaultBalance];
const defaultBalance = { amount: '0', denom: this.currencies.coinMinimalDenom };
const balance = _.get(account, '[0].balances') || [];
const balances = balance?.length > 0 ? account[0]?.balances : [defaultBalance];

return isGetAlBalances
? balances
: lengthBalance > 0
: balance?.length > 0
? account[0]?.balances?.find((item) => item.denom === this.currencies.coinMinimalDenom)
: defaultBalance;
}

// https://github.com/aura-nw/aura-explorer-api/blob/main/src/components/account/services/account.service.ts#L132
parseAvailableBalance(account) {
if (account) {
const spendable_balances = account[0]?.spendable_balances;

const value = spendable_balances?.find((f) => f.denom === this.currencies.coinMinimalDenom);

if (value) {
const amount = value.amount;

return balanceOf(amount, this.currencies.coinDecimals);
}
const spendableBalances = _.get(account, '[0].spendable_balances') || [];
if (spendableBalances?.length == 0) {
return 0;
}

return 0;
const value = spendableBalances?.find((f) => f.denom === this.currencies.coinMinimalDenom);
const amount = value.amount || 0;
return balanceOf(amount, this.currencies.coinDecimals);
}

// https://github.com/aura-nw/aura-explorer-api/blob/main/src/components/account/services/account.service.ts#L283
Expand Down
30 changes: 10 additions & 20 deletions src/app/core/data-services/environment.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ChainInfo } from '@keplr-wallet/types';
import { WalletConnectOptions } from '@cosmos-kit/core';
import * as _ from 'lodash';
import { BehaviorSubject, Subject, lastValueFrom, takeUntil } from 'rxjs';
import { BehaviorSubject, lastValueFrom, Subject, takeUntil } from 'rxjs';
import { TYPE_TRANSACTION } from '../constants/transaction.constant';
import { TRANSACTION_TYPE_ENUM, TypeTransaction } from '../constants/transaction.enum';
import { LCD_COSMOS } from '../constants/url.constant';
import { ELeapMode } from '../constants/wallet.constant';
import { isMobileBrowser } from '../helpers/wallet';

export interface IConfiguration {
environment: {
Expand Down Expand Up @@ -38,7 +37,7 @@ export interface IConfiguration {
logo: string;
}[];
features: string[];
chain_info: ChainInfo & { gasPriceStep: any };
chain_info: any;
cosmos_sdk_version?: string;
};
image: {
Expand Down Expand Up @@ -69,6 +68,7 @@ export interface IConfiguration {
rest: string;
chain: string;
};
walletConnect: WalletConnectOptions;
};
}

Expand Down Expand Up @@ -159,6 +159,10 @@ export class EnvironmentService {
return _.get(this.configValue, 'api.coingecko');
}

get walletConnect() {
return _.get(this.configValue, 'api.walletConnect');
}

setLatestBlockHeight(value: string | number) {
this.latestBlockHeight$.next(value);
}
Expand All @@ -173,7 +177,7 @@ export class EnvironmentService {
this.isMobile = state?.matches ? true : false;
});

this.checkNativeApp();
this.isNativeApp = isMobileBrowser();
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -226,18 +230,4 @@ export class EnvironmentService {
}
});
}

checkNativeApp() {
if ((window.coin98 || window.leap || window.keplr) && this.isMobile) {
try {
if (
window.coin98?.keplr ||
window.leap?.mode == ELeapMode.MobileWeb ||
window.keplr?.mode == ELeapMode.MobileWeb
) {
this.isNativeApp = true;
}
} catch {}
}
}
}
19 changes: 17 additions & 2 deletions src/app/core/directives/common-directive.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ import { BigNumberDirective } from './big-number.directive';
import { ImageDirective } from './image.directive';
import { FeatureDirective } from './feature.directive';
import { LinkDenomDirective } from './link-denom.directive';
import { CopyButtonDirective } from './copy-button.directive';

@NgModule({
declarations: [NumberDirective, BigNumberDirective, ImageDirective, FeatureDirective, LinkDenomDirective],
declarations: [
NumberDirective,
BigNumberDirective,
ImageDirective,
FeatureDirective,
LinkDenomDirective,
CopyButtonDirective,
],
imports: [],
exports: [NumberDirective, BigNumberDirective, ImageDirective, FeatureDirective, LinkDenomDirective],
exports: [
NumberDirective,
BigNumberDirective,
ImageDirective,
FeatureDirective,
LinkDenomDirective,
CopyButtonDirective,
],
})
export class CommonDirectiveModule {}
66 changes: 66 additions & 0 deletions src/app/core/directives/copy-button.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Directive, ElementRef, Input } from '@angular/core';
import { NULL_ADDRESS } from '../constants/common.constant';

@Directive({
selector: 'copyBtn, [copyBtn]',
})
export class CopyButtonDirective {
@Input() copyBtn: string;
@Input() isDisableCopy: boolean = false;
@Input() btnClass: string[];
button;
tooltip;

constructor(private elRef: ElementRef) {}

ngOnInit(): void {
if (this.isDisableCopy || !this.copyBtn || this.copyBtn === NULL_ADDRESS) {
return;
}

const element: HTMLElement = this.elRef.nativeElement;
if (!element) return;
const content = this.copyBtn;
const parent = element.parentNode;
const contain = document.createElement('div');
this.button = document.createElement('button');

const icon = document.createElement('i');
this.button.classList.add('button', 'button--xxs', 'position-relative', 'pr-0');
if (this.btnClass?.length > 0) {
this.btnClass.forEach((c) => {
this.button.classList.add(c);
});
}
icon.classList.add('ph', 'ph-copy', 'text--white', 'body-01');
contain.classList.add('d-inline-flex', 'align-items-center');
parent.replaceChild(contain, element);
this.button.appendChild(icon);
contain.appendChild(element);
// tooltip
this.tooltip = document.createElement('div');
this.tooltip.innerHTML = 'Copied!';
this.tooltip.classList.add('tooltip-copy');
this.button.appendChild(this.tooltip);
contain.appendChild(this.button);

// click show tooltip
this.button.addEventListener('click', () => {
this.tooltip.classList.add('show');
this.copyMessage(content);

setTimeout(() => {
this.tooltip.classList.remove('show');
}, 1000);
});
}

copyMessage(text: string) {
const dummy = document.createElement('textarea');
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
}
}
Loading

0 comments on commit 1e7d423

Please sign in to comment.