-
Notifications
You must be signed in to change notification settings - Fork 389
feat: earn poc #940
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
Open
ganchoradkov
wants to merge
7
commits into
main
Choose a base branch
from
feat/earn-poc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,164
−0
Open
feat: earn poc #940
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb544af
feat: displays providers
ganchoradkov 4b19e43
chore: mock positions
ganchoradkov 5901aa8
chore: styles
ganchoradkov 73930b7
feat: apy
ganchoradkov 70f126b
feat: deposit - withdrawal
ganchoradkov 416d16c
feat: deposits
ganchoradkov 8a45635
chore: disclaimer
ganchoradkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
advanced/wallets/react-wallet-v2/public/icons/earn-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions
109
advanced/wallets/react-wallet-v2/src/components/Earn/AmountInput.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { Input, Button, Row, Text, styled } from '@nextui-org/react' | ||
| import { ChangeEvent, useMemo } from 'react' | ||
|
|
||
| const StyledText = styled(Text, { | ||
| fontWeight: 400 | ||
| } as any) | ||
|
|
||
| interface AmountInputProps { | ||
| value: string | ||
| onChange: (value: string) => void | ||
| balance: string | ||
| tokenSymbol: string | ||
| disabled?: boolean | ||
| label?: string | ||
| placeholder?: string | ||
| } | ||
|
|
||
| export default function AmountInput({ | ||
| value, | ||
| onChange, | ||
| balance, | ||
| tokenSymbol, | ||
| disabled = false, | ||
| label = 'Amount to Deposit', | ||
| placeholder = '0.00' | ||
| }: AmountInputProps) { | ||
| const handleChange = (e: ChangeEvent<any>) => { | ||
| const inputValue = e.target.value | ||
| // Allow only numbers and decimal point | ||
| if (inputValue === '' || /^\d*\.?\d*$/.test(inputValue)) { | ||
| onChange(inputValue) | ||
| } | ||
| } | ||
|
|
||
| const handleMaxClick = () => { | ||
| onChange(balance) | ||
| } | ||
|
|
||
| const isMaxDisabled = useMemo(() => { | ||
| return disabled || !balance || balance === '0' | ||
| }, [disabled, balance]) | ||
|
|
||
| const formattedBalance = useMemo(() => { | ||
| if (!balance || balance === '0') return '0.00' | ||
| const num = parseFloat(balance) | ||
| if (isNaN(num)) return '0.00' | ||
| return num.toLocaleString('en-US', { | ||
| minimumFractionDigits: 2, | ||
| maximumFractionDigits: 2 | ||
| }) | ||
| }, [balance]) | ||
|
|
||
| return ( | ||
| <div style={{ width: '100%' }}> | ||
| <Row justify="space-between" align="center" css={{ marginBottom: '$4' }}> | ||
| <Text css={{ fontSize: '12px', fontWeight: '600' }}>{label}</Text> | ||
| <Text css={{ fontSize: '12px', color: '$gray600' }}> | ||
| Balance: {formattedBalance} {tokenSymbol} | ||
| </Text> | ||
| </Row> | ||
|
|
||
| <div style={{ position: 'relative' }}> | ||
| <Input | ||
| type="text" | ||
| value={value} | ||
| onChange={handleChange} | ||
| placeholder={placeholder} | ||
| disabled={disabled} | ||
| size="lg" | ||
| width="100%" | ||
| css={{ | ||
| '& input': { | ||
| fontSize: '16px', | ||
| fontWeight: '600', | ||
| paddingRight: '120px' | ||
| }, | ||
| '& .nextui-input-wrapper': { | ||
| border: '1px solid rgba(255, 255, 255, 0.1)' | ||
| } | ||
| }} | ||
| /> | ||
| <div | ||
| style={{ | ||
| position: 'absolute', | ||
| right: '12px', | ||
| top: '50%', | ||
| transform: 'translateY(-50%)', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: '8px' | ||
| }} | ||
| > | ||
| <Text css={{ fontSize: '14px', color: '$gray600' }}>{tokenSymbol}</Text> | ||
| <Button | ||
| size="xs" | ||
| auto | ||
| flat | ||
| color="primary" | ||
| onClick={handleMaxClick} | ||
| disabled={isMaxDisabled} | ||
| css={{ fontSize: '11px', minWidth: '50px' }} | ||
| > | ||
| MAX | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
210 changes: 210 additions & 0 deletions
210
advanced/wallets/react-wallet-v2/src/components/Earn/PositionCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,210 @@ | ||||||||||||||||||
| import { Card, Row, Col, Text, Button, styled, Input, Divider } from '@nextui-org/react' | ||||||||||||||||||
| import { UserPosition } from '@/types/earn' | ||||||||||||||||||
| import { PROTOCOL_CONFIGS } from '@/data/EarnProtocolsData' | ||||||||||||||||||
| import { useMemo, useState, ChangeEvent } from 'react' | ||||||||||||||||||
|
|
||||||||||||||||||
| // Simple Badge component since NextUI v1 doesn't have Badge | ||||||||||||||||||
| const Badge = styled('span', { | ||||||||||||||||||
| display: 'inline-block', | ||||||||||||||||||
| padding: '2px 8px', | ||||||||||||||||||
| borderRadius: '4px', | ||||||||||||||||||
| fontSize: '16px', | ||||||||||||||||||
| fontWeight: '500', | ||||||||||||||||||
| backgroundColor: 'rgba(34, 197, 94, 0.1)', | ||||||||||||||||||
| color: 'rgb(34, 197, 94)' | ||||||||||||||||||
| } as any) | ||||||||||||||||||
|
|
||||||||||||||||||
| const StyledCard = styled(Card, { | ||||||||||||||||||
| padding: '0px', | ||||||||||||||||||
| marginBottom: '12px', | ||||||||||||||||||
| border: '1px solid rgba(255, 255, 255, 0.1)' | ||||||||||||||||||
| } as any) | ||||||||||||||||||
|
|
||||||||||||||||||
| const StyledText = styled(Text, { | ||||||||||||||||||
| fontWeight: 400 | ||||||||||||||||||
| } as any) | ||||||||||||||||||
|
|
||||||||||||||||||
| interface PositionCardProps { | ||||||||||||||||||
| position: UserPosition | ||||||||||||||||||
| onWithdraw: (position: UserPosition, amount: string) => void | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export default function PositionCard({ position, onWithdraw }: PositionCardProps) { | ||||||||||||||||||
| const [withdrawAmount, setWithdrawAmount] = useState('') | ||||||||||||||||||
|
|
||||||||||||||||||
| const protocolConfig = useMemo( | ||||||||||||||||||
| () => | ||||||||||||||||||
| PROTOCOL_CONFIGS.find( | ||||||||||||||||||
| p => p.protocol.id === position.protocol && p.chainId === position.chainId | ||||||||||||||||||
| ), | ||||||||||||||||||
| [position.protocol, position.chainId] | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| const protocol = protocolConfig?.protocol | ||||||||||||||||||
|
|
||||||||||||||||||
| const formattedDepositDate = useMemo(() => { | ||||||||||||||||||
| const date = new Date(position.depositedAt) | ||||||||||||||||||
| return date.toLocaleDateString('en-US', { | ||||||||||||||||||
| month: 'short', | ||||||||||||||||||
| day: 'numeric', | ||||||||||||||||||
| year: 'numeric' | ||||||||||||||||||
| }) | ||||||||||||||||||
| }, [position.depositedAt]) | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+45
to
+53
|
||||||||||||||||||
| const formattedDepositDate = useMemo(() => { | |
| const date = new Date(position.depositedAt) | |
| return date.toLocaleDateString('en-US', { | |
| month: 'short', | |
| day: 'numeric', | |
| year: 'numeric' | |
| }) | |
| }, [position.depositedAt]) |
Comment on lines
+54
to
+59
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable durationDays.
Suggested change
| const durationDays = useMemo(() => { | |
| const now = Date.now() | |
| const diff = now - position.depositedAt | |
| return Math.floor(diff / (1000 * 60 * 60 * 24)) | |
| }, [position.depositedAt]) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable StyledText.