Skip to content

Commit

Permalink
total locked value in USD #51
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy committed Oct 23, 2020
1 parent 69afc17 commit 25e1616
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
54 changes: 43 additions & 11 deletions src/pages/Tokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,38 @@ const getColumns = ({ hmyLINKBalanceManager }): IColumn<ITokenInfo>[] => [
title: 'HRC20 Address',
key: 'hrc20Address',
dataIndex: 'hrc20Address',
width: 280,
width: 300,
render: value => oneAddress(getBech32Address(value)),
},
{
title: 'Decimals',
key: 'decimals',
dataIndex: 'decimals',
width: 100,
className: styles.centerHeader,
align: 'center',
},
// {
// title: 'Decimals',
// key: 'decimals',
// dataIndex: 'decimals',
// width: 100,
// className: styles.centerHeader,
// align: 'center',
// },
{
title: 'Total Locked',
sortable: true,
// sortable: true,
key: 'totalLockedNormal',
dataIndex: 'totalLockedNormal',
width: 200,
width: 140,
render: value => (
<Box direction="column" justify="center">
{formatWithTwoDecimals(value)}
</Box>
),
// className: styles.centerHeader,
// align: 'center',
},
{
title: 'Total Locked USD',
sortable: true,
key: 'totalLockedUSD',
defaultSort: 'asc',
dataIndex: 'totalLockedUSD',
width: 210,
className: styles.rightHeaderSort,
align: 'right',
render: value => (
Expand Down Expand Up @@ -149,6 +164,23 @@ export const Tokens = observer((props: any) => {
pad={{ horizontal: 'medium' }}
>
<Title>Bridged Assets</Title>

<Box direction="column">
<Title size="small">
Total Value Locked (USD){' '}
<span
style={{
marginLeft: 5,
color: '#47b8eb',
fontWeight: 600,
letterSpacing: 0.2
}}
>
{formatWithTwoDecimals(tokens.totalLockedUSD)}
</span>
</Title>
</Box>

<Text>{`Last update: ${lastUpdateAgo}sec ago`}</Text>
</Box>

Expand Down
6 changes: 1 addition & 5 deletions src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IOperation, ITokenInfo } from '../stores/interfaces';
import * as agent from 'superagent';
import { divDecimals } from '../utils';

const servers = require('../../appengine-servers.json');

Expand Down Expand Up @@ -121,10 +120,7 @@ export const getTokensInfo = async (
params,
);

const content = res.body.content.map(t => ({
...t,
totalLockedNormal: divDecimals(t.totalLocked, t.decimals),
}));
const content = res.body.content;

return { ...res.body, content };
};
Expand Down
9 changes: 9 additions & 0 deletions src/stores/Tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ import { ITokenInfo } from './interfaces';
import { IStores } from './index';
import * as services from 'services';
import { ListStoreConstructor } from './core/ListStoreConstructor';
import { computed } from 'mobx';

export class Tokens extends ListStoreConstructor<ITokenInfo> {
constructor(stores: IStores) {
super(stores, () => services.getTokensInfo({ page: 0, size: 1000 }), {
pollingInterval: 30000,
isLocal: true,
paginationData: { pageSize: 100 },
sorter: 'totalLockedUSD, asc',
sorters: {
totalLockedUSD: 'asc',
},
});
}

@computed get totalLockedUSD() {
return this.data.reduce((acc, v) => acc + Number(v.totalLockedUSD), 0);
}
}
17 changes: 9 additions & 8 deletions src/stores/core/ListStoreConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ListData<T> {
interface IListStoreOptions {
pollingInterval?: number;
paginationData?: IPagination;
sorter?: string[];
sorter?: string | string[];
sorters?: ISorters;
filters?: IFilters;
isLocal?: boolean;
Expand Down Expand Up @@ -96,7 +96,7 @@ export class ListStoreConstructor<T> extends StoreConstructor {
this.pollingInterval = pollingInterval;

this.sorters = options.sorters || {};
this.sorter = 'none';
this.sorter = options.sorter || 'none';
this.filters = options.filters || {};

this.isLocal = options.isLocal;
Expand Down Expand Up @@ -241,15 +241,16 @@ export class ListStoreConstructor<T> extends StoreConstructor {
@computed
get sortedData() {
if (!this.isLocal) return this.filteredData;
if (
!this.sorter ||
this.sorter === 'none' ||
this.sorter instanceof Array
) {

console.log(this.sorter);

if (!this.sorter || this.sorter === 'none') {
return this.filteredData;
}

const [index, direction] = this.sorter.split(',');
const sorter = Array.isArray(this.sorter) ? this.sorter[0] : this.sorter;

const [index, direction] = sorter.split(',');
const dir = direction === 'asc' ? 1 : -1;
return this.filteredData.sort((a, b) => {
return Number(a[index]) < Number(b[index]) ? dir : -dir;
Expand Down
1 change: 1 addition & 0 deletions src/stores/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ export interface ITokenInfo {
hrc20Address: string;
totalLocked: string;
totalLockedNormal: string;
totalLockedUSD: string;
}

0 comments on commit 25e1616

Please sign in to comment.