Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/main/src/components/AssetSelect/AssetSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const AssetSelect = ({
const displayValueLoading = props.displayValueLoading ?? displayValueLoading_

const { getTransferableBalance } = useAccountBalances()

const maxBalance = ((): string | undefined => {
if (providedMaxBalance) {
return providedMaxBalance
Expand Down
72 changes: 48 additions & 24 deletions apps/main/src/components/AssetSelectModal/AssetSelectModal.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const useAssetSelectModalAssets = ({
search,
selectedAssetId,
ignoreAssetIds,
...sortOptions
tickerOrder,
lowPriorityAssetIds,
highPriorityAssetIds,
}: {
assets: TAssetData[]
ignoreAssetIds?: string[]
Expand All @@ -45,33 +47,54 @@ export const useAssetSelectModalAssets = ({
const { getAssetPrice, isLoading: isPriceLoading } =
useAssetsPrice(assetsBalanceIds)

if (!account || !assets.length) {
return {
sortedAssets: filteredAssets,
isLoading: false,
}
}

const assetsWithBalances = filteredAssets.map((asset) => {
const balance = scaleHuman(getTransferableBalance(asset.id), asset.decimals)
const invalidState = !account || !assets.length

const { price, isValid } = getAssetPrice(asset.id)
const balanceDisplay = isValid ? Big(price).times(balance).toString() : "0"
const isLoading = isPriceLoading || isBalanceLoading

return {
...asset,
balance,
balanceDisplay,
const sortedAssets = useMemo(() => {
if (invalidState || isLoading) {
return filteredAssets
}
})

const sortedAssets = sortAssets(assetsWithBalances, "balanceDisplay", {
firstAssetId: selectedAssetId,
const assetsWithBalances = filteredAssets.map((asset) => {
const balance = scaleHuman(
getTransferableBalance(asset.id),
asset.decimals,
)

const { price, isValid } = getAssetPrice(asset.id)
const balanceDisplay = isValid
? Big(price).times(balance).toString()
: "0"

return {
...asset,
balance,
balanceDisplay,
}
})

return sortAssets(assetsWithBalances, "balanceDisplay", {
firstAssetId: selectedAssetId,
search,
tickerOrder,
lowPriorityAssetIds,
highPriorityAssetIds,
})
}, [
invalidState,
filteredAssets,
getAssetPrice,
getTransferableBalance,
highPriorityAssetIds,
isLoading,
lowPriorityAssetIds,
selectedAssetId,
search,
...sortOptions,
})
tickerOrder,
])

return { sortedAssets, isLoading: isPriceLoading || isBalanceLoading }
return { sortedAssets, isLoading: invalidState ? false : isLoading }
}

export const useFilteredSearchAssets = <T extends TAssetData>(
Expand All @@ -85,6 +108,7 @@ export const useFilteredSearchAssets = <T extends TAssetData>(
}

const ignoredAssetIdSet = new Set(ignoreAssetIds ?? [])
const searchLower = search.length ? search.toLowerCase() : ""

return assets.filter((asset) => {
if (ignoredAssetIdSet.has(asset.id)) {
Expand All @@ -93,8 +117,8 @@ export const useFilteredSearchAssets = <T extends TAssetData>(

if (search.length) {
return (
asset.name.toLowerCase().includes(search.toLowerCase()) ||
asset.symbol.toLowerCase().includes(search.toLowerCase())
asset.name.toLowerCase().includes(searchLower) ||
asset.symbol.toLowerCase().includes(searchLower)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AssetButton,
Box,
Flex,
LoadingButton,
Expand All @@ -8,10 +9,11 @@ import {
Stack,
Text,
} from "@galacticcouncil/ui/components"
import { pxToRem } from "@galacticcouncil/ui/utils"

const AssetSectionSkeleton = () => {
return (
<Stack gap="s" py="m" px="l">
<Stack gap="m" py="l" px="xl">
<Flex justify="space-between">
<Text fs="p6">
<Skeleton width={100} />
Expand All @@ -21,13 +23,14 @@ const AssetSectionSkeleton = () => {
</Text>
</Flex>
<Flex justify="space-between" align="center">
<Flex gap="m" align="center">
<Skeleton width={42} height={42} circle />
<Skeleton width={70} height={30} />
</Flex>
<Flex gap="base" direction="column" align="end">
<Skeleton width={40} height={30} />
<Skeleton width={50} height={14} />
<AssetButton loading error={false} />
<Flex gap="s" direction="column" align="end">
<div sx={{ height: pxToRem(26), lineHeight: 1 }}>
<Skeleton width={pxToRem(40)} height={pxToRem(26)} />
</div>
<div sx={{ height: pxToRem(12), lineHeight: 1 }}>
<Skeleton width={pxToRem(50)} height={pxToRem(12)} />
</div>
</Flex>
</Flex>
</Stack>
Expand All @@ -36,11 +39,11 @@ const AssetSectionSkeleton = () => {

const SwitcherSkeleton = () => {
return (
<Flex align="center" justify="space-between" gap="s">
<Separator sx={{ flexShrink: 0, width: "m" }} />
<Flex align="center" justify="space-between">
<Separator sx={{ flexShrink: 0, width: 32 }} />
<Skeleton
width={30}
height={30}
width={34}
height={34}
circle
sx={{ display: "inline-flex", flexShrink: 0 }}
/>
Expand Down
6 changes: 3 additions & 3 deletions apps/main/src/modules/trade/orders/DcaOrderDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export const DcaOrderDetailsModal = ({ details, onTerminate }: Props) => {
{t("number", {
value: details.isOpenBudget
? details.fromAmountExecuted
: details.status === DcaScheduleStatus.Created
? details.fromAmountRemaining
: "0",
: details.status === DcaScheduleStatus.Completed
? "0"
: (details.fromAmountRemaining ?? details.fromAmountBudget),
})}
{!details.isOpenBudget && (
<>
Expand Down
9 changes: 8 additions & 1 deletion apps/main/src/modules/trade/orders/columns/SwapPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ type Props = {
}

export const SwapPrice: FC<Props> = ({ from, to, price }) => {
const { t } = useTranslation()
const { t } = useTranslation("common")

if (!price)
return (
<Text fw={500} fs="p6" lh="s" color={getToken("text.high")}>
-
</Text>
)

return (
<Flex align="center" gap="s" justify="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ export const PlaceOrderModalContent: FC<Props> = ({ onClose }) => {
)}
</>
)}
<Separator />
</ModalBody>
<ModalFooter>
<Button
Expand Down
14 changes: 12 additions & 2 deletions apps/main/src/modules/trade/otc/place-order/PlaceOrderPrice.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AssetIcon } from "@galacticcouncil/ui/assets/icons"
import { ArrowLeftRight } from "@galacticcouncil/ui/assets/icons"
import {
ButtonIcon,
Flex,
Icon,
NumberInput,
Text,
} from "@galacticcouncil/ui/components"
Expand Down Expand Up @@ -79,6 +80,11 @@ export const PlaceOrderPrice: FC<Props> = ({
<Flex justify="space-between" align="center">
<Flex py="s" pl="s" gap="s" align="center">
<ButtonIcon
sx={{
border: "1px solid",
borderColor: getToken("buttons.secondary.low.borderRest"),
}}
size="small"
onClick={() =>
viewField.onChange(
(isOfferView
Expand All @@ -87,7 +93,11 @@ export const PlaceOrderPrice: FC<Props> = ({
)
}
>
<AssetIcon />
<Icon
component={ArrowLeftRight}
size="s"
color={getToken("icons.onContainer")}
/>
</ButtonIcon>
<Text fw={600} fs="p3" lh="s" color={getToken("text.high")}>
{isOfferView ? buyAsset.symbol : offerAsset.symbol}
Expand Down
4 changes: 3 additions & 1 deletion apps/main/src/states/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Balance as SdkBalance } from "@galacticcouncil/sdk-next"
import { useStableArray } from "@galacticcouncil/utils"
import { useAccount } from "@galacticcouncil/web3-connect"
import { produce } from "immer"
import { useCallback, useMemo } from "react"
import { pick } from "remeda"
Expand Down Expand Up @@ -138,6 +139,7 @@ export const useAccountData = create<
}))

export const useAccountBalances = () => {
const { account } = useAccount()
const { balances, isBalanceLoading } = useAccountData(
useShallow(pick(["balances", "isBalanceLoading"])),
)
Expand All @@ -159,7 +161,7 @@ export const useAccountBalances = () => {

return {
balances,
isBalanceLoading,
isBalanceLoading: account ? isBalanceLoading : false,
getBalance,
getTransferableBalance,
isBalanceLoaded,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@galacticcouncil/common": "^0.6.0",
"@galacticcouncil/descriptors": "^1.15.0",
"@galacticcouncil/sdk-next": "^0.38.0",
"@galacticcouncil/sdk-next": "^0.39.0",
"@galacticcouncil/xc": "^0.5.0",
"@galacticcouncil/xc-cfg": "^0.18.1",
"@galacticcouncil/xc-core": "^0.13.0",
Expand Down
5 changes: 0 additions & 5 deletions packages/ui/src/assets/icons/AssetIcon.svg

This file was deleted.

1 change: 0 additions & 1 deletion packages/ui/src/assets/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { default as ArrowRightLong } from "./ArrowRightLong.svg?react"
export { default as AssetIcon } from "./AssetIcon.svg?react"
export { default as CaretDown } from "./CaretDown.svg?react"
export { default as CircleAlert } from "./CircleAlert.svg?react"
export { default as CircleCheck } from "./CircleCheck.svg?react"
Expand Down
22 changes: 6 additions & 16 deletions packages/ui/src/components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReactNode } from "react"

import { Flex, Icon, MicroButton, Skeleton, Text } from "@/components"
import { FormError } from "@/components/FormError"
import { getToken } from "@/utils"
import { getToken, pxToRem } from "@/utils"

import {
SAssetButton,
Expand Down Expand Up @@ -75,7 +75,8 @@ export const AssetInput = ({
<Flex
direction="column"
gap="m"
sx={{ position: "relative", py: 20, overflow: "hidden" }}
py="l"
sx={{ position: "relative", overflow: "hidden" }}
className={className}
>
<Flex align="center" gap="s" justify="space-between">
Expand Down Expand Up @@ -222,20 +223,9 @@ export const AssetButton = ({
}) => {
if (loading)
return (
<Flex
direction="column"
height="2.375rem"
gap="xs"
justify="center"
className={className}
>
<div sx={{ height: "xs", lineHeight: 1 }}>
<Skeleton sx={{ width: "m", height: "xs" }} />
</div>
<div sx={{ height: "xs", lineHeight: 1 }}>
<Skeleton sx={{ width: "100%", minWidth: "xl", height: "xs" }} />
</div>
</Flex>
<div sx={{ height: pxToRem(34), lineHeight: 1 }}>
<Skeleton sx={{ width: pxToRem(80), height: pxToRem(34) }} />
</div>
)

if (symbol && icon)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2072,10 +2072,10 @@
resolved "https://registry.yarnpkg.com/@galacticcouncil/math-xyk/-/math-xyk-1.3.0.tgz#96d3b3e63a93544c7e60d3fa9e1be9a576a20efe"
integrity sha512-ZYVSyI5W2pQKCqpkaRM7t1AJqtPyxQ0P04T2+KpBEEABMRjSpQz2x44s1tk6r3DdFR8dICeZJEh5BI7eQYlT6w==

"@galacticcouncil/sdk-next@^0.38.0":
version "0.38.0"
resolved "https://registry.yarnpkg.com/@galacticcouncil/sdk-next/-/sdk-next-0.38.0.tgz#5faedd2319c027b342b2fe4f4ed008e28602216b"
integrity sha512-XDRLA/dSOLwV8eAFCks0urpXgmNPrUASGFBeWge/IchinT4idfVzrnmvQFEpL9IcCejqg026Qp5h232mX67tBw==
"@galacticcouncil/sdk-next@^0.39.0":
version "0.39.0"
resolved "https://registry.yarnpkg.com/@galacticcouncil/sdk-next/-/sdk-next-0.39.0.tgz#b4187c793a77124df7929a6511577f976bd32147"
integrity sha512-eGrMzhG9MYXr3LQyLLfDj3q8lV0EtSMuCewd+Wia8cqpBwPvL8d2U5UE2zlgkYlXHA4x1qayH2qRpWe4gRyIIQ==
dependencies:
"@galacticcouncil/math-hsm" "^1.2.0"
"@galacticcouncil/math-lbp" "^1.3.0"
Expand Down
Loading