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

[#522] chore: refactor pending transaction #523

Merged
merged 4 commits into from
Mar 22, 2024
Merged

Conversation

jdyczka
Copy link
Contributor

@jdyczka jdyczka commented Mar 20, 2024

List of changes

  • Extract all logic relating to pending transactions into a separate hook
  • Refactor pending transaction logic

Checklist

  • related issue
  • My changes generate no new warnings
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the changelog
  • I have added tests that prove my fix is effective or that my feature works

@jdyczka jdyczka force-pushed the transaction-state branch from 0f0d73c to 48a585e Compare March 20, 2024 14:58
@Sworzen1 Sworzen1 linked an issue Mar 20, 2024 that may be closed by this pull request
@MSzalowski
Copy link
Contributor

Provide PR description

Copy link
Contributor

@MSzalowski MSzalowski left a comment

Choose a reason for hiding this comment

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

After CR I've got the information that getUTxos getter is copy&pasted and in our case most of the code execution won't go after 1st if, so you can skip comments regarding refactoring that method. I'll just leave the comments for the history

@@ -324,14 +302,14 @@ export const DashboardCards = () => {
<Box
sx={{
columnGap: 3,
display: "grid",
display: 'grid',
gridTemplateColumns:
screenWidth < 1280
Copy link
Contributor

Choose a reason for hiding this comment

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

If refactor of this component already happened - it would be great to also get rid of this nested ternaries

Box, CircularProgress, Tab, Tabs, styled,
} from "@mui/material";
import { useLocation } from "react-router-dom";
Box, CircularProgress, Tab, Tabs, styled
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert this object-curly-newline is faulty set rule and will be removed

{
proposalId: getFullGovActionId(
onClick={() =>
(onDashboard &&
Copy link
Contributor

Choose a reason for hiding this comment

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

get rid of nested ternaries

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably @JanJaroszczak will be modifying this file, so it I will leave it as it to avoid conflicts

const keys = multiasset.keys(); // policy Ids of thee multiasset
const N = keys.len();

for (let i = 0; i < N; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just iterate through keys? What is the reason for using nested for loops with having the builtin methods that does the job for us? 🤔

resourceId?: never;
};

export type TransactionStateWithResource = {
Copy link
Contributor

Choose a reason for hiding this comment

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

They are exactly the same except type which might be passed as generic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resourceId is required in one but not the other

export type TransactionStateWithResource = {
type: TransactionTypeWithResource;
transactionHash: string;
time: Date;
Copy link
Contributor

Choose a reason for hiding this comment

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

If time comes from an API it couldn't be of type Date, as JSON only allows primitive types

Copy link
Contributor

Choose a reason for hiding this comment

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

its point of time which describes when transaction was confirmed, only for internal service/hook connected with pending transactions

let count = 0;
let isDBSyncUpdated = false;
while (!isDBSyncUpdated && count < DB_SYNC_MAX_ATTEMPTS) {
count++;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should avoid ++ as it might cause hard-to-debug problems on production

Copy link
Contributor

@Sworzen1 Sworzen1 Mar 21, 2024

Choose a reason for hiding this comment

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

what do you recomend for this solution ?, I mean insted of while interation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't it confusing only as art of a bigger expression?

};

const isTransactionExpired = (time: Date): boolean =>
new Date().getTime() - time.getTime() > TIME_TO_EXPIRE_TRANSACTION;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just Date.now()? It is ~2 times faster in execution than new Date().getTime() giving the same result

pendingTransaction.registerAsDrep ||
pendingTransaction.registerAsSoleVoter ||
pendingTransaction.retireAsDrep ||
pendingTransaction.retireAsSoleVoter,
],
enabled: !!dRepID,
queryFn: async () => await getVoterInfo(dRepID),
Copy link
Contributor

Choose a reason for hiding this comment

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

By the way - you could also remove async and await here as they are redundant

@jdyczka jdyczka force-pushed the transaction-state branch 2 times, most recently from 210d91c to 66ebbc6 Compare March 22, 2024 14:11
@jdyczka jdyczka force-pushed the transaction-state branch from 66ebbc6 to 467460f Compare March 22, 2024 14:17
Copy link
Contributor

@MSzalowski MSzalowski left a comment

Choose a reason for hiding this comment

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

Awesome work, really appreciate 💪

@jdyczka jdyczka merged commit 22448dd into develop Mar 22, 2024
3 of 4 checks passed
@jdyczka jdyczka deleted the transaction-state branch March 22, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pending transactions refactor
4 participants