2021-12-06 17:02:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-01-07 20:18:02 +01:00
|
|
|
import { NETWORK_CONGESTION_THRESHOLDS } from '../../../../../../shared/constants/gas';
|
2021-12-09 22:34:38 +01:00
|
|
|
import { useGasFeeContext } from '../../../../../contexts/gasFee';
|
2022-07-12 15:59:38 +02:00
|
|
|
import { useI18nContext } from '../../../../../hooks/useI18nContext';
|
2021-12-06 17:02:23 +01:00
|
|
|
import { NetworkStabilityTooltip } from '../tooltips';
|
|
|
|
|
|
|
|
const GRADIENT_COLORS = [
|
|
|
|
'#037DD6',
|
|
|
|
'#1876C8',
|
|
|
|
'#2D70BA',
|
|
|
|
'#4369AB',
|
|
|
|
'#57629E',
|
|
|
|
'#6A5D92',
|
|
|
|
'#805683',
|
|
|
|
'#9A4D71',
|
|
|
|
'#B44561',
|
|
|
|
'#C54055',
|
2021-12-09 22:34:38 +01:00
|
|
|
'#D73A49',
|
2021-12-06 17:02:23 +01:00
|
|
|
];
|
|
|
|
|
2021-12-09 22:34:38 +01:00
|
|
|
const determineStatusInfo = (givenNetworkCongestion) => {
|
|
|
|
const networkCongestion = givenNetworkCongestion ?? 0.5;
|
|
|
|
const colorIndex = Math.round(networkCongestion * 10);
|
|
|
|
const color = GRADIENT_COLORS[colorIndex];
|
|
|
|
const sliderTickValue = colorIndex * 10;
|
2021-12-06 17:02:23 +01:00
|
|
|
|
2022-01-07 20:18:02 +01:00
|
|
|
if (networkCongestion >= NETWORK_CONGESTION_THRESHOLDS.BUSY) {
|
2021-12-09 22:34:38 +01:00
|
|
|
return {
|
2022-01-07 20:18:02 +01:00
|
|
|
statusLabel: 'busy',
|
|
|
|
tooltipLabel: 'highLowercase',
|
2021-12-09 22:34:38 +01:00
|
|
|
color,
|
|
|
|
sliderTickValue,
|
|
|
|
};
|
2022-01-07 20:18:02 +01:00
|
|
|
} else if (networkCongestion >= NETWORK_CONGESTION_THRESHOLDS.STABLE) {
|
2021-12-09 22:34:38 +01:00
|
|
|
return {
|
2022-01-07 20:18:02 +01:00
|
|
|
statusLabel: 'stable',
|
|
|
|
tooltipLabel: 'stableLowercase',
|
2021-12-09 22:34:38 +01:00
|
|
|
color,
|
|
|
|
sliderTickValue,
|
|
|
|
};
|
2021-12-06 17:02:23 +01:00
|
|
|
}
|
2021-12-09 22:34:38 +01:00
|
|
|
return {
|
2022-01-07 20:18:02 +01:00
|
|
|
statusLabel: 'notBusy',
|
|
|
|
tooltipLabel: 'lowLowercase',
|
2021-12-09 22:34:38 +01:00
|
|
|
color,
|
|
|
|
sliderTickValue,
|
|
|
|
};
|
2021-12-06 17:02:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const StatusSlider = () => {
|
2022-07-12 15:59:38 +02:00
|
|
|
const t = useI18nContext();
|
2021-12-09 22:34:38 +01:00
|
|
|
const { gasFeeEstimates } = useGasFeeContext();
|
|
|
|
const statusInfo = determineStatusInfo(gasFeeEstimates.networkCongestion);
|
2021-12-06 17:02:23 +01:00
|
|
|
|
|
|
|
return (
|
2021-12-09 22:34:38 +01:00
|
|
|
<NetworkStabilityTooltip
|
|
|
|
color={statusInfo.color}
|
|
|
|
tooltipLabel={statusInfo.tooltipLabel}
|
|
|
|
>
|
2021-12-06 17:02:23 +01:00
|
|
|
<div className="status-slider">
|
2021-12-09 22:34:38 +01:00
|
|
|
<div className="status-slider__arrow-container">
|
2021-12-06 17:02:23 +01:00
|
|
|
<div
|
2021-12-09 22:34:38 +01:00
|
|
|
className="status-slider__arrow-border"
|
2021-12-06 17:02:23 +01:00
|
|
|
style={{
|
2021-12-09 22:34:38 +01:00
|
|
|
marginLeft: `${statusInfo.sliderTickValue}%`,
|
2021-12-06 17:02:23 +01:00
|
|
|
}}
|
2021-12-09 22:34:38 +01:00
|
|
|
data-testid="status-slider-arrow-border"
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className="status-slider__arrow"
|
|
|
|
style={{
|
|
|
|
borderTopColor: statusInfo.color,
|
|
|
|
}}
|
|
|
|
data-testid="status-slider-arrow"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-12-06 17:02:23 +01:00
|
|
|
</div>
|
|
|
|
<div className="status-slider__line" />
|
|
|
|
<div
|
|
|
|
className="status-slider__label"
|
2021-12-09 22:34:38 +01:00
|
|
|
style={{ color: statusInfo.color }}
|
|
|
|
data-testid="status-slider-label"
|
2021-12-06 17:02:23 +01:00
|
|
|
>
|
2022-07-12 15:59:38 +02:00
|
|
|
{t(statusInfo.statusLabel)}
|
2021-12-06 17:02:23 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</NetworkStabilityTooltip>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default StatusSlider;
|