Banner.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2017-2019 @polkadot/app-accounts 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 { I18nProps } from '@polkadot/react-components/types';
  5. import { detect } from 'detect-browser';
  6. import React from 'react';
  7. import styled from 'styled-components';
  8. import { isWeb3Injected } from '@polkadot/extension-dapp';
  9. import { stringUpperFirst } from '@polkadot/util';
  10. import translate from './translate';
  11. // it would have been really good to import this from detect, however... not exported
  12. type Browser = 'chrome' | 'firefox';
  13. interface Extension {
  14. desc: string;
  15. link: string;
  16. name: string;
  17. }
  18. interface Props extends I18nProps {
  19. className?: string;
  20. }
  21. const available: Record<Browser, Extension[]> = {
  22. chrome: [],
  23. firefox: []
  24. };
  25. [
  26. {
  27. browsers: {
  28. chrome: 'https://chrome.google.com/webstore/detail/polkadot%7Bjs%7D-extension/mopnmbcafieddcagagdcbnhejhlodfdd',
  29. firefox: 'https://addons.mozilla.org/en-US/firefox/addon/polkadot-js-extension/'
  30. },
  31. desc: 'Basic account injection and signer',
  32. name: 'polkadot-js extension'
  33. }
  34. ].forEach(({ browsers, desc, name }): void => {
  35. Object.entries(browsers).forEach(([browser, link]): void => {
  36. available[browser as Browser].push({ link, desc, name });
  37. });
  38. });
  39. const browserInfo = detect();
  40. const browserName: Browser | null = (browserInfo && (browserInfo.name as Browser)) || null;
  41. const isSupported = browserName && Object.keys(available).includes(browserName);
  42. function Banner ({ className, t }: Props): React.ReactElement<Props> | null {
  43. if (isWeb3Injected || !isSupported || !browserName) {
  44. return null;
  45. }
  46. return (
  47. <div className={className}>
  48. <div className='box'>
  49. <div className='info'>
  50. <p>{t('It is recommended that you create/store your accounts securely and externally from the app. On {{yourBrowser}} the following browser extensions are available for use -', {
  51. replace: {
  52. yourBrowser: stringUpperFirst(browserName)
  53. }
  54. })}</p>
  55. <ul>{available[browserName].map(({ desc, name, link }): React.ReactNode => (
  56. <li key={name}>
  57. <a
  58. href={link}
  59. rel='noopener noreferrer'
  60. target='_blank'
  61. >
  62. {name}
  63. </a> ({desc})
  64. </li>
  65. ))
  66. }</ul>
  67. <p>{t('Accounts injected from any of these extensions will appear in this application and be available for use. The above list is updated as more extensions with external signing capability become available.')}&nbsp;<a
  68. href='https://github.com/polkadot-js/extension'
  69. rel='noopener noreferrer'
  70. target='_blank'
  71. >{t('Learn more...')}</a></p>
  72. </div>
  73. </div>
  74. </div>
  75. );
  76. }
  77. export default translate(
  78. styled(Banner)`
  79. padding: 0 0.5rem 0.5rem;
  80. .box {
  81. background: #fff6e5;
  82. border-left: 0.25rem solid darkorange;
  83. border-radius: 0 0.25rem 0.25rem 0;
  84. box-sizing: border-box;
  85. padding: 1rem 1.5rem;
  86. .info {
  87. max-width: 50rem;
  88. }
  89. }
  90. `
  91. );