Limit Ledger capabilities per chain (#1629)
* Limit Ledger capabilities per chain * Linting & Props
This commit is contained in:
parent
98794cb3b8
commit
089719c97e
@ -9,14 +9,11 @@ import store from 'store';
|
||||
import styled from 'styled-components';
|
||||
import { getTypeRegistry } from '@polkadot/types';
|
||||
import { Button, Editor, InputFile } from '@polkadot/react-components';
|
||||
import { ActionStatus } from '@polkadot/react-components/Status/types';
|
||||
import { isJsonObject, stringToU8a, u8aToString } from '@polkadot/util';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
interface Props extends AppProps, I18nProps {
|
||||
onStatusChange: (status: ActionStatus) => void;
|
||||
}
|
||||
interface Props extends AppProps, I18nProps {}
|
||||
|
||||
interface State {
|
||||
code: string;
|
||||
@ -182,10 +179,12 @@ class Developer extends React.PureComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(styled(Developer)`
|
||||
.editor {
|
||||
height: 21rem;
|
||||
margin-left: 2rem;
|
||||
position: relative;
|
||||
}
|
||||
`);
|
||||
export default translate(
|
||||
styled(Developer)`
|
||||
.editor {
|
||||
height: 21rem;
|
||||
margin-left: 2rem;
|
||||
position: relative;
|
||||
}
|
||||
`
|
||||
);
|
||||
|
||||
@ -7,6 +7,7 @@ import { Option } from './types';
|
||||
|
||||
import queryString from 'query-string';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { isLedgerCapable } from '@polkadot/react-api';
|
||||
import { Button, Dropdown } from '@polkadot/react-components';
|
||||
import { ActionStatus } from '@polkadot/react-components/Status/types';
|
||||
import uiSettings from '@polkadot/ui-settings';
|
||||
@ -86,7 +87,7 @@ function General ({ className, t }: Props): React.ReactElement<Props> {
|
||||
options={uiSettings.availableUIModes}
|
||||
/>
|
||||
</div>
|
||||
{WITH_LEDGER && (
|
||||
{WITH_LEDGER && isLedgerCapable() && (
|
||||
<div className='ui--row'>
|
||||
<Dropdown
|
||||
defaultValue={ledgerConn}
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AppProps, I18nProps } from '@polkadot/react-components/types';
|
||||
import { TabItem } from '@polkadot/react-components/Tabs';
|
||||
|
||||
import React from 'react';
|
||||
import { Route, Switch } from 'react-router';
|
||||
|
||||
import { HelpOverlay, Tabs } from '@polkadot/react-components';
|
||||
import uiSettings from '@polkadot/ui-settings';
|
||||
|
||||
@ -17,65 +17,44 @@ import General from './General';
|
||||
|
||||
interface Props extends AppProps, I18nProps {}
|
||||
|
||||
interface State {
|
||||
tabs: TabItem[];
|
||||
}
|
||||
|
||||
const hidden = uiSettings.uiMode === 'full'
|
||||
? []
|
||||
: ['developer'];
|
||||
|
||||
class App extends React.PureComponent<Props, State> {
|
||||
public constructor (props: Props) {
|
||||
super(props);
|
||||
|
||||
const { t } = props;
|
||||
|
||||
this.state = {
|
||||
tabs: [
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'general',
|
||||
text: t('General')
|
||||
},
|
||||
{
|
||||
name: 'developer',
|
||||
text: t('Developer')
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { basePath } = this.props;
|
||||
const { tabs } = this.state;
|
||||
|
||||
function App (props: Props): React.ReactElement<Props> {
|
||||
const _renderDeveloper = (): React.ReactNode => {
|
||||
return (
|
||||
<main className='settings--App'>
|
||||
<HelpOverlay md={md} />
|
||||
<header>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
hidden={hidden}
|
||||
items={tabs}
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
<Route path={`${basePath}/developer`} render={this.DeveloperWithStatus} />
|
||||
<Route component={General} />
|
||||
</Switch>
|
||||
</main>
|
||||
<Developer {...props} />
|
||||
);
|
||||
}
|
||||
};
|
||||
const { basePath, t } = props;
|
||||
|
||||
private DeveloperWithStatus = (): React.ReactNode => {
|
||||
return (
|
||||
<Developer
|
||||
onStatusChange={this.props.onStatusChange}
|
||||
{...this.props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<main className='settings--App'>
|
||||
<HelpOverlay md={md} />
|
||||
<header>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
hidden={hidden}
|
||||
items={[
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'general',
|
||||
text: t('General')
|
||||
},
|
||||
{
|
||||
name: 'developer',
|
||||
text: t('Developer')
|
||||
}
|
||||
]}
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
<Route path={`${basePath}/developer`} render={_renderDeveloper} />
|
||||
<Route component={General} />
|
||||
</Switch>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export default translate(App);
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AppProps, BareProps, I18nProps } from '@polkadot/react-components/types';
|
||||
import { TabItem } from '@polkadot/react-components/Tabs';
|
||||
|
||||
import React from 'react';
|
||||
import { Route, Switch } from 'react-router';
|
||||
@ -17,51 +16,32 @@ import translate from './translate';
|
||||
|
||||
interface Props extends AppProps, BareProps, I18nProps {}
|
||||
|
||||
interface State {
|
||||
tabs: TabItem[];
|
||||
}
|
||||
|
||||
class App extends React.PureComponent<Props, State> {
|
||||
public constructor (props: Props) {
|
||||
super(props);
|
||||
|
||||
const { t } = props;
|
||||
|
||||
this.state = {
|
||||
tabs: [
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'overview',
|
||||
text: t('Treasury overview')
|
||||
}
|
||||
// {
|
||||
// name: 'settings',
|
||||
// text: t('Edit settings')
|
||||
// }
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { basePath } = this.props;
|
||||
const { tabs } = this.state;
|
||||
|
||||
return (
|
||||
<main className='treasury--App'>
|
||||
<HelpOverlay md={basicMd} />
|
||||
<header>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
items={tabs}
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
{/* <Route path={`${basePath}/settings`} component={Settings} /> */}
|
||||
<Route component={Overview} />
|
||||
</Switch>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
function App ({ basePath, t }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<main className='treasury--App'>
|
||||
<HelpOverlay md={basicMd} />
|
||||
<header>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
items={[
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'overview',
|
||||
text: t('Treasury overview')
|
||||
}
|
||||
// {
|
||||
// name: 'settings',
|
||||
// text: t('Edit settings')
|
||||
// }
|
||||
]}
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
{/* <Route path={`${basePath}/settings`} component={Settings} /> */}
|
||||
<Route component={Overview} />
|
||||
</Switch>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export default translate(App);
|
||||
|
||||
@ -5,10 +5,24 @@
|
||||
import { Ledger } from '@polkadot/ui-keyring';
|
||||
import uiSettings from '@polkadot/ui-settings';
|
||||
|
||||
import { api } from './Api';
|
||||
|
||||
const ALLOWED_CHAINS = [
|
||||
'0x3fd7b9eb6a00376e5be61f01abb429ffb0b104be05eaff4d458da48fcd425baf' // Kusama CC1
|
||||
];
|
||||
|
||||
let ledger: Ledger | null = null;
|
||||
|
||||
export function isLedgerCapable (): boolean {
|
||||
try {
|
||||
return !!api && ALLOWED_CHAINS.includes(api.genesisHash.toHex());
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isLedger (): boolean {
|
||||
return uiSettings.ledgerConn !== 'none';
|
||||
return isLedgerCapable() && uiSettings.ledgerConn !== 'none';
|
||||
}
|
||||
|
||||
export function clearLedger (): void {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user