mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-18 11:51:03 +00:00
Remove extension store (#306)
This commit is contained in:
@@ -27,10 +27,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.7.1",
|
||||
"@polkadot/types": "^1.10.0-beta.9",
|
||||
"@polkadot/types": "^1.10.0-beta.11",
|
||||
"@polkadot/util": "^2.7.1",
|
||||
"@types/chrome": "^0.0.103",
|
||||
"@types/firefox-webext-browser": "^70.0.1",
|
||||
"@types/ledgerhq__hw-transport-node-hid": "^4.22.1",
|
||||
"@types/ledgerhq__hw-transport-u2f": "^4.21.1",
|
||||
"@types/mkdirp": "^1.0.0",
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
// Copyright 2019 @polkadot/ui-keyring authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringStore, KeyringJson } from '../types';
|
||||
|
||||
import extension from 'extensionizer';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type StoreValue = Record<string, any>;
|
||||
|
||||
const lastError = (type: string): void => {
|
||||
const error = extension.runtime.lastError;
|
||||
|
||||
if (error) {
|
||||
console.error(`ExtensionStore.${type}:: runtime.lastError:`, error);
|
||||
}
|
||||
};
|
||||
|
||||
export default class ExtensionStore implements KeyringStore {
|
||||
public all (cb: (key: string, value: KeyringJson) => void): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
extension.storage.local.get(null, (result: StoreValue): void => {
|
||||
lastError('all');
|
||||
|
||||
Object.entries(result).forEach(([key, value]): void => {
|
||||
cb(key, value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public get (key: string, cb: (value: KeyringJson) => void): void {
|
||||
extension.storage.local.get([key], (result: StoreValue): void => {
|
||||
lastError('get');
|
||||
|
||||
cb(result[key]);
|
||||
});
|
||||
}
|
||||
|
||||
public remove (key: string, cb?: () => void): void {
|
||||
extension.storage.local.remove(key, (): void => {
|
||||
lastError('remove');
|
||||
|
||||
cb && cb();
|
||||
});
|
||||
}
|
||||
|
||||
public set (key: string, value: KeyringJson, cb?: () => void): void {
|
||||
// shortcut, don't save testing accounts in extension storage
|
||||
if (key.startsWith('account:') && value.meta && value.meta.isTesting) {
|
||||
cb && cb();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
extension.storage.local.set({ [key]: value }, (): void => {
|
||||
lastError('set');
|
||||
|
||||
cb && cb();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,4 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { default as BrowserStore } from './Browser';
|
||||
export { default as ExtensionStore } from './Extension';
|
||||
export { default as FileStore } from './File';
|
||||
|
||||
Reference in New Issue
Block a user