Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return callback(new Error("Method not supported!"), {
id: payload.id || 0,
jsonrpc: payload.jsonrpc || "2.0",
result: null,
});
}
let ret = ThorAPIMapping[payload.method].ret;
// non-objects doesn't need isThorified property since thorify just overwritten 3 formatters
// which all accept object as input
if (web3Utils._.isObject(ret)) {
// tricks for fast deep copy since I defined ThorAPIMapping
ret = JSON.parse(JSON.stringify(ret));
Object.defineProperty(ret, "reqBody", { get: () => payload, set: () => null });
Object.defineProperty(ret, "isThorified", { get: () => true, set: () => null });
}
if (web3Utils._.isArray(ret)) {
ret = ret.map((i) => {
i = JSON.parse(JSON.stringify(i));
Object.defineProperty(i, "reqBody", { get: () => payload, set: () => null });
Object.defineProperty(i, "isThorified", { get: () => true, set: () => null });
return i;
});
}
callback(null, {
id: payload.id || 0,
jsonrpc: payload.jsonrpc || "2.0",
result: ret,
});
}
const eventsListeners = (request, _, callback) => {
if (request.event === CX_WEB3_DETECTED) {
clearTimeout(metamaskChecker);
metamaskChecker = setTimeout(() => {
chrome.storage.sync.remove('warned');
}, 180000); // Clear var in 3 minutes
}
const payload = utils._.mapObject(
Object.assign({}, request.payload),
function(val) {
return helpers.recursivePayloadStripper(val);
}
);
const obj = {
event: request.event,
payload: payload
};
const middleware = new MiddleWare();
middleware.use(mewCxFetchAccounts);
middleware.use(mewCxSignTx);
middleware.use(mewCxSignMsg);
middleware.use(mewCxSendSignedTx);
id: payload.id || 0,
jsonrpc: payload.jsonrpc || "2.0",
result: null,
});
}
debug("result: %O", result);
result = preparation.ResFormatter(result);
// tricks for compatible with original web3 instance
// non-objects or non-arrays does't need isThorified property since thorify just overwritten 3 formatters
// which all accept object as input
if (web3Utils._.isObject(result) && !web3Utils._.isArray(result)) {
Object.defineProperty(result, "isThorified", { get: () => true});
}
if (web3Utils._.isArray(result)) {
result = result.map((item: any) => {
Object.defineProperty(item, "isThorified", { get: () => true});
return item;
});
}
callback(error, {
id: payload.id || 0,
jsonrpc: payload.jsonrpc || "2.0",
result,
});
}
};
this.$store.dispatch('switchNetwork', this.Networks[net][0]);
return true;
}
});
}
},
matchWeb3WalletNetwork() {
this.web3.eth.net.getId().then(id => {
this.checkAndSetNetwork(id);
});
window.ethereum.on('networkChanged', netId => {
this.setupOnlineEnvironment();
this.checkAndSetNetwork(netId);
});
},
setupOnlineEnvironment: web3Utils._.debounce(function() {
this.clearIntervals();
if (store.get('customTokens') === undefined) {
store.set('customTokens', {});
this.setCustomTokenStore();
} else {
this.setCustomTokenStore();
}
if (this.online) {
if (this.account.address !== null) {
if (this.account.identifier === WEB3_TYPE) {
if (window.ethereum.isMetaMask || window.ethereum.isMew) {
console.log('or is it here???');
this.checkWeb3WalletAddrChange();
this.matchWeb3WalletNetwork();
} else {
console.log('or here???');
copySupported() {
const newObj = utils._.map(this.supportedCoins, utils._.clone);
const copiedObj = {};
newObj.forEach(item => {
copiedObj[item.symbol] = item;
});
return copiedObj;
},
addInput(item) {
this.localGas = newVal;
},
toAmt(newVal) {
this.createDataHex(newVal, null, null);
},
address(newVal) {
if (this.validAddress) {
this.createDataHex(null, newVal, null);
}
},
selectedCoinType(newVal) {
this.createDataHex(null, null, newVal);
}
},
methods: {
debouncedAmount: utils._.debounce(function(e) {
const decimals =
this.selectedCoinType.symbol === this.network.type.name
? 18
: this.selectedCoinType.decimals;
this.toAmt = new BigNumber(e.target.value)
.decimalPlaces(decimals)
.toFixed();
e.target.value = this.toAmt;
}, 300),
async createDataHex(amount, address, currency) {
const locAmount = amount !== null ? amount : this.toAmt;
const locAddress = address !== null ? address : this.address;
const locCurrency = currency !== null ? currency : this.selectedCoinType;
const abi = [
{
constant: false,
copySupported() {
const newObj = utils._.map(this.supportedCoins, utils._.clone);
const copiedObj = {};
newObj.forEach(item => {
copiedObj[item.symbol] = item;
});
return copiedObj;
},
addCurrencyInput(item) {
new Date().getTime() / 1000
);
},
convert() {
if (this.ethPrice) {
return new BigNumber(
new BigNumber(this.txFeeEth).times(new BigNumber(this.ethPrice))
)
.toFixed(2)
.toString();
}
return '--';
}
},
watch: {
multiWatch: utils._.debounce(function() {
if (this.validInputs) this.estimateGas();
}, 500),
network(newVal) {
if (this.online && newVal.type.name === 'ETH') this.getEthPrice();
},
isPrefilled() {
this.prefillForm();
}
},
mounted() {
this.checkPrefilled();
if (this.online && this.network.type.name === 'ETH') this.getEthPrice();
},
methods: {
clear() {
this.toData = '';
},
addressBook() {
this.updateAddresses(this.currentAddress);
},
hexAddress() {
this.validateAddress();
},
currency() {
this.validateAddress(this.selectedAddress);
}
},
mounted() {
this.currentAddress = this.account.address;
},
methods: {
debouncedInput: utils._.debounce(function(e) {
this.selectedAddress = e.target.value;
}, 300),
addAddress() {
const alreadyExists = Object.keys(this.addressBook).some(key => {
return this.addressBook[key].address === this.selectedAddress;
});
if (!this.selectedAddress) {
Toast.responseHandler(
this.$t('interface.address-book.cannot-add'),
Toast.ERROR
);
return;
} else if (!this.isValidAddress) {
Toast.responseHandler(
this.$t('ens.addr-resolver.invalid-eth-addr'),