public function addressBalance() { $address = $this->context->takeNextPathComponent(); $fiveSecs = Time\readInterval('5 seconds'); try { return $this->textResponse(Bitcoin\getBalance($address, 'BTC', $maxCacheAge = $fiveSecs)); } catch (Bitcoin\InvalidAddress $_) { return $this->textResponse('Invalid Bitcoin address', $code = 400); } }
function progress(RequestContext $c) { try { $w = $this->takeWidgetFromURI($c); $fiveSecs = Time\readInterval('5 seconds'); $w->updateBalance(Bitcoin\getBalance($w->bitcoinAddress, $maxCacheAge = $fiveSecs)); return $this->textResponse($w->progressPercent); } catch (\SpareParts\WebClient\NetworkError $e) { Log\notice("Caught " . get_class($e) . " when attempting to check Bitcoin-address balance: " . $e->getMessage()); return $this->textResponse("Network error occurred when trying to check address balance", 503); } }
function testDashboard() { $w1 = getWidget($this->user); $threeDaysAgo = (new DateTime('now'))->sub(Time\readInterval('3 days')); $this->updateEndingDate($w1, $threeDaysAgo); $w2 = getWidget($this->user); $inOneHour = (new DateTime('now'))->add(Time\readInterval('1 hour')); $this->updateEndingDate($w2, $inOneHour); $w3 = getWidget($this->user); $manana = (new DateTime('now'))->add(Time\readInterval('1 day')); $this->updateEndingDate($w3, $manana); $this->get('/dashboard/'); # TODO: Test that each widget shows up under appropriate tabs... }