From c70d9a0e635c38f554da01d2b2d9379b02b1c704 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 12 Jul 2019 20:09:44 +0200 Subject: [PATCH] Swap to eslint (#72) * 626 problems (430 errors, 196 warnings) * A start. * < 200 * 80 * 0 --- .eslintignore | 3 + .eslintrc.js | 1 + jest.config.js | 1 + package.json | 2 +- packages/extension-dapp/src/compat/index.ts | 2 +- .../extension-dapp/src/compat/singleSource.ts | 57 +++---- packages/extension-dapp/src/index.ts | 150 ++++++++++-------- packages/extension-dapp/src/types.ts | 19 ++- .../src/Popup/Accounts/Account.tsx | 18 +-- .../extension-ui/src/Popup/Accounts/index.tsx | 12 +- .../src/Popup/Authorize/Request.tsx | 26 +-- .../src/Popup/Authorize/index.tsx | 10 +- packages/extension-ui/src/Popup/Create.tsx | 16 +- packages/extension-ui/src/Popup/Forget.tsx | 12 +- packages/extension-ui/src/Popup/Import.tsx | 18 +-- .../src/Popup/Signing/Details.tsx | 11 +- .../src/Popup/Signing/Request.tsx | 24 +-- .../extension-ui/src/Popup/Signing/Unlock.tsx | 16 +- .../extension-ui/src/Popup/Signing/index.tsx | 10 +- packages/extension-ui/src/Popup/Welcome.tsx | 10 +- packages/extension-ui/src/Popup/index.tsx | 11 +- .../extension-ui/src/components/ActionBar.tsx | 6 +- .../extension-ui/src/components/Address.tsx | 18 +-- packages/extension-ui/src/components/Box.tsx | 6 +- .../extension-ui/src/components/Button.tsx | 62 ++------ .../extension-ui/src/components/Header.tsx | 12 +- packages/extension-ui/src/components/Icon.tsx | 17 +- .../extension-ui/src/components/IconBox.tsx | 16 +- .../extension-ui/src/components/Input.tsx | 52 ++---- .../extension-ui/src/components/Label.tsx | 12 +- packages/extension-ui/src/components/Link.tsx | 34 ++-- .../extension-ui/src/components/Loading.tsx | 8 +- .../extension-ui/src/components/TextArea.tsx | 46 ++---- packages/extension-ui/src/components/Tip.tsx | 40 ++--- packages/extension-ui/src/components/View.tsx | 6 +- .../extension-ui/src/components/contexts.tsx | 15 +- .../extension-ui/src/components/defaults.ts | 2 +- packages/extension-ui/src/components/types.ts | 6 +- .../extension-ui/src/components/unicode.tsx | 2 +- packages/extension-ui/src/createView.tsx | 2 +- packages/extension-ui/src/messaging.ts | 37 ++--- packages/extension-ui/src/partials/Back.tsx | 10 +- packages/extension-ui/src/partials/Name.tsx | 26 +-- .../extension-ui/src/partials/Password.tsx | 12 +- .../src/background/handlers/Extension.ts | 35 ++-- .../src/background/handlers/State.ts | 104 ++++++------ .../extension/src/background/handlers/Tabs.ts | 26 +-- .../src/background/handlers/index.ts | 4 +- .../src/background/handlers/subscriptions.ts | 8 +- packages/extension/src/background/index.ts | 10 +- packages/extension/src/background/types.ts | 119 +++++++------- packages/extension/src/chains/index.ts | 10 +- packages/extension/src/content.ts | 4 +- packages/extension/src/page/Accounts.ts | 9 +- packages/extension/src/page/Injected.ts | 7 +- packages/extension/src/page/Signer.ts | 1 + packages/extension/src/page/index.ts | 23 +-- packages/extension/src/page/types.ts | 1 + packages/extension/webpack.config.js | 4 +- 59 files changed, 598 insertions(+), 643 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..b6f52714 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +**/build/* +**/coverage/* +**/node_modules/* diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..e4f24319 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@polkadot/dev-react/config/eslint'); diff --git a/jest.config.js b/jest.config.js index be2373a8..3794c4a2 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,4 @@ +// eslint-disable-next-line @typescript-eslint/no-var-requires const config = require('@polkadot/dev/config/jest'); module.exports = Object.assign({}, config, { diff --git a/package.json b/package.json index 74c7c6fb..ed2b0a39 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "build": "NODE_ENV=production polkadot-dev-build-ts", "build:zip": "(cd packages/extension/build && zip -r -FS ../../../master-build.zip *)", "check": "yarn lint", - "lint": "tslint --project . && tsc --noEmit --pretty", + "lint": "eslint --ext .js,.jsx,.ts,.tsx . && tsc --noEmit --pretty", "clean": "polkadot-dev-clean-build", "postinstall": "polkadot-dev-yarn-only", "test": "echo \"no tests... yet\"", diff --git a/packages/extension-dapp/src/compat/index.ts b/packages/extension-dapp/src/compat/index.ts index 46a3b382..b8fb91da 100644 --- a/packages/extension-dapp/src/compat/index.ts +++ b/packages/extension-dapp/src/compat/index.ts @@ -8,5 +8,5 @@ import singleSource from './singleSource'; export default function initCompat (): Promise { return Promise.all([ singleSource() - ]).then(() => true); + ]).then((): boolean => true); } diff --git a/packages/extension-dapp/src/compat/singleSource.ts b/packages/extension-dapp/src/compat/singleSource.ts index 41bfec5f..2dd8fc52 100644 --- a/packages/extension-dapp/src/compat/singleSource.ts +++ b/packages/extension-dapp/src/compat/singleSource.ts @@ -3,34 +3,34 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Signer } from '@polkadot/api/types'; -import { InjectedAccount, InjectedWindow } from '../types'; +import { Injected, InjectedAccount, InjectedWindow } from '../types'; // RxJs interface, only the bare-bones of what we need here -type Subscriber = { +interface Subscriber { subscribe: (cb: (value: T) => void) => { - unsubscribe (): any - } -}; + unsubscribe (): void; + }; +} -type SingleSourceAccount = { - address: string, - assets: Array<{ assetId: number }>, - name: string -}; +interface SingleSourceAccount { + address: string; + assets: { assetId: number }[]; + name: string; +} -type SingleSource = { - accounts$: Subscriber>, - environment$: Subscriber, - signer: Signer -}; +interface SingleSource { + accounts$: Subscriber; + environment$: string[]; + signer: Signer; +} type SingleWindow = Window & InjectedWindow & { - SingleSource: SingleSource + SingleSource: SingleSource; }; // transfor the SingleSource accounts into a simple address/name array -function transformAccounts (accounts: Array): Array { - return accounts.map(({ address, name }) => ({ +function transformAccounts (accounts: SingleSourceAccount[]): InjectedAccount[] { + return accounts.map(({ address, name }): InjectedAccount => ({ address, name })); @@ -38,24 +38,25 @@ function transformAccounts (accounts: Array): Array = []; + let accounts: InjectedAccount[] = []; // we don't yet have an accounts subscribe on the interface, simply get the // accounts and store them, any get will resolve the last found values - win.SingleSource.accounts$.subscribe((_accounts) => { + win.SingleSource.accounts$.subscribe((_accounts): void => { accounts = transformAccounts(_accounts); }); // decorate the compat interface win.injectedWeb3['SingleSource'] = { - enable: async (origin: string) => ({ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + enable: async (origin: string): Promise => ({ accounts: { - get: async () => + get: async (): Promise => accounts, - subscribe: (cb: (accounts: Array) => any) => { - const sub = win.SingleSource.accounts$.subscribe((accounts) => - cb(transformAccounts(accounts)) - ); + subscribe: (cb: (accounts: InjectedAccount[]) => void): () => void => { + const sub = win.SingleSource.accounts$.subscribe((accounts): void => { + cb(transformAccounts(accounts)); + }); return (): void => { sub.unsubscribe(); @@ -71,8 +72,8 @@ function injectSingleSource (win: SingleWindow): void { // returns the SingleSource instance, as per // https://github.com/cennznet/singlesource-extension/blob/f7cb35b54e820bf46339f6b88ffede1b8e140de0/react-example/src/App.js#L19 export default function initSingleSource (): Promise { - return new Promise((resolve) => { - window.addEventListener('load', () => { + return new Promise((resolve): void => { + window.addEventListener('load', (): void => { const win = window as SingleWindow; if (win.SingleSource) { diff --git a/packages/extension-dapp/src/index.ts b/packages/extension-dapp/src/index.ts index 9e59232c..ca32b2a6 100644 --- a/packages/extension-dapp/src/index.ts +++ b/packages/extension-dapp/src/index.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { InjectedAccount, InjectedAccountWithMeta, InjectedExtension, InjectedWindow, Unsubcall } from './types'; +import { Injected, InjectedAccount, InjectedAccountWithMeta, InjectedExtension, InjectedExtensionInfo, InjectedWindow, Unsubcall } from './types'; // our extension adaptor for other kinds of extensions import compatInjector from './compat'; @@ -24,8 +24,8 @@ function throwError (method: string): never { } // internal helper to map from Array -> Array -function mapAccounts (source: string, list: Array): Array { - return list.map(({ address, name }) => ({ +function mapAccounts (source: string, list: InjectedAccount[]): InjectedAccountWithMeta[] { + return list.map(({ address, name }): InjectedAccountWithMeta => ({ address, meta: { name, source } })); @@ -35,65 +35,70 @@ function mapAccounts (source: string, list: Array): Array> | null = null; +let web3EnablePromise: Promise | null = null; export { isWeb3Injected, web3EnablePromise }; // enables all the providers found on the injected window interface -export function web3Enable (originName: string): Promise> { - web3EnablePromise = compatInjector().then(() => - Promise.all( - Object.entries(win.injectedWeb3).map(([name, { enable, version }]) => - Promise.all([ - Promise.resolve({ name, version }), - enable(originName).catch((error: Error) => { - console.error(`Error initializing ${name}: ${error.message}`); - }) - ]) - ) - ) - .then((values) => - values - .filter(([, ext]) => ext) - .map(([info, ext]) => { - // if we don't have an accounts subscriber, add a single-shot version - if (ext && !ext.accounts.subscribe) { - ext.accounts.subscribe = (cb: (accounts: Array) => any): Unsubcall => { - ext.accounts.get().then(cb).catch(console.error); +export function web3Enable (originName: string): Promise { + web3EnablePromise = compatInjector() + .then((): Promise => + Promise + .all( + Object.entries(win.injectedWeb3).map(([name, { enable, version }]): Promise<[InjectedExtensionInfo, Injected | void]> => + Promise.all([ + Promise.resolve({ name, version }), + enable(originName).catch((error: Error): void => { + console.error(`Error initializing ${name}: ${error.message}`); + }) + ]) + ) + ) + .then((values: [InjectedExtensionInfo, Injected | void][]): InjectedExtension[] => + values + .filter(([, ext]): boolean => !!ext) + .map(([info, ext]): InjectedExtension => { + // if we don't have an accounts subscriber, add a single-shot version + if (ext && !ext.accounts.subscribe) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ext.accounts.subscribe = (cb: (accounts: InjectedAccount[]) => any): Unsubcall => { + ext.accounts.get().then(cb).catch(console.error); - return (): void => { - // no ubsubscribe needed, this is a single-shot - }; - }; - } + return (): void => { + // no ubsubscribe needed, this is a single-shot + }; + }; + } - return { ...info, ...ext } as InjectedExtension; + const injected: Partial = { ...info, ...ext }; + + return injected as InjectedExtension; + }) + ) + .catch((): InjectedExtension[] => [] as InjectedExtension[]) + .then((values): InjectedExtension[] => { + const names = values.map(({ name, version }): string => `${name}/${version}`); + + isWeb3Injected = web3IsInjected(); + console.log(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`); + + return values; }) - ) - .catch(() => [] as Array) - .then((values) => { - const names = values.map(({ name, version }) => `${name}/${version}`); - - isWeb3Injected = web3IsInjected(); - console.log(`web3Enable: Enabled ${values.length} extension${values.length !== 1 ? 's' : ''}: ${names.join(', ')}`); - - return values; - }) - ); + ); return web3EnablePromise; } // retrieve all the accounts accross all providers -export async function web3Accounts (): Promise> { +export async function web3Accounts (): Promise { if (!web3EnablePromise) { return throwError('web3Accounts'); } - const accounts: Array = []; + const accounts: InjectedAccountWithMeta[] = []; const injected = await web3EnablePromise; const retrieved = await Promise.all( - injected.map(async ({ accounts, name: source }) => { + injected.map(async ({ accounts, name: source }): Promise => { try { const list = await accounts.get(); @@ -105,57 +110,46 @@ export async function web3Accounts (): Promise> { }) ); - retrieved.forEach((result) => accounts.push(...result)); + retrieved.forEach((result): void => { + accounts.push(...result); + }); - const addresses = accounts.map(({ address }) => address); + const addresses = accounts.map(({ address }): string => address); console.log(`web3Accounts: Found ${accounts.length} address${accounts.length !== 1 ? 'es' : ''}: ${addresses.join(', ')}`); return accounts; } -export async function web3AccountsSubscribe (cb: (accounts: Array) => any): Promise { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export async function web3AccountsSubscribe (cb: (accounts: InjectedAccountWithMeta[]) => any): Promise { if (!web3EnablePromise) { return throwError('web3AccountsSubscribe'); } - const accounts: { [source: string]: Array } = {}; + const accounts: Record = {}; const triggerUpdate = (): void => { - cb(Object.entries(accounts).reduce((result, [source, list]) => { + cb(Object.entries(accounts).reduce((result, [source, list]): InjectedAccountWithMeta[] => { result.push(...mapAccounts(source, list)); return result; - }, [] as Array)); + }, [] as InjectedAccountWithMeta[])); }; - const unsubs = (await web3EnablePromise).map(({ accounts: { subscribe }, name: source }) => - subscribe((result) => { + const unsubs = (await web3EnablePromise).map(({ accounts: { subscribe }, name: source }): Unsubcall => + subscribe((result): void => { accounts[source] = result; triggerUpdate(); }) ); return (): void => { - unsubs.forEach((unsub) => unsub()); + unsubs.forEach((unsub): void => { + unsub(); + }); }; } -// find a specific provider based on an address -export async function web3FromAddress (address: string): Promise { - if (!web3EnablePromise) { - return throwError('web3FromAddress'); - } - - const accounts = await web3Accounts(); - const found = address && accounts.find((account) => account.address === address); - - if (!found) { - throw new Error(`web3FromAddress: Unable to find injected ${address}`); - } - - return web3FromSource(found.meta.source); -} - // find a specific provider based on the name export async function web3FromSource (source: string): Promise { if (!web3EnablePromise) { @@ -163,7 +157,7 @@ export async function web3FromSource (source: string): Promise name === source); + const found = source && sources.find(({ name }): boolean => name === source); if (!found) { throw new Error(`web3FromSource: Unable to find an injected ${source}`); @@ -171,3 +165,19 @@ export async function web3FromSource (source: string): Promise { + if (!web3EnablePromise) { + return throwError('web3FromAddress'); + } + + const accounts = await web3Accounts(); + const found = address && accounts.find((account): boolean => account.address === address); + + if (!found) { + throw new Error(`web3FromAddress: Unable to find injected ${address}`); + } + + return web3FromSource(found.meta.source); +} diff --git a/packages/extension-dapp/src/types.ts b/packages/extension-dapp/src/types.ts index 84bb89c2..ec6e33b9 100644 --- a/packages/extension-dapp/src/types.ts +++ b/packages/extension-dapp/src/types.ts @@ -14,17 +14,18 @@ export interface InjectedAccount { export interface InjectedAccountWithMeta { address: string; meta: { - name: string, - source: string + name: string; + source: string; }; } export interface InjectedAccounts { - get: () => Promise>; - subscribe: (cb: (accounts: Array) => any) => Unsubcall; + get: () => Promise; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + subscribe: (cb: (accounts: InjectedAccount[]) => any) => Unsubcall; } -export interface InjectedSigner extends Signer {} +export type InjectedSigner = Signer; export interface InjectedExtensionInfo { name: string; @@ -41,10 +42,8 @@ export interface InjectedWindowProvider { version: string; } -export type InjectedWindow = Window & { - injectedWeb3: { - [index: string]: InjectedWindowProvider - } -}; +export interface InjectedWindow extends Window { + injectedWeb3: Record; +} export type InjectedExtension = InjectedExtensionInfo & Injected; diff --git a/packages/extension-ui/src/Popup/Accounts/Account.tsx b/packages/extension-ui/src/Popup/Accounts/Account.tsx index 354e4576..19f2ed6d 100644 --- a/packages/extension-ui/src/Popup/Accounts/Account.tsx +++ b/packages/extension-ui/src/Popup/Accounts/Account.tsx @@ -11,22 +11,22 @@ import { ActionBar, Address, Link, withOnAction } from '../../components'; import { editAccount } from '../../messaging'; import { Name } from '../../partials'; -type Props = { - address: string, - className?: string, - onAction: OnActionFromCtx -}; +interface Props { + address: string; + className?: string; + onAction: OnActionFromCtx; +} -function Account ({ address, className, onAction }: Props) { +function Account ({ address, className, onAction }: Props): React.ReactElement { const [isEditing, setEditing] = useState(false); const [editedname, setName] = useState(null); - const toggleEdit = () => + const toggleEdit = (): void => setEditing(!isEditing); - const saveChanges = () => { + const saveChanges = (): void => { if (editedname && editedname !== name) { editAccount(address, editedname) - .then(() => onAction()) + .then((): void => onAction()) .catch(console.error); } diff --git a/packages/extension-ui/src/Popup/Accounts/index.tsx b/packages/extension-ui/src/Popup/Accounts/index.tsx index 52c32982..30e53229 100644 --- a/packages/extension-ui/src/Popup/Accounts/index.tsx +++ b/packages/extension-ui/src/Popup/Accounts/index.tsx @@ -9,18 +9,18 @@ import React from 'react'; import { Button, Header, Tip, withAccounts } from '../../components'; import Account from './Account'; -type Props = { - accounts: AccountsFromCtx -}; +interface Props { + accounts: AccountsFromCtx; +} -function Accounts ({ accounts }: Props) { +function Accounts ({ accounts }: Props): React.ReactElement { return (
{ (accounts.length === 0) - ? You currently don't have any accounts. Either create a new account or if you have an existing account you wish to use, import it with the seed phrase - : accounts.map(({ address }) => ( + ? You currently don't have any accounts. Either create a new account or if you have an existing account you wish to use, import it with the seed phrase + : accounts.map(({ address }): React.ReactNode => ( +function Request ({ authId, className, isFirst, onAction, request: { origin }, url }: Props): React.ReactElement { + const onApprove = (): Promise => approveAuthRequest(authId) - .then(() => onAction()) + .then((): void => onAction()) .catch(console.error); - const onReject = () => + const onReject = (): Promise => rejectAuthRequest(authId) - .then(() => onAction()) + .then((): void => onAction()) .catch(console.error); return ( diff --git a/packages/extension-ui/src/Popup/Authorize/index.tsx b/packages/extension-ui/src/Popup/Authorize/index.tsx index def6dccc..de6b4157 100644 --- a/packages/extension-ui/src/Popup/Authorize/index.tsx +++ b/packages/extension-ui/src/Popup/Authorize/index.tsx @@ -9,15 +9,15 @@ import React from 'react'; import { Header, withAuthRequests } from '../../components'; import Request from './Request'; -type Props = { - requests: AuthRequestsFromCtx -}; +interface Props { + requests: AuthRequestsFromCtx; +} -function Authorize ({ requests }: Props) { +function Authorize ({ requests }: Props): React.ReactElement { return (
- {requests.map(([id, request, url], index) => ( + {requests.map(([id, request, url], index): React.ReactNode => ( (null); +function Create ({ onAction }: Props): React.ReactElement { + const [account, setAccount] = useState(null); const [name, setName] = useState(null); const [password, setPassword] = useState(null); - useEffect(() => { + useEffect((): void => { createSeed() .then(setAccount) .catch(console.error); }, []); // FIXME Duplicated between here and Import.tsx - const onCreate = () => { + const onCreate = (): void => { // this should always be the case if (name && password && account) { createAccount(name, password, account.seed) - .then(() => onAction('/')) + .then((): void => onAction('/')) .catch(console.error); } }; diff --git a/packages/extension-ui/src/Popup/Forget.tsx b/packages/extension-ui/src/Popup/Forget.tsx index 9b4686fb..0cee3ae3 100644 --- a/packages/extension-ui/src/Popup/Forget.tsx +++ b/packages/extension-ui/src/Popup/Forget.tsx @@ -11,14 +11,14 @@ import { Address, Button, Header, Tip, withOnAction } from '../components'; import { forgetAccount } from '../messaging'; import { Back } from '../partials'; -type Props = RouteComponentProps<{ address: string }> & { - onAction: OnActionFromCtx -}; +interface Props extends RouteComponentProps<{ address: string }> { + onAction: OnActionFromCtx; +} -function Forget ({ match: { params: { address } }, onAction }: Props) { - const onClick = () => +function Forget ({ match: { params: { address } }, onAction }: Props): React.ReactElement { + const onClick = (): Promise => forgetAccount(address) - .then(() => onAction('/')) + .then((): void => onAction('/')) .catch(console.error); return ( diff --git a/packages/extension-ui/src/Popup/Import.tsx b/packages/extension-ui/src/Popup/Import.tsx index 2e144266..530bdeec 100644 --- a/packages/extension-ui/src/Popup/Import.tsx +++ b/packages/extension-ui/src/Popup/Import.tsx @@ -10,26 +10,26 @@ import { Address, Button, Header, TextArea, withOnAction } from '../components'; import { createAccount, validateSeed } from '../messaging'; import { Back, Name, Password } from '../partials'; -type Props = { - onAction: OnActionFromCtx -}; +interface Props { + onAction: OnActionFromCtx; +} -function Import ({ onAction }: Props) { - const [account, setAccount] = useState(null); +function Import ({ onAction }: Props): React.ReactElement { + const [account, setAccount] = useState(null); const [name, setName] = useState(null); const [password, setPassword] = useState(null); - const onChangeSeed = (seed: string) => + const onChangeSeed = (seed: string): Promise => validateSeed(seed) .then(setAccount) - .catch(() => setAccount(null)); + .catch((): void => setAccount(null)); // FIXME Duplicated between here and Create.tsx - const onCreate = () => { + const onCreate = (): void => { // this should always be the case if (name && password && account) { createAccount(name, password, account.seed) - .then(() => onAction('/')) + .then((): void => onAction('/')) .catch(console.error); } }; diff --git a/packages/extension-ui/src/Popup/Signing/Details.tsx b/packages/extension-ui/src/Popup/Signing/Details.tsx index f76d42af..bbcfa330 100644 --- a/packages/extension-ui/src/Popup/Signing/Details.tsx +++ b/packages/extension-ui/src/Popup/Signing/Details.tsx @@ -9,9 +9,10 @@ import findChain from '@polkadot/extension/chains'; import { Metadata, Method, ExtrinsicEra } from '@polkadot/types'; import { formatNumber } from '@polkadot/util'; -type MethodJson = { - args: { [index: string]: any } -}; +interface MethodJson { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + args: Record; +} interface Props { blockNumber: number; @@ -24,7 +25,7 @@ interface Props { url: string; } -function renderMethod (data: string, meta?: Metadata | null) { +function renderMethod (data: string, meta?: Metadata | null): React.ReactNode { if (!meta) { return ( @@ -73,7 +74,7 @@ function renderMortality (era: ExtrinsicEra, blockNumber: number): string { return `mortal (birth #${formatNumber(mortal.birth(blockNumber))}, death #${formatNumber(mortal.death(blockNumber))})`; } -function Details ({ blockNumber, className, genesisHash, isDecoded, era, method, nonce, url }: Props) { +function Details ({ blockNumber, className, genesisHash, isDecoded, era, method, nonce, url }: Props): React.ReactElement { const chain = findChain(genesisHash); const eera = new ExtrinsicEra(era); diff --git a/packages/extension-ui/src/Popup/Signing/Request.tsx b/packages/extension-ui/src/Popup/Signing/Request.tsx index 08415718..a612e24d 100644 --- a/packages/extension-ui/src/Popup/Signing/Request.tsx +++ b/packages/extension-ui/src/Popup/Signing/Request.tsx @@ -12,22 +12,22 @@ import { approveSignRequest, cancelSignRequest } from '../../messaging'; import Details from './Details'; import Unlock from './Unlock'; -type Props = { - isFirst: boolean, - onAction: OnActionFromCtx, - request: MessageExtrinsicSign, - signId: string, - url: string -}; +interface Props { + isFirst: boolean; + onAction: OnActionFromCtx; + request: MessageExtrinsicSign; + signId: string; + url: string; +} -function Request ({ isFirst, onAction, request: { address, blockNumber, era, genesisHash, method, nonce }, signId, url }: Props) { - const onCancel = () => +function Request ({ isFirst, onAction, request: { address, blockNumber, era, genesisHash, method, nonce }, signId, url }: Props): React.ReactElement { + const onCancel = (): Promise => cancelSignRequest(signId) - .then(() => onAction()) + .then((): void => onAction()) .catch(console.error); - const onSign = (password: string) => + const onSign = (password: string): Promise => approveSignRequest(signId, password) - .then(() => onAction()); + .then((): void => onAction()); return (
diff --git a/packages/extension-ui/src/Popup/Signing/Unlock.tsx b/packages/extension-ui/src/Popup/Signing/Unlock.tsx index 27cb512f..8340c96e 100644 --- a/packages/extension-ui/src/Popup/Signing/Unlock.tsx +++ b/packages/extension-ui/src/Popup/Signing/Unlock.tsx @@ -6,20 +6,20 @@ import React, { useState, useEffect } from 'react'; import { Button, Input } from '../../components'; -type Props = { - className?: string, - onSign: (password: string) => Promise -}; +interface Props { + className?: string; + onSign: (password: string) => Promise; +} -export default function Unlock ({ className, onSign }: Props) { +export default function Unlock ({ className, onSign }: Props): React.ReactElement { const [error, setError] = useState(''); const [password, setPassword] = useState(''); - const onClick = () => + const onClick = (): Promise => onSign(password) - .catch((error) => setError(error.message)); + .catch((error): void => setError(error.message)); - useEffect(() => { + useEffect((): void => { if (error) { setError(''); } diff --git a/packages/extension-ui/src/Popup/Signing/index.tsx b/packages/extension-ui/src/Popup/Signing/index.tsx index f5dc6fd0..785d8507 100644 --- a/packages/extension-ui/src/Popup/Signing/index.tsx +++ b/packages/extension-ui/src/Popup/Signing/index.tsx @@ -9,15 +9,15 @@ import React from 'react'; import { Header, withSignRequests } from '../../components'; import Request from './Request'; -type Props = { - requests: SignRequestsFromCtx -}; +interface Props { + requests: SignRequestsFromCtx; +} -function Signing ({ requests }: Props) { +function Signing ({ requests }: Props): React.ReactElement { return (
- {requests.map(([id, request, url], index) => ( + {requests.map(([id, request, url], index): React.ReactNode => ( { const onClick = (): void => { window.localStorage.setItem('welcome_read', 'ok'); onAction(); @@ -26,7 +26,7 @@ function Welcome ({ onAction }: Props) {
  • We do not send any clicks, pageviews or events to a central server
  • We do not use any trackers or analytics
  • -
  • We don't collect keys, addresses or any information - your information never leaves this machine
  • +
  • We don't collect keys, addresses or any information - your information never leaves this machine
... we are not in the information collection business (even anonymized).