Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Http/Controllers/Inertia/StatisticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function convertFeesChart(array $chartData): array
{
$datasets = array_map(
static function ($value): float {
return BigDecimal::of(NumberFormatter::weiToArk((string) BigDecimal::of($value), false))->toFloat();
return BigDecimal::of(NumberFormatter::weiToArk((string) BigDecimal::of((string) $value), false))->toFloat();
},
$chartData['datasets'] ?? [],
);
Expand All @@ -221,7 +221,7 @@ static function ($value): float {

private function weiToArk(float $value): float
{
return BigDecimal::of(NumberFormatter::weiToArk((string) BigDecimal::of($value), false))->toFloat();
return BigDecimal::of(NumberFormatter::weiToArk((string) BigDecimal::of((string) $value), false))->toFloat();
}

private function chartTheme(string $color): array
Expand Down
34 changes: 27 additions & 7 deletions app/Services/BigNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class BigNumber implements Stringable
*/
private function __construct($value)
{
$this->value = BigDecimal::of($value);
$this->value = BigDecimal::of(self::toBrickValue($value));
}

/**
Expand All @@ -44,11 +44,11 @@ public static function zero(): self
}

/**
* @param BigDecimal|int|string $value
* @param BigDecimal|int|float|string $value
*/
public function plus($value): self
{
$this->value = $this->value->plus($value);
$this->value = $this->value->plus(self::toBrickValue($value));

return $this;
}
Expand All @@ -58,21 +58,26 @@ public function plus($value): self
*/
public function multipliedBy($value): self
{
$this->value = $this->value->multipliedBy($value);
$this->value = $this->value->multipliedBy(self::toBrickValue($value));

return $this;
}

/**
* @param BigNumber|BigDecimal|int|float|string $value
* @param int<0, max>|null $scale Defaults to the scale of the current value
*/
public function dividedBy($value, ?int $scale = null, RoundingMode $roundingMode = RoundingMode::Unnecessary): self
{
if ($value instanceof self) {
$value = $value->valueOf();
}

$this->value = $this->value->dividedBy($value, $scale, $roundingMode);
$this->value = $this->value->dividedBy(
self::toBrickValue($value),
$scale ?? $this->value->getScale(),
$roundingMode,
);

return $this;
}
Expand All @@ -93,7 +98,8 @@ public function toHex(): string
}

/**
* @param float|null $divisor Defaults to 1e18 if not provided
* @param float|null $divisor Defaults to 1e18 if not provided
* @param int<0, max>|null $scale
*
* @return float
*/
Expand All @@ -103,7 +109,7 @@ public function toFloat(?float $divisor = null, ?int $scale = null): float
$divisor = config('currencies.notation.crypto', 1e18);
}

$value = $this->value->dividedBy($divisor, 18, RoundingMode::Down);
$value = $this->value->dividedBy(self::toBrickValue($divisor), 18, RoundingMode::Down);

if ($scale !== null) {
$value = $value->toScale($scale, RoundingMode::Down);
Expand All @@ -116,4 +122,18 @@ public function valueOf(): BigDecimal
{
return $this->value;
}

/**
* Brick doesn't accept floats, so they're passed as their string representation.
*
* @param int|float|string|BigDecimal $value
*/
private static function toBrickValue($value): int|string|BigDecimal
{
if (is_float($value)) {
return (string) $value;
}

return $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function aggregate(): array
'count' => (int) round($count / $daysSinceEpoch),
'amount' => (int) round($totalAmount / $daysSinceEpoch),
'fee' => UnitConverter::formatUnits(
(string) BigNumber::new($fee)->valueOf()->dividedBy($daysSinceEpoch, null, RoundingMode::Down),
(string) BigNumber::new($fee)->dividedBy($daysSinceEpoch, roundingMode: RoundingMode::Down),
'ark'
)->toFloat(),
];
Expand Down
2 changes: 1 addition & 1 deletion app/ViewModels/Concerns/Wallet/CanVote.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public function votePercentage(): ?float
return null;
}

return $this->wallet->balance->valueOf()->multipliedBy(100)->dividedBy($validator->attributes['validatorVoteBalance'], 2, RoundingMode::Down)->toFloat();
return $this->wallet->balance->valueOf()->multipliedBy(100)->dividedBy((string) $validator->attributes['validatorVoteBalance'], 2, RoundingMode::Down)->toFloat();
}
}
3 changes: 3 additions & 0 deletions app/ViewModels/WalletViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function publicKey(): ?string
return $this->wallet->public_key;
}

/**
* @param int<0, max> $scale
*/
public function balance(int $scale = 8): float
{
return $this->wallet->balance->toFloat(scale: $scale);
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
"ext-gmp": "*",
"ardenthq/arkvault-url": "^1.2",
"arkecosystem/crypto": "dev-feat/mainsail",
"arkecosystem/foundation": "^22.3.4",
"arkecosystem/foundation": "^23.0",
"blade-ui-kit/blade-icons": "^1.11",
"brick/math": "^0.14.8",
"brick/math": "^1.0",
"doctrine/dbal": "^4.6",
"geoip2/geoip2": "^3.5",
"http-interop/http-factory-guzzle": "^1.2.1",
"inertiajs/inertia-laravel": "^3.7",
"laravel/horizon": "^5.52",
"laravel/reverb": "^1.14",
Expand Down
Loading
Loading