Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let web3 = typeof(window.web3) !== 'undefined' ? new Web3js(window.web3.currentProvider) : new Web3js(new Web3js.providers.HttpProvider(constant.LOCAL_NODE));
// Reflect required due to metamask providing a proxy object
try {
if (web3.isConnected() === true) {
Reflect.set(web3, 'isRemote', false);
}
else {
throw new Error('No local node connection available...');
}
}
catch (e) {
console.log(e.message);
web3 = new Web3js(new Web3js.providers.HttpProvider(constant.REMOTE_NODE));
Reflect.set(web3, 'isRemote', true);
}
// meta-mask race condition workaround
window.addEventListener('load', () => {
console.log('Page loaded...')
if (web3.isRemote && typeof window.web3 !== 'undefined') {
console.log('Injecting inpage web3...');
// only use provider and use local web3
let web3 = new Web3js(window.web3.currentProvider);
Reflect.set(web3, 'isRemote', false);
Promise.promisifyAll(web3.eth);
exports.default = web3;
}
});
Promise.promisifyAll(web3.eth);
import * as constant from './Constant';
import Promise from 'bluebird';
import Web3js from 'web3';
import Reflect from 'harmony-reflect';
let web3 = typeof(window.web3) !== 'undefined' ? new Web3js(window.web3.currentProvider) : new Web3js(new Web3js.providers.HttpProvider(constant.LOCAL_NODE));
// Reflect required due to metamask providing a proxy object
try {
if (web3.isConnected() === true) {
Reflect.set(web3, 'isRemote', false);
}
else {
throw new Error('No local node connection available...');
}
}
catch (e) {
console.log(e.message);
web3 = new Web3js(new Web3js.providers.HttpProvider(constant.REMOTE_NODE));
Reflect.set(web3, 'isRemote', true);
}
// meta-mask race condition workaround
window.addEventListener('load', () => {
console.log('Page loaded...')
if (web3.isRemote && typeof window.web3 !== 'undefined') {
console.log('Injecting inpage web3...');
registerGlobalDecorators(confObject) {
const decorators = Reflect.get(confObject, 'decorators') || []
this.registerDecorators(GLOBAL_NAMESPACE_DECORATOR, decorators)
}
registerServices(confObject) {
const services = Reflect.get(confObject, 'services') || {}
for (let alias in services) {
const service = Reflect.get(services[alias], 'service')
const args = Reflect.get(services[alias], 'arguments') || []
const tags = Reflect.get(services[alias], 'tags') || []
const decorators = Reflect.get(services[alias], 'decorators') || []
const listeners = Reflect.get(services[alias], 'listeners') || {}
const isSingleton = Reflect.get(services[alias], 'singleton') || false
this.container.addService(alias, service, args, isSingleton)
this.registerTags(alias, tags, this.container.getConfigValue('serviceDelimiter'))
this.registerListeners(alias, listeners)
this.registerDecorators(alias, decorators)
}
}
registerServices(confObject) {
const services = Reflect.get(confObject, 'services') || {}
for (let alias in services) {
const service = Reflect.get(services[alias], 'service')
const args = Reflect.get(services[alias], 'arguments') || []
const tags = Reflect.get(services[alias], 'tags') || []
const decorators = Reflect.get(services[alias], 'decorators') || []
const listeners = Reflect.get(services[alias], 'listeners') || {}
const isSingleton = Reflect.get(services[alias], 'singleton') || false
this.container.addService(alias, service, args, isSingleton)
this.registerTags(alias, tags, this.container.getConfigValue('serviceDelimiter'))
this.registerListeners(alias, listeners)
this.registerDecorators(alias, decorators)
}
}
registerConfigValues(confObject) {
const values = Reflect.get(confObject, 'config') || {}
for (let key in values) {
this.container.addConfigValue(key, values[key])
}
}
find(alias) {
return Reflect.get(this.decorators, alias) || []
}
registerServices(confObject) {
const services = Reflect.get(confObject, 'services') || {}
for (let alias in services) {
const service = Reflect.get(services[alias], 'service')
const args = Reflect.get(services[alias], 'arguments') || []
const tags = Reflect.get(services[alias], 'tags') || []
const decorators = Reflect.get(services[alias], 'decorators') || []
const listeners = Reflect.get(services[alias], 'listeners') || {}
const isSingleton = Reflect.get(services[alias], 'singleton') || false
this.container.addService(alias, service, args, isSingleton)
this.registerTags(alias, tags, this.container.getConfigValue('serviceDelimiter'))
this.registerListeners(alias, listeners)
this.registerDecorators(alias, decorators)
}
}
const registerServices = (services, flask) => {
for (let alias in services) {
const service = Reflect.get(services[alias], 'service')
const args = Reflect.get(services[alias], 'arguments') || []
const tags = Reflect.get(services[alias], 'tags') || []
const decorators = Reflect.get(services[alias], 'decorators') || []
const listeners = Reflect.get(services[alias], 'listeners') || {}
const isSingleton = Reflect.get(services[alias], 'singleton') || false
isSingleton === true
? flask.singleton(alias, service, args)
: flask.service(alias, service, args)
registerTags(alias, tags, flask)
registerDecorators(alias, decorators, flask)
registerServiceListeners(alias, listeners, flask)
}
}
registerGlobalListeners(confObject) {
const listeners = Reflect.get(confObject, 'listeners') || {}
this.registerListeners(GLOBAL_NAMESPACE_LISTENERS, listeners)
}