Adjust import to polyfill for non-Chrome (#917)
* Adjust import to polyfill for non-Chrome * Update packages/extension-ui/src/index.ts * Remove spurious console.log * Dedupe error log * Update error log catch * Adjust * Update packages/extension-ui/src/components/Address.tsx * linting * Adjust
This commit is contained in:
@@ -9,13 +9,13 @@ import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import type { AccountJson, AllowedPath, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountBatchExport, RequestAccountChangePassword, RequestAccountCreateExternal, RequestAccountCreateHardware, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountForget, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestAuthorizeApprove, RequestAuthorizeReject, RequestBatchRestore, RequestDeriveCreate, RequestDeriveValidate, RequestJsonRestore, RequestMetadataApprove, RequestMetadataReject, RequestSeedCreate, RequestSeedValidate, RequestSigningApprovePassword, RequestSigningApproveSignature, RequestSigningCancel, RequestSigningIsLocked, RequestTypes, ResponseAccountExport, ResponseAccountsExport, ResponseAuthorizeList, ResponseDeriveValidate, ResponseJsonGetAccountInfo, ResponseSeedCreate, ResponseSeedValidate, ResponseSigningIsLocked, ResponseType, SigningRequest } from '../types';
|
||||
|
||||
import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults';
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
|
||||
import { assert, isHex } from '@polkadot/util';
|
||||
import { keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
|
||||
|
||||
import { withErrorLog } from './helpers';
|
||||
import State from './State';
|
||||
import { createSubscription, unsubscribe } from './subscriptions';
|
||||
|
||||
@@ -457,10 +457,7 @@ export default class Extension {
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log('open', url);
|
||||
|
||||
// eslint-disable-next-line no-void
|
||||
void chrome.tabs.create({ url });
|
||||
withErrorLog(() => chrome.tabs.create({ url }));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
import { getId } from '@polkadot/extension-base/utils/getId';
|
||||
import { addMetadata, knownMetadata } from '@polkadot/extension-chains';
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
import settings from '@polkadot/ui-settings';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { MetadataStore } from '../../stores';
|
||||
import { withErrorLog } from './helpers';
|
||||
|
||||
interface Resolver <T> {
|
||||
reject: (error: Error) => void;
|
||||
@@ -165,9 +165,8 @@ export default class State {
|
||||
}
|
||||
|
||||
private popupClose (): void {
|
||||
this.#windows.forEach((id: number): void =>
|
||||
// eslint-disable-next-line no-void
|
||||
void chrome.windows.remove(id)
|
||||
this.#windows.forEach((id: number) =>
|
||||
withErrorLog(() => chrome.windows.remove(id))
|
||||
);
|
||||
this.#windows = [];
|
||||
}
|
||||
@@ -275,8 +274,7 @@ export default class State {
|
||||
: (signCount ? `${signCount}` : '')
|
||||
);
|
||||
|
||||
// eslint-disable-next-line no-void
|
||||
void chrome.browserAction.setBadgeText({ text });
|
||||
withErrorLog(() => chrome.browserAction.setBadgeText({ text }));
|
||||
|
||||
if (shouldClose && text === '') {
|
||||
this.popupClose();
|
||||
@@ -411,7 +409,7 @@ export default class State {
|
||||
const provider = this.#injectedProviders.get(port);
|
||||
|
||||
if (provider) {
|
||||
provider.disconnect().catch(console.error);
|
||||
withErrorLog(() => provider.disconnect());
|
||||
}
|
||||
|
||||
this.#injectedProviders.delete(port);
|
||||
|
||||
@@ -17,6 +17,7 @@ import { assert, isNumber } from '@polkadot/util';
|
||||
|
||||
import RequestBytesSign from '../RequestBytesSign';
|
||||
import RequestExtrinsicSign from '../RequestExtrinsicSign';
|
||||
import { withErrorLog } from './helpers';
|
||||
import State from './State';
|
||||
import { createSubscription, unsubscribe } from './subscriptions';
|
||||
|
||||
@@ -118,7 +119,7 @@ export default class Tabs {
|
||||
|
||||
port.onDisconnect.addListener((): void => {
|
||||
unsubscribe(id);
|
||||
this.rpcUnsubscribe({ ...request, subscriptionId }, port).catch(console.error);
|
||||
withErrorLog(() => this.rpcUnsubscribe({ ...request, subscriptionId }, port));
|
||||
});
|
||||
|
||||
return true;
|
||||
@@ -151,8 +152,7 @@ export default class Tabs {
|
||||
.map(({ id }) => id)
|
||||
.filter((id): id is number => isNumber(id))
|
||||
.forEach((id) =>
|
||||
// eslint-disable-next-line no-void
|
||||
void chrome.tabs.update(id, { url })
|
||||
withErrorLog(() => chrome.tabs.update(id, { url }))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2019-2021 @polkadot/extension authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export function withErrorLog (fn: () => unknown): void {
|
||||
try {
|
||||
const p = fn();
|
||||
|
||||
if (p && typeof p === 'object' && typeof (p as Promise<unknown>).catch === 'function') {
|
||||
(p as Promise<unknown>).catch(console.error);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright 2019-2021 @polkadot/extension-base authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
|
||||
type StoreValue = Record<string, unknown>;
|
||||
|
||||
const lastError = (type: string): void => {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/polkadot-js/extension.git"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"sideEffects": true,
|
||||
"type": "module",
|
||||
"version": "0.41.3-7",
|
||||
"main": "index.js",
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// Copyright 2019-2021 @polkadot/extension-inject authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
const extension = typeof chrome !== 'undefined'
|
||||
? chrome
|
||||
: typeof browser !== 'undefined'
|
||||
? browser
|
||||
: null;
|
||||
|
||||
export default extension as typeof chrome;
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2019-2021 @polkadot/extension-inject authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
if (typeof chrome === 'undefined') {
|
||||
self.chrome = self.browser as unknown as typeof chrome;
|
||||
}
|
||||
@@ -111,32 +111,20 @@ function Address ({ actions, address, children, className, genesisHash, isExtern
|
||||
|
||||
useEffect((): void => {
|
||||
if (!address) {
|
||||
setRecoded(defaultRecoded);
|
||||
|
||||
return;
|
||||
return setRecoded(defaultRecoded);
|
||||
}
|
||||
|
||||
const accountByAddress = findAccountByAddress(accounts, address);
|
||||
|
||||
console.log(
|
||||
address,
|
||||
(
|
||||
chain?.definition.chainType === 'ethereum' ||
|
||||
accountByAddress?.type === 'ethereum' ||
|
||||
(!accountByAddress && givenType === 'ethereum')
|
||||
)
|
||||
? { account: accountByAddress, formatted: address, type: 'ethereum' }
|
||||
: recodeAddress(address, accounts, chain, settings)
|
||||
);
|
||||
const account = findAccountByAddress(accounts, address);
|
||||
|
||||
setRecoded(
|
||||
(
|
||||
chain?.definition.chainType === 'ethereum' ||
|
||||
accountByAddress?.type === 'ethereum' ||
|
||||
(!accountByAddress && givenType === 'ethereum')
|
||||
account?.type === 'ethereum' ||
|
||||
(!account && givenType === 'ethereum')
|
||||
)
|
||||
? { account: accountByAddress, formatted: address, type: 'ethereum' }
|
||||
: recodeAddress(address, accounts, chain, settings));
|
||||
? { account, formatted: address, type: 'ethereum' }
|
||||
: recodeAddress(address, accounts, chain, settings)
|
||||
);
|
||||
}, [accounts, address, chain, givenType, settings]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -6,8 +6,6 @@ import '../../../__mocks__/chrome';
|
||||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
||||
import { configure } from 'enzyme';
|
||||
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
|
||||
import { exportAccount } from './messaging';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
|
||||
|
||||
@@ -12,7 +12,6 @@ import type { KeypairType } from '@polkadot/util-crypto/types';
|
||||
import { PORT_EXTENSION } from '@polkadot/extension-base/defaults';
|
||||
import { getId } from '@polkadot/extension-base/utils/getId';
|
||||
import { metadataExpand } from '@polkadot/extension-chains';
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
import { MetadataDef } from '@polkadot/extension-inject/types';
|
||||
|
||||
import allChains from './util/chains';
|
||||
|
||||
@@ -3,19 +3,20 @@
|
||||
|
||||
// Runs in the extension background, handling all keyring access
|
||||
|
||||
import '@polkadot/extension-inject/crossenv';
|
||||
|
||||
import type { RequestSignatures, TransportRequestMessage } from '@polkadot/extension-base/background/types';
|
||||
|
||||
import handlers from '@polkadot/extension-base/background/handlers';
|
||||
import { withErrorLog } from '@polkadot/extension-base/background/handlers/helpers';
|
||||
import { PORT_CONTENT, PORT_EXTENSION } from '@polkadot/extension-base/defaults';
|
||||
import { AccountsStore } from '@polkadot/extension-base/stores';
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { assert } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
// setup the notification (same a FF default background, white text)
|
||||
// eslint-disable-next-line no-void
|
||||
void chrome.browserAction.setBadgeBackgroundColor({ color: '#d90000' });
|
||||
withErrorLog(() => chrome.browserAction.setBadgeBackgroundColor({ color: '#d90000' }));
|
||||
|
||||
// listen to all messages and handle appropriately
|
||||
chrome.runtime.onConnect.addListener((port): void => {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright 2019-2021 @polkadot/extension authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '@polkadot/extension-inject/crossenv';
|
||||
|
||||
import type { Message } from '@polkadot/extension-base/types';
|
||||
|
||||
import { MESSAGE_ORIGIN_CONTENT, MESSAGE_ORIGIN_PAGE, PORT_CONTENT } from '@polkadot/extension-base/defaults';
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
|
||||
// connect to the extension
|
||||
const port = chrome.runtime.connect({ name: PORT_CONTENT });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2019-2021 @polkadot/extension authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '@polkadot/extension-inject/crossenv';
|
||||
|
||||
import { createView, Popup } from '@polkadot/extension-ui';
|
||||
|
||||
createView(Popup);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright 2019-2021 @polkadot/extension authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '@polkadot/extension-inject/crossenv';
|
||||
|
||||
import type { RequestSignatures, TransportRequestMessage } from '@polkadot/extension-base/background/types';
|
||||
import type { Message } from '@polkadot/extension-base/types';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user