Skip to content

Commit

Permalink
feat(refactor): Overlay to kit (#1994)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat authored Feb 27, 2024
1 parent 07bcbef commit e1cd02f
Show file tree
Hide file tree
Showing 124 changed files with 2,053 additions and 189 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

### Validator Operators

To showcase a validator operator on staking dashboard, submit a PR to the [__`@w3ux`__](https://github.com/w3ux/w3ux-library/tree/main) library. The operator will then be available in the __`@w3ux/validator-assets`__ NPM package. [Full instructions](https://github.com/w3ux/w3ux-library/tree/main/library/validator-assets).
To showcase a validator operator on staking dashboard, submit a PR to the [**`@w3ux`**](https://github.com/w3ux/w3ux-library/tree/main) library. The operator will then be available in the **`@w3ux/validator-assets`** NPM package. [Full instructions](https://github.com/w3ux/w3ux-library/tree/main/library/validator-assets).

## URL Variable Support

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@ledgerhq/hw-transport-webhid": "^6.28.4",
"@polkadot-cloud/core": "^1.3.3",
"@polkadot-cloud/react": "^0.5.4",
"@polkadot-cloud/core": "^1.3.4",
"@polkadot-cloud/react": "^0.5.5",
"@polkadot/api": "^10.11.2",
"@polkadot/keyring": "^12.6.2",
"@polkadot/rpc-provider": "^10.11.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { BondedProvider } from 'contexts/Bonded';
import {
ExtensionsProvider,
ExtensionAccountsProvider,
OverlayProvider,
LedgerAccountsProvider,
} from '@polkadot-cloud/react/providers';
import { FastUnstakeProvider } from 'contexts/FastUnstake';
Expand Down Expand Up @@ -44,6 +43,7 @@ import { ExternalAccountsProvider } from 'contexts/Connect/ExternalAccounts';
import type { Provider } from 'hooks/withProviders';
import { withProviders } from 'hooks/withProviders';
import { CommunityProvider } from 'contexts/Community';
import { OverlayProvider } from 'kits/Overlay/Provider';

export const Providers = () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/ManageNominations/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { useOverlay } from '@polkadot-cloud/react/hooks';
import { useOverlay } from 'kits/Overlay/Provider';
import { GenerateNominations } from 'library/GenerateNominations';
import { useEffect, useState } from 'react';
import { Subheading } from 'pages/Nominate/Wrappers';
Expand Down
10 changes: 4 additions & 6 deletions src/canvas/PoolMembers/Prompts/UnbondMember.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright 2024 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import {
ModalNotes,
ModalPadding,
ModalWarnings,
Polkicon,
} from '@polkadot-cloud/react';
import { Polkicon } from '@polkadot-cloud/react';
import {
ellipsisFn,
greaterThanZero,
Expand All @@ -32,6 +27,9 @@ import { useActiveAccounts } from 'contexts/ActiveAccounts';
import { usePrompt } from 'contexts/Prompt';
import type { PoolMembership } from 'contexts/Pools/types';
import { Title } from 'library/Prompt/Title';
import { ModalPadding } from 'kits/Overlay/structure/ModalPadding';
import { ModalWarnings } from 'kits/Overlay/structure/ModalWarnings';
import { ModalNotes } from 'kits/Overlay/structure/ModalNotes';

export const UnbondMember = ({
who,
Expand Down
10 changes: 4 additions & 6 deletions src/canvas/PoolMembers/Prompts/WithdrawMember.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright 2024 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import {
ModalNotes,
ModalPadding,
ModalWarnings,
Polkicon,
} from '@polkadot-cloud/react';
import { Polkicon } from '@polkadot-cloud/react';
import {
ellipsisFn,
isNotZero,
Expand All @@ -29,6 +24,9 @@ import type { PoolMembership } from 'contexts/Pools/types';
import { usePrompt } from 'contexts/Prompt';
import { Title } from 'library/Prompt/Title';
import { useTranslation } from 'react-i18next';
import { ModalPadding } from 'kits/Overlay/structure/ModalPadding';
import { ModalWarnings } from 'kits/Overlay/structure/ModalWarnings';
import { ModalNotes } from 'kits/Overlay/structure/ModalNotes';

export const WithdrawMember = ({
who,
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/PoolMembers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import { faTimes } from '@fortawesome/free-solid-svg-icons';
import { useOverlay } from '@polkadot-cloud/react/hooks';
import { useOverlay } from 'kits/Overlay/Provider';
import { CanvasFullScreenWrapper } from 'canvas/Wrappers';
import { Members } from 'canvas/PoolMembers/Members';
import { useTranslation } from 'react-i18next';
Expand Down
2 changes: 2 additions & 0 deletions src/canvas/Wrappers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CanvasFullScreenWrapper = styled.div`
padding-top: 3rem;
min-height: calc(100vh - 12rem);
padding-bottom: 2rem;
width: 100%;
> .head {
display: flex;
Expand All @@ -24,4 +25,5 @@ export const CanvasSubmitTxFooter = styled.div`
border-radius: 1rem;
overflow: hidden;
margin-bottom: 2rem;
width: 100%;
`;
65 changes: 65 additions & 0 deletions src/kits/Overlay/Background.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2024 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { useAnimation } from 'framer-motion';
import { useEffect } from 'react';
import type { CanvasStatus } from './Provider/types';
import { ModalOverlay } from './structure/ModalOverlay';
import { useOverlay } from './Provider';

export const Background = ({
externalOverlayStatus,
}: {
externalOverlayStatus?: CanvasStatus;
}) => {
const controls = useAnimation();
const {
modal: { status: modalStatus },
canvas: { status: canvasStatus },
} = useOverlay();

let { openOverlayInstances } = useOverlay();
if (externalOverlayStatus === 'open') {
openOverlayInstances++;
}

const onIn = async () => await controls.start('visible');

const onOut = async () => await controls.start('hidden');

useEffect(() => {
if (openOverlayInstances > 0) {
onIn();
}
if (openOverlayInstances === 0) {
onOut();
}
}, [openOverlayInstances]);

return modalStatus === 'closed' &&
canvasStatus === 'closed' &&
externalOverlayStatus === 'closed' ? null : (
<ModalOverlay
blur={
canvasStatus === 'open' || externalOverlayStatus === 'open'
? '1.4rem'
: '0.4rem'
}
initial={{
opacity: 0,
}}
animate={controls}
transition={{
duration: 0.15,
}}
variants={{
hidden: {
opacity: 0,
},
visible: {
opacity: 1,
},
}}
/>
);
};
104 changes: 104 additions & 0 deletions src/kits/Overlay/Canvas.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2024 @paritytech/polkadot-staking-dashboard authors & contributors
// SPDX-License-Identifier: GPL-3.0-only

import { useAnimation } from 'framer-motion';
import type { FC } from 'react';
import { useEffect } from 'react';
import type { CanvasProps } from './Provider/types';
import { ErrorBoundary } from 'react-error-boundary';
import { CanvasContainer } from './structure/CanvasContainer';
import { CanvasScroll } from './structure/CanvasScroll';
import { ModalContent } from './structure/ModalContent';
import { CanvasContent } from './structure/CanvasContent';
import { useOverlay } from './Provider';

export const Canvas = ({
canvas,
externalOverlayStatus,
fallback: Fallback,
}: CanvasProps) => {
const controls = useAnimation();
const {
setOpenOverlayInstances,
activeOverlayInstance,
setActiveOverlayInstance,
modal: { status: modalStatus },
canvas: {
status,
setCanvasStatus,
config: { key, size, scroll },
},
} = useOverlay();

const onIn = async () => {
await controls.start('visible');
};

const onOut = async (closing: boolean) => {
if (closing) {
setOpenOverlayInstances('dec', 'canvas');
setActiveOverlayInstance(modalStatus === 'open' ? 'modal' : null);
}
await controls.start('hidden');

if (closing) {
setCanvasStatus('closed');
}
};

// Control dim help status change.
useEffect(() => {
if (externalOverlayStatus === 'open' && status === 'open') {
onOut(false);
}

if (externalOverlayStatus === 'closing') {
if (activeOverlayInstance === 'canvas') {
setCanvasStatus('open');
onIn();
}
}
}, [externalOverlayStatus]);

// Control fade in and out on opening and closing states.
useEffect(() => {
if (status === 'open') {
onIn();
}
if (status === 'closing') {
onOut(true);
}
}, [status]);

const ActiveCanvas: FC | null = canvas?.[key] || null;

return status === 'closed' ? null : (
<CanvasContainer
initial={{
opacity: 0,
}}
animate={controls}
transition={{
duration: 0.15,
}}
variants={{
hidden: {
opacity: 0,
},
visible: {
opacity: 1,
},
}}
>
<CanvasScroll size={size} scroll={scroll || false}>
<ModalContent canvas>
<CanvasContent>
<ErrorBoundary FallbackComponent={Fallback}>
{ActiveCanvas && <ActiveCanvas />}
</ErrorBoundary>
</CanvasContent>
</ModalContent>
</CanvasScroll>
</CanvasContainer>
);
};
Loading

0 comments on commit e1cd02f

Please sign in to comment.