Add loading state to CFL metrics
This commit is contained in:
@@ -148,7 +148,7 @@ export interface CodeDemoProps {
|
|||||||
children: string;
|
children: string;
|
||||||
language: string;
|
language: string;
|
||||||
fontSize: string;
|
fontSize: string;
|
||||||
hideCopy?: boolean;
|
shouldHideCopy?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CodeDemoState {
|
export interface CodeDemoState {
|
||||||
@@ -160,14 +160,14 @@ export class CodeDemo extends React.Component<CodeDemoProps, CodeDemoState> {
|
|||||||
didCopyCode: false,
|
didCopyCode: false,
|
||||||
};
|
};
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const { fontSize, hideCopy } = this.props;
|
const { fontSize, shouldHideCopy } = this.props;
|
||||||
const copyButtonText = this.state.didCopyCode ? 'Copied!' : 'Copy';
|
const copyButtonText = this.state.didCopyCode ? 'Copied!' : 'Copy';
|
||||||
const hljs = { ...customStyle.hljs, fontSize };
|
const hljs = { ...customStyle.hljs, fontSize };
|
||||||
const style = { ...customStyle, hljs };
|
const style = { ...customStyle, hljs };
|
||||||
return (
|
return (
|
||||||
<Container position="relative" height="100%">
|
<Container position="relative" height="100%">
|
||||||
<Container position="absolute" top="10px" right="10px" zIndex={zIndex.overlay - 1}>
|
<Container position="absolute" top="10px" right="10px" zIndex={zIndex.overlay - 1}>
|
||||||
{!hideCopy && (
|
{!shouldHideCopy && (
|
||||||
<CopyToClipboard text={this.props.children} onCopy={this._handleCopyClick}>
|
<CopyToClipboard text={this.props.children} onCopy={this._handleCopyClick}>
|
||||||
<StyledButton>{copyButtonText}</StyledButton>
|
<StyledButton>{copyButtonText}</StyledButton>
|
||||||
</CopyToClipboard>
|
</CopyToClipboard>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const TabbedCodeDemo: React.FC<TabbedCodeDemoProps> = props => {
|
|||||||
{tab.label}
|
{tab.label}
|
||||||
</Tab>
|
</Tab>
|
||||||
))}
|
))}
|
||||||
<CodeDemo language={language} fontSize="16px" hideCopy={true}>
|
<CodeDemo language={language} fontSize="16px" shouldHideCopy={true}>
|
||||||
{code}
|
{code}
|
||||||
</CodeDemo>
|
</CodeDemo>
|
||||||
</TabbedWrapper>
|
</TabbedWrapper>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
import { Icon } from 'ts/components/icon';
|
import { Icon } from 'ts/components/icon';
|
||||||
import { Paragraph } from 'ts/components/text';
|
import { Paragraph } from 'ts/components/text';
|
||||||
|
import { defaultData } from 'ts/pages/cfl/default_data';
|
||||||
import { Metrics, MetricValue } from 'ts/pages/cfl/metrics';
|
import { Metrics, MetricValue } from 'ts/pages/cfl/metrics';
|
||||||
import { backendClient } from 'ts/utils/backend_client';
|
import { backendClient } from 'ts/utils/backend_client';
|
||||||
|
|
||||||
@@ -56,7 +57,7 @@ const PairTab = styled.label<PairTabProps>`
|
|||||||
interface CFLMetricsProps {}
|
interface CFLMetricsProps {}
|
||||||
|
|
||||||
interface CFLMetricsState {
|
interface CFLMetricsState {
|
||||||
cflMetricsData?: CFLMetricsPairData[];
|
cflMetricsData: CFLMetricsPairData[];
|
||||||
didError: boolean;
|
didError: boolean;
|
||||||
selectedIndex: number;
|
selectedIndex: number;
|
||||||
}
|
}
|
||||||
@@ -65,6 +66,7 @@ export class CFLMetrics extends React.Component<CFLMetricsProps, CFLMetricsState
|
|||||||
public state: CFLMetricsState = {
|
public state: CFLMetricsState = {
|
||||||
didError: false,
|
didError: false,
|
||||||
selectedIndex: 0,
|
selectedIndex: 0,
|
||||||
|
cflMetricsData: defaultData,
|
||||||
};
|
};
|
||||||
public componentDidMount(): void {
|
public componentDidMount(): void {
|
||||||
// tslint:disable-next-line:no-floating-promises
|
// tslint:disable-next-line:no-floating-promises
|
||||||
@@ -72,7 +74,7 @@ export class CFLMetrics extends React.Component<CFLMetricsProps, CFLMetricsState
|
|||||||
}
|
}
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const { cflMetricsData, selectedIndex } = this.state;
|
const { cflMetricsData, selectedIndex } = this.state;
|
||||||
if (!cflMetricsData) {
|
if (!cflMetricsData.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const baseTokenSymbol = this._getSelectedPairData().takerSymbol;
|
const baseTokenSymbol = this._getSelectedPairData().takerSymbol;
|
||||||
@@ -129,6 +131,9 @@ export class CFLMetrics extends React.Component<CFLMetricsProps, CFLMetricsState
|
|||||||
}
|
}
|
||||||
private _getLastPrice(): string {
|
private _getLastPrice(): string {
|
||||||
const data = this._getSelectedPairData();
|
const data = this._getSelectedPairData();
|
||||||
|
if (!data.lastTradePrice) {
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
const num = numeral(data.lastTradePrice);
|
const num = numeral(data.lastTradePrice);
|
||||||
const formattedNum = num.format('0.00');
|
const formattedNum = num.format('0.00');
|
||||||
const currency = data.makerSymbol;
|
const currency = data.makerSymbol;
|
||||||
@@ -136,11 +141,31 @@ export class CFLMetrics extends React.Component<CFLMetricsProps, CFLMetricsState
|
|||||||
}
|
}
|
||||||
private _getVolume(): string {
|
private _getVolume(): string {
|
||||||
const data = this._getSelectedPairData();
|
const data = this._getSelectedPairData();
|
||||||
|
if (!data.volumeUSD) {
|
||||||
|
return '—';
|
||||||
|
}
|
||||||
const num = numeral(data.volumeUSD);
|
const num = numeral(data.volumeUSD);
|
||||||
return num.format('$0,0');
|
return num.format('$0,0');
|
||||||
}
|
}
|
||||||
private _getSlippageMetrics(): MetricValue[] {
|
private _getSlippageMetrics(): MetricValue[] {
|
||||||
const data = this._getSelectedPairData();
|
const data = this._getSelectedPairData();
|
||||||
|
if (!data.exchangeAverageSlippagePercentage) {
|
||||||
|
const placeholder = '—';
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
label: <Icon name="small_0x_logo" size="natural" />,
|
||||||
|
value: placeholder,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: <Icon name="small_kyber_logo" size="natural" />,
|
||||||
|
value: placeholder,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: <Icon name="small_uniswap_logo" size="natural" />,
|
||||||
|
value: placeholder,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
const zeroExSlippage = data.exchangeAverageSlippagePercentage.find(
|
const zeroExSlippage = data.exchangeAverageSlippagePercentage.find(
|
||||||
exchangeSlippage => exchangeSlippage.exchange === 'Radar Relay',
|
exchangeSlippage => exchangeSlippage.exchange === 'Radar Relay',
|
||||||
);
|
);
|
||||||
|
|||||||
19
packages/website/ts/pages/cfl/default_data.ts
Normal file
19
packages/website/ts/pages/cfl/default_data.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { CFLMetricsPairData } from 'ts/types';
|
||||||
|
|
||||||
|
export const defaultData: CFLMetricsPairData[] = [
|
||||||
|
{
|
||||||
|
takerSymbol: 'ETH',
|
||||||
|
makerSymbol: 'DAI',
|
||||||
|
tradeAmount: 10000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
takerSymbol: 'ETH',
|
||||||
|
makerSymbol: 'USDC',
|
||||||
|
tradeAmount: 10000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
takerSymbol: 'DAI',
|
||||||
|
makerSymbol: 'USDC',
|
||||||
|
tradeAmount: 10000,
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -732,10 +732,10 @@ export interface CFLMetricsPairData {
|
|||||||
takerSymbol: string;
|
takerSymbol: string;
|
||||||
makerSymbol: string;
|
makerSymbol: string;
|
||||||
tradeAmount: number;
|
tradeAmount: number;
|
||||||
volumeUSD: number;
|
volumeUSD?: number;
|
||||||
lastTradePrice: number;
|
lastTradePrice?: number;
|
||||||
lastTradeTime: string;
|
lastTradeTime?: string;
|
||||||
exchangeAverageSlippagePercentage: ExchangeSlippageData[];
|
exchangeAverageSlippagePercentage?: ExchangeSlippageData[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WebsiteBackendCFLMetricsData = CFLMetricsPairData[];
|
export type WebsiteBackendCFLMetricsData = CFLMetricsPairData[];
|
||||||
|
|||||||
Reference in New Issue
Block a user