Simple ipfs gateway detection (#2781)

* Simple ipfs gateway detection

* Include ipns
This commit is contained in:
Jaco Greeff 2020-05-20 21:14:37 +02:00 committed by GitHub
parent 3f11ff0a22
commit 6038a4b9ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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}
/>

View 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;
}