rafiki icon indicating copy to clipboard operation
rafiki copied to clipboard

Account crediting doesn't seem to add correctly

Open sabineschaller opened this issue 3 years ago • 1 comments

Pfry starts with initial balance of 0.01 USD.

After receiving payment of 8.71 USD, balance shows 18.71 USD.

sabineschaller avatar Oct 27 '22 03:10 sabineschaller

Hmm, after taking a quick look I think it’s because in the webhook request handling we use

const amt = payment['receivedAmount'] as Amount
...
await mockAccounts.credit(acc.id, amt.value, false)

without casting the value at all to an integer from the incoming request. Then in the credit function we just do acc.creditsPosted += amount which leads to a string concat:

➜ node
Welcome to Node.js v16.17.1.
Type ".help" for more information.
> let num = BigInt(1)
undefined
> num += '871'
'1871'

TL;DR I think whenever we call methods on the AccountsServer we need to properly cast values we are passing in

mkurapov avatar Oct 27 '22 09:10 mkurapov

@mkurapov But isn't it casted in

const amt = payment['receivedAmount'] as Amount

where Amount.value is a bigint?

sabineschaller avatar Oct 28 '22 02:10 sabineschaller