Skip to content

Commit

Permalink
Merge branch 'master' into unlock-tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
vkulinich-cl authored Dec 13, 2024
2 parents d3b8b46 + f919c73 commit ab03e85
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 716 deletions.
2 changes: 1 addition & 1 deletion src/api/deposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const useRefetchAccountAssets = () => {
const { account } = useAccount()

return () => {
queryClient.refetchQueries(QUERY_KEYS.accountAssets(account?.address))
queryClient.resetQueries(QUERY_KEYS.accountAssets(account?.address))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type AssetInputProps = {
onChange: (val: string) => void
name: string
label: string
displayValue?: BigNumber | 0 | null
displayValue?: string
unit?: Maybe<string>
type?: string
placeholder?: string
Expand Down Expand Up @@ -56,7 +56,7 @@ export const AssetInput = forwardRef<HTMLInputElement, AssetInputProps>(
</SInputWrapper>
{props.displayValue != null ? (
<SDollars>
<DisplayValue value={props.displayValue} />
<DisplayValue value={BigNumber(props.displayValue)} />
</SDollars>
) : null}
</SLabelWrapper>
Expand Down
20 changes: 14 additions & 6 deletions src/components/AssetSelect/AssetSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { forwardRef, ReactNode, useMemo } from "react"
import { useTranslation } from "react-i18next"
import { theme } from "theme"
import { getFloatingPointAmount } from "utils/balance"
import { useDisplayPrice } from "utils/displayAsset"
import { useDisplayPrice, useDisplayShareTokenPrice } from "utils/displayAsset"
import { Maybe } from "utils/helpers"
import { SContainer, SMaxButton } from "./AssetSelect.styled"
import { AssetSelectButton } from "./AssetSelectButton"
Expand Down Expand Up @@ -49,15 +49,23 @@ export const AssetSelect = forwardRef<HTMLInputElement, AssetSelectProps>(

const spotPriceId =
isBond(asset) && !asset.isTradable ? asset.underlyingAssetId : asset.id
const { isShareToken } = asset

const spotPriceAsset = useDisplayPrice(spotPriceId)
const spotPriceAsset = useDisplayPrice(
isShareToken ? undefined : spotPriceId,
)
const shareTokenSpotPrice = useDisplayShareTokenPrice(
isShareToken ? [spotPriceId] : [],
)

const spotPrice = spotPriceAsset.data
const spotPrice = isShareToken
? shareTokenSpotPrice.data?.[0].spotPrice
: spotPriceAsset.data?.spotPrice.toString()

const displayValue = useMemo(() => {
if (!props.value) return 0
if (spotPrice?.spotPrice == null) return null
return spotPrice.spotPrice.times(props.value)
if (!props.value || !spotPrice) return undefined

return BigNumber(spotPrice).times(props.value).toString()
}, [props.value, spotPrice])

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/AssetSelect/AssetSelectSkeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const AssetSelectSkeleton = (props: {
name={props.name}
label={t("selectAsset.input.label")}
onChange={() => null}
displayValue={0}
displayValue="0"
placeholder="0.00"
unit="HDX"
css={css`
Expand Down
2 changes: 1 addition & 1 deletion src/components/Stepper/Stepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Stepper = ({ steps, className, width }: StepperProps) => {
const activeIndex = steps.findIndex((step) => step.state === "active")
const activeStep = steps[activeIndex]

const width_ = width ?? steps.length * 100
const width_ = width ?? steps.length * 120

return (
<div sx={{ width: width_, minWidth: 300 }} className={className}>
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
"liquidity.stablepool.transfer.confirm": "Confirm",
"liquidity.stablepool.transfer.adding": "Adding liquidity",
"liquidity.stablepool.transfer.move": "Add to Omnipool",
"liquidity.stablepool.transfer.moveAndJoinFarms": "Add to Omnipool and join farms",
"liquidity.stablepool.asset.details.total": "Value in Stablepool",
"liquidity.stablepool.asset.positions.title": "Stablepool positions",
"liquidity.stablepool.asset.incentives.title": "Farming incentives",
Expand Down Expand Up @@ -300,6 +301,8 @@
"liquidity.add.modal.information.linkText": "Learn more about risks?",
"liquidity.add.modal.toast.onLoading": "<0>Adding </0><1>{{value}} {{symbol}}</1><0> to </0><1>{{where}}</1><0>...</0>",
"liquidity.add.modal.toast.onSuccess": "<0>Added </0><1>{{value}} {{symbol}}</1><0> to </0><1>{{where}}</1><0>.</0>",
"liquidity.add.modal.andJoinFarms.toast.onLoading": "<0>Adding </0><1>{{value}} {{symbol}}</1><0> to </0><1>{{where}}</1><0> and joining farms...</0> ",
"liquidity.add.modal.andJoinFarms.toast.onSuccess": "<0>Added </0><1>{{value}} {{symbol}}</1><0> to </0><1>{{where}}</1><0> and joined farms.</0>",
"liquidity.add.modal.xyk.toast.onLoading": "<0>Adding liquidity in exchange for </0><1>{{shares, bignumber(type: 'token')}}</1><0> asset shares.</0>",
"liquidity.add.modal.xyk.toast.onSuccess": "<0>Added liquidity in exchange for </0><1>{{shares, bignumber(type: 'token')}}</1><0> asset shares.</0>",
"liquidity.remove.modal.title": "Remove liquidity",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const FarmDetailsRow = ({ farm }: FarmDetailsRowProps) => {
/>
<div>
<Text fs={12} lh={12} color="brightBlue300" font="GeistMedium">
{BN(farm.apr).gt(0) && t("value.APR", { apr: BN(farm.apr) })}
{t("value.APR", { apr: BN(farm.apr) })}
</Text>
</div>
<div sx={{ ml: "auto", flex: "row", align: "center" }}>
Expand Down
56 changes: 3 additions & 53 deletions src/sections/pools/farms/modals/join/JoinFarmsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { TFarmAprData, useFarmCurrentPeriod } from "api/farms"
import { Modal } from "components/Modal/Modal"
import { useModalPagination } from "components/Modal/Modal.utils"
import {
LoadingPage,
ModalContents,
} from "components/Modal/contents/ModalContents"
import { ModalContents } from "components/Modal/contents/ModalContents"
import { Text } from "components/Typography/Text/Text"
import { useState } from "react"
import { useTranslation } from "react-i18next"
Expand All @@ -13,7 +10,6 @@ import { FarmDetailsCard } from "sections/pools/farms/components/detailsCard/Far
import { FarmDetailsModal } from "sections/pools/farms/modals/details/FarmDetailsModal"
import { TLPData } from "utils/omnipool"
import { JoinFarmsForm } from "./JoinFarmsForm"
import { getStepState, Stepper } from "components/Stepper/Stepper"
import { usePoolData } from "sections/pools/pool/Pool"
import { TDeposit } from "api/deposits"

Expand All @@ -27,7 +23,6 @@ type JoinFarmModalProps = {
export enum Page {
JOIN_FARM,
FARM_DETAILS,
WAIT,
}

export const JoinFarmModal = ({
Expand All @@ -41,25 +36,16 @@ export const JoinFarmModal = ({
pool: { meta, id: poolId, farms: allFarms },
} = usePoolData()
const [selectedFarm, setSelectedFarm] = useState<TFarmAprData | null>(null)
const [currentStep, setCurrentStep] = useState(0)

const { getCurrentPeriod } = useFarmCurrentPeriod()
const { page, direction, paginateTo } = useModalPagination()

const farms = initialFarms ?? allFarms
const isMultipleFarms = farms.length > 1

const joinFarms = useJoinFarms({
poolId,
farms,
deposit: {
onClose,
disableAutoClose: isMultipleFarms,
onSuccess: () => setCurrentStep(1),
onSubmitted: () => (isMultipleFarms ? paginateTo(Page.WAIT) : null),
onError: onClose,
},
redeposit: {
options: {
onClose,
onError: onClose,
},
Expand All @@ -74,39 +60,8 @@ export const JoinFarmModal = ({
setSelectedFarm(null)
}

const steps = [
{
id: 0,
label: t("farms.modal.join.first"),
loadingLabel: t("farms.modal.join.first.loading"),
},
...(isMultipleFarms
? [
{
id: 1,
label: t("farms.modal.join.rest"),
loadingLabel: t("farms.modal.join.rest.loading"),
},
]
: []),
]

return (
<Modal
open
onClose={onClose}
disableCloseOutside
topContent={
isMultipleFarms ? (
<Stepper
steps={steps.map((step) => ({
label: step.label,
state: getStepState(step.id, currentStep),
}))}
/>
) : undefined
}
>
<Modal open onClose={onClose} disableCloseOutside>
<ModalContents
onClose={onClose}
page={page}
Expand Down Expand Up @@ -158,11 +113,6 @@ export const JoinFarmModal = ({
/>
),
},
{
title: steps[currentStep].label,
headerVariant: "gradient",
content: <LoadingPage title={steps[currentStep].loadingLabel} />,
},
]}
/>
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function JoinedFarmsDetailsRedeposit(props: {
const joinFarms = useJoinFarms({
poolId,
farms: availableFarms,
redeposit: {
options: {
onSubmitted: () => props.onTxClose(),
onBack: () => {},
onClose: () => props.onTxClose(),
Expand Down
43 changes: 25 additions & 18 deletions src/sections/pools/farms/position/FarmingPosition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,27 @@ export const FarmingPosition = ({
}
})

const totalRewardsValue = claimableAssets
.map((claimableAsset) =>
t("value.tokenWithSymbol", {
value: claimableAsset.value.rewards,
symbol: claimableAsset.symbol,
}),
)
.join(" + ")

const maxTotalRewardsValue = claimableAssets
.map((claimableAsset) =>
t("value.tokenWithSymbol", {
value: BigNumber(claimableAsset.value.maxRewards),
symbol: claimableAsset.symbol,
}),
)
.join(" + ")
const totalRewardsValue = claimableAssets.length
? claimableAssets
.map((claimableAsset) =>
t("value.tokenWithSymbol", {
value: claimableAsset.value.rewards,
symbol: claimableAsset.symbol,
}),
)
.join(" + ")
: "0"

const maxTotalRewardsValue = claimableAssets.length
? claimableAssets
.map((claimableAsset) =>
t("value.tokenWithSymbol", {
value: BigNumber(claimableAsset.value.maxRewards),
symbol: claimableAsset.symbol,
}),
)
.join(" + ")
: "0"

// use latest entry date
const enteredDate = useEnteredDate(
Expand Down Expand Up @@ -341,7 +345,10 @@ export const FarmingPosition = ({
)}
<div sx={{ flex: "column", align: "flex-end" }}>
{isDesktop && (
<Text fs={14} color={color}>
<Text
fs={14}
color={isClaimable === undefined ? "white" : color}
>
{totalRewardsValue}
</Text>
)}
Expand Down
Loading

0 comments on commit ab03e85

Please sign in to comment.