Skip to content

Commit

Permalink
Merge pull request #2929 from aura-nw/baseline/main_20240123
Browse files Browse the repository at this point in the history
Baseline/main 20240123
  • Loading branch information
nhphuc2411 authored Jan 24, 2024
2 parents 131779d + 5d2ce5c commit 560a457
Show file tree
Hide file tree
Showing 230 changed files with 4,065 additions and 2,398 deletions.
29 changes: 27 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { inject, NgModule } from '@angular/core';
import { Router, RouterModule, Routes, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { EnvironmentService } from './core/data-services/environment.service';
import { EFeature } from './core/models/common.model';
import { LayoutComponent } from './layouts/layout.component';

export const isEnabled = (
functionNames: string,
): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> => {
const config = inject(EnvironmentService);
const router = inject(Router);

const features = config.configValue['chainConfig']?.features;

if (features.findIndex((item) => item === functionNames) >= 0 || features.length === 0) {
return true;
}

return router.navigate(['']);
};

const routes: Routes = [
{
path: '',
Expand Down Expand Up @@ -50,19 +68,23 @@ const routes: Routes = [
{
path: 'fee-grant',
loadChildren: () => import('./pages/fee-grant/fee-grant.module').then((m) => m.FeeGrantModule),
canMatch: [() => isEnabled(EFeature.FeeGrant)],
},
{
path: 'accountbound',
loadChildren: () =>
import('./pages/soulbound-token/soulbound-token.module').then((m) => m.SoulboundTokenModule),
canMatch: [() => isEnabled(EFeature.Cw4973)],
},
{
path: 'community-pool',
loadChildren: () => import('./pages/community-pool/community-pool.module').then((m) => m.CommunityPoolModule),
canMatch: [() => isEnabled(EFeature.CommunityPool)],
},
{
path: 'login',
loadChildren: () => import('./pages/login/login.module').then((m) => m.LoginModule),
canMatch: [() => isEnabled(EFeature.Profile)],
},
{
path: 'user',
Expand All @@ -71,10 +93,12 @@ const routes: Routes = [
{
path: 'profile',
loadChildren: () => import('./pages/profile/profile.module').then((m) => m.ProfileModule),
canMatch: [() => isEnabled(EFeature.Profile)],
},
{
path: 'export-csv',
loadChildren: () => import('./pages/export-csv/export-csv.module').then((m) => m.ExportCsvModule),
canMatch: [() => isEnabled(EFeature.ExportCsv)],
},
{
path: 'account',
Expand All @@ -91,6 +115,7 @@ const routes: Routes = [
{
path: 'ibc-relayer',
loadChildren: () => import('./pages/ibc/ibc.module').then((m) => m.IBCModule),
canMatch: [() => isEnabled(EFeature.IbcRelayer)],
},
],
},
Expand Down
74 changes: 42 additions & 32 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { STORAGE_KEYS, TOKEN_ID_GET_PRICE } 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 * as _ from 'lodash';
import { forkJoin, map } from 'rxjs';
import { forkJoin, map, Subject, takeUntil } from 'rxjs';
import { NameTagService } from './core/services/name-tag.service';
import { NotificationsService } from './core/services/notifications.service';
import { ValidatorService } from './core/services/validator.service';
import { WatchListService } from './core/services/watch-list.service';
import local from './core/utils/storage/local';
import { UserStorage } from './core/models/auth.models';
import { IUser } from './core/models/auth.models';
import { UserService } from './core/services/user.service';
import { EnvironmentService } from './core/data-services/environment.service';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
export class AppComponent implements OnInit, OnDestroy {
// TESTNET = ['aura-testnet-2', 'serenity-testnet-001'];
// isTestnet = this.TESTNET.includes(
// this.chainInfo?.chainId || ''
// );
isFirstLoad = true;
userEmail = '';
user: IUser;

destroyed$ = new Subject<void>();
coinMinimalDenom = this.environmentService.chainInfo.currencies[0].coinMinimalDenom;

constructor(
private commonService: CommonService,
private globals: Globals,
Expand All @@ -34,11 +40,32 @@ export class AppComponent implements OnInit {
private validatorService: ValidatorService,
private notificationsService: NotificationsService,
private watchListService: WatchListService,
private userService: UserService,
private environmentService: EnvironmentService,
) {}

ngOnDestroy(): void {
this.destroyed$.next();
this.destroyed$.complete();
}

ngOnInit(): void {
this.userEmail = local.getItem<UserStorage>(STORAGE_KEYS.USER_DATA)?.email;
this.userService.user$?.pipe(takeUntil(this.destroyed$)).subscribe((user) => {
this.user = user;

this.getListNameTag();

if (this.user?.accessToken) {
this.getWatchlist();
// check register fcm token
const registerFCM = local.getItem(STORAGE_KEYS.REGISTER_FCM);
if (registerFCM == 'true') {
this.notificationsService.registerFcmToken();
}
}
});

this.getInfoCommon();
this.getPriceToken();
this.getDataFromStorage();
//get list token market
this.tokenService.getCoinData();
Expand All @@ -49,7 +76,6 @@ export class AppComponent implements OnInit {

setInterval(() => {
this.getListValidator();
this.getPriceToken();
//get list token market
this.tokenService.getCoinData();
}, 600000);
Expand All @@ -71,20 +97,14 @@ export class AppComponent implements OnInit {
});
}

getPriceToken(): void {
this.tokenService.getPriceToken(TOKEN_ID_GET_PRICE.AURA).subscribe((res) => {
this.globals.price.aura = res.data || 0;
});
}

getListNameTag() {
const payload = {
limit: 500,
nextKey: 0,
};

// get list name tag if not login email
if (!this.userEmail) {
if (!this.user?.accessToken) {
this.nameTagService.getListNameTag(payload).subscribe((res) => {
this.nameTagService.listNameTag = res.data?.nameTags;
local.setItem(STORAGE_KEYS.LIST_NAME_TAG, res.data?.nameTags);
Expand Down Expand Up @@ -156,23 +176,8 @@ export class AppComponent implements OnInit {
// get name tag form local storage
const listNameTag = local.getItem<[]>(STORAGE_KEYS.LIST_NAME_TAG);
this.nameTagService.listNameTag = listNameTag;
this.getListNameTag();

// get watch list form local storage
if (this.userEmail) {
this.getWatchlist();
// check register fcm token
const registerFCM = local.getItem(STORAGE_KEYS.REGISTER_FCM);
if (registerFCM == 'true') {
this.notificationsService.registerFcmToken();
}
}

// get list name validator form local storage
const listTokenIBC = local.getItem<[]>(STORAGE_KEYS.LIST_TOKEN_IBC);
if (!listTokenIBC) {
this.commonService.listTokenIBC = listTokenIBC;
}
// get list token IBC
this.getListTokenIBC();
}

Expand All @@ -195,7 +200,12 @@ export class AppComponent implements OnInit {
.getTokenMarketData(payload)
.pipe(
map((res) => {
return res.map((element) => ({
const nativeData = res.find((k) => k.denom === this.coinMinimalDenom);
if (nativeData?.coin_id) {
local.setItem(STORAGE_KEYS.DATA_NATIVE, nativeData);
}
const listFilterIBC = res.filter((k) => k.denom !== this.coinMinimalDenom);
return listFilterIBC?.map((element) => ({
...element,
display: element['display'] || element['symbol'],
}));
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/constants/account.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export enum WalletAcount {

export enum TabsAccount {
ExecutedTxs = 'Executed',
NativeTxs = 'Native Transfer',
NativeTxs = 'Native/ibc Transfer',
FtsTxs = 'CW20 Transfer',
NftTxs = 'NFT transfer',
NftTxs = 'NFT Transfer',
}

export enum TabsAccountLink {
Expand Down
7 changes: 6 additions & 1 deletion src/app/core/constants/common.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const NETWORK = [
export const DATEFORMAT = {
DATETIME_UTC: 'yyyy-MM-dd HH:mm:ss',
DATE_ONLY: 'yyyy-MM-dd',
TIME_ONLY: 'HH:mm:ss',
};

export const NUMBER_CONVERT = 1000000; //10^6 satoshi unit
Expand Down Expand Up @@ -55,6 +56,7 @@ export const CHART_RANGE = {
MONTH_12: '12M',
};

// Only aura address
export const LENGTH_CHARACTER = {
ADDRESS: 43,
CONTRACT: 63,
Expand Down Expand Up @@ -108,5 +110,8 @@ export const STORAGE_KEYS = {
CONTRACT_RAW_DATA: 'contractRawData',
IS_VERIFY_TAB: 'isVerifyTab',
TAB_UNEQUIP: 'tabUnEquip',
LAST_USED_PROVIDER: 'LAST_USED_PROVIDER'
LAST_USED_PROVIDER: 'LAST_USED_PROVIDER',
DATA_NATIVE: 'nativeData',
};

export const TITLE_LOGO = 'images/logo/title-logo.png';
8 changes: 7 additions & 1 deletion src/app/core/constants/token.constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TokenTab } from "./token.enum";
import {TokenTab} from "./token.enum";

export const TOKEN_TAB = [
{
Expand Down Expand Up @@ -28,3 +28,9 @@ export const TOKEN_TAB = [
];

export const MAX_LENGTH_SEARCH_TOKEN = 100;

export enum ETokenCoinType {
NATIVE = 'Native',
IBC = 'IBC Token',
CW20 = 'CW20 Token',
}
6 changes: 6 additions & 0 deletions src/app/core/constants/token.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ export enum ABTActionType {
Reject = 'Reject this ABT',
RejectAll = 'Reject all ABTs from this Creator'
}

export enum EModeToken {
Native = 'Native',
IBCCoin = 'IBC Token',
CWToken = 'CW20 Token',
}
2 changes: 1 addition & 1 deletion src/app/core/constants/transaction.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export enum ModeExecuteTransaction {
Send = 'send',
ProvideLiquidity = 'provide_liquidity',
Approve = 'approve',
Revoke = 'revoke'
Revoke = 'revoke',
}

export enum pipeTypeData {
Expand Down
4 changes: 3 additions & 1 deletion src/app/core/constants/url.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export const LCD_COSMOS = {
DISTRIBUTION: 'cosmos/distribution/v1beta1/community_pool',
BALANCE: 'cosmos/bank/v1beta1/balances',
DELEGATION: 'cosmos/staking/v1beta1/delegations',
REWARD: 'cosmos/distribution/v1beta1/delegators'
REWARD: 'cosmos/distribution/v1beta1/delegators',
SUPPLY: 'cosmos/bank/v1beta1/supply',
MODULE_ACCOUNTS: 'cosmos/auth/v1beta1/module_accounts',
};
5 changes: 5 additions & 0 deletions src/app/core/constants/wallet.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ export enum ESigningType {
Coin98 = 'Coin98',
Leap = 'Leap',
}

export enum ELeapMode {
Core = 'core',
MobileWeb = 'mobile-web'
}
23 changes: 16 additions & 7 deletions src/app/core/data-services/api-cw20-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ export class ApiCw20TokenService {

chainInfo = this.env.chainInfo;
currencies = this.chainInfo.currencies[0];
nativeName = this.env.environment.nativeName;

apiAccount = inject(ApiAccountService);

constructor(private http: HttpClient, private env: EnvironmentService, private tokenService: TokenService) {}
constructor(
private http: HttpClient,
private env: EnvironmentService,
private tokenService: TokenService,
) {}

getByOwner(address: string) {
return forkJoin([
Expand All @@ -64,7 +69,13 @@ export class ApiCw20TokenService {

const totalValue = allTokens
.filter((item) => item.verify_status === 'VERIFIED')
.reduce((prev, current) => BigNumber(current?.value).plus(prev).toFixed(), 0);
.reduce(
(prev, current) =>
BigNumber(current?.value)
.plus(prev)
.toFixed(),
0,
);

return { data: allTokens, meta: { count: allTokens.length }, totalValue };
}),
Expand Down Expand Up @@ -107,9 +118,10 @@ export class ApiCw20TokenService {
}

parseNativeToken(account, coinsMarkets) {
const coinMarket = coinsMarkets.find((coin) => coin.coin_id === TOKEN_ID_GET_PRICE.AURA);
const nativeId = this.env.coingecko.ids[0];
const coinMarket = coinsMarkets.find((coin) => coin.coin_id === nativeId);
return {
name: 'Aura',
name: this.env.chainName,
symbol: this.currencies.coinDenom,
decimals: this.currencies.coinDecimals,
denom: this.currencies.coinMinimalDenom,
Expand All @@ -128,15 +140,12 @@ export class ApiCw20TokenService {

parseIbcTokens(account, coinsMarkets): IAsset[] {
const ibcBalances = account.data?.balances?.filter((balance) => balance.denom !== this.currencies.coinMinimalDenom);

return ibcBalances
? ibcBalances
.map((item): Partial<IAsset> => {
const coinMarket = coinsMarkets.find((coin) => item.denom === coin.denom);

const amount = getBalance(item?.amount, item?.cw20_contract?.decimal || this.currencies.coinDecimals);
const value = new BigNumber(amount).multipliedBy(coinMarket?.current_price || 0);

return coinMarket
? {
name: coinMarket?.name,
Expand Down
Loading

0 comments on commit 560a457

Please sign in to comment.