Remove extensionizer indirection (#309)
* Remove extensionizer indirection * Slight duplication * Chrome mock * Update package.json * chrome types, chrome import
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import '../../../../../__mocks__/chrome';
|
||||
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import ExtensionStore from '@polkadot/ui-keyring/stores/Extension';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
@@ -6,7 +6,6 @@ import { MetadataDef } from '@polkadot/extension-inject/types';
|
||||
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
|
||||
import { AccountJson, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountCreateExternal, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountValidate, RequestAuthorizeApprove, RequestAuthorizeReject, RequestDeriveCreate, ResponseDeriveValidate, RequestMetadataApprove, RequestMetadataReject, RequestSigningApprovePassword, RequestSigningApproveSignature, RequestSigningCancel, RequestSeedCreate, RequestTypes, ResponseAccountExport, RequestAccountForget, ResponseSeedCreate, RequestSeedValidate, RequestDeriveValidate, ResponseSeedValidate, ResponseType, SigningRequest } from '../types';
|
||||
|
||||
import extension from 'extensionizer';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import accountsObservable from '@polkadot/ui-keyring/observable/accounts';
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
@@ -14,6 +13,7 @@ import { KeyringPair, KeyringPair$Meta } from '@polkadot/keyring/types';
|
||||
import { assert, isHex } from '@polkadot/util';
|
||||
import { keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
|
||||
|
||||
import chrome from '../../chrome';
|
||||
import State from './State';
|
||||
import { createSubscription, unsubscribe } from './subscriptions';
|
||||
|
||||
@@ -270,8 +270,8 @@ export default class Extension {
|
||||
}
|
||||
|
||||
private windowOpen (): boolean {
|
||||
extension.tabs.create({
|
||||
url: extension.extension.getURL('index.html')
|
||||
chrome.tabs.create({
|
||||
url: chrome.extension.getURL('index.html')
|
||||
});
|
||||
|
||||
return true;
|
||||
|
||||
@@ -7,11 +7,11 @@ import { ProviderMeta, MetadataDef } from '@polkadot/extension-inject/types';
|
||||
import { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
|
||||
import { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest, RequestRpcUnsubscribe } from '../types';
|
||||
|
||||
import extension from 'extensionizer';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import MetadataStore from './MetadataStore';
|
||||
import chrome from '../../chrome';
|
||||
import { MetadataStore } from '../stores';
|
||||
|
||||
interface AuthRequest {
|
||||
id: string;
|
||||
@@ -65,7 +65,7 @@ const WINDOW_OPTS = {
|
||||
left: 150,
|
||||
top: 150,
|
||||
type: 'popup',
|
||||
url: extension.extension.getURL('index.html'),
|
||||
url: chrome.extension.getURL('index.html'),
|
||||
width: 480
|
||||
};
|
||||
|
||||
@@ -144,13 +144,13 @@ export default class State {
|
||||
|
||||
private popupClose (): void {
|
||||
this.#windows.forEach((id: number): void =>
|
||||
extension.windows.remove(id)
|
||||
chrome.windows.remove(id)
|
||||
);
|
||||
this.#windows = [];
|
||||
}
|
||||
|
||||
private popupOpen (): void {
|
||||
extension.windows.create({ ...WINDOW_OPTS }, (window?: chrome.windows.Window): void => {
|
||||
chrome.windows.create({ ...WINDOW_OPTS }, (window?: chrome.windows.Window): void => {
|
||||
if (window) {
|
||||
this.#windows.push(window.id);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ export default class State {
|
||||
: (signCount ? `${signCount}` : '')
|
||||
);
|
||||
|
||||
extension.browserAction.setBadgeText({ text });
|
||||
chrome.browserAction.setBadgeText({ text });
|
||||
|
||||
if (shouldClose && text === '') {
|
||||
this.popupClose();
|
||||
|
||||
+8
-8
@@ -4,23 +4,23 @@
|
||||
|
||||
import { MetadataDef } from '@polkadot/extension-inject/types';
|
||||
|
||||
import extension from 'extensionizer';
|
||||
import chrome from '@polkadot/extension-base/chrome';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type StoreValue = Record<string, any>;
|
||||
|
||||
const lastError = (type: string): void => {
|
||||
const error = extension.runtime.lastError;
|
||||
const error = chrome.runtime.lastError;
|
||||
|
||||
if (error) {
|
||||
console.error(`ChainStore.${type}:: runtime.lastError:`, error);
|
||||
console.error(`MetadataStore.${type}:: runtime.lastError:`, error);
|
||||
}
|
||||
};
|
||||
|
||||
export default class Store {
|
||||
export default class MetadataStore {
|
||||
public all (cb: (key: string, value: MetadataDef) => void): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
extension.storage.local.get(null, (result: StoreValue): void => {
|
||||
chrome.storage.local.get(null, (result: StoreValue): void => {
|
||||
lastError('all');
|
||||
|
||||
Object.entries(result).forEach(([key, value]): void => {
|
||||
@@ -30,7 +30,7 @@ export default class Store {
|
||||
}
|
||||
|
||||
public get (key: string, cb: (value: MetadataDef) => void): void {
|
||||
extension.storage.local.get([key], (result: StoreValue): void => {
|
||||
chrome.storage.local.get([key], (result: StoreValue): void => {
|
||||
lastError('get');
|
||||
|
||||
cb(result[key]);
|
||||
@@ -38,7 +38,7 @@ export default class Store {
|
||||
}
|
||||
|
||||
public remove (key: string, cb?: () => void): void {
|
||||
extension.storage.local.remove(key, (): void => {
|
||||
chrome.storage.local.remove(key, (): void => {
|
||||
lastError('remove');
|
||||
|
||||
cb && cb();
|
||||
@@ -46,7 +46,7 @@ export default class Store {
|
||||
}
|
||||
|
||||
public set (key: string, value: MetadataDef, cb?: () => void): void {
|
||||
extension.storage.local.set({ [key]: value }, (): void => {
|
||||
chrome.storage.local.set({ [key]: value }, (): void => {
|
||||
lastError('set');
|
||||
|
||||
cb && cb();
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright 2019 @polkadot/extension-chains authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { default as MetadataStore } from './Metadata';
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright 2019 @polkadot/extension-chains authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
const extension = typeof chrome !== 'undefined'
|
||||
? chrome
|
||||
: typeof browser !== 'undefined'
|
||||
? browser
|
||||
: null;
|
||||
|
||||
export default extension as typeof chrome;
|
||||
Reference in New Issue
Block a user