Simple ipfs gateway detection (#2781)
* Simple ipfs gateway detection * Include ipns
This commit is contained in:
parent
3f11ff0a22
commit
6038a4b9ab
@ -16,6 +16,7 @@ import { FormatBalance } from '@polkadot/react-query';
|
||||
import { Button, Input, Table } from '@polkadot/react-components';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import useIsIpfs from './useIsIpfs';
|
||||
import CreateModal from './modals/Create';
|
||||
import ImportModal from './modals/Import';
|
||||
import Multisig from './modals/MultisigCreate';
|
||||
@ -94,6 +95,7 @@ function Overview ({ className, onStatusChange }: Props): React.ReactElement<Pro
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { allAccounts } = useAccounts();
|
||||
const isIpfs = useIsIpfs();
|
||||
const [isCreateOpen, toggleCreate] = useToggle();
|
||||
const [isImportOpen, toggleImport] = useToggle();
|
||||
const [isMultisigOpen, toggleMultisig] = useToggle();
|
||||
@ -185,11 +187,13 @@ function Overview ({ className, onStatusChange }: Props): React.ReactElement<Pro
|
||||
<Button.Group>
|
||||
<Button
|
||||
icon='add'
|
||||
isDisabled={isIpfs}
|
||||
label={t('Add account')}
|
||||
onClick={toggleCreate}
|
||||
/>
|
||||
<Button
|
||||
icon='sync'
|
||||
isDisabled={isIpfs}
|
||||
label={t('Restore JSON')}
|
||||
onClick={toggleImport}
|
||||
/>
|
||||
|
||||
13
packages/page-accounts/src/Accounts/useIsIpfs.ts
Normal file
13
packages/page-accounts/src/Accounts/useIsIpfs.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2020 @polkadot/app-accounts 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 { useState } from 'react';
|
||||
|
||||
const KNOWN = ['/ipfs/', '/ipns/'];
|
||||
|
||||
export default function useIsIpfs (): boolean {
|
||||
const [isIpfs] = useState(KNOWN.some((part) => window.location.href.includes(part)));
|
||||
|
||||
return isIpfs;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user