Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass rollback #7

Merged
merged 8 commits into from
Jul 8, 2024
Merged

Bypass rollback #7

merged 8 commits into from
Jul 8, 2024

Conversation

Vishtar
Copy link
Collaborator

@Vishtar Vishtar commented Jul 5, 2024

No description provided.

}
const secondsFromPurchase = Date.now() / 1000 - firstPurchase.timestamp
// Estimated time to bypass a rollback
if (secondsFromPurchase <= 60) {
Copy link
Owner

Choose a reason for hiding this comment

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

Please move to an env variable

@@ -27,6 +28,15 @@ export async function* getNotifications(
const addressJettonsFromDb = await getJettonsFromDB(wallet.id)
for (const jetton of addressJettonsFromDb) {
if (!addressJettonsFromChainObj[jetton.token]) {
const firstPurchase = await getFirstAddressJettonPurchaseFromDB(jetton.id)
if (!firstPurchase) {
Copy link
Owner

Choose a reason for hiding this comment

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

Is this possible? If we think it's not, we need to log this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is technically possible. if we have a race condition.
I replaced multiple queries with a single postgres transaction with these queries to completly avoid that possibility now.

@@ -21,7 +21,9 @@ export const api = async (address: string) => {
res[jettonInfo.symbol] = {
...jettonInfo,
pnlPercentage,
chart: (slicedChart.length >= 2 ? slicedChart : chart).reverse().map(entity => [entity[0], normalizePrice(entity[1], jettonInfo.decimals)]),
chart: (slicedChart.length >= 2 ? slicedChart : chart)
Copy link
Owner

Choose a reason for hiding this comment

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

If slicedChart does not have at least two elements, that means our algorithm is wrong. log it as error.

Copy link
Owner

Choose a reason for hiding this comment

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

Do not reverse the chart here. Reverse it on the frontend

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just didn't touch that, but sure.

chart: (slicedChart.length >= 2 ? slicedChart : chart).reverse().map(entity => [entity[0], normalizePrice(entity[1], jettonInfo.decimals)]),
chart: (slicedChart.length >= 2 ? slicedChart : chart)
.reverse()
.map(entity => [entity[0], normalizePrice(entity[1], jettonInfo.decimals)]),
Copy link
Owner

Choose a reason for hiding this comment

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

This logic should not be here. return the literal price value, and normalize it on the frontend. Less load on the server + eventually I want to turn it into a string (not valid number at all), e.g. something like 0.₉1234

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, frontend is completely ok with displaying a string. But I guess our clients have decent hardware and don't care about some client-side transformations anyway.

@Vishtar Vishtar merged commit 6168f72 into vishtar/features Jul 8, 2024
1 check passed
@Vishtar Vishtar deleted the vishtar/bypass_rollback branch July 8, 2024 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants