Skip to content

Commit

Permalink
feat: handle thorchain liquidity lockup (#7762)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Sep 19, 2024
1 parent 1d4512b commit 7f22ed6
Show file tree
Hide file tree
Showing 28 changed files with 440 additions and 290 deletions.
2 changes: 1 addition & 1 deletion src/assets/translations/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Einzahlungen sind vorübergehend deaktiviert.",
"haltedWithdrawTitle": "Auszahlungen sind vorübergehend gestoppt.",
"disabledWithdrawTitle": "Auszahlungen sind vorübergehend deaktiviert.",
"runePoolWithdrawLockedTitle": "Sie müssen %{timeHuman} warten, um abzuheben.",
"withdrawLockedTitle": "Sie müssen %{timeHuman} warten, um abzuheben.",
"haltedDescription": "Bitte twittern Sie an @THORChain, um die Obergrenzen zu erhöhen!",
"protocolFee": "Protokollgebühr",
"fee": "Gebühr",
Expand Down
4 changes: 3 additions & 1 deletion src/assets/translations/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
"disabledDepositTitle": "Deposits are temporarily disabled.",
"haltedWithdrawTitle": "Withdraws are temporarily halted.",
"disabledWithdrawTitle": "Withdraws are temporarily disabled.",
"runePoolWithdrawLockedTitle": "You have to wait %{timeHuman} to withdraw.",
"withdrawLockedTitle": "You have to wait %{timeHuman} to withdraw.",
"haltedDescription": "Please tweet at @THORChain to raise the caps!",
"protocolFee": "Protocol Fee",
"fee": "Fee",
Expand Down Expand Up @@ -505,6 +505,8 @@
"myRewardsBody": "Your active positions with claimable rewards will appear here.",
"viewAllPositions": "View All Positions",
"liquidityPools": "Liquidity Pools",
"liquidityLockupWarning": "There is a lockup period of %{time}. During lockup you can't access your liquidity.",
"liquidityLocked": "Liquidity Locked (%{time})",
"stakingVaults": "Staking & Vaults",
"farming": "Farming",
"totalEarningBalance": "Total Earning Balance",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/es/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Depósitos temporalmente deshabilitados.",
"haltedWithdrawTitle": "Retiros suspendidos temporalmente.",
"disabledWithdrawTitle": "Retiros temporalmente deshabilitados.",
"runePoolWithdrawLockedTitle": "Tienes que esperar %{timeHuman} para retirar.",
"withdrawLockedTitle": "Tienes que esperar %{timeHuman} para retirar.",
"haltedDescription": "¡Tuitee a @THORChain para aumentar los límites!",
"protocolFee": "Tarifa de Protocolo",
"fee": "Comisión",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Les dépôts sont temporairement désactivés.",
"haltedWithdrawTitle": "Les retraits sont temporairement interrompus.",
"disabledWithdrawTitle": "Les retraits sont temporairement désactivés.",
"runePoolWithdrawLockedTitle": "Vous devez attendre %{timeHuman} pour retirer.",
"withdrawLockedTitle": "Vous devez attendre %{timeHuman} pour retirer.",
"haltedDescription": "Veuillez tweeter @THORChain pour augmenter les plafonds !",
"protocolFee": "Frais de protocole",
"fee": "Frais",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/ja/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "デポジットは一時的に無効になります。",
"haltedWithdrawTitle": "出金を一時停止しております。",
"disabledWithdrawTitle": "引き出しは一時的に無効になっています。",
"runePoolWithdrawLockedTitle": "引き出すには%{timeHuman}待つ必要があります。",
"withdrawLockedTitle": "引き出すには%{timeHuman}待つ必要があります。",
"haltedDescription": "上限を増やすには、@THORChain でツイートしてください。",
"protocolFee": "プロトコル手数料",
"fee": "手数料",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/pt/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Os depósitos estão temporariamente desativados.",
"haltedWithdrawTitle": "As retiradas estão temporariamente suspensas.",
"disabledWithdrawTitle": "Os saques estão temporariamente desativados.",
"runePoolWithdrawLockedTitle": "Você tem que esperar %{timeHuman} para sacar.",
"withdrawLockedTitle": "Você tem que esperar %{timeHuman} para sacar.",
"haltedDescription": "Por favor, twitte em @THORChain para aumentar o limite!",
"protocolFee": "Taxas do Protocolo",
"fee": "Taxa",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/ru/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Депозиты временно отключены.",
"haltedWithdrawTitle": "Вывод средств временно приостановлен.",
"disabledWithdrawTitle": "Вывод средств временно отключен.",
"runePoolWithdrawLockedTitle": "Чтобы снять деньги, вам придется подождать %{timeHuman}.",
"withdrawLockedTitle": "Чтобы снять деньги, вам придется подождать %{timeHuman}.",
"haltedDescription": "Пожалуйста, напишите в твиттере @THORChain, чтобы поднять капитализацию!",
"protocolFee": "Плата за протокол",
"fee": "Комиссия",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/tr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Para yatırma işlemleri geçici olarak devre dışı bırakıldı.",
"haltedWithdrawTitle": "Para çekme işlemleri geçici olarak durdurulmuştur.",
"disabledWithdrawTitle": "Para çekme işlemleri geçici olarak devre dışı bırakıldı.",
"runePoolWithdrawLockedTitle": "Para çekmek için %{timeHuman} beklemeniz gerekiyor.",
"withdrawLockedTitle": "Para çekmek için %{timeHuman} beklemeniz gerekiyor.",
"haltedDescription": "Lütfen @THORChain adresine tweet atarak üst sınırınızı yükseltin!",
"protocolFee": "Protokol Ücreti",
"fee": "Ücret",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/uk/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "Депозити тимчасово не працюють.",
"haltedWithdrawTitle": "Виведення коштів тимчасово призупинено.",
"disabledWithdrawTitle": "Виведення коштів тимчасово відключено.",
"runePoolWithdrawLockedTitle": "Ви повинні дочекатися %{timeHuman}, щоб вивести кошти.",
"withdrawLockedTitle": "Ви повинні дочекатися %{timeHuman}, щоб вивести кошти.",
"haltedDescription": "Будь ласка, напишіть у твіттері @THORChain, щоб підняти наш рівень!",
"protocolFee": "Плата за протокол",
"fee": "Комісія",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/translations/zh/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
"disabledDepositTitle": "暂时禁止存款。",
"haltedWithdrawTitle": "提款暂时停止。",
"disabledWithdrawTitle": "暂时禁止提款。",
"runePoolWithdrawLockedTitle": "您必须等待 %{timeHuman} 才能提款。",
"withdrawLockedTitle": "您必须等待 %{timeHuman} 才能提款。",
"haltedDescription": "请 @THORChain 发推文以提高上限!",
"protocolFee": "协议费",
"fee": "费用",
Expand Down
7 changes: 5 additions & 2 deletions src/components/Acknowledgement/Acknowledgement.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ComponentWithAs, IconProps, ThemeTypings } from '@chakra-ui/react'
import type { ComponentWithAs, IconProps, ResponsiveValue, ThemeTypings } from '@chakra-ui/react'
import { Box, Button, Checkbox, Link, useColorModeValue } from '@chakra-ui/react'
import type * as CSS from 'csstype'
import type { AnimationDefinition, MotionStyle } from 'framer-motion'
import { AnimatePresence, motion } from 'framer-motion'
import type { InterpolationOptions } from 'node-polyglot'
Expand Down Expand Up @@ -91,6 +92,7 @@ type AcknowledgementProps = {
buttonTranslation?: string | [string, InterpolationOptions]
icon?: ComponentWithAs<'svg', IconProps>
disableButton?: boolean
position?: ResponsiveValue<CSS.Property.Position>
}

type StreamingAcknowledgementProps = Omit<AcknowledgementProps, 'message'> & {
Expand All @@ -113,6 +115,7 @@ export const Acknowledgement = ({
buttonTranslation,
disableButton,
icon: CustomIcon,
position = 'relative',
}: AcknowledgementProps) => {
const translate = useTranslate()
const [isShowing, setIsShowing] = useState(false)
Expand Down Expand Up @@ -149,7 +152,7 @@ export const Acknowledgement = ({

return (
<Box
position='relative'
position={position}
borderRadius={boxBorderRadius}
overflow={isShowing ? 'hidden' : 'visible'}
width={'100%'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useTranslate } from 'react-polyglot'
import { useHistory } from 'react-router-dom'
import { encodeFunctionData, getAddress, maxUint256 } from 'viem'
import type { AccountDropdownProps } from 'components/AccountDropdown/AccountDropdown'
import { InfoAcknowledgement } from 'components/Acknowledgement/Acknowledgement'
import { Amount } from 'components/Amount/Amount'
import type { StepComponentProps } from 'components/DeFi/components/Steps'
import { HelperTooltip } from 'components/HelperTooltip/HelperTooltip'
Expand All @@ -36,6 +37,8 @@ import { fetchHasEnoughBalanceForTxPlusFeesPlusSweep } from 'lib/utils/thorchain
import { BASE_BPS_POINTS, RUNEPOOL_DEPOSIT_MEMO } from 'lib/utils/thorchain/constants'
import { useGetThorchainSaversDepositQuoteQuery } from 'lib/utils/thorchain/hooks/useGetThorchainSaversDepositQuoteQuery'
import { useSendThorTx } from 'lib/utils/thorchain/hooks/useSendThorTx'
import { useThorchainMimirTimes } from 'lib/utils/thorchain/hooks/useThorchainMimirTimes'
import { formatSecondsToDuration } from 'lib/utils/time'
import { isUtxoChainId } from 'lib/utils/utxo'
import type { EstimatedFeesQueryKey } from 'pages/Lending/hooks/useGetEstimatedFeesQuery'
import { queryFn as getEstimatedFeesQueryFn } from 'pages/Lending/hooks/useGetEstimatedFeesQuery'
Expand Down Expand Up @@ -92,6 +95,8 @@ export const Deposit: React.FC<DepositProps> = ({
null,
)
const [daysToBreakEven, setDaysToBreakEven] = useState<string | null>(null)
const [shouldShowInfoAcknowledgement, setShouldShowInfoAcknowledgement] = useState(false)
const [depositValues, setDepositValues] = useState<DepositValues>()
const [inputValues, setInputValues] = useState<{
fiatAmount: string
cryptoAmount: string
Expand Down Expand Up @@ -166,6 +171,9 @@ export const Deposit: React.FC<DepositProps> = ({
selectPortfolioCryptoBalanceBaseUnitByFilter(state, balanceFilter),
)

const { data: thorchainMimirTimes, isLoading: isThorchainMimirTimesLoading } =
useThorchainMimirTimes()

const {
data: thorchainSaversDepositQuote,
isLoading: isThorchainSaversDepositQuoteLoading,
Expand Down Expand Up @@ -816,60 +824,103 @@ export const Deposit: React.FC<DepositProps> = ({
[validateFiatAmountDebounced],
)

const handleContinueOrAcknowledgement = useCallback(
(formValues: DepositValues) => {
setDepositValues(formValues)
if (isRunePool && thorchainMimirTimes?.runePoolDepositMaturityTime) {
setShouldShowInfoAcknowledgement(true)
return
}

if (!isRunePool && thorchainMimirTimes?.liquidityLockupTime) {
setShouldShowInfoAcknowledgement(true)
return
}

handleContinue(formValues)
},
[thorchainMimirTimes, isRunePool, handleContinue],
)

const handleAcknowledge = useCallback(() => {
if (!depositValues) return
handleContinue(depositValues)
}, [depositValues, handleContinue])

if (!state || !contextDispatch || !opportunityData) return null

return (
<ReusableDeposit
accountId={accountId}
onAccountIdChange={handleAccountIdChange}
asset={asset}
apy={opportunityData.apy ?? undefined}
cryptoAmountAvailable={balanceCryptoPrecision.toPrecision()}
cryptoInputValidation={cryptoInputValidation}
fiatAmountAvailable={fiatAmountAvailable.toFixed(2)}
fiatInputValidation={fiatInputValidation}
marketData={assetMarketData}
onCancel={handleCancel}
onPercentClick={handlePercentClick}
onContinue={handleContinue}
onBack={handleBack}
onChange={handleInputChange}
percentOptions={percentOptions}
enableSlippage={false}
isLoading={
isEstimatedFeesDataLoading ||
isSweepNeededLoading ||
isThorchainSaversDepositQuoteLoading ||
state.loading
}
<InfoAcknowledgement
message={translate('defi.liquidityLockupWarning', {
time: formatSecondsToDuration(
isRunePool
? thorchainMimirTimes?.runePoolDepositMaturityTime ?? 0
: thorchainMimirTimes?.liquidityLockupTime ?? 0,
),
})}
onAcknowledge={handleAcknowledge}
shouldShowAcknowledgement={shouldShowInfoAcknowledgement}
setShouldShowAcknowledgement={setShouldShowInfoAcknowledgement}
position='static'
>
{!isRunePool ? (
<>
<Row>
<Row.Label>{translate('common.slippage')}</Row.Label>
<Row.Value>
<Skeleton isLoaded={isThorchainSaversDepositQuoteSuccess}>
<Amount.Crypto value={slippageCryptoAmountPrecision ?? ''} symbol={asset.symbol} />
</Skeleton>
</Row.Value>
</Row>
<Row>
<Row.Label>
<HelperTooltip label={translate('defi.modals.saversVaults.timeToBreakEven.tooltip')}>
{translate('defi.modals.saversVaults.timeToBreakEven.title')}
</HelperTooltip>
</Row.Label>
<Row.Value>
<Skeleton isLoaded={isThorchainSaversDepositQuoteSuccess}>
{translate(
`defi.modals.saversVaults.${bnOrZero(daysToBreakEven).eq(1) ? 'day' : 'days'}`,
{ amount: daysToBreakEven ?? '0' },
)}
</Skeleton>
</Row.Value>
</Row>
</>
) : null}
</ReusableDeposit>
<ReusableDeposit
accountId={accountId}
onAccountIdChange={handleAccountIdChange}
asset={asset}
apy={opportunityData.apy ?? undefined}
cryptoAmountAvailable={balanceCryptoPrecision.toPrecision()}
cryptoInputValidation={cryptoInputValidation}
fiatAmountAvailable={fiatAmountAvailable.toFixed(2)}
fiatInputValidation={fiatInputValidation}
marketData={assetMarketData}
onCancel={handleCancel}
onPercentClick={handlePercentClick}
onContinue={handleContinueOrAcknowledgement}
onBack={handleBack}
onChange={handleInputChange}
percentOptions={percentOptions}
enableSlippage={false}
isLoading={
isEstimatedFeesDataLoading ||
isSweepNeededLoading ||
isThorchainSaversDepositQuoteLoading ||
isThorchainMimirTimesLoading ||
state.loading
}
>
{!isRunePool ? (
<>
<Row>
<Row.Label>{translate('common.slippage')}</Row.Label>
<Row.Value>
<Skeleton isLoaded={isThorchainSaversDepositQuoteSuccess}>
<Amount.Crypto
value={slippageCryptoAmountPrecision ?? ''}
symbol={asset.symbol}
/>
</Skeleton>
</Row.Value>
</Row>
<Row>
<Row.Label>
<HelperTooltip
label={translate('defi.modals.saversVaults.timeToBreakEven.tooltip')}
>
{translate('defi.modals.saversVaults.timeToBreakEven.title')}
</HelperTooltip>
</Row.Label>
<Row.Value>
<Skeleton isLoaded={isThorchainSaversDepositQuoteSuccess}>
{translate(
`defi.modals.saversVaults.${bnOrZero(daysToBreakEven).eq(1) ? 'day' : 'days'}`,
{ amount: daysToBreakEven ?? '0' },
)}
</Skeleton>
</Row.Value>
</Row>
</>
) : null}
</ReusableDeposit>
</InfoAcknowledgement>
)
}
Loading

0 comments on commit 7f22ed6

Please sign in to comment.