Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 14, 2021
1 parent 0640c56 commit db1cfac
Show file tree
Hide file tree
Showing 22 changed files with 306 additions and 276 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
'.yarn/**',
'**/build/*',
'**/coverage/*',
'**/node_modules/*'
'**/node_modules/*',
'**/config.ts'
],
parserOptions: {
...base.parserOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { SignerPayloadJSON } from '@polkadot/types/types';

import { ResponseSigning } from '@cennznet/extension-base/background/types';
import { MetadataDef } from '@cennznet/extension-inject/types';

import { KeyringPair } from '@polkadot/keyring/types';
import { TypeRegistry } from '@polkadot/types';
import keyring from '@polkadot/ui-keyring';
Expand Down
7 changes: 3 additions & 4 deletions packages/extension-base/src/background/handlers/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { MetadataDef } from '@cennznet/extension-inject/types';
import type { KeyringPair, KeyringPair$Json, KeyringPair$Meta } from '@polkadot/keyring/types';
import type { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import type {
AccountJson,
import type { AccountJson,
AllowedPath,
AuthorizeRequest,
MessageTypes,
Expand Down Expand Up @@ -45,11 +44,11 @@ import type {
ResponseSeedValidate,
ResponseSigningIsLocked,
ResponseType,
SigningRequest
} from '../types';
SigningRequest } from '../types';

import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@cennznet/extension-base/defaults';
import chrome from '@cennznet/extension-inject/chrome';

import { TypeRegistry } from '@polkadot/types';
import keyring from '@polkadot/ui-keyring';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-base/src/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { MetadataDef, ProviderMeta } from '@cennznet/extension-inject/types
import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
import type { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types';

import { BehaviorSubject } from 'rxjs';

import { addMetadata, knownMetadata } from '@cennznet/extension-chains';
import chrome from '@cennznet/extension-inject/chrome';
import { BehaviorSubject } from 'rxjs';

import { assert } from '@polkadot/util';

import { MetadataStore } from '../../stores';
Expand Down
1 change: 1 addition & 0 deletions packages/extension-base/src/background/handlers/Tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { MessageTypes, RequestAccountList, RequestAuthorizeTab, RequestRpcS

import { PHISHING_PAGE_REDIRECT } from '@cennznet/extension-base/defaults';
import { canDerive } from '@cennznet/extension-base/utils';

import { checkIfDenied } from '@polkadot/phishing';
import keyring from '@polkadot/ui-keyring';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
Expand Down
446 changes: 224 additions & 222 deletions packages/extension-chains/src/config.ts

Large diffs are not rendered by default.

48 changes: 35 additions & 13 deletions packages/extension-chains/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import type { MetadataDef } from '@cennznet/extension-inject/types';
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { Chain, MetadataFetched, RuntimeTypes } from './types';

import { Metadata } from '@polkadot/metadata';
import { TypeRegistry } from '@polkadot/types';
import { base64Decode } from '@polkadot/util-crypto';

import config from './config';
// imports chain details, generally metadata. For the generation of these,
// inside the api, run `yarn chain:info --ws <url>`
Expand All @@ -20,50 +22,70 @@ const definitions = new Map<string, MetadataDef>(
/** when metadata definition stored in extension is outdated
* get the definition for @cennznet/api/extension-releases
* for cennznet specific chains **/
export function getLatestMetaFromServer(genesisHashExpected: string): MetadataFetched | null {
export function getLatestMetaFromServer (genesisHashExpected: string): MetadataFetched | null {
try {
const xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/metaCalls.json", false);

xmlHttp.open('GET', 'https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/metaCalls.json', false);
xmlHttp.send(null);
let response = xmlHttp.responseText;
const response: string = xmlHttp.responseText;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const metadataDetails = JSON.parse(response);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const metaCallsList = metadataDetails?.metaCalls;

if (metaCallsList) {
// metaCalls is { genesisHash-specVersion: metaCalls }
const key = Object.keys(metaCallsList).filter(v => v.includes(genesisHashExpected));
const key = Object.keys(metaCallsList).filter((v) => v.includes(genesisHashExpected));

if (!key[0]) {
return null;
}

const [, specVersion] = key[0].split('-');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const metaCalls = metaCallsList[key[0]];
return {metaCalls, specVersion: parseInt(specVersion)};

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return { metaCalls, specVersion: parseInt(specVersion) } as MetadataFetched;
}

return null;
} catch (e) {
console.log('Err:',e);
console.log('Err:', e);

return null;
}
}

/** when types stored in extension is outdated
* get the types for @cennznet/api/extension-releases
* for cennznet specific chains **/
export function getLatestTypesFromServer(genesisHashExpected: string): RuntimeTypes | null {
export function getLatestTypesFromServer (genesisHashExpected: string): RuntimeTypes | null {
try {
const xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/runtimeModuleTypes.json", false);

xmlHttp.open('GET', 'https://raw.githubusercontent.com/cennznet/api.js/master/extension-releases/runtimeModuleTypes.json', false);
xmlHttp.send(null);
let response = xmlHttp.responseText;
const response = xmlHttp.responseText;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const additionalTypes = JSON.parse(response);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const typesForCurrentChain = additionalTypes[genesisHashExpected];

if (typesForCurrentChain) {
const types = typesForCurrentChain.types;
const userExtensions = typesForCurrentChain.userExtensions;
return {types, userExtensions};
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const types: Record<string, Record<string, string> | string> = typesForCurrentChain.types;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
const userExtensions: ExtDef = typesForCurrentChain.userExtensions;

return { types, userExtensions } as RuntimeTypes;
}

return null;
} catch (e) {
console.log('Err:',e);
console.log('Err:', e);

return null;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/extension-chains/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2019-2021 @polkadot/extension-chains authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';

import type { MetadataDef } from '@cennznet/extension-inject/types';
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { Registry } from '@polkadot/types/types';

export interface Chain {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-dapp/src/compat/singleSource.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2019-2021 @polkadot/extension-dapp authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { Signer } from '@polkadot/api/types';
import type { Injected, InjectedAccount, InjectedWindow } from '@cennznet/extension-inject/types';
import type { Signer } from '@polkadot/api/types';

// RxJs interface, only the bare-bones of what we need here
interface Subscriber<T> {
Expand Down
10 changes: 6 additions & 4 deletions packages/extension-dapp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,22 @@ let web3EnablePromise: Promise<InjectedExtension[]> | null = null;

export { isWeb3Injected, web3EnablePromise };

const CENNZNET_EXT = "cennznet-extension";
const CENNZNET_EXT = 'cennznet-extension';

function getWindowExtensions (originName: string): Promise<[InjectedExtensionInfo, Injected | void][]> {
if (win.injectedWeb3["cennznet-extension"]) {
if (win.injectedWeb3['cennznet-extension']) {
return Promise.all(
Object.entries([win.injectedWeb3[CENNZNET_EXT]]).map(([name, {enable, version}]): Promise<[InjectedExtensionInfo, Injected | void]> =>
Object.entries([win.injectedWeb3[CENNZNET_EXT]]).map(([name, { enable, version }]): Promise<[InjectedExtensionInfo, Injected | void]> =>
Promise.all([
Promise.resolve({name, version}),
Promise.resolve({ name, version }),
enable(originName).catch((error: Error): void => {
console.error(`Error initializing ${name}: ${error.message}`);
})
])
)
);
}

return Promise.resolve([]);
}

Expand Down Expand Up @@ -118,6 +119,7 @@ export async function web3Accounts ({ ss58Format }: Web3AccountsOptions = {}): P
return mapAccounts(source, list, ss58Format);
} catch (error) {
console.error('web3accounts failed:', error);

// cannot handle this one
return [];
}
Expand Down
16 changes: 8 additions & 8 deletions packages/extension-ui/src/Popup/Accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

import type { AccountJson } from '@cennznet/extension-base/background/types';

import React, { useCallback, useMemo, useState } from 'react';
import styled from 'styled-components';

import { canDerive } from '@cennznet/extension-base/utils';
import defaultConfig from '@cennznet/extension-chains/config';
import { ThemeProps } from '@cennznet/extension-ui/types';
import React, { useCallback, useMemo, useState } from 'react';
import styled from 'styled-components';

import { Address, Dropdown, Link, MenuDivider } from '../../components';
import useGenesisHashOptions from '../../hooks/useGenesisHashOptions';
import useTranslation from '../../hooks/useTranslation';
import { editAccount, tieAccount } from '../../messaging';
import { Name } from '../../partials';
import defaultConfig from "@cennznet/extension-chains/config";

interface Props extends AccountJson {
className?: string;
Expand All @@ -31,7 +30,7 @@ function Account ({ address, className, genesisHash, isExternal, isHardware, isH
const [{ isEditing, toggleActions }, setEditing] = useState<EditState>({ isEditing: false, toggleActions: 0 });
const [editedName, setName] = useState<string | undefined | null>(name);
const genesisOptions = useGenesisHashOptions();
const nikauChain = defaultConfig.CENNZNetChain.find(blkChain => blkChain.chain === 'CENNZnet Nikau');
const nikauChain = defaultConfig.CENNZNetChain.find((blkChain) => blkChain.chain === 'CENNZnet Nikau');

const _onChangeGenesis = useCallback(
(genesisHash?: string | null): void => {
Expand Down Expand Up @@ -74,8 +73,9 @@ function Account ({ address, className, genesisHash, isExternal, isHardware, isH
</Link>
)}
<a className='menuItem'
href={genesisHash === nikauChain?.genesisHash ? `https://uncoverexplorer.com/account/${address}?network=Nikau` : `https://uncoverexplorer.com/account/${address}`}
target="_blank"
href={genesisHash === nikauChain?.genesisHash ? `https://uncoverexplorer.com/account/${address}?network=Nikau` : `https://uncoverexplorer.com/account/${address}`}
rel='noreferrer'
target='_blank'
>
{t<string>('View on UNcover')}
</a>
Expand Down Expand Up @@ -111,7 +111,7 @@ function Account ({ address, className, genesisHash, isExternal, isHardware, isH
</>
)}
</>
), [_onChangeGenesis, _toggleEdit, address, genesisHash, genesisOptions, isExternal, isHardware, t, type]);
), [_onChangeGenesis, _toggleEdit, address, genesisHash, genesisOptions, isExternal, isHardware, t, type, nikauChain]);

return (
<div className={className}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import type { ThemeProps } from '../../types';

import React, { useCallback } from 'react';
import styled from 'styled-components';

import { AuthUrlInfo } from '@cennznet/extension-base/background/handlers/State';
import { Switch } from '@cennznet/extension-ui/components';
import React, { useCallback } from 'react';
import styled from 'styled-components';

import useTranslation from '../../hooks/useTranslation';

Expand Down
5 changes: 2 additions & 3 deletions packages/extension-ui/src/Popup/AuthManagement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import type { ThemeProps } from '../../types';

import React, { useCallback, useEffect, useState } from 'react';
import styled from 'styled-components';

import { AuthUrlInfo, AuthUrls } from '@cennznet/extension-base/background/handlers/State';
import { InputFilter } from '@cennznet/extension-ui/components';
import React, { useCallback, useEffect, useState } from 'react';
import styled from 'styled-components';

import useTranslation from '../../hooks/useTranslation';
import { getAuthList, toggleAuthorization } from '../../messaging';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Derive/SelectParent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright 2019-2021 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';

import { canDerive } from '@cennznet/extension-base/utils';
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';

import { AccountContext, ActionContext, Address, ButtonArea, InputWithLabel, Label, NextStepButton, VerticalSpace, Warning } from '../../components';
import useTranslation from '../../hooks/useTranslation';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/ImportSeed/SeedAndPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import type { ThemeProps } from '../../types';
import type { AccountInfo } from '.';

import { validateSeed } from '@cennznet/extension-ui/messaging';
import { faCaretDown, faCaretRight } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useCallback, useEffect, useState } from 'react';
import styled from 'styled-components';

import { validateSeed } from '@cennznet/extension-ui/messaging';

import { ButtonArea, Dropdown, InputWithLabel, NextStepButton, TextAreaWithLabel, VerticalSpace, Warning } from '../../components';
import useGenesisHashOptions from '../../hooks/useGenesisHashOptions';
import useTranslation from '../../hooks/useTranslation';
Expand Down
3 changes: 1 addition & 2 deletions packages/extension-ui/src/Popup/Signing/Request/SignArea.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Copyright 2019-2021 @polkadot/extension-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { PASSWORD_EXPIRY_MIN } from '@cennznet/extension-base/defaults';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import styled from 'styled-components';

import { PASSWORD_EXPIRY_MIN } from '@cennznet/extension-base/defaults';

import { ActionBar, ActionContext, Button, ButtonArea, Checkbox, Link } from '../../../components';
import useTranslation from '../../../hooks/useTranslation';
import { approveSignPassword, cancelSignRequest, isSignLocked } from '../../../messaging';
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-ui/src/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import type { AccountJson, AccountsContext, AuthorizeRequest, MetadataRequest, SigningRequest } from '@cennznet/extension-base/background/types';
import type { SettingsStruct } from '@polkadot/ui-settings/types';

import { PHISHING_PAGE_REDIRECT } from '@cennznet/extension-base/defaults';
import { canDerive } from '@cennznet/extension-base/utils';
import React, { useEffect, useState } from 'react';
import { Route, Switch } from 'react-router';

import { PHISHING_PAGE_REDIRECT } from '@cennznet/extension-base/defaults';
import { canDerive } from '@cennznet/extension-base/utils';
import uiSettings from '@polkadot/ui-settings';

import { ErrorBoundary, Loading } from '../components';
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-ui/src/components/Address.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import '../../../../__mocks__/chrome';

import type { ReactWrapper } from 'enzyme';
import type { AccountJson } from '@cennznet/extension-base/background/types';
import type { ReactWrapper } from 'enzyme';
import type { IconTheme } from '@polkadot/react-identicon/types';
import type { Props as AddressComponentProps } from './Address';

Expand Down
4 changes: 2 additions & 2 deletions packages/extension-ui/src/hooks/useMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import type { Chain } from '@cennznet/extension-chains/types';

import BN from 'bn.js';
import { useEffect, useState } from 'react';

import { getMetadata } from '../messaging';
import BN from 'bn.js';

export default function useMetadata (genesisHash?: string | null, specVersion?: BN | null, isPartial?: boolean): Chain | null {
const [chain, setChain] = useState<Chain | null>(null);
Expand All @@ -22,7 +22,7 @@ export default function useMetadata (genesisHash?: string | null, specVersion?:
} else {
setChain(null);
}
}, [genesisHash, isPartial]);
}, [genesisHash, specVersion, isPartial]);

return chain;
}
3 changes: 1 addition & 2 deletions packages/extension-ui/src/messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

import '../../../__mocks__/chrome';

import chrome from '@cennznet/extension-inject/chrome';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import { configure } from 'enzyme';

import chrome from '@cennznet/extension-inject/chrome';

import { exportAccount } from './messaging';

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
Expand Down
Loading

0 comments on commit db1cfac

Please sign in to comment.