Skip to content

Commit

Permalink
feat(ux):JoinPool: Inline sync for provided pool (#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat authored Apr 7, 2024
1 parent 1a1847d commit e146bfc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
21 changes: 12 additions & 9 deletions src/canvas/JoinPool/Overview/PerformanceGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ChartJS.register(
export const PerformanceGraph = ({
bondedPool,
performanceKey,
graphSyncing,
}: OverviewSectionProps) => {
const { t } = useTranslation();
const { mode } = useTheme();
Expand All @@ -59,15 +60,17 @@ export const PerformanceGraph = ({
const size = useSize(graphInnerRef?.current || undefined);
const { width, height } = formatSize(size, 150);

// Format reward points as an array of strings.
const dataset = Object.values(
Object.fromEntries(
Object.entries(rawEraRewardPoints).map(([k, v]: AnyJson) => [
k,
new BigNumber(v).toString(),
])
)
);
// Format reward points as an array of strings, or an empty array if syncing.
const dataset = graphSyncing
? []
: Object.values(
Object.fromEntries(
Object.entries(rawEraRewardPoints).map(([k, v]: AnyJson) => [
k,
new BigNumber(v).toString(),
])
)
);

// Format labels, only displaying the first and last era.
const labels = Object.keys(rawEraRewardPoints).map(() => '');
Expand Down
45 changes: 34 additions & 11 deletions src/canvas/JoinPool/Overview/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import type { OverviewSectionProps } from '../types';
import { useTranslation } from 'react-i18next';
import { usePoolPerformance } from 'contexts/Pools/PoolPerformance';
import { MaxEraRewardPointsEras } from 'consts';
import { StyledLoader } from 'library/PoolSync/Loader';
import type { CSSProperties } from 'styled-components';
import { PoolSync } from 'library/PoolSync';

export const Stats = ({ bondedPool, performanceKey }: OverviewSectionProps) => {
export const Stats = ({
bondedPool,
performanceKey,
graphSyncing,
}: OverviewSectionProps) => {
const { t } = useTranslation('library');
const {
networkData: {
Expand Down Expand Up @@ -56,20 +63,36 @@ export const Stats = ({ bondedPool, performanceKey }: OverviewSectionProps) => {
}
}, [bondedPool.id, bondedPool.points, isReady]);

const vars = {
'--loader-color': 'var(--text-color-secondary)',
} as CSSProperties;

return (
<HeadingWrapper>
<h4>
{rawEraRewardPoints.length === MaxEraRewardPointsEras && (
<span className="active">{t('activelyNominating')}</span>
)}
{graphSyncing ? (
<span>
{t('syncing')}
<StyledLoader style={{ ...vars, marginRight: '1.25rem' }} />
<PoolSync performanceKey={performanceKey} />
</span>
) : (
<>
{rawEraRewardPoints.length === MaxEraRewardPointsEras && (
<span className="active">{t('activelyNominating')}</span>
)}

<span className="balance">
<Token className="icon" />
{!poolBalance
? `...`
: planckToUnit(poolBalance, units).decimalPlaces(3).toFormat()}{' '}
{unit} {t('bonded')}
</span>
<span className="balance">
<Token className="icon" />
{!poolBalance
? `...`
: planckToUnit(poolBalance, units)
.decimalPlaces(3)
.toFormat()}{' '}
{unit} {t('bonded')}
</span>
</>
)}
</h4>
</HeadingWrapper>
);
Expand Down
7 changes: 6 additions & 1 deletion src/canvas/JoinPool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ export const JoinPool = () => {

return (
<CanvasFullScreenWrapper>
{poolJoinPerformanceTask.status !== 'synced' || !bondedPool ? (
{(!providedPoolId && poolJoinPerformanceTask.status !== 'synced') ||
!bondedPool ? (
<Preloader performanceKey={performanceKey} />
) : (
<>
Expand All @@ -125,6 +126,10 @@ export const JoinPool = () => {
<Overview
bondedPool={bondedPool}
performanceKey={performanceKey}
graphSyncing={
providedPoolId &&
poolJoinPerformanceTask.status !== 'synced'
}
/>
)}
{activeTab === 1 && (
Expand Down
1 change: 1 addition & 0 deletions src/canvas/JoinPool/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface AddressSectionProps {
export interface OverviewSectionProps {
bondedPool: BondedPool;
performanceKey: PoolRewardPointsKey;
graphSyncing: boolean;
}
3 changes: 2 additions & 1 deletion src/library/PoolSync/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const StyledLoader = styled.div`
height: 0.8rem;
margin-left: 1.6rem;
aspect-ratio: 5;
--_g: no-repeat radial-gradient(farthest-side, white 94%, #0000);
--_g: no-repeat
radial-gradient(farthest-side, var(--loader-color, white) 94%, #0000);
background: var(--_g), var(--_g), var(--_g), var(--_g);
background-size: 20% 100%;
animation:
Expand Down

0 comments on commit e146bfc

Please sign in to comment.