From 49d3ae96373117664c570386ea8bd69958fc0475 Mon Sep 17 00:00:00 2001 From: Pedro Ferreira Date: Tue, 14 Jan 2025 11:49:45 -0300 Subject: [PATCH] feat: use cloneDeep to get token data from storage in the get balance --- src/new/wallet.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/new/wallet.js b/src/new/wallet.js index a43b5015..ff86487b 100644 --- a/src/new/wallet.js +++ b/src/new/wallet.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import { get } from 'lodash'; +import { cloneDeep, get } from 'lodash'; import bitcore, { HDPrivateKey } from 'bitcore-lib'; import EventEmitter from 'events'; import { NATIVE_TOKEN_UID, P2SH_ACCT_PATH, P2PKH_ACCT_PATH } from '../constants'; @@ -699,7 +699,9 @@ class HathorWallet extends EventEmitter { throw new WalletError('Not implemented.'); } const uid = token || this.token.uid; - let tokenData = await this.storage.getToken(uid); + // Using clone deep so the balance returned will not be updated in case + // we change the storage + let tokenData = cloneDeep(await this.storage.getToken(uid)); if (tokenData === null) { // We don't have the token on storage, so we need to return an empty default response tokenData = {