diff --git a/package.json b/package.json index 477bbd36..b5cd5f33 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ ], "globals": { "ts-jest": { - "tsConfigFile": "/Users/mwoywode/Documents/workspace/KILT/prototype-client/tsconfig.test.json" + "tsConfigFile": "tsconfig.test.json" } } }, diff --git a/src/components/AttestedClaimVerificationView/AttestedClaimVerificationView.tsx b/src/components/AttestedClaimVerificationView/AttestedClaimVerificationView.tsx index 135aa0e2..995da655 100644 --- a/src/components/AttestedClaimVerificationView/AttestedClaimVerificationView.tsx +++ b/src/components/AttestedClaimVerificationView/AttestedClaimVerificationView.tsx @@ -4,25 +4,24 @@ import AttestationService from '../../services/AttestationService' import * as UiState from '../../state/ducks/UiState' import PersistentStore from '../../state/PersistentStore' -import { CType } from '../../types/Ctype' +import { ICType } from '../../types/Ctype' import AttestationStatus from '../AttestationStatus/AttestationStatus' import ContactPresentation from '../ContactPresentation/ContactPresentation' import CTypePresentation from '../CTypePresentation/CTypePresentation' import Spinner from '../Spinner/Spinner' - +import { getCtypePropertyTitle } from '../../utils/CtypeUtils' import './AttestedClaimVerificationView.scss' type Props = { attestedClaim: sdk.IAttestedClaim context?: string - cType?: CType + cType?: ICType } type State = {} class AttestedClaimVerificationView extends React.Component { private static readonly BLOCK_CHAR: string = '\u2588' - constructor(props: Props) { super(props) this.state = {} @@ -88,7 +87,9 @@ class AttestedClaimVerificationView extends React.Component { return (
{propertyNames.map((propertyName: string) => { - const propertyTitle = this.getCtypePropertyTitle(propertyName) + const propertyTitle = this.props.cType + ? getCtypePropertyTitle(propertyName, this.props.cType) + : propertyName return (
@@ -112,11 +113,6 @@ class AttestedClaimVerificationView extends React.Component { return contents[propertyName] + '' } } - - private getCtypePropertyTitle(propertyName: string): string { - const { cType } = this.props - return cType ? cType.getPropertyTitle(propertyName) : propertyName - } } export default AttestedClaimVerificationView diff --git a/src/components/CTypePresentation/CTypePresentation.tsx b/src/components/CTypePresentation/CTypePresentation.tsx index d9142280..c0c1b0ad 100644 --- a/src/components/CTypePresentation/CTypePresentation.tsx +++ b/src/components/CTypePresentation/CTypePresentation.tsx @@ -13,13 +13,13 @@ import { SubmitLegitimationsProps } from '../../containers/Tasks/SubmitLegitimat import CTypeRepository from '../../services/CtypeRepository' import * as UiState from '../../state/ducks/UiState' import PersistentStore from '../../state/PersistentStore' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import SelectAction, { Action } from '../SelectAction/SelectAction' import './CTypePresentation.scss' type Props = RouteComponentProps<{}> & { - cTypeHash: ICType['cType']['hash'] + cTypeHash: ICTypeWithMetadata['cType']['hash'] inline?: true size?: number @@ -30,7 +30,7 @@ type Props = RouteComponentProps<{}> & { } type State = { - cType?: ICType + cType?: ICTypeWithMetadata } const DEFAULT_SIZE = 24 @@ -91,7 +91,7 @@ class CTypePresentation extends React.Component { size={size || DEFAULT_SIZE} theme="polkadot" /> - {this.getLabel(cType.cType.metadata.title.default)} + {this.getLabel(cType.metaData.metadata.title.default)} )} {!!actions.length && ( @@ -121,7 +121,7 @@ class CTypePresentation extends React.Component { private async setCType() { const { cTypeHash } = this.props - CTypeRepository.findByHash(cTypeHash).then((_cType: ICType) => { + CTypeRepository.findByHash(cTypeHash).then((_cType: ICTypeWithMetadata) => { this.setState({ cType: _cType }) }) } @@ -188,7 +188,7 @@ class CTypePresentation extends React.Component { UiState.Store.updateCurrentTaskAction({ objective: sdk.MessageBodyType.SUBMIT_LEGITIMATIONS, props: { - claim: { cTypeHash: cTypeHash }, + claim: { cTypeHash }, } as SubmitLegitimationsProps, }) ) diff --git a/src/components/CtypeDetailView/CtypeDetailView.tsx b/src/components/CtypeDetailView/CtypeDetailView.tsx index d19db787..9a80736e 100644 --- a/src/components/CtypeDetailView/CtypeDetailView.tsx +++ b/src/components/CtypeDetailView/CtypeDetailView.tsx @@ -2,7 +2,7 @@ import * as React from 'react' import { Link } from 'react-router-dom' import CTypeRepository from '../../services/CtypeRepository' -import { ICType } from '../../types/Ctype' +import { ICType, ICTypeWithMetadata } from '../../types/Ctype' import Code from '../Code/Code' import ContactPresentation from '../ContactPresentation/ContactPresentation' import CTypePresentation from '../CTypePresentation/CTypePresentation' @@ -14,7 +14,7 @@ type Props = { } type State = { - cType?: ICType + cType?: ICTypeWithMetadata } class CtypeDetailView extends React.Component { @@ -25,7 +25,7 @@ class CtypeDetailView extends React.Component { public componentDidMount() { const { cTypeHash } = this.props - CTypeRepository.findByHash(cTypeHash).then((_cType: ICType) => { + CTypeRepository.findByHash(cTypeHash).then((_cType: ICTypeWithMetadata) => { this.setState({ cType: _cType }) }) } @@ -41,13 +41,13 @@ class CtypeDetailView extends React.Component {
-
{cType.cType.metadata.title.default}
+
{cType.metaData.metadata.title.default}
@@ -58,6 +58,12 @@ class CtypeDetailView extends React.Component { {cType.cType}
+
+ +
+ {cType.metaData.metadata} +
+
diff --git a/src/components/CtypeListView/CtypeListView.tsx b/src/components/CtypeListView/CtypeListView.tsx index c21ca534..24f01732 100644 --- a/src/components/CtypeListView/CtypeListView.tsx +++ b/src/components/CtypeListView/CtypeListView.tsx @@ -5,16 +5,16 @@ import { Link, RouteComponentProps, withRouter } from 'react-router-dom' import CTypeRepository from '../../services/CtypeRepository' import * as CTypes from '../../state/ducks/CTypes' import { State as ReduxState } from '../../state/PersistentStore' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import ContactPresentation from '../ContactPresentation/ContactPresentation' import CTypePresentation from '../CTypePresentation/CTypePresentation' import './CtypeListView.scss' type Props = RouteComponentProps<{}> & { - onRequestLegitimation: (cType: ICType) => void + onRequestLegitimation: (cType: ICTypeWithMetadata) => void // mapStateToProps - cTypes?: ICType[] + cTypes?: ICTypeWithMetadata[] } type State = { @@ -64,7 +64,7 @@ class CtypeListView extends React.Component { right={true} /> @@ -78,7 +78,7 @@ class CtypeListView extends React.Component { diff --git a/src/components/DevTools/DevTools.attestations.tsx b/src/components/DevTools/DevTools.attestations.tsx index c62737d0..81099714 100644 --- a/src/components/DevTools/DevTools.attestations.tsx +++ b/src/components/DevTools/DevTools.attestations.tsx @@ -8,13 +8,14 @@ import * as Attestations from '../../state/ducks/Attestations' import { MyDelegation } from '../../state/ducks/Delegations' import PersistentStore from '../../state/PersistentStore' import { MyIdentity } from '../../types/Contact' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import { BsClaim, BsClaimsPool, BsClaimsPoolElement } from './DevTools.claims' import { BsCType } from './DevTools.ctypes' import { BsDelegation, BsDelegationsPool } from './DevTools.delegations' import { BsIdentitiesPool, BsIdentity } from './DevTools.wallet' import attestationsPool from './data/attestations.json' +import { IPartialClaim } from '@kiltprotocol/sdk-js' type UpdateCallback = (bsAttestationKey: keyof BsAttestationsPool) => void @@ -240,9 +241,9 @@ class BsAttestation { const { attesterKey } = attest const attesterIdentity: MyIdentity = await BsIdentity.getByKey(attesterKey) - const cType: ICType = await BsCType.getByKey(bsClaim.cTypeKey) + const cType: ICTypeWithMetadata = await BsCType.getByKey(bsClaim.cTypeKey) - const partialClaim = { + const partialClaim: IPartialClaim = { cTypeHash: cType.cType.hash as string, contents: bsClaim.data, owner: claimerIdentity.identity.address, diff --git a/src/components/DevTools/DevTools.ctypes.tsx b/src/components/DevTools/DevTools.ctypes.tsx index 2a7890d7..a2d08e53 100644 --- a/src/components/DevTools/DevTools.ctypes.tsx +++ b/src/components/DevTools/DevTools.ctypes.tsx @@ -3,8 +3,8 @@ import * as sdk from '@kiltprotocol/sdk-js' import BlockchainService from '../../services/BlockchainService' import CTypeRepository from '../../services/CtypeRepository' import errorService from '../../services/ErrorService' -import { notifySuccess } from '../../services/FeedbackService' -import { ICType } from '../../types/Ctype' +import { notifySuccess, notifyError } from '../../services/FeedbackService' +import { ICTypeWithMetadata } from '../../types/Ctype' import { BsIdentity } from './DevTools.wallet' import cTypesPool from './data/cTypes.json' @@ -13,6 +13,7 @@ type UpdateCallback = (bsCTypeKey: keyof BsCTypesPool) => void interface BsCTypesPoolElement extends sdk.ICType { owner: string + metadata: sdk.ICTypeMetadata['metadata'] } type BsCTypesPool = { @@ -28,17 +29,19 @@ class BsCType { .identity const cType = sdk.CType.fromCType({ - ...bsCTypeData, + schema: bsCTypeData.schema, + hash: bsCTypeData.hash, owner: ownerIdentity.address, }) return cType .store(ownerIdentity) .then((value: any) => { - const cTypeWrapper: ICType = { + const cTypeWrapper: ICTypeWithMetadata = { cType, metaData: { - author: ownerIdentity.address, + metadata: bsCTypeData.metadata, + ctypeHash: cType.hash, }, } // TODO: add onrejected when sdk provides error handling @@ -46,14 +49,14 @@ class BsCType { }) .then(() => { notifySuccess( - `CTYPE ${cType.metadata.title.default} successfully created.` + `CTYPE ${bsCTypeData.metadata.title.default} successfully created.` ) }) .catch(error => { errorService.log({ error, message: 'Could not submit CTYPE', - origin: 'CTypeCreate.submit()', + origin: 'DevTools.ctypes.tsx.BsCType.save()', }) }) } @@ -71,7 +74,9 @@ class BsCType { return requests } - public static async getByHash(hash: sdk.ICType['hash']): Promise { + public static async getByHash( + hash: sdk.ICType['hash'] + ): Promise { const cType = await CTypeRepository.findByHash(hash) if (cType) { return cType @@ -79,13 +84,15 @@ class BsCType { throw new Error(`Could not find cType with hash '${hash}'`) } - public static async get(bsCType: BsCTypesPoolElement): Promise { + public static async get( + bsCType: BsCTypesPoolElement + ): Promise { return BsCType.getByHash(bsCType.hash) } public static async getByKey( bsCTypeKey: keyof BsCTypesPool - ): Promise { + ): Promise { const { hash } = BsCType.pool[bsCTypeKey] return BsCType.getByHash(hash) } diff --git a/src/components/DevTools/DevTools.delegations.tsx b/src/components/DevTools/DevTools.delegations.tsx index 64ec5fdd..86930d19 100644 --- a/src/components/DevTools/DevTools.delegations.tsx +++ b/src/components/DevTools/DevTools.delegations.tsx @@ -7,7 +7,7 @@ import * as Delegations from '../../state/ducks/Delegations' import { DelegationType, MyDelegation } from '../../state/ducks/Delegations' import PersistentStore from '../../state/PersistentStore' import { MyIdentity } from '../../types/Contact' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import { BsCType, BsCTypesPool } from './DevTools.ctypes' import { BsIdentitiesPool, BsIdentity } from './DevTools.wallet' @@ -172,7 +172,7 @@ class BsDelegation { } const ownerIdentity: MyIdentity = await BsIdentity.getByKey(ownerKey) await BsIdentity.selectIdentity(ownerIdentity) - const cType: ICType = await BsCType.getByKey(cTypeKey) + const cType: ICTypeWithMetadata = await BsCType.getByKey(cTypeKey) if (updateCallback) { updateCallback(bsDelegationKey) diff --git a/src/components/Modal/SelectCTypesModal.tsx b/src/components/Modal/SelectCTypesModal.tsx index e77870c1..d3843d75 100644 --- a/src/components/Modal/SelectCTypesModal.tsx +++ b/src/components/Modal/SelectCTypesModal.tsx @@ -4,7 +4,7 @@ import Select from 'react-select' import CTypeRepository from '../../services/CtypeRepository' import ErrorService from '../../services/ErrorService' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import SelectCTypes from '../SelectCTypes/SelectCTypes' import Modal, { ModalType } from './Modal' @@ -17,13 +17,13 @@ type Props = { showOnInit?: boolean onCancel?: () => void - onConfirm: (selectedCTypes: ICType[]) => void + onConfirm: (selectedCTypes: ICTypeWithMetadata[]) => void } type State = { - cTypes?: ICType[] + cTypes?: ICTypeWithMetadata[] isSelectCTypesOpen: boolean - selectedCTypes: ICType[] + selectedCTypes: ICTypeWithMetadata[] } class SelectCTypesModal extends React.Component { @@ -85,7 +85,7 @@ class SelectCTypesModal extends React.Component { >
{ } } - private onSelectCTypes(selectedCTypes: ICType[]) { + private onSelectCTypes(selectedCTypes: ICTypeWithMetadata[]) { this.setState({ selectedCTypes }) } diff --git a/src/components/MyClaimCreateView/MyClaimCreateView.tsx b/src/components/MyClaimCreateView/MyClaimCreateView.tsx index bb5e07d2..2cd8cd36 100644 --- a/src/components/MyClaimCreateView/MyClaimCreateView.tsx +++ b/src/components/MyClaimCreateView/MyClaimCreateView.tsx @@ -11,7 +11,7 @@ import FeedbackService, { notifySuccess } from '../../services/FeedbackService' import * as Claims from '../../state/ducks/Claims' import * as Wallet from '../../state/ducks/Wallet' import { State as ReduxState } from '../../state/PersistentStore' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import { BlockUi } from '../../types/UserFeedback' import { getClaimInputModel } from '../../utils/CtypeUtils' @@ -30,7 +30,7 @@ type State = { partialClaim: sdk.IPartialClaim name: string isValid: boolean - cType?: sdk.CType + cType?: ICTypeWithMetadata } class MyClaimCreateView extends Component { @@ -57,9 +57,8 @@ class MyClaimCreateView extends Component { }) CTypeRepository.findByHash(cTypeHash) - .then((dbCtype: ICType) => { - const cType = sdk.CType.fromCType(dbCtype.cType) - this.setState({ cType }) + .then((dbCtype: ICTypeWithMetadata) => { + this.setState({ cType: dbCtype }) blockUi.remove() }) .catch(error => { @@ -87,7 +86,10 @@ class MyClaimCreateView extends Component {
- +
@@ -150,7 +152,7 @@ class MyClaimCreateView extends Component { if (cType && selectedIdentity) { const newClaim: sdk.IClaim = sdk.Claim.fromCTypeAndClaimContents( - cType, + sdk.CType.fromCType(cType.cType), contents || {}, selectedIdentity.identity.address ) diff --git a/src/components/MyClaimListView/MyClaimListView.tsx b/src/components/MyClaimListView/MyClaimListView.tsx index cd24cdef..9208692f 100644 --- a/src/components/MyClaimListView/MyClaimListView.tsx +++ b/src/components/MyClaimListView/MyClaimListView.tsx @@ -3,7 +3,7 @@ import * as React from 'react' import { Link } from 'react-router-dom' import * as Claims from '../../state/ducks/Claims' -import { ICType } from '../../types/Ctype' +import { ICTypeWithMetadata } from '../../types/Ctype' import CTypePresentation from '../CTypePresentation/CTypePresentation' import SelectCTypesModal from '../Modal/SelectCTypesModal' import SelectAction from '../SelectAction/SelectAction' @@ -13,7 +13,7 @@ import './MyClaimListView.scss' type Props = { claimStore: Claims.Entry[] - onCreateClaimFromCType: (selectedCTypes: ICType[]) => void + onCreateClaimFromCType: (selectedCTypes: ICTypeWithMetadata[]) => void onRemoveClaim: (claimEntry: Claims.Entry) => void onRequestAttestation: (claimEntry: Claims.Entry) => void onRequestLegitimation: (claimEntry: Claims.Entry) => void @@ -134,7 +134,7 @@ class MyClaimListView extends React.Component { } } - private createClaimFromCType(selectedCTypes: ICType[]) { + private createClaimFromCType(selectedCTypes: ICTypeWithMetadata[]) { const { onCreateClaimFromCType } = this.props onCreateClaimFromCType(selectedCTypes) } diff --git a/src/components/SelectAttestedClaim/SelectAttestedClaim.tsx b/src/components/SelectAttestedClaim/SelectAttestedClaim.tsx index 236e509b..501ab3d1 100644 --- a/src/components/SelectAttestedClaim/SelectAttestedClaim.tsx +++ b/src/components/SelectAttestedClaim/SelectAttestedClaim.tsx @@ -8,12 +8,13 @@ import isEqual from 'lodash/isEqual' import CTypeRepository from '../../services/CtypeRepository' import * as Claims from '../../state/ducks/Claims' import { State as ReduxState } from '../../state/PersistentStore' -import { CType, ICType } from '../../types/Ctype' +import { ICType, ICTypeWithMetadata } from '../../types/Ctype' import AttestationStatus from '../AttestationStatus/AttestationStatus' import ContactPresentation from '../ContactPresentation/ContactPresentation' import { SelectAttestedClaimsLabels } from '../SelectAttestedClaims/SelectAttestedClaims' import './SelectAttestedClaim.scss' +import { getCtypePropertyTitle } from '../../utils/CtypeUtils' type Props = { claimEntry: Claims.Entry @@ -25,7 +26,7 @@ type Props = { export type State = { allAttestedClaimsSelected?: boolean allClaimPropertiesSelected?: boolean - cType?: CType + cType?: ICType isSelected: boolean selectedAttestedClaims: sdk.IAttestedClaim[] selectedClaimProperties: string[] @@ -47,9 +48,16 @@ class SelectAttestedClaim extends React.Component { public componentDidMount() { const { cTypeHash } = this.props if (cTypeHash) { - CTypeRepository.findByHash(cTypeHash).then((cType: ICType) => { - this.setState({ cType: CType.fromObject(cType) }) - }) + CTypeRepository.findByHash(cTypeHash).then( + (cType: ICTypeWithMetadata) => { + const cTypeReference: ICType = { + cType: cType.cType, + metadata: cType.metaData.metadata, + ctypeHash: cType.cType.hash, + } + this.setState({ cType: cTypeReference }) + } + ) } } @@ -126,7 +134,9 @@ class SelectAttestedClaim extends React.Component { {propertyNames.map((propertyName: string) => { - const propertyTitle = this.getCtypePropertyTitle(propertyName) + const propertyTitle = this.state.cType + ? getCtypePropertyTitle(propertyName, this.state.cType) + : propertyName return (