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

feat(synapse-interface): Added /returntomonke pfp generator #2460

Merged
merged 7 commits into from
Apr 18, 2024

Conversation

Defi-Moses
Copy link
Collaborator

@Defi-Moses Defi-Moses commented Apr 5, 2024

Adds a page for /returntomonke, that allows users to upload an image, and have an image returned with the synapse profile picture background.

Summary by CodeRabbit

  • New Features
    • Introduced a new page component "Return to Monke" for generating Synaptic Profile Pictures.
    • Added a "PfpGeneratorCard" component for creating profile pictures.
    • Implemented image upload functionality with drag-and-drop, overlay application, and download capabilities.

131e9c649ebe7ec1a96b4c6c9a701fc859fa9cce: synapse-interface preview link
49ca6f57f73afb8d89d6f22fc66602d2cb0e045f: synapse-interface preview link
ba420a853fe11c655255d2a1244f82a22b15bb2b: synapse-interface preview link
fa2bf5411b57ca169a05a66e5c7c8da24dc27beb: synapse-interface preview link

Copy link
Contributor

coderabbitai bot commented Apr 5, 2024

Walkthrough

The latest update enhances the Synapse interface with a new feature that allows users to create Synaptic Profile Pictures. This feature enables users to generate personalized profile pictures by interacting with the ReturnToMonkePage component, which facilitates the creation process using account information and the PfpGeneratorCard.

Changes

File Path Change Summary
.../pages/returntomonke/index.tsx Added ReturnToMonkePage for Synaptic Profile Picture creation.
.../pages/returntomonke/PfpGeneratorCard.tsx
.../pages/returntomonke/ImageUploader.tsx
Introduced PfpGeneratorCard for image upload and styling, enabling image processing and download.

🐇✨
In the realm where codes align,
Pixels waltz, intertwine,
A rabbit dances, joy refined,
Synapse profiles uniquely designed.
Click, drag, a new design,
Images blend, a magic so fine.
🌟📸🎨


Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 8ce094f and 92a3ba6.
Files selected for processing (1)
  • packages/synapse-interface/pages/returntomonke/index.tsx (1 hunks)
Additional comments not posted (5)
packages/synapse-interface/pages/returntomonke/index.tsx (5)

1-9: Imports are well-organized and relevant to the functionality of the page.


16-18: The logic to set connectedChainId is correct and efficiently handles the case where chain.id might be undefined.


20-22: The hook for setting the address is straightforward and correctly updates the state when currentAddress changes.


24-48: The JSX structure is clean and well-organized. The use of LandingPageWrapper and StandardPageContainer helps maintain a consistent layout style. The props passed to StandardPageContainer are correctly derived from state.


42-44: The PfpGeneratorCard is correctly placed within the grid layout. Ensure that all necessary props are passed to it if it requires more data to function properly.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.98425%. Comparing base (f5a7f22) to head (92a3ba6).
Report is 2 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2460         +/-   ##
===================================================
- Coverage   47.05001%   46.98425%   -0.06576%     
===================================================
  Files            384         382          -2     
  Lines          29373       28948        -425     
  Branches          83          83                 
===================================================
- Hits           13820       13601        -219     
+ Misses         14102       13910        -192     
+ Partials        1451        1437         -14     
Flag Coverage Δ
packages 90.62500% <ø> (+0.09766%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Apr 5, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92a3ba6
Status: ✅  Deploy successful!
Preview URL: https://3b0ba00d.sanguine-fe.pages.dev
Branch Preview URL: https://fe-add-return-to-monke.sanguine-fe.pages.dev

View logs

Copy link

cloudflare-workers-and-pages bot commented Apr 5, 2024

Deploying sanguine with  Cloudflare Pages  Cloudflare Pages

Latest commit: 92a3ba6
Status: ✅  Deploy successful!
Preview URL: https://57400e87.sanguine.pages.dev
Branch Preview URL: https://fe-add-return-to-monke.sanguine.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 38fcca1 and c7196cd.
Files ignored due to path filters (1)
  • packages/synapse-interface/public/synpfpborder.png is excluded by !**/*.png
Files selected for processing (3)
  • packages/synapse-interface/pages/returntomonke/ImageUploader.tsx (1 hunks)
  • packages/synapse-interface/pages/returntomonke/PfpGeneratorCard.tsx (1 hunks)
  • packages/synapse-interface/pages/returntomonke/index.tsx (1 hunks)
Additional comments not posted (3)
packages/synapse-interface/pages/returntomonke/PfpGeneratorCard.tsx (1)

1-20: LGTM! The PfpGeneratorCard component is well-structured and integrates the ImageUploader component effectively.

packages/synapse-interface/pages/returntomonke/index.tsx (1)

1-55: LGTM! The ReturnToMonkePage component is correctly set up to fetch user information and render the page with the PfpGeneratorCard.

packages/synapse-interface/pages/returntomonke/ImageUploader.tsx (1)

51-51: Verify the path to the overlay image (./synpfpborder.png) to ensure it's correctly accessible from this component's location.

Comment on lines 33 to 62
const applyImageOverlay = () => {
const canvas = imgRef.current;
const ctx = canvas.getContext('2d');

// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);

// Load the uploaded image
const img = new Image();
img.src = URL.createObjectURL(uploadedImage);
img.onload = () => {
// Set the canvas size to match the uploaded image
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);

// Load the overlay image
const overlay = new Image();
overlay.src = './synpfpborder.png';
overlay.onload = () => {
// Draw the overlay image on top of the uploaded image
ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height);

// Convert the canvas to a Blob and update the state
canvas.toBlob((blob) => {
setProcessedImage(blob);
}, 'image/jpeg');
};
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding error handling for the image processing logic to gracefully handle cases where image loading fails.

img.onload = () => {
+ img.onerror = (error) => {
+   console.error('Error loading image:', error);
+   // Handle the error appropriately
+ };
  // Set the canvas size to match the uploaded image
  canvas.width = img.width;
  canvas.height = img.height;
  ctx.drawImage(img, 0, 0);
  // Load the overlay image
  const overlay = new Image();
  overlay.src = './synpfpborder.png';
  overlay.onload = () => {
    // Draw the overlay image on top of the uploaded image
    ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height);
    // Convert the canvas to a Blob and update the state
    canvas.toBlob((blob) => {
      setProcessedImage(blob);
    }, 'image/jpeg');
  };
+ overlay.onerror = (error) => {
+   console.error('Error loading overlay image:', error);
+   // Handle the error appropriately
+ };
};

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.

Suggested change
const applyImageOverlay = () => {
const canvas = imgRef.current;
const ctx = canvas.getContext('2d');
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Load the uploaded image
const img = new Image();
img.src = URL.createObjectURL(uploadedImage);
img.onload = () => {
// Set the canvas size to match the uploaded image
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
// Load the overlay image
const overlay = new Image();
overlay.src = './synpfpborder.png';
overlay.onload = () => {
// Draw the overlay image on top of the uploaded image
ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height);
// Convert the canvas to a Blob and update the state
canvas.toBlob((blob) => {
setProcessedImage(blob);
}, 'image/jpeg');
};
};
};
const applyImageOverlay = () => {
const canvas = imgRef.current;
const ctx = canvas.getContext('2d');
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Load the uploaded image
const img = new Image();
img.src = URL.createObjectURL(uploadedImage);
img.onload = () => {
img.onerror = (error) => {
console.error('Error loading image:', error);
// Handle the error appropriately
};
// Set the canvas size to match the uploaded image
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
// Load the overlay image
const overlay = new Image();
overlay.src = './synpfpborder.png';
overlay.onload = () => {
// Draw the overlay image on top of the uploaded image
ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height);
// Convert the canvas to a Blob and update the state
canvas.toBlob((blob) => {
setProcessedImage(blob);
}, 'image/jpeg');
};
overlay.onerror = (error) => {
console.error('Error loading overlay image:', error);
// Handle the error appropriately
};
};
};

@@ -0,0 +1,134 @@
import _ from 'lodash'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think lodash used in this file

@abtestingalpha abtestingalpha changed the title Adding return to monke to main frontend feat(synapse-interface): adding return to monke to main frontend Apr 5, 2024
img.src = URL.createObjectURL(uploadedImage);
img.onload = () => {
// Set the canvas size to match the uploaded image
canvas.width = img.width;
Copy link
Collaborator

@bigboydiamonds bigboydiamonds Apr 5, 2024

Choose a reason for hiding this comment

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

Currently uploading an image that doesn't have equal image width and height will cause for the PFP to distort (see screenshot attached below)

To fix this to always create a square PFP output, we could set the canvas.width and canvas.height equal to each other.

As an example, updated the applyImageOverlay() function to achieve that effect: https://github.com/synapsecns/sanguine/pull/2465/files#diff-1f5949bc4b332bdd1d21bc1fccf989474ccf9b40c36d9b78bbae84a5f7a89b71R44-R50

Given that an uploaded image could differ in height or width, chose to set both canvas.width and canvas.height to whichever was greater, image.width or image.height so that we could always generate a square PFP output image.

Can test out here: https://fe-center-synape-pf.sanguine-fe.pages.dev/returntomonke

synape_Screenshot 2024-04-04 a <img width="78" alt="Screenshot 2024-04-04 at 1 07 05 PM" src="https://github.com/synapsecns/sanguine/assets/57741810/5c70672f-4375-4bba-8cbf-358695540fef"> t 1

[do not merge] center generated synape pfp example
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Comment on lines +33 to +71
const applyImageOverlay = () => {
const canvas = imgRef.current
const ctx = canvas.getContext('2d')

// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height)

// Load the uploaded image
const img = new Image()
img.src = URL.createObjectURL(uploadedImage)
img.onload = () => {
if (img.width >= img.height) {
canvas.width = img.width
canvas.height = img.width
} else {
canvas.width = img.height
canvas.height = img.height
}

// Calculate the start positions to center the image
const startX = (canvas.width - img.width) / 2
const startY = (canvas.height - img.height) / 2

// Draw the uploaded image centered
ctx.drawImage(img, startX, startY)

// Load the overlay image
const overlay = new Image()
overlay.src = './synpfpborder.png'
overlay.onload = () => {
// Draw the overlay image on top of the uploaded image
ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height)

// Convert the canvas to a Blob and update the state
canvas.toBlob((blob) => {
setProcessedImage(blob)
}, 'image/jpeg')
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error handling is added for image loading failures. Consider implementing the error handling as suggested in previous comments.

img.onload = () => {
+ img.onerror = (error) => {
+   console.error('Error loading image:', error);
+   // Handle the error appropriately
+ };
  // Set the canvas size to match the uploaded image
  canvas.width = img.width;
  canvas.height = img.height;
  ctx.drawImage(img, 0, 0);
  // Load the overlay image
  const overlay = new Image();
  overlay.src = './synpfpborder.png';
  overlay.onload = () => {
    // Draw the overlay image on top of the uploaded image
    ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height);
    // Convert the canvas to a Blob and update the state
    canvas.toBlob((blob) => {
      setProcessedImage(blob);
    }, 'image/jpeg');
  };
+ overlay.onerror = (error) => {
+   console.error('Error loading overlay image:', error);
+   // Handle the error appropriately
+ };
};

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.

Suggested change
const applyImageOverlay = () => {
const canvas = imgRef.current
const ctx = canvas.getContext('2d')
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height)
// Load the uploaded image
const img = new Image()
img.src = URL.createObjectURL(uploadedImage)
img.onload = () => {
if (img.width >= img.height) {
canvas.width = img.width
canvas.height = img.width
} else {
canvas.width = img.height
canvas.height = img.height
}
// Calculate the start positions to center the image
const startX = (canvas.width - img.width) / 2
const startY = (canvas.height - img.height) / 2
// Draw the uploaded image centered
ctx.drawImage(img, startX, startY)
// Load the overlay image
const overlay = new Image()
overlay.src = './synpfpborder.png'
overlay.onload = () => {
// Draw the overlay image on top of the uploaded image
ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height)
// Convert the canvas to a Blob and update the state
canvas.toBlob((blob) => {
setProcessedImage(blob)
}, 'image/jpeg')
}
}
const applyImageOverlay = () => {
const canvas = imgRef.current
const ctx = canvas.getContext('2d')
// Clear the canvas
ctx.clearRect(0, 0, canvas.width, canvas.height)
// Load the uploaded image
const img = new Image()
img.src = URL.createObjectURL(uploadedImage)
img.onload = () => {
img.onerror = (error) => {
console.error('Error loading image:', error);
// Handle the error appropriately
};
if (img.width >= img.height) {
canvas.width = img.width
canvas.height = img.width
} else {
canvas.width = img.height
canvas.height = img.height
}
// Calculate the start positions to center the image
const startX = (canvas.width - img.width) / 2
const startY = (canvas.height - img.height) / 2
// Draw the uploaded image centered
ctx.drawImage(img, startX, startY)
// Load the overlay image
const overlay = new Image()
overlay.src = './synpfpborder.png'
overlay.onload = () => {
// Draw the overlay image on top of the uploaded image
ctx.drawImage(overlay, 0, 0, canvas.width, canvas.height)
// Convert the canvas to a Blob and update the state
canvas.toBlob((blob) => {
setProcessedImage(blob)
}, 'image/jpeg')
}
overlay.onerror = (error) => {
console.error('Error loading overlay image:', error);
// Handle the error appropriately
};
}

@bigboydiamonds bigboydiamonds self-requested a review April 16, 2024 20:26
@abtestingalpha abtestingalpha changed the title feat(synapse-interface): adding return to monke to main frontend feat(synapse-interface): Added /returntomonke pfp generator Apr 17, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Comment on lines +11 to +22
const ReturnToMonkePage = () => {
const { address: currentAddress, chain } = useAccount()
const [connectedChainId, setConnectedChainId] = useState(0)
const [address, setAddress] = useState(undefined)

useEffect(() => {
setConnectedChainId(chain?.id ?? DEFAULT_FROM_CHAIN)
}, [chain])

useEffect(() => {
setAddress(currentAddress)
}, [currentAddress])
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the initial state for address is explicitly set to null or an empty string for clarity and to avoid potential issues with undefined.

-  const [address, setAddress] = useState(undefined)
+  const [address, setAddress] = useState('')

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.

Suggested change
const ReturnToMonkePage = () => {
const { address: currentAddress, chain } = useAccount()
const [connectedChainId, setConnectedChainId] = useState(0)
const [address, setAddress] = useState(undefined)
useEffect(() => {
setConnectedChainId(chain?.id ?? DEFAULT_FROM_CHAIN)
}, [chain])
useEffect(() => {
setAddress(currentAddress)
}, [currentAddress])
const ReturnToMonkePage = () => {
const { address: currentAddress, chain } = useAccount()
const [connectedChainId, setConnectedChainId] = useState(0)
const [address, setAddress] = useState('')
useEffect(() => {
setConnectedChainId(chain?.id ?? DEFAULT_FROM_CHAIN)
}, [chain])
useEffect(() => {
setAddress(currentAddress)
}, [currentAddress])

@Defi-Moses Defi-Moses merged commit efdd57c into master Apr 18, 2024
42 checks passed
@Defi-Moses Defi-Moses deleted the fe/add-return-to-monke branch April 18, 2024 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants