Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((): void => {
console.log('crypto initialized');
// load all the keyring data
keyring.loadAll({ store: new ExtensionStore(), type: 'sr25519' });
console.log('initialization completed');
})
.catch((error): void => {
const systemChain = _systemChain
? _systemChain.toString()
: '';
const isDevelopment = isTestChain(systemChain);
console.log('api: found chain', systemChain, JSON.stringify(properties));
// first setup the UI helpers
formatBalance.setDefaults({
decimals: tokenDecimals,
unit: tokenSymbol
});
TokenUnit.setAbbr(tokenSymbol);
// finally load the keyring
keyring.loadAll({
addressPrefix: ss58Format,
genesisHash: api.genesisHash,
isDevelopment,
ss58Format,
type: 'ed25519'
}, injectedAccounts);
const defaultSection = Object.keys(api.tx)[0];
const defaultMethod = Object.keys(api.tx[defaultSection])[0];
const apiDefaultTx = api.tx[defaultSection][defaultMethod];
const apiDefaultTxSudo =
(api.tx.system && api.tx.system.setCode) || // 2.x
(api.tx.consensus && api.tx.consensus.setCode) || // 1.x
apiDefaultTx; // other
const isSubstrateV2 = !!Object.keys(api.consts).length;
.subscribe(([chain, health, name, properties, version]) => {
if (!keyringInitialized) {
// keyring with Schnorrkel support
keyring.loadAll({
ss58Format: properties.ss58Format.unwrapOr(createType('u8', SS58_PREFIX)).toNumber(),
genesisHash: api.genesisHash,
isDevelopment: isTestChain(chain.toString()),
type: 'ed25519'
});
keyringInitialized = true;
} else {
// The keyring can only be initialized once. To make sure that the
// keyring values are up-to-date in case the node has changed settings
// we need to reinitialize it.
window.location.reload();
return;
}
l.log(`Api connected to ${WS_URL}`);
l.log(`Api ready, connected to chain "${chain}" with properties ${JSON.stringify(properties)}`);
).subscribe((properties) => {
const networkId = properties.get('networkId') || 42;
// Setup keyring (loadAll) only after prefix has been set
keyring.setAddressPrefix(networkId);
keyring.loadAll();
this.setState({ isReady: true });
});
}
const initialize = async (): Promise => {
try {
keyring.loadAll({ ss58Format: 42, type: 'sr25519' });
} catch (e) {
console.log('Error loading keyring ', e);
}
await globalAny.localStorage.init();
await cryptoWaitReady();
setReady(true);
_onClickNew();
};
cryptoWaitReady().then((): void => {
keyring.loadAll({ ss58Format: 42, type: 'sr25519' });
ReactDOM.render(, rootElement);
});
export function createApp (App: React.ComponentType, props: Props = {}, rootId: string = 'root'): void {
const rootElement = document.getElementById(rootId);
if (!rootElement) {
throw new Error(`Unable to find element with id '${rootId}'`);
}
keyring.loadAll();
ReactDOM.render(
,
rootElement
);
}