...
 
Commits (3)
......@@ -50,7 +50,10 @@ class wallet implements Interfaces\Api
$offChainBalanceVal = BigNumber::_($offChainBalance->get());
$offchainAvailableVal = BigNumber::_($offChainBalance->getAvailable());
$balance = $onChainBalanceVal->add($offChainBalanceVal);
$balance = $onChainBalanceVal
? $onChainBalanceVal->add($offChainBalanceVal)
: $offChainBalanceVal;
$wireCap = Di::_()->get('Blockchain\Wallets\OffChain\Cap')
->setUser(Session::getLoggedinUser())
......
......@@ -60,6 +60,11 @@ class Balance
}
$balance = $this->token->balanceOf($address);
if ($balance === null) {
return null;
}
$this->cache->set($cacheKey, serialize($balance), 60);
return $balance;
......
......@@ -70,4 +70,26 @@ class BalanceSpec extends ObjectBehavior
$this->setUser($user);
$this->get()->shouldReturn(0);
}
public function it_should_not_store_null_values_in_cache(User $user)
{
$user->getEthWallet()
->shouldBeCalled()
->willReturn('0x123');
$this->cache->get('blockchain:balance:0x123')
->shouldBeCalled()
->willReturn(null);
$this->token->balanceOf('0x123')
->shouldBeCalled()
->willReturn(null);
$this->cache->set('blockchain:balance:0x123', null, 60)
->shouldBeCalledTimes(0);
$this->setUser($user);
$this->get()->shouldReturn(null);
}
}