Copy contract data into new object to avoid object is not extensible error

It seems the new ethers.js version returns contract data as a non-
extensible object. We have to clone it before adding the IPFS data.
This commit is contained in:
bumi 2020-06-27 20:39:23 +02:00
parent c2dcedfe58
commit bc38dcb136
2 changed files with 4 additions and 2 deletions

View File

@ -9,7 +9,8 @@ class Contributor extends Record {
getById (id) {
return this.functions.getContributorById(id)
.then(data => {
.then(contractData => {
let data = {...contractData};
data.balanceInt = formatKredits(data.balance);
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
});

View File

@ -11,7 +11,8 @@ class IPFS {
this._ipfsAPI = ipfsClient(config);
}
catAndMerge (data, deserialize) {
catAndMerge (contractData, deserialize) {
let data = {...contractData}; // data from ethers.js is not extensible. this copy the attributes in a new object
// if no hash details are found simply return the data; nothing to merge
if (!data.hashSize || data.hashSize === 0) {
return data;