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

V0.5.0 rc1 #583

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

V0.5.0 rc1 #583

wants to merge 2 commits into from

Conversation

Kodylow
Copy link
Member

@Kodylow Kodylow commented Dec 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new components: BalancesSummary, EcashCard, LightningCard, and OnchainCard for enhanced wallet functionality.
    • Added a new localization key for "Balances Summary" in the English language file.
  • Bug Fixes

    • Improved state management in the WalletModal component to prevent potential memory leaks.
  • Documentation

    • Updated .gitignore to exclude todo.md.
  • Chores

    • Updated the fedimint input reference in flake.nix.

@Kodylow Kodylow requested review from a team as code owners December 9, 2024 23:08
Copy link

vercel bot commented Dec 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 9, 2024 11:10pm

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/router/src/gateway-ui/components/walletCard/BalancesSummary.tsx

Oops! Something went wrong! :(

ESLint: 8.40.0

Error: Cannot read config file: /apps/router/.eslintrc.js
Error: Cannot find module '@fedimint/eslint-config'
Require stack:

  • /apps/router/.eslintrc.js
  • /node_modules/@eslint/eslintrc/dist/eslintrc.cjs
  • /node_modules/eslint/lib/cli-engine/cli-engine.js
  • /node_modules/eslint/lib/eslint/eslint.js
  • /node_modules/eslint/lib/eslint/index.js
  • /node_modules/eslint/lib/cli.js
  • /node_modules/eslint/bin/eslint.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Module._load (node:internal/modules/cjs/loader:1074:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
    at Module.require (node:internal/modules/cjs/loader:1339:12)
    at require (node:internal/modules/helpers:135:16)
    at Object. (/apps/router/.eslintrc.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
    at Module.load (node:internal/modules/cjs/loader:1317:32)
📝 Walkthrough

Walkthrough

The changes in this pull request include the addition of several new React components for wallet management, specifically BalancesSummary, EcashCard, LightningCard, and OnchainCard, which enhance the user interface for displaying wallet balances and managing transactions. The existing WalletCard component has been refactored to utilize these new components, simplifying its structure. Additionally, modifications to the .gitignore, localization files, and type definitions have been made, along with updates to the WalletModal component and the flake.nix file for dependency management.

Changes

File Path Change Summary
.gitignore Added entry: todo.md
apps/router/src/gateway-ui/components/walletCard/BalancesSummary.tsx New component: BalancesSummary for displaying wallet balances.
apps/router/src/gateway-ui/components/walletCard/EcashCard.tsx New component: EcashCard for managing ecash transactions.
apps/router/src/gateway-ui/components/walletCard/LightningCard.tsx New component: LightningCard for managing Lightning Network transactions.
apps/router/src/gateway-ui/components/walletCard/OnchainCard.tsx New component: OnchainCard for managing on-chain transactions.
apps/router/src/gateway-ui/components/walletCard/WalletCard.tsx Refactored to remove balance logic; now renders new components instead.
apps/router/src/gateway-ui/components/walletModal/WalletModal.tsx Simplified state management and refactored modal structure; added getModalTitle function.
apps/router/src/hooks/gateway/useGateway.tsx Modified useLoadGateway to encapsulate dispatch logic in useEffect and added cleanup for intervals.
apps/router/src/languages/en.json Added new localization key: "balances-summary": "Balances Summary".
apps/router/src/types/gateway.tsx Added Lightning to WalletModalType enum.
flake.nix Updated input reference for fedimint repository.

Suggested reviewers

  • dpc

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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
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: 8

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cf02442 and 2ac76fd.

⛔ Files ignored due to path filters (1)
  • flake.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • .gitignore (1 hunks)
  • apps/router/src/gateway-ui/components/walletCard/BalancesSummary.tsx (1 hunks)
  • apps/router/src/gateway-ui/components/walletCard/EcashCard.tsx (1 hunks)
  • apps/router/src/gateway-ui/components/walletCard/LightningCard.tsx (1 hunks)
  • apps/router/src/gateway-ui/components/walletCard/OnchainCard.tsx (1 hunks)
  • apps/router/src/gateway-ui/components/walletCard/WalletCard.tsx (1 hunks)
  • apps/router/src/gateway-ui/components/walletModal/WalletModal.tsx (3 hunks)
  • apps/router/src/hooks/gateway/useGateway.tsx (2 hunks)
  • apps/router/src/languages/en.json (1 hunks)
  • apps/router/src/types/gateway.tsx (1 hunks)
  • flake.nix (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🧰 Additional context used
📓 Learnings (1)
apps/router/src/gateway-ui/components/walletCard/LightningCard.tsx (1)
Learnt from: Kodylow
PR: fedimint/ui#570
File: apps/router/src/gateway-ui/components/lightning/LightningCard.tsx:90-91
Timestamp: 2024-11-12T07:32:55.886Z
Learning: In the codebase, `gatewayInfo.lightning_mode` is always defined.
🔇 Additional comments (5)
apps/router/src/hooks/gateway/useGateway.tsx (2)

58-65: LGTM: Auth state management looks good

The useEffect correctly manages the auth state based on sessionStorage, with proper dependencies.


124-124: LGTM: Proper cleanup of interval

Added interval cleanup prevents memory leaks when component unmounts.

apps/router/src/languages/en.json (1)

427-427: LGTM!

The new translation key follows the existing conventions and aligns with the UI changes.

apps/router/src/gateway-ui/components/walletCard/WalletCard.tsx (1)

10-14: Approved: Refactored WalletCard component utilizes new modular components effectively.

The integration of BalancesSummary, EcashCard, LightningCard, and OnchainCard simplifies the WalletCard component, enhancing readability and maintainability.

apps/router/src/types/gateway.tsx (1)

24-24: Approved: Addition of Lightning to WalletModalType enum aligns with new functionality.

Including Lightning as a valid modal type ensures consistency across the application and supports the new LightningCard component.

Comment on lines +16 to +59
const handleModalOpen = (action: WalletModalAction) => {
const federations = state.gatewayInfo?.federations;
if (!federations?.length) return;

dispatch({
type: GATEWAY_APP_ACTION_TYPE.SET_WALLET_MODAL_STATE,
payload: {
action,
type: WalletModalType.Ecash,
selectedFederation: federations[0],
showSelector: true,
isOpen: true,
},
});
};

return (
<Box p={6} bg='white' borderRadius='lg' borderWidth='1px' mb={4}>
<Flex justify='space-between' align='center' mb={4}>
<Text fontSize='xl'>{t('wallet.ecash')}</Text>
<Flex gap={2}>
<Button
leftIcon={<FaArrowDown />}
colorScheme='blue'
variant='solid'
onClick={() => handleModalOpen(WalletModalAction.Receive)}
>
{t('wallet.receive')}
</Button>
<Button
leftIcon={<FaArrowUp />}
variant='outline'
onClick={() => handleModalOpen(WalletModalAction.Send)}
>
{t('wallet.send')}
</Button>
</Flex>
</Flex>
<Text color='gray.600'>
Send and receive federated ecash between federation members
</Text>
</Box>
);
});
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 refactoring duplicated code into a reusable component

The EcashCard component shares significant code with the LightningCard component. To improve maintainability and reduce duplication, consider abstracting the shared logic into a common component.

Comment on lines +16 to +59
const handleModalOpen = (action: WalletModalAction) => {
const federations = state.gatewayInfo?.federations;
if (!federations?.length) return;

dispatch({
type: GATEWAY_APP_ACTION_TYPE.SET_WALLET_MODAL_STATE,
payload: {
action,
type: WalletModalType.Lightning,
selectedFederation: federations[0],
showSelector: true,
isOpen: true,
},
});
};

return (
<Box p={6} bg='white' borderRadius='lg' borderWidth='1px' mb={4}>
<Flex justify='space-between' align='center' mb={4}>
<Text fontSize='xl'>{t('wallet.lightning-payments')}</Text>
<Flex gap={2}>
<Button
leftIcon={<FaArrowDown />}
colorScheme='blue'
variant='solid'
onClick={() => handleModalOpen(WalletModalAction.Receive)}
>
{t('wallet.receive')}
</Button>
<Button
leftIcon={<FaArrowUp />}
variant='outline'
onClick={() => handleModalOpen(WalletModalAction.Send)}
>
{t('wallet.send')}
</Button>
</Flex>
</Flex>
<Text color='gray.600'>
Send and receive Lightning Network payments through the federation
</Text>
</Box>
);
});
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 9, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring duplicated code into a reusable component

The LightningCard component has substantial overlap with the EcashCard component in terms of structure and functionality. Refactoring the common code into a shared component can enhance maintainability and reduce redundancy.

Copy link
Member

Choose a reason for hiding this comment

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

TODO ^^

Copy link
Contributor

Choose a reason for hiding this comment

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

@alexlwn123, understood. Would you like me to open a GitHub issue to track this refactoring suggestion?

Comment on lines +67 to +70
payload: {
...state.walletModalState,
isOpen: false,
},
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

Consider resetting modal state on close

The current implementation only updates isOpen while preserving other state values. This could lead to stale state being shown when the modal is reopened.

 payload: {
-  ...state.walletModalState,
   isOpen: false,
+  action: null,
+  type: null,
+  selectedFederation: null,
 },
📝 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
payload: {
...state.walletModalState,
isOpen: false,
},
payload: {
isOpen: false,
action: null,
type: null,
selectedFederation: null,
},

Comment on lines +74 to +84
<Button
leftIcon={<FaArrowDown />}
colorScheme='blue'
variant='solid'
>
{t('wallet.receive')}
</Button>
<Button leftIcon={<FaArrowUp />} variant='outline'>
{t('wallet.send')}
</Button>
</Flex>
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 missing onClick handlers for node wallet buttons

The receive and send buttons in the node's onchain wallet section are non-functional.

Comment on lines +16 to +19
const handleModalOpen = (action: WalletModalAction) => {
const federations = state.gatewayInfo?.federations;
if (!federations?.length) return;

Copy link
Contributor

@coderabbitai coderabbitai bot Dec 9, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error feedback for missing federations

The function silently returns when no federations are available. Consider showing a toast or error message to inform users.

Copy link
Member

Choose a reason for hiding this comment

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

TODO: ^^^

maybe create a hook that guards the specific operations we're using within the useGatewayContext hook

Copy link
Contributor

Choose a reason for hiding this comment

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

@alexlwn123, that's a great idea. Implementing a hook to guard the operations within useGatewayContext can ensure proper handling when federations are missing. Here's an example of how you might create such a hook:

// In useGatewayContext.tsx
export function useGuardedGatewayContext() {
  const context = useGatewayContext();

  const { state, dispatch } = context;

  if (!state.gatewayInfo?.federations?.length) {
    // Handle the case when no federations are available
    // For example, show an error message or redirect the user
    // dispatch an action or set a state to show an error message
  }

  return { state, dispatch };
}

Then, in your component, you can use the guarded context:

const { state, dispatch } = useGuardedGatewayContext();

This approach ensures that any component using the context will handle missing federations appropriately.

function BalancesSummary(): JSX.Element {
const { t } = useTranslation();
const { state } = useGatewayContext();
const balanceAmounts = useBalanceCalculations(state.balances ?? undefined);
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

Handle undefined balances more gracefully

The useBalanceCalculations hook receives undefined when state.balances is null, but there's no handling for this case in the component.

Consider adding a loading state or default values:

- const balanceAmounts = useBalanceCalculations(state.balances ?? undefined);
+ const balanceAmounts = useBalanceCalculations(state.balances ?? { ecash: 0, lightning: 0, onchain: 0 });
📝 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
const balanceAmounts = useBalanceCalculations(state.balances ?? undefined);
const balanceAmounts = useBalanceCalculations(state.balances ?? { ecash: 0, lightning: 0, onchain: 0 });

Comment on lines +20 to +44
formattedValue: formatValue(
balanceAmounts.ecash as MSats,
state.unit,
true
),
color: '#FF6384',
},
{
title: 'Lightning',
value: balanceAmounts.lightning,
formattedValue: formatValue(
balanceAmounts.lightning as MSats,
state.unit,
true
),
color: '#36A2EB',
},
{
title: 'Onchain',
value: balanceAmounts.onchain,
formattedValue: formatValue(
balanceAmounts.onchain as MSats,
state.unit,
true
),
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

Remove redundant type casting

The MSats type casting is redundant as the values from balanceAmounts should already be of the correct type.

- formattedValue: formatValue(balanceAmounts.ecash as MSats, state.unit, true),
+ formattedValue: formatValue(balanceAmounts.ecash, state.unit, true),

Committable suggestion skipped: line range outside the PR's diff.

flake.nix Show resolved Hide resolved
@elsirion elsirion requested a review from alexlwn123 December 10, 2024 14:55
@alexlwn123
Copy link
Member

Missing locales after merging applications:

#584

Copy link
Member

@alexlwn123 alexlwn123 left a comment

Choose a reason for hiding this comment

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

Still a decent amount of work to get this ready

</Flex>
</Flex>
<Text color='gray.600'>
Send and receive federated ecash between federation members
Copy link
Member

Choose a reason for hiding this comment

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

TODO: add translation

Comment on lines +75 to +83
leftIcon={<FaArrowDown />}
colorScheme='blue'
variant='solid'
>
{t('wallet.receive')}
</Button>
<Button leftIcon={<FaArrowUp />} variant='outline'>
{t('wallet.send')}
</Button>
Copy link
Member

Choose a reason for hiding this comment

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

TODO: Implement send/receive onchain

Comment on lines +16 to +59
const handleModalOpen = (action: WalletModalAction) => {
const federations = state.gatewayInfo?.federations;
if (!federations?.length) return;

dispatch({
type: GATEWAY_APP_ACTION_TYPE.SET_WALLET_MODAL_STATE,
payload: {
action,
type: WalletModalType.Lightning,
selectedFederation: federations[0],
showSelector: true,
isOpen: true,
},
});
};

return (
<Box p={6} bg='white' borderRadius='lg' borderWidth='1px' mb={4}>
<Flex justify='space-between' align='center' mb={4}>
<Text fontSize='xl'>{t('wallet.lightning-payments')}</Text>
<Flex gap={2}>
<Button
leftIcon={<FaArrowDown />}
colorScheme='blue'
variant='solid'
onClick={() => handleModalOpen(WalletModalAction.Receive)}
>
{t('wallet.receive')}
</Button>
<Button
leftIcon={<FaArrowUp />}
variant='outline'
onClick={() => handleModalOpen(WalletModalAction.Send)}
>
{t('wallet.send')}
</Button>
</Flex>
</Flex>
<Text color='gray.600'>
Send and receive Lightning Network payments through the federation
</Text>
</Box>
);
});
Copy link
Member

Choose a reason for hiding this comment

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

TODO ^^

Comment on lines +16 to +19
const handleModalOpen = (action: WalletModalAction) => {
const federations = state.gatewayInfo?.federations;
if (!federations?.length) return;

Copy link
Member

Choose a reason for hiding this comment

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

TODO: ^^^

maybe create a hook that guards the specific operations we're using within the useGatewayContext hook

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.

3 participants