Skip to content

Commit

Permalink
fixes ui contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmagnus committed Dec 13, 2023
1 parent 353f6be commit 86ebc1a
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 196 deletions.
1 change: 1 addition & 0 deletions frontend/src/app/core/pages/contracts-create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const ContractsCreate: React.FC = () => {
const { vaults, loadingVaults, getVaults } = useVaults()
const { sign, submit, getSponsorPK } = useTransactions()
const { getLatestSequenceLedger } = useHorizon()

const toast = useToast()
const navigate = useNavigate()

Expand Down
37 changes: 30 additions & 7 deletions frontend/src/app/core/pages/contracts-detail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Flex, useToast } from '@chakra-ui/react'
import React, { useCallback, useEffect, useState } from 'react'
import { FieldValues, UseFormSetValue } from 'react-hook-form'
import { useParams } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'

import { useAuth } from 'hooks/useAuth'
import { useContracts } from 'hooks/useContracts'
Expand Down Expand Up @@ -38,6 +38,7 @@ export const ContractsDetail: React.FC = () => {
const [currentInVault, setCurrentInVault] = useState<string>()

const { id } = useParams()
const navigate = useNavigate()

useEffect(() => {
getUserPermissions()
Expand Down Expand Up @@ -66,10 +67,10 @@ export const ContractsDetail: React.FC = () => {
const userYield =
Number((await getYield(wallet, contract.address)) || 0) / 10000000

const estimatedPrematureWithdraw = await getEstimatedPrematureWithdraw(
wallet,
contract.address
)
const estimatedPrematureWithdraw =
Number(
(await getEstimatedPrematureWithdraw(wallet, contract.address)) || 0
) / 10000000

if (!timeLeft) {
timeLeft =
Expand Down Expand Up @@ -236,21 +237,43 @@ export const ContractsDetail: React.FC = () => {
return history ? history[0]?.deposit_amount : undefined
}

const hasAssetInVault = (): boolean => {
return (
profile?.vault?.accountData?.balances.find(
balance =>
balance.asset_code === contract?.asset.code &&
balance.asset_issuer === contract?.asset.issuer.key.publicKey
) !== undefined
)
}

const accessWallet = (): void => {
navigate(`${PathRoute.VAULT_DETAIL}/${profile?.vault_id}`)
}

const accessProfile = (): void => {
navigate(`${PathRoute.PROFILE}`)
}

return (
<Flex>
<Sidebar highlightMenu={PathRoute.SOROBAN_SMART_CONTRACTS}>
<ContractsDetailTemplate
onSubmitWithdraw={onSubmitWithdraw}
onSubmitDeposit={onSubmitDeposit}
currentBalance={getCurrentBalance()}
deposited={getDepositedValue()}
hasAssetInVault={hasAssetInVault()}
accessWallet={accessWallet}
accessProfile={accessProfile}
hasWallet={profile?.vault_id !== undefined}
loading={loadingPosition}
contract={contract}
userAccount={profile?.vault?.wallet?.key.publicKey}
isDepositing={isDepositing}
isWithdrawing={isWithdrawing}
contractData={contractData}
currentBalance={getCurrentBalance()}
history={history}
deposited={getDepositedValue()}
userPermissions={userPermissions}
currentInVault={currentInVault}
/>
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/components/molecules/select-asset/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { useColorMode } from '@chakra-ui/react'
import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'
import { Flex, Text, useColorMode } from '@chakra-ui/react'
import React, {
Dispatch,
ReactNode,
SetStateAction,
useEffect,
useState,
} from 'react'
import Select from 'react-select'

export interface IOption {
Expand Down Expand Up @@ -38,6 +44,13 @@ export const SelectAsset: React.FC<ISelectAsset> = ({
setOptions(ops || [])
}, [assets])

const formatLabel = (data: IOption): ReactNode => (
<Flex alignItems="center" gap="0.75rem">
<Text fontSize="xs" minW="3rem">{data.label}</Text>
<Text fontSize="sm">{data.value.name}</Text>
</Flex>
)

return (
<Select
options={options}
Expand All @@ -46,6 +59,7 @@ export const SelectAsset: React.FC<ISelectAsset> = ({
}}
value={selected}
placeholder="Select asset"
formatOptionLabel={formatLabel}
styles={{
control: baseStyles => ({
...baseStyles,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/molecules/select-vault/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const SelectVault: React.FC<ISelectVault> = ({
setOptions(ops || [])
}, [distributorWallet, vaults])

const formatGroupLabel = (data: IOption): ReactNode => (
const formatLabel = (data: IOption): ReactNode => (
<Flex alignItems="center" gap="0.75rem">
{data.isPersonal ? (
<User width="16px" height="16px" fill="gray" />
Expand All @@ -80,7 +80,7 @@ export const SelectVault: React.FC<ISelectVault> = ({
options={options}
onChange={(newValue): void => setWallet(newValue?.value)}
isOptionDisabled={(option): boolean => option.disabled}
formatOptionLabel={formatGroupLabel}
formatOptionLabel={formatLabel}
styles={{
control: baseStyles => ({
...baseStyles,
Expand Down
Loading

0 comments on commit 86ebc1a

Please sign in to comment.