Skip to content

Commit

Permalink
Add fund shares and liquid assets UI
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy committed Feb 6, 2025
1 parent 915c940 commit 9373aaa
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 11 deletions.
16 changes: 11 additions & 5 deletions centrifuge-app/src/components/Dashboard/assets/CreateAssetForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tooltipText } from 'src/components/Tooltips'
import { useTheme } from 'styled-components'
import { useSuitableAccounts } from '../../../../src/utils/usePermissions'
import { CheckboxOption } from '../../../pages/IssuerCreatePool/PoolStructureSection'
import { CreateAssetFormValues } from './CreateAssetsDrawer'
import { CreateAssetFormValues, PoolWithMetadata } from './CreateAssetsDrawer'
import { CustomAssetForm } from './CustomAssetForm'
import { FundSharesForm } from './FundSharesForm'
import { LiquidAssetsForm } from './LiquidAssetsForm'
Expand All @@ -16,7 +16,13 @@ const assetTypes = [
{ label: 'Custom assets', tooltip: 'customAsset', id: 'custom' },
]

export function CreateAssetsForm({ hasTemplates }: { hasTemplates: boolean }) {
export function CreateAssetsForm({
hasTemplates,
selectedPool,
}: {
hasTemplates: boolean
selectedPool: PoolWithMetadata
}) {
const form = useFormikContext<CreateAssetFormValues>()
const theme = useTheme()
const canCreateAssets =
Expand All @@ -25,11 +31,11 @@ export function CreateAssetsForm({ hasTemplates }: { hasTemplates: boolean }) {
const renderBody = () => {
switch (form.values.assetType) {
case 'liquid':
return <LiquidAssetsForm />
return <LiquidAssetsForm selectedPool={selectedPool} />
case 'fund':
return <FundSharesForm />
return <FundSharesForm selectedPool={selectedPool} />
case 'custom':
return <CustomAssetForm />
return <CustomAssetForm selectedPool={selectedPool} />
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type CreateAssetFormValues = {
poolId: string
assetType: string
assetName: string
oracleSource: string
maturity: string
interestRate: number
linearPricing: number
}

export function CreateAssetsDrawer({ open, onClose, type }: { open: boolean; onClose: () => void; type: Step }) {
Expand All @@ -38,6 +42,10 @@ export function CreateAssetsDrawer({ open, onClose, type }: { open: boolean; onC
poolId: poolsMetadata[0]?.id,
assetType: 'cash',
assetName: '',
oracleSource: 'isin',
maturity: 'fixed',
interestRate: 0,
linearPricing: false,
},
onSubmit: (values) => {
console.log(values)
Expand Down Expand Up @@ -82,7 +90,9 @@ export function CreateAssetsDrawer({ open, onClose, type }: { open: boolean; onC
)}
</Field>
</Box>
{step === 'create-asset' && <CreateAssetsForm hasTemplates={!!selectedPool.meta.loanTemplates?.length} />}
{step === 'create-asset' && (
<CreateAssetsForm hasTemplates={!!selectedPool.meta.loanTemplates?.length} selectedPool={selectedPool} />
)}
{step === 'upload-template' && !!poolAdmin && <UploadAssetTemplateForm pool={selectedPool} />}
<FooterActionButtons onClose={onClose} pool={selectedPool} type={type} onClick={() => handleButtonClick} />
</Form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export const FundSharesForm = () => {
return <div>FundSharesForm</div>
import { PoolWithMetadata } from './CreateAssetsDrawer'
import { LiquidAssetsForm } from './LiquidAssetsForm'

export const FundSharesForm = ({ selectedPool }: { selectedPool: PoolWithMetadata }) => {
return <LiquidAssetsForm selectedPool={selectedPool} />
}
156 changes: 154 additions & 2 deletions centrifuge-app/src/components/Dashboard/assets/LiquidAssetsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,155 @@
export const LiquidAssetsForm = () => {
return <div>LiquidAssetsForm</div>
import { CurrencyInput, DateInput, Grid, NumberInput, Select, TextInput } from '@centrifuge/fabric'
import { Field, FieldProps, useFormikContext } from 'formik'
import { useTheme } from 'styled-components'
import { Tooltips } from '../../../../src/components/Tooltips'
import { CreateAssetFormValues, PoolWithMetadata } from './CreateAssetsDrawer'

const oracleSources = [
{
label: 'ISIN',
value: 'isin',
},
{
label: 'Asset specific',
value: 'assetSpecific',
},
]

const linearPricingOptions = [
{ label: 'Yes', value: 'true' },
{ label: 'No', value: 'false' },
]

const maturityOptions = [
{ label: 'Fixed', value: 'fixed' },
{ label: 'Fixed with extension', value: 'fixedWithExtension' },
{ label: 'Open-end', value: 'none' },
]

export const LiquidAssetsForm = ({ selectedPool }: { selectedPool: PoolWithMetadata }) => {
const theme = useTheme()
const form = useFormikContext<CreateAssetFormValues>()
return (
<Grid
backgroundColor="backgroundSecondary"
borderRadius={8}
p={2}
border={`1px solid ${theme.colors.borderPrimary}`}
gap={2}
>
<Field name="oracleSource">
{({ field, form }: FieldProps) => (
<Select
name="oracleSource"
label="Oracle source"
value={field.value}
options={oracleSources}
onChange={(event) => {
form.setFieldValue('oracleSource', event.target.value)
}}
/>
)}
</Field>
{form.values.oracleSource === 'isin' && (
<Field name="isin">
{({ field, form }: FieldProps) => (
<TextInput
name="isin"
label={<Tooltips type="isin" size="med" color={theme.colors.textPrimary} label="ISIN*" />}
value={field.value}
onChange={(event) => {
form.setFieldValue('isin', event.target.value)
}}
/>
)}
</Field>
)}
<Field name="notionalValue">
{({ field, form }: FieldProps) => (
<CurrencyInput
name="notionalValue"
label={
<Tooltips type="notionalValue" size="med" color={theme.colors.textPrimary} label="Notional value*" />
}
value={field.value}
onChange={(event) => {
form.setFieldValue('notionalValue', event)
}}
currency={selectedPool.currency.displayName}
/>
)}
</Field>
<Field name="linearPricing">
{({ field, form }: FieldProps) => (
<Select
name="linearPricing"
label="With linear pricing?"
value={field.value}
options={linearPricingOptions}
onChange={(event) => {
form.setFieldValue('linearPricing', event.target.value)
}}
/>
)}
</Field>
<Field name="interestRate">
{({ field, form }: FieldProps) => (
<NumberInput
name="interestRate"
label={<Tooltips type="interestRate" size="med" color={theme.colors.textPrimary} label="Interest rate*" />}
value={field.value}
onChange={(event) => {
form.setFieldValue('interestRate', event.target.value)
}}
symbol="%"
placeholder="0.00"
/>
)}
</Field>
<Field name="maturity">
{({ field, form }: FieldProps) => (
<Select
name="maturity"
label="Maturity"
value={field.value}
options={maturityOptions}
onChange={(event) => {
form.setFieldValue('maturity', event.target.value)
}}
/>
)}
</Field>
{(form.values.maturity === 'fixed' || form.values.maturity === 'fixedWithExtension') && (
<>
<Field name="maturityDate">
{({ field, form }: FieldProps) => (
<DateInput
name="maturityDate"
label="Maturity date*"
value={field.value}
onChange={(event) => {
form.setFieldValue('maturityDate', event.target.value)
}}
/>
)}
</Field>
{form.values.maturity === 'fixedWithExtension' && (
<Field name="maturityExtensionDays">
{({ field, form }: FieldProps) => (
<NumberInput
name="maturityExtensionDays"
label={<Tooltips type="maturityExtensionDays" size="med" color={theme.colors.textPrimary} />}
symbol="days"
value={field.value}
onChange={(event) => {
form.setFieldValue('maturityExtensionDays', event.target.value)
}}
/>
)}
</Field>
)}
</>
)}
</Grid>
)
}
2 changes: 1 addition & 1 deletion centrifuge-app/src/components/Tooltips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export function Tooltips({ type, label: labelOverride, size = 'sm', props, color
<Text
textAlign="left"
variant={size === 'sm' ? 'label2' : size === 'xs' ? 'body4' : 'label1'}
color={size === 'sm' && !color ? 'textPrimary' : 'textSecondary'}
color={size === 'sm' && !color ? 'textPrimary' : color || 'textSecondary'}
fontWeight={size === 'sm' ? 'inherit' : 400}
>
{labelOverride || label}
Expand Down

0 comments on commit 9373aaa

Please sign in to comment.