Reputation: 11
I am running a Meteor application and faced with an error I cannot figure out. I am using a quick form to insert a document into a collection and one of the fields is a Hash address to be obtained from a web3 api call using auto value.
//Schema with autovalue to obtain hash address via web3 call
CustomerSchema = new SimpleSchema({
customerBlockchainAddress: {
type: String,
label: "Blockchain Address",
autoValue: function() {
var address = web3.personal.newAccount("password");
console.log("Address: ", address);
return address;
},
autoform: {
type: "hidden"
}
},
//additional schema fields
The method is invoked by a quick form. See below:
//HTML
<template name="NewCompany">
<div class="new-document-container">
{{#if isSuccessfulCompany }}
<h3 class="success">Successfully registered company information. <br /> <br /> </h3>
{{else}}
<h3>Register Company Information:</h3><br />
{{> quickForm collection="Companies" id="insertCompanyForm" type="method" meteormethod="insertCompany" class="new-Company-form"}}
{{/ if}}
</div>
Insert method:
insertCustomer:function(customer){
CustomerSchema.clean(customer, {
extendAutoValueContext: {
isInsert: true,
isUpdate: false,
isUpsert: false,
isFromTrustedCode: false
}
});
check(customer, CustomerSchema);
if (! this.userId) {
throw new Meteor.Error('not-authorized');
}
if(! Roles.userIsInRole(this.userId,'individual')){
throw new Meteor.Error('not-authorized for your role');
}
//custom API that takes fields from the customer doc and stores
them on the blockchain
Meteor.call('individualRegistration', customer, function (error,
result) {
if (error) {
console.log("error", error);
};
console.log(result);
});
return Customers.insert(customer);
}
The error I am getting is:
Exception while invoking method 'insertCustomer' TypeError:
XMLHttpRequest is not a function
Using log statements, the AutoValue function is obtaining a new address from the web3 call as expected but it is printing four times with different addresses before the error is thrown. If I hard code the address with just a string, the insert function works properly as expected with the custom API.
I rolled back to a previous version of my app when API calls were working and inserting into a collection and that version was using an out of date version of Meteor with out of date packages. Upon calling "meteor update" the calls stopped working and the same error is displayed. Can someone please explain what might be causing this error.
Update: I correctly updated aldeed:autoform and removed aldeed:simple-schema and installed the NPM simpl-schema as directed in the readmes of the packages. The error still is being thrown.
Thanks
Upvotes: 1
Views: 188