index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2017-2020 @polkadot/app-toolbox authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { AppProps as Props } from '@polkadot/react-components/types';
  5. import React, { useMemo } from 'react';
  6. import { Route, Switch } from 'react-router';
  7. import Tabs from '@polkadot/react-components/Tabs';
  8. import { useAccounts } from '@polkadot/react-hooks';
  9. import Hash from './Hash';
  10. import Rpc from './Rpc';
  11. import Sign from './Sign';
  12. import Verify from './Verify';
  13. import { useTranslation } from './translate';
  14. function ToolboxApp ({ basePath }: Props): React.ReactElement<Props> {
  15. const { t } = useTranslation();
  16. const { hasAccounts } = useAccounts();
  17. const items = useMemo(() => [
  18. {
  19. isRoot: true,
  20. name: 'rpc',
  21. text: t<string>('RPC calls')
  22. },
  23. {
  24. name: 'hash',
  25. text: t<string>('Hash data')
  26. },
  27. {
  28. name: 'sign',
  29. text: t<string>('Sign message')
  30. },
  31. {
  32. name: 'verify',
  33. text: t<string>('Verify signature')
  34. }
  35. ], [t]);
  36. return (
  37. <main className='toolbox--App'>
  38. <header>
  39. <Tabs
  40. basePath={basePath}
  41. hidden={
  42. hasAccounts
  43. ? []
  44. : ['sign', 'verify']
  45. }
  46. items={items}
  47. />
  48. </header>
  49. <Switch>
  50. <Route path={`${basePath}/hash`}><Hash /></Route>
  51. <Route path={`${basePath}/sign`}><Sign /></Route>
  52. <Route path={`${basePath}/verify`}><Verify /></Route>
  53. <Route><Rpc /></Route>
  54. </Switch>
  55. </main>
  56. );
  57. }
  58. export default React.memo(ToolboxApp);