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

Mava customer support #1734

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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: 9 additions & 1 deletion web/src/context/AtlasProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,15 @@ const AtlasProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) =
queryFn: async () => {
try {
if (!isVerified || isUndefined(address)) return undefined;
return await fetchUser(atlasGqlClient);
const user = await fetchUser(atlasGqlClient);

if (user?.email && window.Mava) {
window.Mava.initialize();
window.Mava.identify({ emailAddress: user.email });
window.Mava.identify({ customAttributes: [{ label: "Wallet Address", value: address }] });
}
Comment on lines +138 to +142
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add type safety for window.Mava integration.

The code assumes window.Mava is globally available without proper TypeScript declarations. This could lead to runtime errors.

Add a type declaration file (e.g., mava.d.ts):

interface MavaIdentifyOptions {
  emailAddress?: string;
  customAttributes?: Array<{
    label: string;
    value: string;
  }>;
}

interface MavaSDK {
  initialize(): void;
  identify(options: MavaIdentifyOptions): void;
}

declare global {
  interface Window {
    Mava?: MavaSDK;
  }
}

⚠️ Potential issue

Add error handling for Mava initialization.

The Mava integration lacks error handling which could cause silent failures.

Consider wrapping the Mava calls in a try-catch:

-        if (user?.email && window.Mava) {
-          window.Mava.initialize();
-          window.Mava.identify({ emailAddress: user.email });
-          window.Mava.identify({ customAttributes: [{ label: "Wallet Address", value: address }] });
-        }
+        if (user?.email && window.Mava) {
+          try {
+            window.Mava.initialize();
+            window.Mava.identify({ 
+              emailAddress: user.email,
+              customAttributes: [{ label: "Wallet Address", value: address }]
+            });
+          } catch (error) {
+            console.error('Failed to initialize Mava:', error);
+          }
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (user?.email && window.Mava) {
window.Mava.initialize();
window.Mava.identify({ emailAddress: user.email });
window.Mava.identify({ customAttributes: [{ label: "Wallet Address", value: address }] });
}
if (user?.email && window.Mava) {
try {
window.Mava.initialize();
window.Mava.identify({
emailAddress: user.email,
customAttributes: [{ label: "Wallet Address", value: address }]
});
} catch (error) {
console.error('Failed to initialize Mava:', error);
}
}

🛠️ Refactor suggestion

Optimize Mava initialization.

Currently, Mava is initialized on every user fetch, which might be inefficient.

Consider moving the initialization to a more appropriate lifecycle:

+  // Track if Mava has been initialized
+  const [isMavaInitialized, setIsMavaInitialized] = useState(false);
+
+  // Initialize Mava once when the component mounts
+  useEffect(() => {
+    if (window.Mava && !isMavaInitialized) {
+      try {
+        window.Mava.initialize();
+        setIsMavaInitialized(true);
+      } catch (error) {
+        console.error('Failed to initialize Mava:', error);
+      }
+    }
+  }, [isMavaInitialized]);

   const {
     data: user,
     isLoading: isFetchingUser,
     refetch: refetchUser,
   } = useQuery({
     queryKey: [`UserSettings`],
     enabled: isVerified && !isUndefined(address),
     queryFn: async () => {
       try {
         if (!isVerified || isUndefined(address)) return undefined;
         const user = await fetchUser(atlasGqlClient);
 
-        if (user?.email && window.Mava) {
-          window.Mava.initialize();
+        if (user?.email && window.Mava && isMavaInitialized) {
           window.Mava.identify({ 
             emailAddress: user.email,
             customAttributes: [{ label: "Wallet Address", value: address }]
           });
         }
 
         return user;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (user?.email && window.Mava) {
window.Mava.initialize();
window.Mava.identify({ emailAddress: user.email });
window.Mava.identify({ customAttributes: [{ label: "Wallet Address", value: address }] });
}
// Track if Mava has been initialized
const [isMavaInitialized, setIsMavaInitialized] = useState(false);
// Initialize Mava once when the component mounts
useEffect(() => {
if (window.Mava && !isMavaInitialized) {
try {
window.Mava.initialize();
setIsMavaInitialized(true);
} catch (error) {
console.error('Failed to initialize Mava:', error);
}
}
}, [isMavaInitialized]);
const {
data: user,
isLoading: isFetchingUser,
refetch: refetchUser,
} = useQuery({
queryKey: [`UserSettings`],
enabled: isVerified && !isUndefined(address),
queryFn: async () => {
try {
if (!isVerified || isUndefined(address)) return undefined;
const user = await fetchUser(atlasGqlClient);
if (user?.email && window.Mava && isMavaInitialized) {
window.Mava.identify({
emailAddress: user.email,
customAttributes: [{ label: "Wallet Address", value: address }]
});
}
return user;


return user;
} catch {
return undefined;
}
Expand Down
13 changes: 9 additions & 4 deletions web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
name="description"
content="Kleros is a decentralized, blockchain-based dispute resolution platform that offers fast and affordable arbitration for various type of dispute. Join the future of dispute resolution with Kleros Court."
/>
<meta
name="keywords"
content="dispute resolution, decentralized arbitration, Kleros, blockchain court"
/>
<meta name="keywords" content="dispute resolution, decentralized arbitration, Kleros, blockchain court" />
<link rel="shortcut icon" type="image/svg+xml" href="./favicon.ico" />
<title>Kleros · Court</title>
<script
defer
src="https://widget.mava.app"
widget-version="v2"
id="MavaWebChat"
enable-sdk="true"
data-token="1fea31aa0b93836faca36269f324468e08cc26f0298f8d8e6c5b089d0d58eb1c"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security concern: Exposed API token

The Mava token is currently exposed in the HTML source, making it visible to anyone who views the page source. If this token provides access to sensitive operations or customer data, it should be handled more securely.

Consider:

  1. Using environment variables and server-side injection of the token
  2. Implementing token rotation mechanisms
  3. Adding appropriate CORS and domain restrictions in the Mava dashboard

Would you like assistance in implementing a more secure token handling solution?

🧰 Tools
🪛 Gitleaks

19-19: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

></script>
</head>
<body>
<div id="app"></div>
Expand Down
Loading