-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into attestation-tweaks
- Loading branch information
Showing
40 changed files
with
2,654 additions
and
953 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
centrifuge-app/src/pages/IssuerCreatePool/FormAddressInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { evmToSubstrateAddress } from '@centrifuge/centrifuge-js' | ||
import { useCentrifugeUtils } from '@centrifuge/centrifuge-react' | ||
import { TextInput } from '@centrifuge/fabric' | ||
import { useField } from 'formik' | ||
import React from 'react' | ||
import { FieldWithErrorMessage } from '../../../src/components/FieldWithErrorMessage' | ||
import { isEvmAddress } from '../../../src/utils/address' | ||
import { truncate } from '../../utils/web3' | ||
|
||
interface FormAddressInputProps { | ||
name: string | ||
chainId?: number | ||
placeholder?: string | ||
} | ||
|
||
export const FormAddressInput = ({ name, chainId, placeholder }: FormAddressInputProps) => { | ||
const [field, meta, helpers] = useField(name) | ||
const utils = useCentrifugeUtils() | ||
|
||
let truncated: string | undefined | ||
try { | ||
truncated = truncate(utils.formatAddress(field.value)) | ||
} catch (e) { | ||
truncated = undefined | ||
} | ||
|
||
function handleBlur() { | ||
helpers.setTouched(true) | ||
|
||
if (!truncated || meta.error) { | ||
helpers.setError('Invalid address') | ||
return | ||
} | ||
|
||
helpers.setValue(isEvmAddress(field.value) ? evmToSubstrateAddress(field.value, chainId ?? 0) : field.value) | ||
} | ||
|
||
return ( | ||
<FieldWithErrorMessage | ||
{...field} | ||
placeholder={placeholder ?? 'Type address...'} | ||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => helpers.setValue(e.target.value)} | ||
onBlur={handleBlur} | ||
errorMessage={meta.touched && meta.error ? meta.error : undefined} | ||
as={TextInput} | ||
/> | ||
) | ||
} |
113 changes: 113 additions & 0 deletions
113
centrifuge-app/src/pages/IssuerCreatePool/IssuerCategories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { PoolMetadataInput } from '@centrifuge/centrifuge-js' | ||
import { Box, Grid, IconButton, IconTrash, Select, Text, TextInput } from '@centrifuge/fabric' | ||
import { Field, FieldArray, FieldProps, useFormikContext } from 'formik' | ||
import { FieldWithErrorMessage } from '../../../src/components/FieldWithErrorMessage' | ||
import { AddButton } from './PoolDetailsSection' | ||
import { StyledGrid } from './PoolStructureSection' | ||
|
||
const PROVIDERS = [ | ||
{ label: 'Please select...', value: '' }, | ||
{ label: 'Fund admin', value: 'fundAdmin' }, | ||
{ label: 'Trustee', value: 'trustee' }, | ||
{ label: 'Pricing oracle provider', value: 'pricingOracleProvider' }, | ||
{ label: 'Auditor', value: 'auditor' }, | ||
{ label: 'Custodian', value: 'custodian' }, | ||
{ label: 'Investment manager', value: 'investmentManager' }, | ||
{ label: 'Sub-advisor', value: 'subadvisor' }, | ||
{ label: 'Historical default rate', value: 'historicalDefaultRate' }, | ||
{ label: 'Other', value: 'other' }, | ||
] | ||
|
||
export const LabelWithDeleteButton = ({ | ||
onDelete, | ||
hideButton, | ||
label, | ||
}: { | ||
onDelete: () => void | ||
hideButton: boolean | ||
label: string | ||
}) => { | ||
return ( | ||
<Box display="flex" justifyContent="space-between" alignItems="center"> | ||
<Text variant="heading4">{label}</Text> | ||
{!hideButton && ( | ||
<IconButton onClick={onDelete}> | ||
<IconTrash color="textSecondary" /> | ||
</IconButton> | ||
)} | ||
</Box> | ||
) | ||
} | ||
|
||
export const IssuerCategoriesSection = () => { | ||
const form = useFormikContext<PoolMetadataInput>() | ||
return ( | ||
<Box mt={4} mb={3}> | ||
<Text variant="heading2">Service providers</Text> | ||
<StyledGrid gridTemplateColumns={['1fr', '1fr 1fr']} mt={3}> | ||
<FieldArray name="issuerCategories"> | ||
{({ push, remove }) => ( | ||
<> | ||
{form.values.issuerCategories.map((category, index) => ( | ||
<> | ||
<Grid gridTemplateColumns={['1fr', category.type === 'other' ? '1fr 1fr' : '1fr']} gap={2}> | ||
<Field name={`issuerCategories.${index}.type`}> | ||
{({ field, meta }: FieldProps) => ( | ||
<Select | ||
name={field.name} | ||
label="Type" | ||
onChange={(event) => form.setFieldValue(field.name, event.target.value)} | ||
onBlur={field.onBlur} | ||
value={field.value} | ||
options={PROVIDERS} | ||
errorMessage={meta.touched && meta.error ? meta.error : undefined} | ||
/> | ||
)} | ||
</Field> | ||
{category.type === 'other' && ( | ||
<Field name={`issuerCategories.${index}.description`}> | ||
{({ field, meta }: FieldProps) => ( | ||
<FieldWithErrorMessage | ||
{...field} | ||
label="Description" | ||
placeholder="Type here..." | ||
maxLength={100} | ||
as={TextInput} | ||
errorMessage={meta.touched && meta.error ? meta.error : undefined} | ||
onBlur={field.onBlur} | ||
/> | ||
)} | ||
</Field> | ||
)} | ||
</Grid> | ||
<Field name={`issuerCategories.${index}.value`}> | ||
{({ field, meta }: FieldProps) => ( | ||
<FieldWithErrorMessage | ||
{...field} | ||
label={ | ||
<LabelWithDeleteButton | ||
onDelete={() => remove(index)} | ||
hideButton={form.values.issuerCategories.length === 1} | ||
label="Name of provider" | ||
/> | ||
} | ||
placeholder="Type here..." | ||
maxLength={100} | ||
errorMessage={meta.touched && meta.error ? meta.error : undefined} | ||
onBlur={field.onBlur} | ||
as={TextInput} | ||
/> | ||
)} | ||
</Field> | ||
</> | ||
))} | ||
<Box gridColumn="span 2"> | ||
<AddButton onClick={() => push({ type: '', value: '' })} /> | ||
</Box> | ||
</> | ||
)} | ||
</FieldArray> | ||
</StyledGrid> | ||
</Box> | ||
) | ||
} |
Oops, something went wrong.