const e=require(`../../types/balances.types.cjs`),t=require(`./upToDateState.cjs`),n=require(`../../error-handling/logger.cjs`),r=require(`../../mutexes/mutex.cjs`),i=require(`../web3/events/balanceChangedHandler.cjs`);var a=async(a,o=!1)=>{let s=await a.getEthereumAddress();i.balanceChangedHandler({updateType:e.PrivateBalanceUpdateType.OnlyCache,balanceChangeState:{ethereumAddress:s}}),await r.resetStateMutex.runExclusive(async()=>{try{await t.checkAddressNotUpdated(a,s),o||(await a.resetMerkle(),await t.checkAddressNotUpdated(a,s)),i.balanceChangedHandler({updateType:e.PrivateBalanceUpdateType.FreshWithoutLoader,balanceChangeState:{ethereumAddress:s,userKeys:a.userKeys},updateTokensListBefore:!0})}catch(e){n.Logger.log(`resetMerkleAndRefreshPrivateBalance error`,e)}})},o=async(n,a=!1)=>{let o=await n.getEthereumAddress();await r.resetStateMutex.runExclusive(async()=>{let{userKeys:r}=n;await t.checkAddressNotUpdated(n,o),await n.resetMerkleTreesIfNecessary(),await t.checkAddressNotUpdated(n,o),i.balanceChangedHandler({updateType:e.PrivateBalanceUpdateType.Fresh,balanceChangeState:{ethereumAddress:o,userKeys:r},updateTokensListBefore:!0,resetCacheBefore:a})})},s=async e=>{await o(e,!0)};exports.hardRefreshPrivateBalance=s,exports.initialMerkleAndPrivateBalanceRefresh=a,exports.refreshPrivateBalance=o;