-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v5.3.0
- Loading branch information
Showing
194 changed files
with
19,291 additions
and
9,918 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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,28 @@ | ||
import { Chain, Wallet } from '@rainbow-me/rainbowkit'; | ||
import { InjectedConnector } from 'wagmi/connectors/injected'; | ||
|
||
import FrameIcon from 'assets/png/rainbowkit/frame.png'; | ||
|
||
type FrameOptions = { | ||
chains: Chain[]; | ||
shimDisconnect?: boolean; | ||
}; | ||
|
||
const Frame = ({ chains, shimDisconnect }: FrameOptions): Wallet => ({ | ||
id: 'frame', | ||
iconBackground: '#FFF', | ||
name: 'Frame', | ||
iconUrl: async () => FrameIcon, | ||
downloadUrls: { | ||
browserExtension: | ||
'https://chrome.google.com/webstore/detail/frame-companion/ldcoohedfbjoobcadoglnnmmfbdlmmhf', | ||
}, | ||
createConnector: () => { | ||
const connector = new InjectedConnector({ chains, options: { shimDisconnect } }); | ||
return { | ||
connector, | ||
}; | ||
}, | ||
}); | ||
|
||
export default Frame; |
This file contains 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 @@ | ||
export { default } from './Frame'; |
This file contains 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,163 @@ | ||
import Wei from '@synthetixio/wei'; | ||
import { FC, memo, useCallback, useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styled from 'styled-components'; | ||
|
||
import Button from 'components/Button'; | ||
import NumericInput from 'components/Input/NumericInput'; | ||
import SegmentedControl from 'components/SegmentedControl'; | ||
import { DEFAULT_CRYPTO_DECIMALS, DEFAULT_TOKEN_DECIMALS } from 'constants/defaults'; | ||
import { StakingCard } from 'sections/dashboard/Stake/common'; | ||
import { FlexDivRowCentered, numericValueCSS } from 'styles/common'; | ||
import { toWei, truncateNumbers } from 'utils/formatters/number'; | ||
|
||
type StakeCardProps = { | ||
title: string; | ||
stakeBalance: Wei; | ||
unstakeBalance: Wei; | ||
onStake(amount: string): void; | ||
onUnstake(amount: string): void; | ||
stakeEnabled?: boolean; | ||
unstakeEnabled?: boolean; | ||
isApproved?: boolean; | ||
onApprove?: () => void; | ||
}; | ||
|
||
const StakeCard: FC<StakeCardProps> = memo( | ||
({ | ||
title, | ||
stakeBalance, | ||
unstakeBalance, | ||
onStake, | ||
onUnstake, | ||
stakeEnabled = true, | ||
unstakeEnabled = true, | ||
isApproved, | ||
onApprove, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const [amount, setAmount] = useState(''); | ||
const [activeTab, setActiveTab] = useState(0); | ||
|
||
const balance = useMemo(() => { | ||
return activeTab === 0 ? stakeBalance : unstakeBalance; | ||
}, [activeTab, stakeBalance, unstakeBalance]); | ||
|
||
const isEnabled = useMemo(() => { | ||
return toWei(amount).gt(0) && balance.gt(0); | ||
}, [amount, balance]); | ||
|
||
const isStakeEnabled = useMemo(() => { | ||
return activeTab === 0 && isEnabled && stakeEnabled; | ||
}, [activeTab, isEnabled, stakeEnabled]); | ||
|
||
const isUnstakeEnabled = useMemo(() => { | ||
return activeTab === 1 && isEnabled && unstakeEnabled; | ||
}, [activeTab, isEnabled, unstakeEnabled]); | ||
|
||
const isDisabled = useMemo(() => { | ||
return activeTab === 0 ? !isStakeEnabled : !isUnstakeEnabled; | ||
}, [activeTab, isStakeEnabled, isUnstakeEnabled]); | ||
|
||
const balanceString = useMemo(() => { | ||
return truncateNumbers(balance, DEFAULT_CRYPTO_DECIMALS); | ||
}, [balance]); | ||
|
||
const onMaxClick = useCallback(() => { | ||
setAmount(truncateNumbers(balance, DEFAULT_TOKEN_DECIMALS)); | ||
}, [balance]); | ||
|
||
const handleTabChange = useCallback((tabIndex: number) => { | ||
setAmount(''); | ||
setActiveTab(tabIndex); | ||
}, []); | ||
|
||
const handleSubmit = useCallback(() => { | ||
if (!isApproved) { | ||
onApprove?.(); | ||
} else if (isStakeEnabled) { | ||
onStake(amount); | ||
} else if (isUnstakeEnabled) { | ||
onUnstake(amount); | ||
} | ||
}, [isStakeEnabled, isUnstakeEnabled, onStake, onUnstake, amount, onApprove, isApproved]); | ||
|
||
const handleChange = useCallback((_, newValue: string) => { | ||
if (newValue !== '' && newValue.indexOf('.') === -1) { | ||
setAmount(parseFloat(newValue).toString()); | ||
} else { | ||
setAmount(newValue); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<StakingInputCardContainer> | ||
<SegmentedControl | ||
values={[ | ||
t('dashboard.stake.tabs.stake-table.stake'), | ||
t('dashboard.stake.tabs.stake-table.unstake'), | ||
]} | ||
onChange={handleTabChange} | ||
selectedIndex={activeTab} | ||
/> | ||
<StakeInputContainer> | ||
<StakeInputHeader> | ||
<div>{title}</div> | ||
<StyledFlexDivRowCentered> | ||
<div>{t('dashboard.stake.tabs.stake-table.balance')}</div> | ||
<div className="max" onClick={onMaxClick}> | ||
{balanceString} | ||
</div> | ||
</StyledFlexDivRowCentered> | ||
</StakeInputHeader> | ||
<StyledInput value={amount} onChange={handleChange} /> | ||
</StakeInputContainer> | ||
<Button fullWidth variant="flat" size="sm" disabled={isDisabled} onClick={handleSubmit}> | ||
{!isApproved | ||
? t('dashboard.stake.tabs.stake-table.approve') | ||
: activeTab === 0 | ||
? t('dashboard.stake.tabs.stake-table.stake') | ||
: t('dashboard.stake.tabs.stake-table.unstake')} | ||
</Button> | ||
</StakingInputCardContainer> | ||
); | ||
} | ||
); | ||
|
||
const StyledFlexDivRowCentered = styled(FlexDivRowCentered)` | ||
column-gap: 5px; | ||
`; | ||
|
||
const StakingInputCardContainer = styled(StakingCard)` | ||
min-height: 125px; | ||
max-height: 250px; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
`; | ||
|
||
const StakeInputHeader = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 10px; | ||
color: ${(props) => props.theme.colors.selectedTheme.title}; | ||
font-size: 14px; | ||
.max { | ||
cursor: pointer; | ||
color: ${(props) => props.theme.colors.selectedTheme.button.text.primary}; | ||
${numericValueCSS}; | ||
} | ||
`; | ||
|
||
const StakeInputContainer = styled.div` | ||
margin: 20px 0; | ||
`; | ||
|
||
const StyledInput = styled(NumericInput)` | ||
font-family: ${(props) => props.theme.fonts.monoBold}; | ||
`; | ||
|
||
export default StakeCard; |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.