= ApiContext.Provider;
10 |
11 | export default ApiContext;
12 |
13 | export { ApiConsumer, ApiProvider };
14 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/hoc/calls.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable @typescript-eslint/no-explicit-any */
2 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | import React from 'react';
6 | import type { ApiProps, SubtractProps } from '../types';
7 | import withCall from './call';
8 | import type { Options } from './types';
9 |
10 | type Call = string | [string, Options];
11 |
12 | export default function withCalls(
13 | ...calls: Call[]
14 | ): (Component: React.ComponentType
) => React.ComponentType> {
15 | return (Component: React.ComponentType): React.ComponentType => {
16 | // NOTE: Order is reversed so it makes sense in the props, i.e. component
17 | // after something can use the value of the preceding version
18 | return calls.reverse().reduce((Comp, call): React.ComponentType => {
19 | return Array.isArray(call) ? withCall(...call)(Comp as any) : withCall(call)(Comp as any);
20 | }, Component);
21 | };
22 | }
23 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/hoc/index.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | export { default as withApi } from './api';
5 | export { default as withCall } from './call';
6 | export { default as withCalls } from './calls';
7 | export { default as withCallDiv } from './callDiv';
8 | export { default as withMulti } from './multi';
9 | export { default as withObservable } from './observable';
10 | export * from './onlyOn';
11 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/hoc/multi.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable @typescript-eslint/no-explicit-any */
2 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | import React from 'react';
6 |
7 | type HOC = (Component: React.ComponentType) => React.ComponentType;
8 |
9 | export default function withMulti(Component: React.ComponentType, ...hocs: HOC[]): React.ComponentType {
10 | // NOTE: Order is reversed so it makes sense in the props, i.e. component
11 | // after something can use the value of the preceding version
12 | return hocs.reverse().reduce((Comp, hoc): React.ComponentType => hoc(Comp), Component);
13 | }
14 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/hoc/onlyOn.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/app-accounts authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 | /* eslint-disable @typescript-eslint/no-explicit-any */
4 |
5 | import { ComponentType } from 'react';
6 | import type { Environment } from '../types';
7 | import { getEnvironment } from '../util';
8 |
9 | const onlyOn =
10 | (environment: Environment) =>
11 | >(component: T): T | (() => null) => {
12 | if (getEnvironment() === environment) {
13 | return component;
14 | }
15 |
16 | return () => null;
17 | };
18 |
19 | export const onlyOnWeb = onlyOn('web');
20 | export const onlyOnApp = onlyOn('app');
21 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/index.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import Api, { api, DEFAULT_DECIMALS, DEFAULT_SS58 } from './Api';
5 | import ApiContext from './ApiContext';
6 | import { withApi, withCallDiv, withCalls, withMulti, withObservable } from './hoc';
7 |
8 | export {
9 | api,
10 | Api,
11 | ApiContext,
12 | DEFAULT_DECIMALS,
13 | DEFAULT_SS58,
14 | withApi,
15 | withCalls,
16 | withCallDiv,
17 | withMulti,
18 | withObservable,
19 | };
20 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/transform/echo.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
5 | export default function echoTransform(x: T, _: number): T {
6 | return x;
7 | }
8 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/typeRegistry.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import { TypeRegistry } from '@polkadot/types/create';
5 |
6 | const registry = new TypeRegistry();
7 |
8 | export default registry;
9 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/util/getEnvironment.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable @typescript-eslint/no-explicit-any */
2 | // Copyright 2017-2021 @polkadot/app-accounts authors & contributors
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | import type { Environment } from '../types';
6 |
7 | // https://github.com/electron/electron/issues/2288
8 | function isElectron() {
9 | if ((process?.versions as any)?.electron) {
10 | return true;
11 | }
12 |
13 | if ((window?.process as any)?.type === 'renderer') {
14 | return true;
15 | }
16 |
17 | return navigator?.userAgent?.indexOf('Electron') >= 0;
18 | }
19 |
20 | export default function getEnvironment(): Environment {
21 | if (isElectron()) {
22 | return 'app';
23 | }
24 |
25 | return 'web';
26 | }
27 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/util/historic.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import type { Hash } from '@polkadot/types/interfaces';
5 | import type { Codec } from '@polkadot/types/types';
6 |
7 | // eslint-disable-next-line
8 | type AtQuery = (hash: string | Uint8Array, ...params: I) => Promise;
9 |
10 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
11 | export default async function getHistoric(
12 | atQuery: AtQuery,
13 | params: I,
14 | hashes: Hash[]
15 | ): Promise<[Hash, T][]> {
16 | return Promise.all(hashes.map((hash): Promise => atQuery(hash, ...params) as Promise)).then(
17 | (results): [Hash, T][] => results.map((value, index): [Hash, T] => [hashes[index], value])
18 | );
19 | }
20 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/util/index.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import getEnvironment from './getEnvironment';
5 | import getHistoric from './historic';
6 | import intervalObservable from './intervalObservable';
7 | import isEqual from './isEqual';
8 | import triggerChange from './triggerChange';
9 |
10 | export { getHistoric, intervalObservable, isEqual, triggerChange, getEnvironment };
11 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/util/intervalObservable.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-magic-numbers */
2 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | import { interval, Subscription } from '@polkadot/x-rxjs';
6 | import type { CallState } from '../types';
7 |
8 | const interval$ = interval(500);
9 |
10 | export default function intervalObservable(
11 | that: React.Component
12 | ): Subscription {
13 | return interval$.subscribe((): void => {
14 | const elapsed = Date.now() - ((that.state.callUpdatedAt as number) || 0);
15 | const callUpdated = elapsed <= 1500;
16 |
17 | if (callUpdated !== that.state.callUpdated) {
18 | that.setState({
19 | callUpdated,
20 | });
21 | }
22 | });
23 | }
24 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/util/isEqual.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | function flatten(key: string | null, value?: unknown): unknown {
5 | return !value
6 | ? value
7 | : (value as Record).$$typeof
8 | ? ''
9 | : Array.isArray(value)
10 | ? value.map((item) => flatten(null, item))
11 | : value;
12 | }
13 |
14 | export default function isEqual(a?: T, b?: T): boolean {
15 | return JSON.stringify({ test: a }, flatten) === JSON.stringify({ test: b }, flatten);
16 | }
17 |
--------------------------------------------------------------------------------
/src/packages/react-api/src/util/triggerChange.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import { isFunction, isObservable } from '@polkadot/util';
5 | import type { OnChangeCb } from '../types';
6 |
7 | export default function triggerChange(value?: unknown, ...callOnResult: (OnChangeCb | undefined)[]): void {
8 | if (!callOnResult || !callOnResult.length) {
9 | return;
10 | }
11 |
12 | // eslint-disable-next-line @typescript-eslint/no-shadow
13 | callOnResult.forEach((callOnResult): void => {
14 | if (isObservable(callOnResult)) {
15 | callOnResult.next(value);
16 | } else if (isFunction(callOnResult)) {
17 | callOnResult(value);
18 | }
19 | });
20 | }
21 |
--------------------------------------------------------------------------------
/src/packages/react-api/test/enzyme.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable @typescript-eslint/no-var-requires */
2 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
3 | // SPDX-License-Identifier: Apache-2.0
4 |
5 | const Adapter = require('enzyme-adapter-react-16');
6 | const Enzyme = require('enzyme');
7 |
8 | Enzyme.configure({
9 | adapter: new Adapter(),
10 | });
11 |
12 | module.exports = Enzyme;
13 |
--------------------------------------------------------------------------------
/src/packages/react-api/test/observable.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable no-magic-numbers */
2 | /* eslint-disable @typescript-eslint/no-var-requires */
3 | // Copyright 2017-2021 @polkadot/react-api authors & contributors
4 | // SPDX-License-Identifier: Apache-2.0
5 |
6 | const createObservable = require('@polkadot/api-rx/observable');
7 |
8 | module.exports = function observable(method) {
9 | const fn = () => Promise.resolve(12345);
10 |
11 | fn.unsubscribe = () => Promise.resolve(true);
12 |
13 | return createObservable(`section_${method}`, method, {
14 | [method]: fn,
15 | })();
16 | };
17 |
--------------------------------------------------------------------------------
/src/packages/react-components/.skip-build:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subscan-explorer/subscan-multisig-react/20c580c14fd077ab6327ced9a573973330d47324/src/packages/react-components/.skip-build
--------------------------------------------------------------------------------
/src/packages/react-components/.skip-npm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/subscan-explorer/subscan-multisig-react/20c580c14fd077ab6327ced9a573973330d47324/src/packages/react-components/.skip-npm
--------------------------------------------------------------------------------
/src/packages/react-components/README.md:
--------------------------------------------------------------------------------
1 | # @polkadot/react-components
2 |
3 | WARNING: This is an internal package to [polkadot-js/apps](https://github.com/polkadot-js/apps) so is not inteded (yet) for broad use.
4 |
5 | For the existing sharable components usable in external React-based projects, take a look at the [polkadot-js/ui documentation](https://polkadot.js.org/ui/)
6 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/Available.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-components authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
5 |
6 | import React from 'react';
7 |
8 | import { Available } from '@polkadot/react-query';
9 |
10 | export interface Props {
11 | className?: string;
12 | label?: React.ReactNode;
13 | params?: AccountId | AccountIndex | Address | string | Uint8Array | null;
14 | }
15 |
16 | function AvailableDisplay({ className = '', label, params }: Props): React.ReactElement | null {
17 | if (!params) {
18 | return null;
19 | }
20 |
21 | return ;
22 | }
23 |
24 | export default React.memo(AvailableDisplay);
25 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/BatchWarning.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/app-accounts authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import React from 'react';
5 |
6 | import { isFunction } from '@polkadot/util';
7 | import { useApi } from '@polkadot/react-hooks';
8 |
9 | import { useTranslation } from './translate';
10 | import { MarkWarning } from '.';
11 |
12 | function BatchWarning(): React.ReactElement | null {
13 | const { t } = useTranslation();
14 | const { api } = useApi();
15 |
16 | if (isFunction(api.tx.utility.batchAll)) {
17 | return null;
18 | }
19 |
20 | return (
21 | (
23 | 'This chain does not yet support atomic batch operations. This means that if the transaction gets executed and one of the operations do fail (due to invalid data or lack of available funds) some of the changes made may not be applied.'
24 | )}
25 | />
26 | );
27 | }
28 |
29 | export default React.memo(BatchWarning);
30 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/Bonded.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-components authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import type BN from 'bn.js';
5 | import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
6 |
7 | import React from 'react';
8 |
9 | import { Bonded } from '@polkadot/react-query';
10 |
11 | import { renderProvided } from './Balance';
12 |
13 | export interface Props {
14 | bonded?: BN | BN[];
15 | className?: string;
16 | label?: React.ReactNode;
17 | params?: AccountId | AccountIndex | Address | string | Uint8Array | null;
18 | withLabel?: boolean;
19 | }
20 |
21 | function BondedDisplay(props: Props): React.ReactElement | null {
22 | const { bonded, className = '', label, params } = props;
23 |
24 | if (!params) {
25 | return null;
26 | }
27 |
28 | return bonded ? (
29 | <>{renderProvided({ className, label, value: bonded })}>
30 | ) : (
31 |
32 | );
33 | }
34 |
35 | export default React.memo(BondedDisplay);
36 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/Button/Group.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-components authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import React from 'react';
5 | import styled from 'styled-components';
6 | import type { GroupProps } from './types';
7 |
8 | function ButtonGroup({ children, className = '', isCentered }: GroupProps): React.ReactElement {
9 | return {children}
;
10 | }
11 |
12 | export default React.memo(styled(ButtonGroup)`
13 | margin: 1rem 0;
14 | text-align: right;
15 |
16 | &.isCentered {
17 | margin-bottom: 0.5rem;
18 | text-align: center;
19 | }
20 |
21 | & + .ui--Table {
22 | margin-top: 1.5rem;
23 | }
24 |
25 | .ui--Button {
26 | margin: 0 0.25rem;
27 | }
28 |
29 | .ui--CopyButton {
30 | display: inline-block;
31 | }
32 | `);
33 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/Button/index.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-components authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import type { ButtonType } from './types';
5 |
6 | import IButton from './Button';
7 | import Group from './Group';
8 |
9 | const Button = IButton as unknown as ButtonType;
10 |
11 | Button.Group = Group;
12 |
13 | export default Button;
14 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/Button/types.ts:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-components authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import type { IconName } from '@fortawesome/fontawesome-svg-core';
5 | import type { BareProps } from '../types';
6 |
7 | export type Button$Callback = () => void | Promise;
8 |
9 | export interface ButtonProps {
10 | children?: React.ReactNode;
11 | className?: string;
12 | dataTestId?: string;
13 | icon: IconName;
14 | isBasic?: boolean;
15 | isBusy?: boolean;
16 | isCircular?: boolean;
17 | isDisabled?: boolean;
18 | isFull?: boolean;
19 | isIcon?: boolean;
20 | isSelected?: boolean;
21 | isToplevel?: boolean;
22 | label?: React.ReactNode;
23 | onClick?: Button$Callback;
24 | onMouseEnter?: Button$Callback;
25 | onMouseLeave?: Button$Callback;
26 | tabIndex?: number;
27 | tooltip?: React.ReactNode;
28 | withoutLink?: boolean;
29 | }
30 |
31 | export type DividerProps = BareProps;
32 |
33 | export interface GroupProps {
34 | children?: React.ReactNode;
35 | className?: string;
36 | isCentered?: boolean;
37 | }
38 |
39 | export type ButtonType = React.ComponentType & {
40 | Group: React.ComponentType;
41 | };
42 |
--------------------------------------------------------------------------------
/src/packages/react-components/src/ButtonCancel.tsx:
--------------------------------------------------------------------------------
1 | // Copyright 2017-2021 @polkadot/react-components authors & contributors
2 | // SPDX-License-Identifier: Apache-2.0
3 |
4 | import React from 'react';
5 |
6 | import Button from './Button';
7 | import { useTranslation } from './translate';
8 |
9 | interface Props {
10 | className?: string;
11 | isDisabled?: boolean;
12 | label?: string;
13 | onClick: () => void;
14 | tabIndex?: number;
15 | }
16 |
17 | function ButtonCancel({ className = '', isDisabled, label, onClick, tabIndex }: Props): React.ReactElement {
18 | const { t } = useTranslation();
19 |
20 | return (
21 |