Skip to content

Commit 20042e3

Browse files
authored
fix: compare balance to value with assetscale in mind when checking balance (#2001)
compare balance to value with assetscale in mind
1 parent a0ad79b commit 20042e3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/wallet/backend/src/quote/service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,24 @@ export class QuoteService implements IQuoteService {
5151
params.userId
5252
)
5353

54+
let asset: Pick<Asset, 'scale' | 'code'> | undefined =
55+
await this.rafikiClient.getAssetById(assetId)
56+
if (!asset) {
57+
throw new NotFound()
58+
}
59+
5460
const account = await this.accountService.getAccountById(
5561
params.userId,
5662
existingWalletAddress.accountId
5763
)
5864
const balance = account.balance
5965

60-
if (Number(balance) < params.amount) {
61-
throw new BadRequest('Not enough funds in account')
62-
}
66+
const originalValue = BigInt((params.amount * 10 ** asset.scale).toFixed())
6367

64-
let asset: Pick<Asset, 'scale' | 'code'> | undefined =
65-
await this.rafikiClient.getAssetById(assetId)
66-
if (!asset) {
67-
throw new NotFound()
68+
if (Number(balance) < originalValue) {
69+
throw new BadRequest('Not enough funds in account')
6870
}
6971

70-
const originalValue = BigInt((params.amount * 10 ** asset.scale).toFixed())
7172
let value = originalValue
7273

7374
let paymentUrl = params.receiver

0 commit comments

Comments
 (0)