Skip to content

Commit

Permalink
Merge pull request #3179 from aura-nw/baseline/main_20240321
Browse files Browse the repository at this point in the history
Baseline/main 20240321
  • Loading branch information
nhphuc2411 authored Mar 25, 2024
2 parents 1e7d423 + 22b4801 commit 19825de
Show file tree
Hide file tree
Showing 148 changed files with 2,254 additions and 3,197 deletions.
32 changes: 17 additions & 15 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
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 BigNumber from 'bignumber.js';
import eruda from 'eruda';
import * as _ from 'lodash';
import { forkJoin, map, Subject, takeUntil } from 'rxjs';
import { Subject, forkJoin, map, takeUntil } from 'rxjs';
import { STORAGE_KEYS } from './core/constants/common.constant';
import { ETokenCoinTypeBE } from './core/constants/token.constant';
import { EnvironmentService } from './core/data-services/environment.service';
import { IUser } from './core/models/auth.models';
import { CommonService } from './core/services/common.service';
import { IBCService } from './core/services/ibc.service';
import { NameTagService } from './core/services/name-tag.service';
import { NotificationsService } from './core/services/notifications.service';
import { TokenService } from './core/services/token.service';
import { UserService } from './core/services/user.service';
import { ValidatorService } from './core/services/validator.service';
import { WatchListService } from './core/services/watch-list.service';
import { getInfo } from './core/utils/common/info-common';
import local from './core/utils/storage/local';
import { IUser } from './core/models/auth.models';
import { UserService } from './core/services/user.service';
import { EnvironmentService } from './core/data-services/environment.service';
import { IBCService } from './core/services/ibc.service';
import BigNumber from 'bignumber.js';
import { Globals } from './global/global';

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -96,7 +97,7 @@ export class AppComponent implements OnInit, OnDestroy {
getInfoCommon(): void {
this.commonService.status().subscribe({
next: (res) => {
getInfo(this.globals, res);
getInfo(this.globals, res, this.environmentService.coinDecimals);
this.environmentService.setLatestBlockHeight(res?.total_blocks || null);
},
error: () => {
Expand Down Expand Up @@ -208,11 +209,12 @@ export class AppComponent implements OnInit, OnDestroy {
.getTokenMarketData(payload)
.pipe(
map((res) => {
const nativeData = res.find((k) => k.denom === this.coinMinimalDenom);
if (nativeData?.coin_id) {
const nativeData = res?.find((k) => k.denom === this.coinMinimalDenom);
if (nativeData?.coinId) {
this.getDataNative(nativeData);
}
const listFilterIBC = res.filter((k) => k.denom !== this.coinMinimalDenom);

const listFilterIBC = res?.filter((k) => k.type === ETokenCoinTypeBE.IBC);
return listFilterIBC?.map((element) => ({
...element,
display: element['display'] || element['symbol'],
Expand Down
12 changes: 12 additions & 0 deletions src/app/core/constants/account.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ export enum AccountTxType {
Sent = 'Sent',
Received = 'Received',
}

export enum ENameTag {
Normal = 'Normal',
Public = 'Public',
Private = 'Private',
}

export enum EScreen {
Contract = 'Contract',
Account = 'Account',
WatchList = 'WatchList',
}
5 changes: 2 additions & 3 deletions src/app/core/constants/common.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export const DATEFORMAT = {
TIME_ONLY: 'HH:mm:ss',
};

export const NUMBER_CONVERT = 1000000; //10^6 satoshi unit

export const PAGE_EVENT = {
LENGTH: 0,
PAGE_SIZE: 5,
Expand Down Expand Up @@ -114,4 +112,5 @@ export const STORAGE_KEYS = {
DATA_NATIVE: 'nativeData',
};

export const TITLE_LOGO = 'images/logo/title-logo.png';
export const TITLE_LOGO = 'assets/images/logo/title-logo.png';
export const MAX_LENGTH_NAME_TAG = 35;
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 @@ -34,3 +34,9 @@ export enum ETokenCoinType {
IBC = 'IBC Token',
CW20 = 'CW20 Token',
}

export enum ETokenCoinTypeBE {
NATIVE = 'NATIVE',
IBC = 'IBC_TOKEN',
CW20 = 'CW20_TOKEN',
}
43 changes: 22 additions & 21 deletions src/app/core/data-services/api-cw20-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
import { catchError, filter, forkJoin, map, of, take } from 'rxjs';
import { COIN_TOKEN_TYPE, TOKEN_ID_GET_PRICE } from '../constants/common.constant';
import { filter, forkJoin, map, take } from 'rxjs';
import { COIN_TOKEN_TYPE } from '../constants/common.constant';
import { ETokenCoinTypeBE } from '../constants/token.constant';
import { TokenService } from '../services/token.service';
import { balanceOf, getBalance } from '../utils/common/parsing';
import { ApiAccountService } from './api-account.service';
Expand All @@ -18,7 +19,7 @@ export interface IAsset {
balance: number;
max_total_supply: number;
price: number;
price_change_percentage_24h: number;
priceChangePercentage24h: number;
value: number | string;
denom: string;
decimals: number;
Expand Down Expand Up @@ -86,11 +87,11 @@ export class ApiCw20TokenService {
return tokens
.map((item): Partial<IAsset> => {
const coinMarket = coinsMarkets.find(
(coin) => coin.contract_address === item.cw20_contract.smart_contract.address,
(coin) => coin.type === ETokenCoinTypeBE.CW20 && coin.denom === item.cw20_contract.smart_contract.address,
);

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

return {
name: coinMarket?.name || item?.cw20_contract?.name,
Expand All @@ -100,12 +101,12 @@ export class ApiCw20TokenService {
max_total_supply: item?.cw20_contract?.total_supply,
contract_address: item?.cw20_contract?.smart_contract?.address || '-',
balance: item?.amount,
price: coinMarket?.current_price || 0,
price_change_percentage_24h: coinMarket?.price_change_percentage_24h || 0,
price: coinMarket?.currentPrice || 0,
priceChangePercentage24h: coinMarket?.priceChangePercentage24h || 0,
type: COIN_TOKEN_TYPE.CW20,
value: value.toFixed(),
verify_status: coinMarket?.verify_status || '',
verify_text: coinMarket?.verify_text || '',
verify_status: coinMarket?.verifyStatus || '',
verify_text: coinMarket?.verifyText || '',
};
})
.sort((item1, item2) => {
Expand All @@ -119,7 +120,7 @@ export class ApiCw20TokenService {

parseNativeToken(account, coinsMarkets) {
const nativeId = this.env.coingecko.ids[0];
const coinMarket = coinsMarkets.find((coin) => coin.coin_id === nativeId);
const coinMarket = coinsMarkets.find((coin) => coin.coinId === nativeId);
return {
name: this.env.chainName,
symbol: this.currencies.coinDenom,
Expand All @@ -128,13 +129,13 @@ export class ApiCw20TokenService {
image: this.currencies.coinImageUrl,
contract_address: '-',
balance: account.data.total,
price: coinMarket?.current_price || 0,
price_change_percentage_24h: coinMarket?.price_change_percentage_24h || 0,
value: account.data.total * coinMarket?.current_price || 0,
max_total_supply: coinMarket?.max_total_supply || 0,
price: coinMarket?.currentPrice || 0,
priceChangePercentage24h: coinMarket?.priceChangePercentage24h || 0,
value: account.data.total * coinMarket?.currentPrice || 0,
max_total_supply: coinMarket?.max_total_supply || coinMarket?.totalSupply || 0,
type: COIN_TOKEN_TYPE.NATIVE,
verify_status: coinMarket?.verify_status || 'VERIFIED',
verify_text: coinMarket?.verify_text || 'Verified by Aura Network',
verify_status: coinMarket?.verifyStatus || 'VERIFIED',
verify_text: coinMarket?.verifyText || 'Verified by Aura Network',
};
}

Expand All @@ -145,7 +146,7 @@ export class ApiCw20TokenService {
.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);
const value = new BigNumber(amount).multipliedBy(coinMarket?.currentPrice || 0);
return coinMarket
? {
name: coinMarket?.name,
Expand All @@ -156,12 +157,12 @@ export class ApiCw20TokenService {
max_total_supply: 0,
contract_address: '-',
balance: balanceOf(item.amount, this.currencies.coinDecimals),
price: coinMarket?.current_price || 0,
price_change_percentage_24h: coinMarket?.price_change_percentage_24h || 0,
price: coinMarket?.currentPrice || 0,
priceChangePercentage24h: coinMarket?.priceChangePercentage24h || 0,
value: value.toFixed(),
type: COIN_TOKEN_TYPE.IBC,
verify_status: coinMarket?.verify_status || '',
verify_text: coinMarket?.verify_text || '',
verify_status: coinMarket?.verifyStatus || '',
verify_text: coinMarket?.verifyText || '',
}
: null;
})
Expand Down
59 changes: 0 additions & 59 deletions src/app/core/data-services/coingecko.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,6 @@ export class CoingeckoService {

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

getCoinMarkets(ids: string[] = this.coinIds): Observable<any> {
if (ids?.length === 0) {
return of([]);
}

return this.http
.get(`${this.coingecko.url}/coins/markets`, {
params: {
ids: ids.toString(),
vs_currency: 'usd',
order: 'market_cap_desc',
per_page: 250,
page: 1,
sparkline: false,
price_change_percentage: '24h',
locale: 'en',
},
headers: {
[NgHttpCachingHeaders.ALLOW_CACHE]: '1',
},
})
.pipe(
catchError((error) => {
console.log(error);
return of([]);
}),
);
}

getChartData(
id: string,
ranges: {
Expand Down Expand Up @@ -150,34 +121,4 @@ export class CoingeckoService {
}),
);
}

getCoinById(id: string) {
if (!id) {
return of({ data: null });
}
return this.http
.get<any>(`${this.coingecko.url}/coins/${id}`, {
headers: {
[NgHttpCachingHeaders.ALLOW_CACHE]: '1',
},
})
.pipe(
map((res) => {
const data = {
coinId: _.get(res, 'id'),
current_price: _.get(res, "market_data.current_price['usd']"),
market_cap: _.get(res, "market_data.market_cap['usd']"),
max_supply: _.get(res, 'market_data.max_supply'),
price_change_percentage_24h: _.get(res, 'market_data.price_change_percentage_24h'),
timestamp: moment(_.get(res, 'market_data.last_updated')).unix().toString(),
total_volume: _.get(res, "market_data.total_volume['usd']"),
symbol: _.get(res, 'symbol'),
};

return {
data,
};
}),
);
}
}
6 changes: 1 addition & 5 deletions src/app/core/data-services/environment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { WalletConnectOptions } from '@cosmos-kit/core';
import * as _ from 'lodash';
import { BehaviorSubject, lastValueFrom, Subject, takeUntil } from 'rxjs';
import { BehaviorSubject, Subject, lastValueFrom, takeUntil } from 'rxjs';
import { TYPE_TRANSACTION } from '../constants/transaction.constant';
import { TRANSACTION_TYPE_ENUM, TypeTransaction } from '../constants/transaction.enum';
import { isMobileBrowser } from '../helpers/wallet';
Expand Down Expand Up @@ -113,10 +113,6 @@ export class EnvironmentService {
return _.get(this.configValue, 'chainConfig.stakingTime');
}

get coins() {
return _.get(this.configValue, 'chainConfig.coins');
}

get imageUrl() {
return _.get(this.configValue, 'image.assets');
}
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/directives/common-directive.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ImageDirective } from './image.directive';
import { FeatureDirective } from './feature.directive';
import { LinkDenomDirective } from './link-denom.directive';
import { CopyButtonDirective } from './copy-button.directive';
import { TooltipCustomizeDirective } from 'src/app/core/directives/tooltip-customize.directive';

@NgModule({
declarations: [
Expand All @@ -14,6 +15,7 @@ import { CopyButtonDirective } from './copy-button.directive';
FeatureDirective,
LinkDenomDirective,
CopyButtonDirective,
TooltipCustomizeDirective,
],
imports: [],
exports: [
Expand All @@ -23,6 +25,7 @@ import { CopyButtonDirective } from './copy-button.directive';
FeatureDirective,
LinkDenomDirective,
CopyButtonDirective,
TooltipCustomizeDirective,
],
})
export class CommonDirectiveModule {}
Loading

0 comments on commit 19825de

Please sign in to comment.