Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/react-qr/src/NetworkSpecs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2017-2020 @polkadot/react-qr authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { NetworkSpecsStruct } from '@polkadot/ui-settings';

import React, { useEffect, useState } from 'react';
import QrDisplay from './Display';
import { BaseProps } from './types';

import { encodeString } from './util';

interface Props extends BaseProps {
networkSpecs: NetworkSpecsStruct;
}

function DisplayNetworkSpecs ({ className, networkSpecs, size, style }: Props): React.ReactElement<Props> | null {
const [data, setData] = useState<Uint8Array | null>(null);

useEffect((): void => {
setData(encodeString(JSON.stringify(networkSpecs)));
}, [networkSpecs]);

if (!data) {
return null;
}

return (
<QrDisplay
className={className}
skipEncoding={true}
size={size}
style={style}
value={data}
/>
);
}

export default React.memo(DisplayNetworkSpecs);
1 change: 1 addition & 0 deletions packages/react-qr/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as QrDisplayAddress } from './DisplayAddress';
export { default as QrDisplayPayload } from './DisplayPayload';
export { default as QrScanAddress } from './ScanAddress';
export { default as QrScanSignature } from './ScanSignature';
export { default as QrNetworkSpecs } from './NetworkSpecs';
2 changes: 1 addition & 1 deletion packages/ui-settings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import settings, { Settings } from './Settings';
export { ENDPOINT_DEFAULT, ICON_DEFAULT, ICON_DEFAULT_HOST, LANGUAGE_DEFAULT, LOCKING_DEFAULT, PREFIX_DEFAULT, UIMODE_DEFAULT, UITHEME_DEFAULT } from './defaults';
export { SettingsStruct } from './types';
export { SettingsStruct, NetworkSpecsStruct } from './types';

export default settings;

Expand Down
9 changes: 9 additions & 0 deletions packages/ui-settings/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ export interface SettingsStruct {
uiMode: string;
uiTheme: string;
}

export interface NetworkSpecsStruct {
color: string;
decimals: number;
genesisHash: string;
prefix: number;
title: string;
unit: string;
}