mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-16 21:21:04 +00:00
Adjust keyring load with additional hashes (#574)
This commit is contained in:
@@ -258,13 +258,16 @@ export class Keyring extends Base implements KeyringStruct {
|
|||||||
this.accounts.add(this._store, pair.address, json, pair.type);
|
this.accounts.add(this._store, pair.address, json, pair.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private allowGenesis (hashes: string[], json?: KeyringJson | { meta: KeyringJson$Meta } | null): boolean {
|
private allowGenesis (json?: KeyringJson | { meta: KeyringJson$Meta } | null): boolean {
|
||||||
if (json && json.meta) {
|
if (json && json.meta && this.genesisHash) {
|
||||||
|
const hashes: (string | null | undefined)[] = Object.values(chains).find((hashes): boolean =>
|
||||||
|
hashes.includes(this.genesisHash || '')
|
||||||
|
) || [this.genesisHash];
|
||||||
|
|
||||||
if (json.meta.genesisHash) {
|
if (json.meta.genesisHash) {
|
||||||
return hashes.includes(json.meta.genesisHash);
|
return hashes.includes(json.meta.genesisHash) || this.genesisHashes.includes(json.meta.genesisHash);
|
||||||
} else if (json.meta.contract && json.meta.contract.genesisHash) {
|
} else if (json.meta.contract) {
|
||||||
// for contracts, we only allow the primary/first hash
|
return hashes.includes(json.meta.contract.genesisHash);
|
||||||
return hashes[0] === json.meta.contract.genesisHash;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,20 +277,10 @@ export class Keyring extends Base implements KeyringStruct {
|
|||||||
public loadAll (options: KeyringOptions, injected: { address: string; meta: KeyringJson$Meta, type?: KeypairType }[] = []): void {
|
public loadAll (options: KeyringOptions, injected: { address: string; meta: KeyringJson$Meta, type?: KeypairType }[] = []): void {
|
||||||
super.initKeyring(options);
|
super.initKeyring(options);
|
||||||
|
|
||||||
const hashes = [
|
|
||||||
...this.genesisHashes,
|
|
||||||
...(
|
|
||||||
Object
|
|
||||||
.values(chains)
|
|
||||||
.find((h) => h.includes(this.genesisHash || '')) ||
|
|
||||||
[]
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
this._store.all((key: string, json: KeyringJson): void => {
|
this._store.all((key: string, json: KeyringJson): void => {
|
||||||
if (!isFunction(options.filter) || options.filter(json)) {
|
if (!isFunction(options.filter) || options.filter(json)) {
|
||||||
try {
|
try {
|
||||||
if (this.allowGenesis(hashes, json)) {
|
if (this.allowGenesis(json)) {
|
||||||
if (accountRegex.test(key)) {
|
if (accountRegex.test(key)) {
|
||||||
this.loadAccount(json, key);
|
this.loadAccount(json, key);
|
||||||
} else if (addressRegex.test(key)) {
|
} else if (addressRegex.test(key)) {
|
||||||
@@ -303,7 +296,7 @@ export class Keyring extends Base implements KeyringStruct {
|
|||||||
});
|
});
|
||||||
|
|
||||||
injected.forEach((account): void => {
|
injected.forEach((account): void => {
|
||||||
if (this.allowGenesis(hashes, account)) {
|
if (this.allowGenesis(account)) {
|
||||||
try {
|
try {
|
||||||
this.loadInjected(account.address, account.meta, account.type);
|
this.loadInjected(account.address, account.meta, account.type);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user