From bc38dcb13699305f099c58b023ad6988e0d1b4b1 Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Sat, 27 Jun 2020 20:39:23 +0200 Subject: [PATCH] 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. --- lib/contracts/contributor.js | 3 ++- lib/utils/ipfs.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/contracts/contributor.js b/lib/contracts/contributor.js index 6a1c1ed..218e21e 100644 --- a/lib/contracts/contributor.js +++ b/lib/contracts/contributor.js @@ -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); }); diff --git a/lib/utils/ipfs.js b/lib/utils/ipfs.js index 18b17d4..84a4692 100644 --- a/lib/utils/ipfs.js +++ b/lib/utils/ipfs.js @@ -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;