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

Testnets #132

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/data/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import { MeQuery } from "generated/graphql";
// function should be removed
const sanitize = (res: MeQuery[]) => {
res.map((claimer) => {
if (claimer.claimer?.currentRequest && claimer.claimer?.registration)
claimer.claimer.registration = null;
if (claimer.claimer?.currentRequest && claimer.claimer?.registration) {
if (claimer.claimer?.currentRequest.index <= -100) {
claimer.claimer.currentRequest = null;
} else {
claimer.claimer.registration = null;
}
}
Comment on lines +10 to +16
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding type safety and immutable data handling.

The current implementation has several potential issues:

  1. Direct mutation of input parameters can lead to unexpected side effects
  2. Unsafe property access without proper null checks
  3. No type guards for the index property

Consider refactoring to:

const sanitize = (res: MeQuery[]): MeQuery[] => {
  return res.map((claimer) => {
    if (!claimer.claimer?.currentRequest || !claimer.claimer?.registration) {
      return claimer;
    }

    const sanitizedClaimer = { ...claimer };
    if (sanitizedClaimer.claimer) {
      if (sanitizedClaimer.claimer.currentRequest?.index <= -100) {
        sanitizedClaimer.claimer.currentRequest = null;
      } else {
        sanitizedClaimer.claimer.registration = null;
      }
    }
    return sanitizedClaimer;
  });
};

});
};

export const getMyData = async (account: string) => {
const res = await Promise.all(
supportedChains.map((chain) => sdk[chain.id].Me({ id: account })),
);

sanitize(res);

const homeChain = supportedChains.find(
Expand Down
Loading