Skip to content

Commit

Permalink
Merge pull request bavix#152 from bavix/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rez1dent3 authored Mar 19, 2020
2 parents 1762837 + c3f7c90 commit 8e82228
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
14 changes: 12 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.0.1] - 2020-03-19
### Added
- Added a patch from version 4.2.1 #150

## [5.0.0] - 2020-03-13

### Added
Expand All @@ -22,6 +26,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- all deprecated methods are removed
- `nesbot/carbon` is no longer needed for the library to work

## [4.2.1] - 2020-03-19
### Fixed
- Fixed wallet recalculate command #150

## [4.2.0] - 2020-03-08

### Added
Expand Down Expand Up @@ -469,8 +477,10 @@ The operation is now executed in the transaction and updates the new `refund` fi
- Exceptions: AmountInvalid, BalanceIsEmpty.
- Models: Transfer, Transaction.

[Unreleased]: https://github.com/bavix/laravel-wallet/compare/5.0.0...develop
[5.0.0]: https://github.com/bavix/laravel-wallet/compare/4.2.0...5.0.0
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/5.0.1...develop
[5.0.1]: https://github.com/bavix/laravel-wallet/compare/5.0.0...5.0.1
[5.0.0]: https://github.com/bavix/laravel-wallet/compare/4.2.1...5.0.0
[4.2.1]: https://github.com/bavix/laravel-wallet/compare/4.2.0...4.2.1
[4.2.0]: https://github.com/bavix/laravel-wallet/compare/4.1.2...4.2.0
[4.1.2]: https://github.com/bavix/laravel-wallet/compare/4.1.1...4.1.2
[4.1.1]: https://github.com/bavix/laravel-wallet/compare/4.1.0...4.1.1
Expand Down
14 changes: 7 additions & 7 deletions src/Commands/RefreshBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class RefreshBalance extends Command
public function handle(): void
{
app(DbService::class)->transaction(function () {
$wallet = config('wallet.wallet.table', 'wallets');
app(DbService::class)
->connection()
->table($wallet)
->update(['balance' => 0]);

if (app(DbService::class)->connection() instanceof SQLiteConnection) {
$wallet = config('wallet.wallet.table', 'wallets');
app(DbService::class)
->connection()
->table($wallet)
->update(['balance' => 0]);

$this->sqliteUpdate();
} else {
$this->multiUpdate();
Expand Down Expand Up @@ -88,7 +88,7 @@ protected function multiUpdate(): void
->connection()
->table($wallet)
->joinSub($availableBalance, 'b', $joinClause, null, null, 'left')
->update(['balance' => app(DbService::class)->raw('b.balance')]);
->update(["$wallet.balance" => app(DbService::class)->raw('ifnull(b.balance, 0)')]);
}

}
26 changes: 26 additions & 0 deletions tests/WalletFloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,30 @@ public function testBitcoin(): void
}
}

/**
* Case from @ucanbehack
* @see https://github.com/bavix/laravel-wallet/issues/149
*/
public function testBitcoin2(): void
{
if (app(Mathable::class) instanceof BCMath) {
/**
* @var User $user
*/
$user = factory(User::class)->create();
$this->assertEquals($user->balance, 0);

$user->wallet->decimal_places = 8;
$user->wallet->save();

$user->depositFloat(0.09699977);

$user->wallet->refreshBalance();
$user->refresh();

$this->assertEquals($user->balanceFloat, 0.09699977);
$this->assertEquals($user->balance, 9699977);
}
}

}

0 comments on commit 8e82228

Please sign in to comment.