Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

refactor: bet price functions #21

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open

refactor: bet price functions #21

wants to merge 4 commits into from

Conversation

r0jer
Copy link

@r0jer r0jer commented Sep 30, 2021

No description provided.

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);
Copy link
Contributor

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

Copy link
Author

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) {
Copy link
Contributor

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?

Copy link
Author

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)}`;
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants