Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The decimal value is converted to an integer in the transfer #857

Closed
hamedkhorasani opened this issue Jan 21, 2024 · 6 comments · Fixed by #870
Closed

The decimal value is converted to an integer in the transfer #857

hamedkhorasani opened this issue Jan 21, 2024 · 6 comments · Fixed by #870
Assignees
Labels
docs good issue Good for newcomers performance question Further information is requested

Comments

@hamedkhorasani
Copy link

Hello @rez1dent3
In the example below, I want to transfer $0.93, but it transfers $1.

$fee = app(TransferQueryHandlerInterface::class)->apply([
	new TransferQuery($targetWallet, $feeWallet, 0.93, new Extra(
		deposit: new Option(
			meta: [
				'name' => 'exchange_fee',
			],
			confirmed: true
		),
		withdraw: new Option(
			meta: [
				'name' => 'exchange_fee',
			],
			confirmed: true
		)
	))
]);
@sinamiandashti
Copy link

same issue !

@sinamiandashti
Copy link

ah you should use HasWalletFloat trait hamed jan @hamedkhorasani

@hamedkhorasani
Copy link
Author

@sinamiandashti It didn't work.

class User extends Authenticatable implements HasMedia, Wallet, WalletFloat
{
    use Notifiable,
        HasRoles,
        InteractsWithMedia,
        MetaTrait,
        HasHashId,
        SavesHashId,
        HasApiTokens,
        HasWalletFloat,
        HasWallets,
        CanConfirm;
}

@rez1dent3
Copy link
Member

Hello. The architecture of laravel wallet is built around integers, which is surprising to many. You have decimal_places, which specifies the shift of decimal places.

For example, we have a wallet ($) and decimal_places=2. We deposit 123 into the account.

123 / 10^2 => $1,23

Those, you have 123 stored in your balance, but when displaying the float balance, additional calculations are performed.

High-performance APIs are low-level programming in laravel-wallet, they do not check anything and write directly to the database. You need to do this:

$fee = app(TransferQueryHandlerInterface::class)->apply([
	new TransferQuery($targetWallet, $feeWallet, 93, new Extra(
		deposit: new Option(
			meta: [
				'name' => 'exchange_fee',
			],
			confirmed: true
		),
		withdraw: new Option(
			meta: [
				'name' => 'exchange_fee',
			],
			confirmed: true
		)
	))
]);

For example, $targetWallet has decimal_places=2 and by this we mean $.

93 // $0.93
123 // $1.23
100000 // $1000.00
123456789 // $1234567.89

That is, storage is carried out in the minimum currency.
It's all about numerical methods and mantis. Example.

@rez1dent3 rez1dent3 self-assigned this Jan 22, 2024
@rez1dent3 rez1dent3 added good issue Good for newcomers question Further information is requested performance docs labels Jan 22, 2024
@hamedkhorasani
Copy link
Author

Thanks a lot.

@rez1dent3
Copy link
Member

rez1dent3 commented Jan 25, 2024

@hamedkhorasani Hello. Version 11.x will add two more contracts to make your life easier.

// first
TransactionFloatQuery::createDeposit(...);
TransactionFloatQuery::createWithdraw(...);

// second
new TransferFloatQuery(...);

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs good issue Good for newcomers performance question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants