Adjust metadata loop with allMap (#953)
* Adjust metadata loop with allMap * Remove debug log
This commit is contained in:
parent
1ca94bcf4d
commit
344091d48b
@ -30,8 +30,8 @@
|
||||
"@polkadot/phishing": "^0.6.584",
|
||||
"@polkadot/rpc-provider": "^7.1.2-1",
|
||||
"@polkadot/types": "^7.1.2-1",
|
||||
"@polkadot/ui-keyring": "^0.87.8-1",
|
||||
"@polkadot/ui-settings": "^0.87.8-1",
|
||||
"@polkadot/ui-keyring": "^0.87.8-2",
|
||||
"@polkadot/ui-settings": "^0.87.8-2",
|
||||
"@polkadot/util": "^8.2.2",
|
||||
"@polkadot/util-crypto": "^8.2.2",
|
||||
"eventemitter3": "^4.0.7",
|
||||
|
||||
@ -87,35 +87,39 @@ export enum NotificationOptions {
|
||||
const AUTH_URLS_KEY = 'authUrls';
|
||||
|
||||
function extractMetadata (store: MetadataStore): void {
|
||||
const knownEntries = Object.entries(knownGenesis);
|
||||
const defs: Record<string, { def: MetadataDef, index: number, key: string }> = {};
|
||||
const removals: string[] = [];
|
||||
store.allMap((map): void => {
|
||||
const knownEntries = Object.entries(knownGenesis);
|
||||
const defs: Record<string, { def: MetadataDef, index: number, key: string }> = {};
|
||||
const removals: string[] = [];
|
||||
|
||||
store.all((key: string, def: MetadataDef): void => {
|
||||
const entry = knownEntries.find(([, hashes]) => hashes.includes(def.genesisHash));
|
||||
Object
|
||||
.entries(map)
|
||||
.forEach(([key, def]): void => {
|
||||
const entry = knownEntries.find(([, hashes]) => hashes.includes(def.genesisHash));
|
||||
|
||||
if (entry) {
|
||||
const [name, hashes] = entry;
|
||||
const index = hashes.indexOf(def.genesisHash);
|
||||
if (entry) {
|
||||
const [name, hashes] = entry;
|
||||
const index = hashes.indexOf(def.genesisHash);
|
||||
|
||||
// flatten the known metadata based on the genesis index
|
||||
// (lower is better/newer)
|
||||
if (!defs[name] || (defs[name].index > index)) {
|
||||
if (defs[name]) {
|
||||
// remove the old version of the metadata
|
||||
removals.push(defs[name].key);
|
||||
// flatten the known metadata based on the genesis index
|
||||
// (lower is better/newer)
|
||||
if (!defs[name] || (defs[name].index > index)) {
|
||||
if (defs[name]) {
|
||||
// remove the old version of the metadata
|
||||
removals.push(defs[name].key);
|
||||
}
|
||||
|
||||
defs[name] = { def, index, key };
|
||||
}
|
||||
} else {
|
||||
// this is not a known entry, so we will just apply it
|
||||
defs[key] = { def, index: 0, key };
|
||||
}
|
||||
});
|
||||
|
||||
defs[name] = { def, index, key };
|
||||
}
|
||||
} else {
|
||||
// this is not a known entry, so we will just apply it
|
||||
defs[key] = { def, index: 0, key };
|
||||
}
|
||||
removals.forEach((key) => store.remove(key));
|
||||
Object.values(defs).forEach(({ def }) => addMetadata(def));
|
||||
});
|
||||
|
||||
removals.forEach((key) => store.remove(key));
|
||||
Object.values(defs).forEach(({ def }) => addMetadata(def));
|
||||
}
|
||||
|
||||
export default class State {
|
||||
|
||||
@ -19,15 +19,29 @@ export default abstract class BaseStore <T> {
|
||||
}
|
||||
|
||||
public all (update: (key: string, value: T) => void): void {
|
||||
this.allMap((map): void => {
|
||||
Object.entries(map).forEach(([key, value]): void => {
|
||||
update(key, value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public allMap (update: (value: Record<string, T>) => void): void {
|
||||
chrome.storage.local.get(null, (result: StoreValue): void => {
|
||||
lastError('all');
|
||||
|
||||
Object
|
||||
.entries(result)
|
||||
.filter(([key]) => key.startsWith(this.#prefix))
|
||||
.forEach(([key, value]): void => {
|
||||
update(key.replace(this.#prefix, ''), value as T);
|
||||
});
|
||||
const entries = Object.entries(result);
|
||||
const map: Record<string, T> = {};
|
||||
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const [key, value] = entries[i];
|
||||
|
||||
if (key.startsWith(this.#prefix)) {
|
||||
map[key.replace(this.#prefix, '')] = value as T;
|
||||
}
|
||||
}
|
||||
|
||||
update(map);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -29,12 +29,12 @@
|
||||
"@polkadot/hw-ledger": "^8.2.2",
|
||||
"@polkadot/keyring": "^8.2.2",
|
||||
"@polkadot/networks": "^8.2.2",
|
||||
"@polkadot/react-identicon": "^0.87.8-1",
|
||||
"@polkadot/react-qr": "^0.87.8-1",
|
||||
"@polkadot/react-identicon": "^0.87.8-2",
|
||||
"@polkadot/react-qr": "^0.87.8-2",
|
||||
"@polkadot/types": "^7.1.2-1",
|
||||
"@polkadot/types-augment": "^7.1.2-1",
|
||||
"@polkadot/ui-keyring": "^0.87.8-1",
|
||||
"@polkadot/ui-settings": "^0.87.8-1",
|
||||
"@polkadot/ui-keyring": "^0.87.8-2",
|
||||
"@polkadot/ui-settings": "^0.87.8-2",
|
||||
"@polkadot/util": "^8.2.2",
|
||||
"@polkadot/util-crypto": "^8.2.2",
|
||||
"file-saver": "^2.0.5",
|
||||
|
||||
60
yarn.lock
60
yarn.lock
@ -2490,8 +2490,8 @@ __metadata:
|
||||
"@polkadot/phishing": ^0.6.584
|
||||
"@polkadot/rpc-provider": ^7.1.2-1
|
||||
"@polkadot/types": ^7.1.2-1
|
||||
"@polkadot/ui-keyring": ^0.87.8-1
|
||||
"@polkadot/ui-settings": ^0.87.8-1
|
||||
"@polkadot/ui-keyring": ^0.87.8-2
|
||||
"@polkadot/ui-settings": ^0.87.8-2
|
||||
"@polkadot/util": ^8.2.2
|
||||
"@polkadot/util-crypto": ^8.2.2
|
||||
eventemitter3: ^4.0.7
|
||||
@ -2587,12 +2587,12 @@ __metadata:
|
||||
"@polkadot/hw-ledger": ^8.2.2
|
||||
"@polkadot/keyring": ^8.2.2
|
||||
"@polkadot/networks": ^8.2.2
|
||||
"@polkadot/react-identicon": ^0.87.8-1
|
||||
"@polkadot/react-qr": ^0.87.8-1
|
||||
"@polkadot/react-identicon": ^0.87.8-2
|
||||
"@polkadot/react-qr": ^0.87.8-2
|
||||
"@polkadot/types": ^7.1.2-1
|
||||
"@polkadot/types-augment": ^7.1.2-1
|
||||
"@polkadot/ui-keyring": ^0.87.8-1
|
||||
"@polkadot/ui-settings": ^0.87.8-1
|
||||
"@polkadot/ui-keyring": ^0.87.8-2
|
||||
"@polkadot/ui-settings": ^0.87.8-2
|
||||
"@polkadot/util": ^8.2.2
|
||||
"@polkadot/util-crypto": ^8.2.2
|
||||
"@types/bn.js": ^4.11.6
|
||||
@ -2713,14 +2713,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/react-identicon@npm:^0.87.8-1":
|
||||
version: 0.87.8-1
|
||||
resolution: "@polkadot/react-identicon@npm:0.87.8-1"
|
||||
"@polkadot/react-identicon@npm:^0.87.8-2":
|
||||
version: 0.87.8-2
|
||||
resolution: "@polkadot/react-identicon@npm:0.87.8-2"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.5
|
||||
"@polkadot/keyring": ^8.2.2
|
||||
"@polkadot/ui-settings": 0.87.8-1
|
||||
"@polkadot/ui-shared": 0.87.8-1
|
||||
"@polkadot/ui-settings": 0.87.8-2
|
||||
"@polkadot/ui-shared": 0.87.8-2
|
||||
"@polkadot/util": ^8.2.2
|
||||
"@polkadot/util-crypto": ^8.2.2
|
||||
color: ^3.2.1
|
||||
@ -2736,16 +2736,16 @@ __metadata:
|
||||
react-dom: "*"
|
||||
react-is: "*"
|
||||
styled-components: "*"
|
||||
checksum: 416369a83165c269efbb6943937705105b6eb5cb4f689bbf0209342c1cd046850e153f4f8f3a8b71374be44fae20163841924a154072023a687717f1770e0248
|
||||
checksum: b0443d62ae6c67e243b5b951fdd86f7ac52a05462c5c147c10d9d1121f6697c8e0c7f9598fe2c0a6a5725130c2989ea896cd03ca1618f8d039fa9c2b8a2ec850
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/react-qr@npm:^0.87.8-1":
|
||||
version: 0.87.8-1
|
||||
resolution: "@polkadot/react-qr@npm:0.87.8-1"
|
||||
"@polkadot/react-qr@npm:^0.87.8-2":
|
||||
version: 0.87.8-2
|
||||
resolution: "@polkadot/react-qr@npm:0.87.8-2"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.5
|
||||
"@polkadot/ui-settings": 0.87.8-1
|
||||
"@polkadot/ui-settings": 0.87.8-2
|
||||
"@polkadot/util": ^8.2.2
|
||||
"@polkadot/util-crypto": ^8.2.2
|
||||
qrcode-generator: ^1.4.4
|
||||
@ -2757,7 +2757,7 @@ __metadata:
|
||||
react: "*"
|
||||
react-dom: "*"
|
||||
styled-components: "*"
|
||||
checksum: 622c055e41effba4834473c8215372657510f698f4317a260a6fd532733a97b6efe1cd023beba8c91ee95edbb72c05ba9a02b6c2618b27a4e224e13a0a62678b
|
||||
checksum: 9c737667819f92e1977714e8d63d8aec9213cad2da559873d3f7f8e17349a09b31c8297a43091561c1e1a61402fdab92df7d1f7756eaf8d9db78d17e4453b68b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -2881,14 +2881,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/ui-keyring@npm:^0.87.8-1":
|
||||
version: 0.87.8-1
|
||||
resolution: "@polkadot/ui-keyring@npm:0.87.8-1"
|
||||
"@polkadot/ui-keyring@npm:^0.87.8-2":
|
||||
version: 0.87.8-2
|
||||
resolution: "@polkadot/ui-keyring@npm:0.87.8-2"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.5
|
||||
"@polkadot/hw-ledger": ^8.2.2
|
||||
"@polkadot/keyring": ^8.2.2
|
||||
"@polkadot/ui-settings": 0.87.8-1
|
||||
"@polkadot/ui-settings": 0.87.8-2
|
||||
"@polkadot/util": ^8.2.2
|
||||
"@polkadot/util-crypto": ^8.2.2
|
||||
mkdirp: ^1.0.4
|
||||
@ -2898,13 +2898,13 @@ __metadata:
|
||||
"@polkadot/keyring": "*"
|
||||
"@polkadot/ui-settings": "*"
|
||||
"@polkadot/util": "*"
|
||||
checksum: ab4e82032c44d9bfce03b72e09dd350e2cf75112f4db159f5cb28081699cc862a3da721a6270f1bf315a6471547c1a49807ad52e3dd04ba5bcb88abd0c033229
|
||||
checksum: 41f93135cbe1f70bfbe739280ae7dcefe7cd096167b64feeb2fc040adb6354bbc60d94dd5567ba647a119826b2d312aab764ace654a544d47c2774e13806d71f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/ui-settings@npm:0.87.8-1, @polkadot/ui-settings@npm:^0.87.8-1":
|
||||
version: 0.87.8-1
|
||||
resolution: "@polkadot/ui-settings@npm:0.87.8-1"
|
||||
"@polkadot/ui-settings@npm:0.87.8-2, @polkadot/ui-settings@npm:^0.87.8-2":
|
||||
version: 0.87.8-2
|
||||
resolution: "@polkadot/ui-settings@npm:0.87.8-2"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.5
|
||||
"@polkadot/networks": ^8.2.2
|
||||
@ -2914,20 +2914,20 @@ __metadata:
|
||||
peerDependencies:
|
||||
"@polkadot/networks": "*"
|
||||
"@polkadot/util": "*"
|
||||
checksum: 60e6976b4796714b3b72ebc7d1606d79080a514fde8b4c75691009baf454ffe0e5ee1c53fb2416e4f117a0b6470d665db4a486104aeddbab205f75458279842f
|
||||
checksum: 2a4110870998e5c6d23b55ea5ca00b1eba13e81033aa5f27d2dcca01dedd26d36c6ec0a352f4017feccca0545cc064e3c1cef3d7c06c08e11b6ccd29d4597e53
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/ui-shared@npm:0.87.8-1":
|
||||
version: 0.87.8-1
|
||||
resolution: "@polkadot/ui-shared@npm:0.87.8-1"
|
||||
"@polkadot/ui-shared@npm:0.87.8-2":
|
||||
version: 0.87.8-2
|
||||
resolution: "@polkadot/ui-shared@npm:0.87.8-2"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.16.5
|
||||
color: ^3.2.1
|
||||
peerDependencies:
|
||||
"@polkadot/util": "*"
|
||||
"@polkadot/util-crypto": "*"
|
||||
checksum: 90588a9b84a9a75464abb3b074fdf1e1352d77904996c76a91d31e8576e5f655278ba7a7ddf2b858e1c293b555e974f522be2d9dfbc7c5d92e13891f939475a6
|
||||
checksum: 3fe9658e0c31bdd1e23e42cdb9e6c7e9e4648e3966b84590aa908bfdabf7514f35da454da9041a179af7f14974ec40b9a2f5929d06d5ad862b814669ed209948
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user