-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: bet price functions #21
base: trunk
Are you sure you want to change the base?
Conversation
const one = new BigDecimal(1); | ||
const oneToken = new BigDecimal(this.ONE); | ||
const priceString = one.divide(input).multiply(oneToken).round(2); | ||
const price = Number(priceString.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not use Number. floats are banned in this library :) use BigInt everywhere and decimals for prices. to store values in database use DECIMAL type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed, it is already decimal in db. thanks
const client = await createDBTransaction(); | ||
let results = []; | ||
try { | ||
for (const command of commands) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! should we move all function that require transaction to use this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that would remove a lot of duplicate transaction creating and error handling code
}); | ||
|
||
test('outcome prices change on buy', async () => { | ||
const id = `test_id_${nanoid(10)}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for nanoid
}); | ||
|
||
test('Converts price to decimal', () => { | ||
const bet = new Bet('test-bet', 4); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not use same bet id twice. you have dependency on the previous test here. the nanoid you use below is the way to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated thanks
No description provided.