Files
pwap/pezkuwi-sdk-ui/packages/page-contracts/src/store.ts
T
pezkuwichain 971df8edba Rebrand: Remove 3rd party chains, update domains to PezkuwiChain
- Remove all 3rd party parachain configurations from endpoints:
  - productionRelayPolkadot.ts: Keep only system parachains
  - productionRelayDicle.ts: Keep only system parachains
  - testingRelayZagros.ts: Keep only system parachains
  - testingRelayTeyrChain.ts: Keep only system parachains

- Update domain references:
  - polkadot.js.org → pezkuwichain.app
  - wiki.polkadot.network → wiki.pezkuwichain.io
  - dotapps.io → pezkuwichain.app
  - statement.polkadot.network → docs.pezkuwichain.io/statement
  - support.polkadot.network → docs.pezkuwichain.io

- Update repository references:
  - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap

- Rename system parachains to Pezkuwi ecosystem:
  - PolkadotAssetHub → PezkuwiAssetHub
  - polkadotBridgeHub → pezkuwiBridgeHub
  - polkadotCollectives → pezkuwiCollectives
  - polkadotCoretime → pezkuwiCoretime
  - polkadotPeople → pezkuwiPeople

- Update network name in claims utility:
  - Polkadot → Pezkuwi
2026-01-09 03:08:11 +03:00

95 lines
2.5 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/app-contracts authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Hash } from '@pezkuwi/types/interfaces';
import type { CodeJson, CodeStored } from './types.js';
import { EventEmitter } from 'eventemitter3';
import store from 'store';
import { Abi } from '@pezkuwi/api-contract';
import { statics } from '@pezkuwi/react-api/statics';
import { isString } from '@pezkuwi/util';
const KEY_CODE = 'code:';
class Store extends EventEmitter {
#allCode: Record<string, CodeStored> = {};
public get hasCode (): boolean {
return Object.keys(this.#allCode).length !== 0;
}
public getAllCode (): CodeStored[] {
return Object.values(this.#allCode);
}
public getCode (codeHash: string): CodeStored | undefined {
return this.#allCode[codeHash];
}
public saveCode (_codeHash: string | Hash, partial: Partial<CodeJson>): void {
const codeHash = (isString(_codeHash) ? statics.api.registry.createType('Hash', _codeHash) : _codeHash).toHex();
const existing = this.getCode(codeHash);
const json = {
...(existing ? existing.json : {}),
...partial,
codeHash,
genesisHash: statics.api.genesisHash.toHex(),
whenCreated: existing?.json.whenCreated || Date.now()
};
const key = `${KEY_CODE}${json.codeHash}`;
store.set(key, json);
this.addCode(key, json as CodeJson);
}
public forgetCode (codeHash: string): void {
this.removeCode(`${KEY_CODE}${codeHash}`, codeHash);
}
public loadAll (onLoaded?: () => void): void {
try {
const genesisHash = statics.api.genesisHash.toHex();
store.each((json: CodeJson, key: string): void => {
if (json && json.genesisHash === genesisHash && key.startsWith(KEY_CODE)) {
this.addCode(key, json);
}
});
onLoaded && onLoaded();
} catch (error) {
console.error('Unable to load code', error);
}
}
private addCode (key: string, json: CodeJson): void {
try {
this.#allCode[json.codeHash] = {
contractAbi: json.abi
? new Abi(json.abi, statics.api.registry.getChainProperties())
: undefined,
json
};
this.emit('new-code');
} catch (error) {
console.error(error);
this.removeCode(key, json.codeHash);
}
}
private removeCode (key: string, codeHash: string): void {
try {
delete this.#allCode[codeHash];
store.remove(key);
this.emit('removed-code');
} catch (error) {
console.error(error);
}
}
}
export default new Store();