From e1034cb1fdabd32b73b44e7f1a7eedcf055de395 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Mon, 21 Feb 2022 00:18:08 +0100 Subject: [PATCH] fixed data conversion error on sendCoins --- backend/src/graphql/resolver/TransactionResolver.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index edbe6373e..417760982 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -114,6 +114,7 @@ async function calculateAndAddDecayTransactions( } else if (userTransaction.transactionTypeId === TransactionTypeId.SEND) { // send coin let otherUser: dbUser | undefined + console.log('converting', transaction.amount) finalTransaction.balance = roundFloorFrom4(Number(transaction.amount)) // Todo unsafe conversion if (transaction.userId === user.id) { finalTransaction.type = TransactionType.SEND @@ -422,7 +423,10 @@ export class TransactionResolver { throw new Error('db data corrupted, recipiant') } - transaction.sendSenderFinalBalance = BigInt(senderStateBalance.amount) + // TODO: WTF? + // I just assume that due to implicit type conversion the decimal places were cut. + // Using `Math.trunc` to simulate this behaviour + transaction.sendSenderFinalBalance = BigInt(Math.trunc(senderStateBalance.amount)) await queryRunner.manager.save(transaction).catch((error) => { throw new Error('error saving transaction with tx hash: ' + error)